韦东山笔记之用busybox构建根文件系统

1 百度搜索busybox进入busybox官网(https://busybox.net/)作者:恒久力行 QQ:624668529

 点击左侧DownloadSource下载最新稳定版的busybox-1.24.2.tar.bz2
 2 将其复制到服务器并解压缩
  1. tar xjf busybox-1.24.2.tar.bz2
3进入根目录,在其根目录下有一个INSTALL文件告诉我们怎么使用busybox
   
  1. make menuconfig
什么都不设置,但要保存设置。然后执行下列指令更改CROSS_COMPILE ?=arm-linux-
  1. vi Makefile
  1. CROSS_COMPILE ?=arm-linux-
然后执行make
  1. make
然后出现一大堆错误
错误1 
miscutils/i2c_tools.c: At top level:
miscutils/i2c_tools.c:1046: error: `I2C_FUNC_SMBUS_PEC‘ undeclared here (not in a function)
miscutils/i2c_tools.c:1046: error: initializer element is not constant
miscutils/i2c_tools.c:1046: error: (near initialization for `i2c_funcs_tab[12].value‘)
miscutils/i2c_tools.c:1047: error: initializer element is not constant
miscutils/i2c_tools.c:1047: error: (near initialization for `i2c_funcs_tab[12]‘)
miscutils/i2c_tools.c:1049: error: initializer element is not constant
miscutils/i2c_tools.c:1049: error: (near initialization for `i2c_funcs_tab[13]‘)
miscutils/i2c_tools.c:1051: error: initializer element is not constant
miscutils/i2c_tools.c:1051: error: (near initialization for `i2c_funcs_tab[14]‘)
miscutils/i2c_tools.c:1052: error: initializer element is not constant
miscutils/i2c_tools.c:1052: error: (near initialization for `i2c_funcs_tab[15]‘)
make[1]: *** [miscutils/i2c_tools.o] Error 1
make: *** [miscutils] Error 2
错误1 解决方法
别急没事咱们一点一点的解决,首先进入make menuconfig,去掉 i2c 相关模块
 
再次make
错误2
 miscutils/ionice.c: In function `ioprio_set‘
miscutils/ionice.c:23: error: `SYS_ioprio_set‘ undeclared (first use in this function)
miscutils/ionice.c:23: error: (Each undeclared identifier is reported only once
miscutils/ionice.c:23: error: for each function it appears in.)
miscutils/ionice.c: In function `ioprio_get‘:
miscutils/ionice.c:28: error: `SYS_ioprio_get‘ undeclared (first use in this function)
make[1]: *** [miscutils/ionice.o] Error 1
make: *** [miscutils] Error 
错误2解决方法:
根据提示是ionice出问题了,进入make menuconfig 屏蔽它去掉 ionice 相关模块
 
再次make
错误3
miscutils/nandwrite.c:117: error: storage size of 'meminfo' isn't known
miscutils/nandwrite.c:118: error: storage size of 'oob' isn't known
miscutils/nandwrite.c:145: error: `MEMGETINFO' undeclared (first use in this function)
miscutils/nandwrite.c:252: error: `MEMREADOOB' undeclared (first use in this function)
miscutils/nandwrite.c:117: warning: unused variable `meminfo'
miscutils/nandwrite.c:118: warning: unused variable `oob'
scripts/Makefile.build:197: recipe for target 'miscutils/nandwrite.o' failed
make[1]: *** [miscutils/nandwrite.o] Error 1
Makefile:741: recipe for target 'miscutils' failed
make: *** [miscutils] Error 2
 
错误3解决方法:
make menuconfig 去掉 nandwrite,nanddump模块
 
再次make
错误4
miscutils/ubi_tools.c:106: error: `UBI_DEV_NUM_AUTO' undeclared (first use in this function)
miscutils/ubi_tools.c:106: error: (Each undeclared identifier is reported only once
miscutils/ubi_tools.c:106: error: for each function it appears in.)
miscutils/ubi_tools.c:107: error: `UBI_VOL_NUM_AUTO' undeclared (first use in this function)
miscutils/ubi_tools.c:115: error: field `attach_req' has incomplete type
miscutils/ubi_tools.c:116: error: field `mkvol_req' has incomplete type
miscutils/ubi_tools.c:117: error: field `rsvol_req' has incomplete type
miscutils/ubi_tools.c:181: error: `UBI_IOCATT' undeclared (first use in this function)
miscutils/ubi_tools.c:194: error: `UBI_IOCDET' undeclared (first use in this function)
miscutils/ubi_tools.c:237: error: `UBI_DYNAMIC_VOLUME' undeclared (first use in this function)
miscutils/ubi_tools.c:239: error: `UBI_STATIC_VOLUME' undeclared (first use in this function)
miscutils/ubi_tools.c:242: error: `UBI_MAX_VOLUME_NAME' undeclared (first use in this function)
miscutils/ubi_tools.c:247: error: `UBI_IOCMKVOL' undeclared (first use in this function)
miscutils/ubi_tools.c:260: error: `UBI_IOCRMVOL' undeclared (first use in this function)
miscutils/ubi_tools.c:278: error: `UBI_IOCRSVOL' undeclared (first use in this function)
miscutils/ubi_tools.c:294: error: `UBI_IOCVOLUP' undeclared (first use in this function)
scripts/Makefile.build:197: recipe for target 'miscutils/ubi_tools.o' failed
make[1]: *** [miscutils/ubi_tools.o] Error 1
Makefile:741: recipe for target 'miscutils' failed
make: *** [miscutils] Error 2
 
