使用busybox构建根文件系统以及过程中遇到的问题

本文详细记录了在构建基于Busybox的Linux根文件系统过程中遇到的问题及解决方案,包括修改Makefile配置、处理类型冲突错误、解决头文件缺失问题、创建必要目录、安装glibc库等步骤,最后成功制作yaffs2镜像文件并进行验证。
摘要由CSDN通过智能技术生成

目录

1 下载busybox

2 修改Makefile

3 配置busybox

4 编译安装

4.1 /usr/include/unistd.h:203: error: conflicting types for 'gid_t'

4.2 miscutils/seedrng.c:45:24: fatal error: sys/random.h: No such file or directory

4.3 Makefile:405: *** mixed implicit and normal rules: deprecated syntax

4.4 linux/netfilter.h:44: error: field 'in' has incomplete type

5  创建必要的文件夹

6 安装glibc库

7 构建etc目录

7.1 创建etc/inittab文件

7.2 创建etc/init.d/rcS文件

7.3 创建etc/fstab文件

8 构建dev目录

9 制作yaff2镜像

10 文件系统验证


1 下载busybox

去网址:https://busybox.net/downloads/

下载busybox源码,这里下载的1.36版本,然后解压

tar xvf busybox-1.36.0.tar.bz2
cd busybox-1.36.0/

2 修改Makefile

164行 CROSS_COMPILE ?=  改为:CROSS_COMPILE ?= arm-linux-

190行 ARCH ?= $(SUBARCH) 改为:ARCH ?= arm

3 配置busybox

make defconfig
make menuconfig

4 编译安装

make -j8
make CONFIG_PREFIX=../fs install

4.1 /usr/include/unistd.h:203: error: conflicting types for 'gid_t'

然后编译报下面的错误 

  CC      libbb/capability.o
In file included from include/platform.h:333,
                 from include/libbb.h:13,
                 from libbb/capability.c:18:
/usr/local/arm/4.3.2/bin/../arm-none-linux-gnueabi/libc/usr/include/unistd.h:203: error: conflicting types for 'gid_t'
/usr/local/arm/4.3.2/bin/../arm-none-linux-gnueabi/libc/usr/include/linux/types.h:27: error: previous declaration of 'gid_t' was here
/usr/local/arm/4.3.2/bin/../arm-none-linux-gnueabi/libc/usr/include/unistd.h:208: error: conflicting types for 'uid_t'
/usr/local/arm/4.3.2/bin/../arm-none-linux-gnueabi/libc/usr/include/linux/types.h:26: error: previous declaration of 'uid_t' was here
/usr/local/arm/4.3.2/bin/../arm-none-linux-gnueabi/libc/usr/include/unistd.h:216: error: conflicting types for 'off_t'
/usr/local/arm/4.3.2/bin/../arm-none-linux-gnueabi/libc/usr/include/linux/types.h:17: error: previous declaration of 'off_t' was here
In file included from include/libbb.h:16,
                 from libbb/capability.c:18:
/usr/local/arm/4.3.2/bin/../arm-none-linux-gnueabi/libc/usr/include/dirent.h:37: error: conflicting types for 'ino_t'
/usr/local/arm/4.3.2/bin/../arm-none-linux-gnueabi/libc/usr/include/linux/types.h:14: error: previous declaration of 'ino_t' was here
In file included from /usr/local/arm/4.3.2/bin/../arm-none-linux-gnueabi/libc/usr/include/bits/fcntl.h:25,
                 from /usr/local/arm/4.3.2/bin/../arm-none-linux-gnueabi/libc/usr/include/fcntl.h:34,
                 from include/libbb.h:18,
                 from libbb/capability.c:18:
/usr/local/arm/4.3.2/bin/../arm-none-linux-gnueabi/libc/usr/include/sys/types.h:62: error: conflicting types for 'dev_t'
/usr/local/arm/4.3.2/bin/../arm-none-linux-gnueabi/libc/usr/include/linux/types.h:13: error: previous declaration of 'dev_t' was here
/usr/local/arm/4.3.2/bin/../arm-none-linux-gnueabi/libc/usr/include/sys/types.h:72: error: conflicting types for 'mode_t'
/usr/local/arm/4.3.2/bin/../arm-none-linux-gnueabi/libc/usr/include/linux/types.h:15: error: previous declaration of 'mode_t' was here
/usr/local/arm/4.3.2/bin/../arm-none-linux-gnueabi/libc/usr/include/sys/types.h:77: error: conflicting types for 'nlink_t'
/usr/local/arm/4.3.2/bin/../arm-none-linux-gnueabi/libc/usr/include/linux/types.h:16: error: previous declaration of 'nlink_t' was here
In file included from /usr/local/arm/4.3.2/bin/../arm-none-linux-gnueabi/libc/usr/include/sys/types.h:133,
                 from /usr/local/arm/4.3.2/bin/../arm-none-linux-gnueabi/libc/usr/include/bits/fcntl.h:25,
                 from /usr/local/arm/4.3.2/bin/../arm-none-linux-gnueabi/libc/usr/include/fcntl.h:34,
                 from include/libbb.h:18,
                 from libbb/capability.c:18:
