Buildroot根文件系统之最小系统(三)

一、登录后显示路径

如果重新编译 buildroot 并解压以后,/etc/profile 文件又会被重新替换掉,我们又得修改/etc/profile。所以我们可以在/etc/profile.d 目录下创建一个自定义的.sh 脚本文件,然后在此脚本文件里面添加 PS1 初始化代码就行了,这样即使后面重新编译了 buildroot 也不用担心此.sh 脚本会被替换掉。
创建/etc/profile.d/myprofile.sh 添加如下内容:

#!/bin/sh

PS1='[\u@\h]:\w# '
export PS1

二、修改busybox源码支持中文字符

如果默认直接编译 busybox 的话,在使用 SecureCRT 的时候中文字符是显示不正常的,中文字符会显示为“?”,比如你的中文目录,中文文件都显示为“?”。即使内核支持中文但在 shell 下也依然无法正确显示。
打开文件 busybox-1.32.0/libbb/printable_string.c,找到函数 printable_string2,注释修改如下:

const char* FAST_FUNC printable_string2(uni_stat_t *stats, const
char *str)
{
	char *dst;
	const char *s;
	
	s = str;
	while (1) {
		unsigned char c = *s;
		if (c == '\0') {
			/* 99+% of inputs do not need conversion */
			if (stats) {
			stats->byte_count = (s - str);
			stats->unicode_count = (s - str);
			stats->unicode_width = (s - str);
		}
		return str;
	}
	if (c < ' ')
		break;
		/* 注释掉下面这个两行代码 */
		/* if (c >= 0x7f)
			break; */
		s++;
	}
	
#if ENABLE_UNICODE_SUPPORT
	dst = unicode_conv_to_printable(stats, str);
#else
{
	char *d = dst = xstrdup(str);
	while (1) {
		unsigned char c = *d;
		if (c == '\0')
			break;
		/* 修改下面代码 */
		/* if (c < ' ' || c >= 0x7f) */
		if( c < ' ')
			*d = '?';
		d++;
	}
	if (stats) {
		stats->byte_count = (d - dst);
		stats->unicode_count = (d - dst);
		stats->unicode_width = (d - dst);
	}
}
#endif
	return auto_string(dst);
 }

打开文件 busybox-1.32.0/libbb/unicode.c

1009 static char* FAST_FUNC unicode_conv_to_printable2(uni_stat_t 
*stats, const char *src, unsigned width, int flags)
{
1011 char *dst;
1012 unsigned dst_len;
1013 unsigned uni_count;
1014 unsigned uni_width;
1015
1016 if (unicode_status != UNICODE_ON) {
1017 	char *d;
1018 	if (flags & UNI_FLAG_PAD) {
1019 		d = dst = xmalloc(width + 1);
1020 		while ((int)--width >= 0) {
1021 			unsigned char c = *src;
1022 			if (c == '\0') {
1023 				do
1024					*d++ = ' ';
1025 				while ((int)--width >= 0);
1026				break;
1027 			}
1028 			/* 修改下面一行代码 */
1029 			/* *d++ = (c >= ' ' && c < 0x7f) ? c : '?'; */
1030 			*d++ = (c >= ' ') ? c : '?';
1031 			src++;
1032 		}
1033 		*d = '\0';
1034	 } else {
1035 		d = dst = xstrndup(src, width);
1036 		while (*d) {
1037 			unsigned char c = *d;
1038 			/* 修改下面一行代码 */
1039 			/* if (c < ' ' || c >= 0x7f) */
1040 			if(c < ' ')
1041 				*d = '?';
1042 			d++;
1043 		}
1044	 }
1045 	if (stats) {
1046 		stats->byte_count = (d - dst);
1047 		stats->unicode_count = (d - dst);
1048 		stats->unicode_width = (d - dst);
1049 	}
1050 	return dst;
1051 }
......

三、Buildroot下的busybox配置

sudo make busybox-menuconfig

配置路径如下:

Location: 
	 -> Settings 
		-> Build static binary (no shared libs)

选项“Build static binary (no shared libs)”用来决定是静态编译是动态编译,静态编译的话
就不需要库文件,但是编译出来的根文件系统会很大。动态编译的话要求根文件系统中有库文
件,但是编译出来的 busybox 会小很多。这里我们不能采用静态编译!因为采用静态编译的话
DNS 会出问题!无法进行域名解析。
在这里插入图片描述
配置路径:

Location: 
	-> Settings 
		-> vi-style line editing commands

在这里插入图片描述
配置路径:

Location: 
	-> Linux Module Utilities
		-> Simplified modutils

默认会选中“Simplified modutils”,这里我们要取消勾选!!
在这里插入图片描述
配置路径:

Location: 
	-> Linux System Utilities 
		 -> mdev (16 kb) //确保下面的全部选中,默认都是选中的

在这里插入图片描述
使能 busybox 的 unicode 编码以支持中文,配置路径如下:

Location: 
	-> Settings
		-> Support Unicode //选中
			-> Check $LC_ALL, $LC_CTYPE and $LANG environment variables //选中

在这里插入图片描述
我们使用图形化修改过 Busybox 的配置以后最好保存一下配置文件,以防“make clean”以后删除掉以前的配置,在配置主界面上,选中“Save Configuration to an Alternate File”。
在这里插入图片描述选中以后会让你输入配置文件名,Busybox 的默认配置文件都是保存到 configs 目录下,配置文件的名字后缀必须是“_defconfig”
在这里插入图片描述以后要想使用我们的自己的配置文件,直接输入:

make imx6ull_seeker_busybox_defconfig

四、Buildroot下的busybox重新编译

①找到/output/build/busybox-1.29.3 这个文件夹,此文件夹就是解压后的 busybox 源码然后进入这个目录。按自己的要求修改文件。
②删除这个目录下的.stamp_built和.stamp_target_installed.
除了以上两个文件,还有4个类似的,这六个分别为
.stamp_configured, 此文件表示已经配置过
.stamp_downloaded, 此文件表示源码已经下载过,没有此文件会重新下载
.stamp_patched, 此文件表示已经打过补丁
.stamp_extracted 此文件表示已经解压过
.stamp_built 此文件表示源码已经编译
.stamp_target_installed 此文件表示软件已经安装过
其实每个工具包里都有这样的几个文件,而根据我们的需要是要修改然后重新编译,安装即可。所以删除.stamp_built和.stamp_target_installed就可以啦。然后编译完了再进去看看。
这两个文件又产生啦,如果我们仅仅是修改了文件,而没有删除这两个文件是不会编译的。
③ 修改源码或修改配置(记得加sudo)
sudo make imx6ull_seeker_busybox_defconfig (保存的默认配置)
④ 退回到buildroot文件夹,重新编译该package
sudo make busybox
⑤ 编译完成以后重新编译 buildroot,主要是对其进行打包
sudo make

产品介绍
https://seeker.taobao.com/?spm=a1z10.1-c.0.0.292b68c7NJfyhD

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值