错误4解决办法:
make menuconfig 去掉 ubi 相关模块
 
再次make
错误5
util-linux/umount.c: In function `umount_main':
util-linux/umount.c:87: error: `MNT_DETACH' undeclared (first use in this function)
util-linux/umount.c:87: error: (Each undeclared identifier is reported only once
util-linux/umount.c:87: error: for each function it appears in.)
scripts/Makefile.build:197: recipe for target 'util-linux/umount.o' failed
make[1]: *** [util-linux/umount.o] Error 1
Makefile:741: recipe for target 'util-linux' failed
make: *** [util-linux] Error 2
 
错误5解决办法:
umount 这里不能去掉了,因为这个功能是需要的 打开源码看看
  1. vi util-linux/umount.c
  1. // MNT_FORCE and MNT_DETACH (from linux/fs.h) must match
  2. // OPT_FORCE and OPT_LAZY.
  3. {
  4. typedefchar bug[
  5. (OPT_FORCE != MNT_FORCE || OPT_LAZY != MNT_DETACH)?-1:1
  6. ];
改成
  1. // MNT_FORCE and MNT_DETACH (from linux/fs.h) must match
  2. // OPT_FORCE and OPT_LAZY.
  3. {
  4. typedefchar bug[
  5. (OPT_FORCE != MNT_FORCE || OPT_LAZY !=2)?-1:1
  6. ];
  7. }
这里MNT_DETAC直接改成2
 
再次make
错误6
debianutils/lib.a(mktemp.o)(.text.mktemp_main+0x9c): In function `mktemp_main':
: warning: the use of `mktemp' is dangerous, better use `mkstemp'
coreutils/lib.a(touch.o)(.text.touch_main+0x1ac): In function `touch_main':
: warning: warning: lutimes is not implemented and will always fail
/work/tools/gcc-3.4.5-glibc-2.3.6/lib/gcc/arm-linux/3.4.5/../../../../arm-linux/bin/ld: Warning: gc-sections option ignored
coreutils/lib.a(sync.o)(.text.sync_main+0x80): In function `sync_main':
: undefined reference to `syncfs'
collect2: ld returned 1 exit status
Makefile:716: recipe for target 'busybox_unstripped' failed
make: *** [busybox_unstripped] Error 1
 
错误6解决办法:

vi ./coreutils/sync.c
/*
* syncfs is documented to only fail with EBADF,
* which can‘t happen here. So, no error checks.
*/
86行 syncfs(fd);

18 行 //config: bool "Enable -d and -f flags (requres syncfs(2) in libc)"

找了一个 arm-libc 中并没有这个函数

下载了 busybox-1.23.0.tar.bz2 找到同名文件,发现这个内容明显要简单很多。用 1.23 的版本替换 1.24 的。
#include "libbb.h"

/* This is a NOFORK applet. Be very careful! */

int sync_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int sync_main(int argc UNUSED_PARAM, char **argv IF_NOT_DESKTOP(UNUSED_PARAM))
{
/* coreutils-6.9 compat */
bb_warn_ignoring_args(argv[1]);

sync();

return EXIT_SUCCESS;
}

 

再次编译就通过了

Your linker does not support --sort-section,alignment

Trying libraries: crypt m

 Library crypt is not needed, excluding it

 Library m is needed, can't exclude it (yet)

Final link with: m

  DOC     busybox.pod

  DOC     BusyBox.txt

  DOC     busybox.1

  DOC     BusyBox.html

 
既然编译过了,就安装上吧,执行下列指令安装。
  1. make CONFIG_PREFIX=/work/nfs_root/first_fs install
安装上后里面有下列文件
waobot@waobot:/work/nfs_root/first_fs$ ls
bin  linuxrc  sbin  usr
  
 
 
4最小根文件系统:
 ①/dev/console /dev/null
 ②init本身,即busybox
 ③/etc/inittab
 ④配置文件里指定的应用程序
 ⑤c库
 
①/dev/console /dev/null
waobot@waobot:/work/nfs_root/first_fs$ mkdir dev
waobot@waobot:/work/nfs_root/first_fs$ cd dev/
waobot@waobot:/work/nfs_root/first_fs/dev$ sudo mknod console c 5 1
[sudo] waobot 的密码: 
waobot@waobot:/work/nfs_root/first_fs/dev$ sudo mknod null c 1 3
 
做③/etc/inittab:
 
 
做⑤c库:
waobot@waobot:/work/nfs_root/first_fs$ mkdir lib
waobot@waobot:/work/nfs_root/first_fs$ cd /work/tools/gcc-3.4.5-glibc-2.3.6/arm-linux/lib
waobot@waobot:/work/tools/gcc-3.4.5-glibc-2.3.6/arm-linux/lib$ cp *.so* /work/nfs_root/first_fs/lib -d
waobot@waobot:/work/tools/gcc-3.4.5-glibc-2.3.6/arm-linux/lib$ cd /work/nfs_root/first_fs
waobot@waobot:/work/nfs_root/first_fs$ ls
bin  dev  etc  lib  linuxrc  sbin  usr
最小根文件系统已经做好了
 
5制作yaffs映像文件,完善最小根文件系统
制作工具
waobot@waobot:/work/nfs_root/first_fs$ cd /work/system/
waobot@waobot:/work/system$ tar xjf yaffs_source_util_larger_small_page_nand.tar.bz2
waobot@waobot:/work/system$ cd Development_util_ok/
waobot@waobot:/work/system/Development_util_ok$  cd yaffs2
waobot@waobot:/work/system/Development_util_ok/yaffs2$ cd utils/
waobot@waobot:/work/system/Development_util_ok/yaffs2/utils$ pwd
/work/system/Development_util_ok/yaffs2/utils
waobot@waobot:/work/system/Development_util_ok/yaffs2/utils$ make
waobot@waobot:/work/system/Development_util_ok/yaffs2/utils$ sudo cp mkyaffs2image /usr/local/bin/
waobot@waobot:/work/system/Development_util_ok/yaffs2/utils$ sudo chmod +x /usr/local/bin/mkyaffs2image
waobot@waobot:/work/system/Development_util_ok/yaffs2/utils$ cd /work/nfs_root/
waobot@waobot:/work/nfs_root$ mkyaffs2image first_fs first_fs.yaffs2
 
遇到一个问题,不能启动提示:kernel panic - not syncing: No init found.  Try passing init= option to kernel.
问题解决:主要原因是编译器的问题,我用的是高版本的编译器,但是库加载的是低版本的编译器。换成低版本的编译器后,改一下环境变量如下
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/work/tools/gcc-3.4.5-glibc-2.3.6/bin"
 
创建其他引导文件
①etc/inittab
②etc/init.d/rcS
③etc/fstab
 
①etc/inittab如果不想手工挂载,要加一个配置文件:
  1. book@book-desktop:/work/nfs_root/first_fs$ vi etc/inittab
  2. console::askfirst:-/bin/sh
  3. ::sysinit:/etc/init.d/rcS
  1. chmod +x etc/init.d/rcS
②etc/init.d/rcS增加mdev机制 创建proc路径和sys路径
  1. book@book-desktop:/work/nfs_root/first_fs$ vi etc/init.d/rcS
  2. #mount -t proc none /proc
  3. mount -a
  4. mkdir /dev/pts
  5. mount -t devpts devpts /dev/pts
  6. echo /sbin/mdev >/proc/sys/kernel/hotplug
  7. mdev -s
③etc/fstab 
  1. book@book-desktop:/work/nfs_root/first_fs$ vi etc/fstab
  2. #device mount-point type options dump fsck order
  3. proc /proc proc defaults 00
  4. sysfs /sys sysfs defaults 00
  5. tmpfs /dev tmpfs defaults 00
到这里最小根文件系统已经很完善了
 
6直接从NFS启动:

重启可以看到启动参数:
bootargs=noinitrd root=/dev/mtdblock3 rootfstype=jffs2 init=/linuxrc console=ttySAC0
修改启动参数:在linux-2.6.22.6\Documentation的nfsroot.txt里面有参数的说明
nfsroot=[<server-ip>:]<root-dir>[,<nfs-options>]
ip=<client-ip>:<server-ip>:<gw-ip>:<netmask>:<hostname>:<device>:<autoconf>

bootargs noinitrd root=/dev/nfs nfsroot=192.168.1.51:/work/nfs_root/first_fs ip=192.168.1.11:192.168.1.51:192.168.1.1:255.255.255.0::eth0:off init=/linuxrc console=ttySAC0

OpenJTAG> set bootargs noinitrd root=/dev/nfs nfsroot=192.168.1.51:/work/nfs_root/first_fs ip=192.168.1.11:192.168.1.51:192.168.1.1:255.255.255.0::eth0:off init=/linuxrc console=ttySAC0
OpenJTAG> save
OpenJTAG> boot
到这里网络文件系统已经搭建好了,这样你可以在服务器上面编辑代码,编译,然后在单板上面运行了。

 
 
 
 
作者:恒久力行 QQ:624668529
 





posted @ 2016-07-30 11:10  恒久力行  阅读(4916)  评论(0编辑  收藏  举报