/usr/local/arm/4.3.2/bin/../arm-none-linux-gnueabi/libc/usr/include/time.h:105: error: conflicting types for 'timer_t'
/usr/local/arm/4.3.2/bin/../arm-none-linux-gnueabi/libc/usr/include/linux/types.h:22: error: previous declaration of 'timer_t' was here
In file included from /usr/local/arm/4.3.2/bin/../arm-none-linux-gnueabi/libc/usr/include/sys/types.h:220,
                 from /usr/local/arm/4.3.2/bin/../arm-none-linux-gnueabi/libc/usr/include/bits/fcntl.h:25,
                 from /usr/local/arm/4.3.2/bin/../arm-none-linux-gnueabi/libc/usr/include/fcntl.h:34,
                 from include/libbb.h:18,
                 from libbb/capability.c:18:
/usr/local/arm/4.3.2/bin/../arm-none-linux-gnueabi/libc/usr/include/sys/select.h:78: error: conflicting types for 'fd_set'
/usr/local/arm/4.3.2/bin/../arm-none-linux-gnueabi/libc/usr/include/linux/types.h:12: error: previous declaration of 'fd_set' was here
In file included from /usr/local/arm/4.3.2/bin/../arm-none-linux-gnueabi/libc/usr/include/bits/fcntl.h:25,
                 from /usr/local/arm/4.3.2/bin/../arm-none-linux-gnueabi/libc/usr/include/fcntl.h:34,
                 from include/libbb.h:18,
                 from libbb/capability.c:18:
/usr/local/arm/4.3.2/bin/../arm-none-linux-gnueabi/libc/usr/include/sys/types.h:248: error: conflicting types for 'blkcnt_t'
/usr/local/arm/4.3.2/bin/../arm-none-linux-gnueabi/libc/usr/include/linux/types.h:124: error: previous declaration of 'blkcnt_t' was here
scripts/Makefile.build:197: recipe for target 'libbb/capability.o' failed
make[1]: *** [libbb/capability.o] Error 1
Makefile:744: recipe for target 'libbb' failed
make: *** [libbb] Error 2

conflicting types for 'dev_t'的原因_小饼仙子的博客-CSDN博客

我看了下这篇博客,然后我这样修改

 没用还是有错误。继续搜,看到

3.5.3内核编译出错~求救【linux吧】_百度贴吧

那更换成4.9.4的交叉编译工具链吧

4.2 miscutils/seedrng.c:45:24: fatal error: sys/random.h: No such file or directory

换成4.9.4的交叉编译工具后,编译报下面的错误

miscutils/seedrng.c:45:24: fatal error: sys/random.h: No such file or directory
 #include <sys/random.h>
                        ^
compilation terminated.
scripts/Makefile.build:197: recipe for target 'miscutils/seedrng.o' failed
make[1]: *** [miscutils/seedrng.o] Error 1
Makefile:746: recipe for target 'miscutils' failed
make: *** [miscutils] Error 2

网上继续搜,看到

嵌入式开发六:busybox编译根文件系统的一些错误解决办法_busybox编译报错miscutils/seedrng.c:45:24: fatal error:_zhubenfulovepoem的博客-CSDN博客

上面说

进入make menuconfig:
在   Miscellaneous Utilities ---> 
[ ] taskset 
将其前的星号去掉即可。

但是我在   Miscellaneous Utilities中没找到tasknet,于是搜索了下,发现它在Linux System Utilities中。

 但是发现问题未解决,于是继续找,搜到了类似的

那应该还是交叉编译工具链的版本太低,我去看了下我交叉编译工具链里面的libc库,是2.19版本的。 

