busybox下载地址:https://busybox.net/downloads/
这里我下载的是busybox1.26.0版本
解压:
tar xjf busybox-1.26.0.tar.bz2
cd busybox-1.26.0/
vi Makefile
找到
ARCH?=$(SUBARCH)和CROSS_COMPILE?=
修改为:
ARCH?=arm和CROSS_COMPILE?=arm-linux-
make menuconfig
这里我们选择默认即可,退出保存
make编译
发现报错:
miscutils/nandwrite.c: In function 'nandwrite_main':
miscutils/nandwrite.c:151: error: 'MTD_FILE_MODE_RAW' undeclared (first use in this function)
miscutils/nandwrite.c:151: error: (Each undeclared identifier is reported only once
miscutils/nandwrite.c:151: error: for each function it appears in.)
scripts/Makefile.build:197: recipe for target 'miscutils/nandwrite.o' failed
make[1]: *** [miscutils/nandwrite.o] Error 1
Makefile:742: recipe for target 'miscutils' failed
make: *** [miscutils] Error 2
我们发现MTD_FILE_MODE_RAW
是在ubuntu下/usr/include/mtd/mtd-abi.h里定义
那直接把这个文件复制到我们busybox的include下:
sudo cp /usr/include/mtd/mtd-abi.h /work/system/busybox-1.26.0/include/
在miscutils/nandwrite.c里的
#include
上面写上:
#include "mtd-abi.h"
make继续编译
报错:
util-linux/blkdiscard.c: In function 'blkdiscard_main':util-linux/blkdiscard.c:72: error: 'BLKSECDISCARD' undeclared (first use in this function)util-linux/blkdiscard.c:72: error: (Each undeclared identifier is reported only onceutil-linux/blkdiscard.c:72: error: for each function it appears in.)make[1]: [util-linux/blkdiscard.o] Error 1make: [util-linux] Error 2
表示在编译blkdiscard.c时报错,那我们干脆不编译你:
make menuconfig
取消选中Linux System Utilities->blkdiscard
make编译
还是报错:
debianutils/lib.a(mktemp.o): In function `mktemp_main':
mktemp.c:(.text.mktemp_main+0x98): warning: the use of `mktemp' is dangerous, better use `mkstemp'
util-linux/lib.a(nsenter.o): In function `nsenter_main':
nsenter.c:(.text.nsenter_main+0x1b0): undefined reference to `setns'
coreutils/lib.a(sync.o): In function `sync_main':
sync.c:(.text.sync_main+0x7c): undefined reference to `syncfs'
collect2: ld returned 1 exit status
Note: if build needs additional libraries, put them in CONFIG_EXTRA_LDLIBS.
Example: CONFIG_EXTRA_LDLIBS="pthread dl tirpc audit pam"
Makefile:717: recipe for target 'busybox_unstripped' failed
make: *** [busybox_unstripped] Error 1
同理,我们也把你去掉
make menuconfig
取消选中Linux System Utilities->nsenter
取消选中Coreutils->sync
make
终于编译成功!
附:
如果你的busybox版本比较低,可能就是另外的错误了:
Error:
Makefile:405: *** mixed implicit and normal rules: deprecated syntax
Makefile:1242: *** mixed implicit and normal rules: deprecated syntax
报错的意思就是系统的make工具太新了,make的新规则不兼容旧版
在顶层makefile里,405行config %config: scripts_basic outputmakefile FORCE改为%config: scripts_basic outputmakefile FORCE
1242行/ %/: prepare scripts FORCE改为%/: prepare scripts FORCE
Error:
error: field ‘in’ has incompletetype
error: field ‘in6′ has incomplete type
find -name "netfilter.h"找到这个文件
比如我的在 /usr/local/arm/opt/FriendlyARM/toolschain/4.4.3/arm-none-linux-gnueabi/sys-root/usr/include/linux/netfilter.h
在这个文件添加缺少的头文件:
#include
强制修改保存(:wq!)
编译成功后
make install CONFIG_PREFIX=/work/nfs/root/
把busybox安装到/work/nfs/root/目录下
a).制作lib文件夹:
cd /work/nfs/root/
mkdir lib
cd usr/
mkdir lib
echo $PATH
可以看出我们的gcc工具链的路径
cd /usr/local/arm/opt/FriendlyARM/toolschain/4.4.3
find -name lib
发现lib库:
./lib
./arm-none-linux-gnueabi/debug-root/usr/lib
./arm-none-linux-gnueabi/sys-root/usr/lib
./arm-none-linux-gnueabi/sys-root/lib
./arm-none-linux-gnueabi/lib
sudo cp arm-none-linux-gnueabi/sys-root/lib/*so* /work/nfs/root/lib -d
sudo cp arm-none-linux-gnueabi/sys-root/usr/lib/*so* /work/nfs/root/usr/lib -d
b).制作etc文件夹:
cd /work/nfs/root/
mkdir etc
cd etc/
vi inittab
在inittab里写上:
::sysinit:/etc/init.d/rcS
console::respawn:-/bin/sh
::ctrlaltdel:/sbin/reboot
::shutdown:/bin/umount -a -r
vi fstab
在fstab里写上:
# device mount-point type options dump fsck order
proc /proc proc defaults 0 0
sysfs /sys sysfs defaults 0 0
tmpfs /dev tmpfs defaults 0 0
mkdir init.d
cd init.d
vi rcS
在rcS里写上:
#mount -t proc none /proc
mount -a
mkdir /dev/pts
mount -t devpts devpts /dev/pts
echo /sbin/mdev > /proc/sys/kernel/hotplug
mdev -s
c).制作dev文件夹:
cd /work/nfs/root/
mkdir dev
ls -l /dev/console /dev/null
仿照这两个创建设备:
sudo mknod dev/console c 5 1
sudo mknod dev/null c 1 3
d).制作其他文件夹:
cd /work/nfs/root/
mkdir proc tmp mnt sys root