使用 busybox 搭建I.MX6ULL开发板的根文件系统

目录

根文件系统构建

busybox 中文字符支持

最后还需要配置 busybox

向 rootfs添加库文件

使用 NFS 网络挂载


busybox源码百度网盘下载地址:

链接: https://pan.baidu.com/s/17MNKwJXphIWMGUBG9rvjag  密码: 0809
--来自百度网盘超级会员V2的分享

 

根文件系统构建

同 Uboot 和 Linux 移植一样,打开 busybox 的顶层 Makefile,添加 ARCH 和 CROSS_COMPILE
的值  makefile文件166行

CROSS_COMPILE ?= /home/hong/arm_gcc/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-

makefile文件190行
ARCH ?= arm

busybox 中文字符支持


打开文件 busybox-1.29.0/libbb/printable_string.c,找到函数 printable_string

第 31 和 32 行,当字符大于 0X7F 以后就跳出去了。
第 45 和 46 行,如果支持 UNICODE 码的话,当字符大于 0X7F 就直接输出‘?’

所以我们需要对这 4 行代码进行修改。修改后的函数
const char* FAST_FUNC printable_string(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.29.0/libbb/unicode.c

找到
static char* FAST_FUNC unicode_conv_to_printable2(uni_stat_t
*stats, const char *src, unsigned width, int flags)

第 1022 行,当字符大于 0X7F 以后,*d++就为‘?’
第 1030 和 1031 行,当字符大于 0X7F 以后,*d 也为‘?’
下面把其替换
/* *d++ = (c >= ' ' && c < 0x7f) ? c : '?'; */
*d++ = (c >= ' ' ) ? c : '?';

下面替换
/*    if (c < ' ' || c >= 0x7f)*/
    if(c < ' ')

最后还需要配置 busybox


来使能 unicode 码,配置 busybox 的时候在设置。
一般使用默认配置即可,因此使用如下命令先使用默认配置来配置一下 busybox:
make defconfig

busybox 也支持图形化配置,通过图形化配置我们可以进一步选择自己想要的功能,输入
如下命令打开图形化配置界面:
make menuconfig

配置路径如下:
Location:
-> Settings
-> Build static binary (no shared libs)

取消选中

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

继续配置如下路径配置项:
Location:
-> Settings
-> vi-style line editing commands

按y键选择这个选项

继续配置如下路径配置项:
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 的配置就到此结束了

译 busybox
配置好 busybox 以后就可以编译了,指定编译结果的存放目录,在nft或者tftp服务目录下创建rootfs目录

make
make install CONFIG_PREFIX=/home/hong/nfs_rootfs/rootfs  


编译完成以后会在 busybox 的所有工具和文件就会被安装到 rootfs 目录中

busybox 的工作就完成了,但是此时的根文件系统还不能使用,还需要一些其他的文件

向 rootfs添加库文件

向 rootfs 的“/lib”目录添加库文件

在 rootfs 中创建一个名为“lib”的文件夹,命令如下:
mkdir lib

简单粗暴的把所有的库文件都放到我们的根文件系统

/home/hong/arm_gcc/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/lib/

目录下有很多的*so*(*是通配符)和.a 文件,这些就是库文件,将此目录下所有的*so*和.a
文件都拷贝到 rootfs/lib 目录中

cp *so* *.a /home/hong/nfs_rootfs/rootfs/lib/ -d 

有个比较特殊的库文件:ld-linux-armhf.so.3因为其是一个“快捷方式”,因此大小只有 24B。但是,ld-linux-
armhf.so.3 不能作为符号链接,否则的话在根文件系统中执行程序无法执行!
将 rootfs/lib 中的 ld-linux-armhf.so.3 文件删除掉

然 后 重 新 进 入 到 /home/hong/arm_gcc/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/lib/目录中,重新拷贝 ld-linux-armhf.so.3,命令如下:

cp ld-linux-armhf.so.3  /home/hong/nfs_rootfs/rootfs/lib/

此时去rootfs/lib/下面查看 ld-linux-armhf.so.3 已经不是软连接了,而是实实在在的一个
库文件,而且文件大小为 724392B。

在 rootfs 的 usr 目录下创建一个名为 lib 的目录,将如下目录中的库文件拷贝到 rootfs/usr/lib
目录下:
/home/hong/arm_gcc/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/usr/lib/

将此目录下的 so 和.a 库文件都拷贝到 rootfs/usr/lib 目录中,命令如下:
cp *so* *.a /home/hong/nfs_rootfs/rootfs/usr/lib/ -d

cd  ~/nfs_rootfs/rootfs/
du ./lib ./usr/lib/ -sh
    57M    ./lib
    67M    ./usr/lib/

根文件系统的库文件就全部添加好了

创建其他文件夹
在根文件系统中创建其他文件夹,如 dev、proc、mnt、sys、tmp 和 root

测试 测试方法就是

使用 NFS 网络挂载
 

进入uboot 设置好网络 保证能ping通服务器 然后设置添加以下变量

setenv bootcmd 'tftp 80800000 zImage; tftp 83000000 imx_hjd_uboot_emmc.dtb; bootz 80800000 - 83000000'

下面的IP地址根据自己设置 或者去看我的uboot移植下面有设置步骤

setenv bootargs 'console=ttymxc0,115200 root=/dev/nfs nfsroot=192.168.1.66:/home/hong/nfs_rootfs/rootfs,proto=tcp rw ip=192.168.1.55:192.168.1.66:192.168.1.1:255.255.255.0::eth0:off'

saveen

boot

正常挂载

 

 

你可能感兴趣的:(嵌入式,linux,ubuntu)