这时候我不再更换交叉编译工具链版本了,因为我用的开发板芯片太老,用新的交叉编译工具链可能还会有其他稀奇古怪的错误,所以这里我反向操作,不升级交叉编译工具链的版本而是降低busybox的版本,这里用busy1.7.0版本,并且交叉编译工具链用回4.3.2。

4.3 Makefile:405: *** mixed implicit and normal rules: deprecated syntax

编译报下面的错误

Makefile:405: *** mixed implicit and normal rules: deprecated syntax
Makefile:1242: *** mixed implicit and normal rules: deprecated syntax
make: *** No rule to make target 'defconfig'.  Stop.

解决方法在下面的博客 

编译busybox-1.7.0出现Makefile:405:*** mixed implicit and normal rules: deprecated syntax_骑着蜗牛写代码的博客-CSDN博客

4.4 linux/netfilter.h:44: error: field 'in' has incomplete type

继续编译又报下面的错误

linux/netfilter.h:44: error: field 'in' has incomplete type

解决方法

在 .../arm-none-linux-gnueabi/libc/usr/include/linux/netfilter.h 的开头
添加缺少的头文件:
#include <netinet/in.h>

然后编译不再报错,然后安装安装

make CONFIG_PREFIX=../fs/ install

可以在fs下面看到生成的文件和目录

 5  创建必要的文件夹

 到fs目录下,执行下面的命令

mkdir dev etc lib mnt proc sys tmp var

6 安装glibc库

这里直接把交叉编译工具链路径下的库拷贝到上面创建的lib文件夹中。

在交叉编译工具链的位置里面用下面的命令搜索

由于ARM9属于ARMv4T架构,所以拷贝上面第三个第四个lib到fs文件夹里面

mkdir lib
mkdir usr/lib
cp -drf /usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/armv4t/lib/*.so* ./lib/
cp -drf /usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/armv4t/usr/lib/*.so* ./usr/lib/

 上面拷贝的时候要注意,后面是*.so*,有两个星号,不是*.so。

7 构建etc目录

etc目录下的内容取决于要运行的程序,本节只需要创建3个文件:etc/inittab, etc/init.d/rcS, etc/fstab。

7.1 创建etc/inittab文件

我们在etc目录下创建inittab文件,文件内容如下

7.2 创建etc/init.d/rcS文件

这是一个脚本文件,可以在里面添加想自动执行的命令,以下命令配置IP地址、挂接/etc/fstab指定的文件系统。

  • 第一行表示这是一个脚本文件,运行时使用/bin/sh解析。
  • 第二行用来配置IP地址。
  • 第三行挂接/etc/fstab文件指定的所有文件系统。

创建完成后改变它的属性,

chmod +x rcS

7.3 创建etc/fstab文件

内容如下,表示执行mount -a命令后将挂载proc、tmpfs文件系统。

 8 构建dev目录

cd dev
sudo mknod console c 5 1
sudo mknod null c 1 3
sudo mknod ttySAC0 c 204 64
sudo mknod mtdblock0 b 31 0
sudo mknod mtdblock1 b 31 1
sudo mknod mtdblock2 b 31 2

执行完之后

9 制作yaff2镜像

这里不自己编译makeyaffe工具了,直接用韦老师的工具mkyaffs2image。

./mkyaffs2image fs/ fs_chw.yaffs

10 文件系统验证

把制作完成的文件系统下载到开发板中,发现报下面的错误

 可能是rcS脚本写错了,去看一下

 但是我看上面的笔记,当初是有i的,不知怎么成了fconfig了,

改完重新制作镜像文件,然后下载到板子上,这时候可以看到文件系统了。

参考文献

使用 busyBox 构建 linux 根文件系统_busybox制作linux_砌墙师傅的博客-CSDN博客

【ARM】使用Busybox构建根文件系统_busybox 制作根文件系统_凉开水白菜的博客-CSDN博客

Part6: 构建根文件系统(在s3c2440开发板演示)_韦东山 s3c2440 文件系统_ZMK_02的博客-CSDN博客

S3C2440 制作最新busybox文件系统

conflicting types for 'dev_t'的原因_小饼仙子的博客-CSDN博客

嵌入式开发六:busybox编译根文件系统的一些错误解决办法_busybox编译报错miscutils/seedrng.c:45:24: fatal error:_zhubenfulovepoem的博客-CSDN博客

https://www.cnblogs.com/electronic/p/11146614.html

S3C2440移植linux3.4.2内核之修改分区以及制作根文件系统_busybox构建s3c2440根文件系统_嵌入式与Linux那些事的博客-CSDN博客

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

陈 洪 伟

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值