- 論壇徽章:
- 0
|
交叉編譯器: 3.3.2
# wget -c http://www.busybox.net/downloads/busybox-1.7.0.tar.bz2
# tar jxvf busybox-1.7.0.tar.bz2
修改源碼、配置、編譯
-----------------------------------------------
# cd busybox-1.7.0
# vi Makefile +176
ARCH ?= arm
CROSS_COMPILE ?= /usr/local/arm/3.3.2/bin/arm-linux-
# make menuconfig
Busybox Settings --->
Build Options --->
Build BusyBox as a static binary (no shared libs) //(1)
Installation Options --->
Don't use /usr //(2)
Linux System Utilities --->
mdev //(3)
Support /etc/mdev.conf
Support command execution at device addition/removal
Shells --->
Choose your default shell (msh) ---> //(4)
(1) 這個(gè)選項(xiàng)是一定要選擇的,這樣才能把busybox編譯成靜態(tài)鏈接的可執(zhí)行文件,運(yùn)行時(shí)才獨(dú)立于其他函數(shù)庫(kù).否則必需要其他庫(kù)文件才能運(yùn)行,在單一個(gè)linux內(nèi)核不能使他正常工作。
(2) 這個(gè)選項(xiàng)也一定要選,否則make install后,busybox將安裝在原系統(tǒng)的/usr下,這將覆蓋掉系統(tǒng)原有的命令.選擇這個(gè)選項(xiàng)后,make install后會(huì)在busybox目錄下生成一個(gè)叫_install的目錄,里面有busybox和指向他的鏈接.
(3) 如果沒有啟動(dòng),造成/dev下沒有設(shè)備文件。也就是說(shuō)所有的設(shè)備都沒有掛接進(jìn)來(lái)。最新的busybox已經(jīng)包含了udev的簡(jiǎn)化版本即mdev,且使用非常簡(jiǎn)單。 要使用mdev還需要在rootfs中做適當(dāng)配置。
vi rootfs/etc/init.d/rcS
---------------------------
mount -t tmpfs mdev /dev
mkdir /dev/pts
mount -t devpts devpts /dev/pts
mount -t sysfs sysfs /sys
mount -a
echo /sbin/mdev > /proc/sys/kernel/hotplug
mdev -s
配置linux kernel
-----------------------------------------------
mdev需要改寫/dev和/sys兩個(gè)目錄。所以必須保證這兩個(gè)目錄是可寫的(一般會(huì)用到sysfs,tmpfs。所以要重新編譯內(nèi)核)。然后在你的啟動(dòng)腳本文件中加入/sbin/mdev -s
linux-2.6.19 -- make menuconfig
File systems --->
Pseudo filesystems --->
sysfs file system support
Virtual memory file system support (former shm fs)
Tmpfs POSIX Access Control Lists
(4) 由于ash功能不夠強(qiáng)大,不能支持tab補(bǔ)齊,歷史紀(jì)錄等等的高級(jí)功能,所以使用busybox里面的msh代替ash.
因?yàn)閎usybox主要應(yīng)用于對(duì)空間要求非常嚴(yán)格的嵌入式系統(tǒng),所以它推薦使用uclibc而不鼓勵(lì)使用glibc,如果你沒有安裝uclibc,而且在 build Options也選擇了Build BusyBox as a static binary(no shared libs),那肯定無(wú)法編譯通過的,當(dāng)然如果你之前build Options選擇的是動(dòng)態(tài)編譯的話就不會(huì)有這樣的問題出現(xiàn)了。假設(shè)你是第一種情況,我們可以這樣解決:把a(bǔ)pplets/applets.c開頭的幾行 warning注釋掉
# vi applets/applets.c
/*
#if ENABLE_STATIC && defined(__GLIBC__) && !defined(__UCLIBC__)
#warning Static linking against glibc produces buggy executables
#warning (glibc does not cope well with ld --gc-sections).
#warning See sources.redhat.com/bugzilla/show_bug.cgi?id=3400
#warning Note that glibc is unsuitable for static linking anyway.
#warning If you still want to do it, remove -Wl,--gc-sections
#warning from top-level Makefile and remove this warning.
#error Aborting compilation.
#endif
*/
# make
# make install
這時(shí)會(huì)在你的編譯目錄下生成一個(gè)_install的目錄,里面包含了生成的所有文件和目錄結(jié)構(gòu)。
編譯時(shí)遇到的問題(1):
-----------------------------------------------
如果busybox編譯成static linking
Busybox Settings --->
Build Options --->
Build BusyBox as a static binary (no shared libs)
# make
將會(huì)遇到下面問題:
applets/applets.c:20:2: error: #warning Static linking against glibc produces buggy executables
applets/applets.c:21:2: error: #warning (glibc does not cope well with ld --gc-sections).
applets/applets.c:22:2: error: #warning See sources.redhat.com/bugzilla/show_bug.cgi?id=3400
applets/applets.c:23:2: error: #warning Note that glibc is unsuitable for static linking anyway.
applets/applets.c:24:2: error: #warning If you still want to do it, remove -Wl,--gc-sections
applets/applets.c:25:2: error: #warning from top-level Makefile and remove this warning.
make[1]: *** [applets/applets.o] Error 1
這個(gè)警告的定義在applets/applets.c中。將這段警告注釋掉就可以了。這段警告的意思是告訴你最好用uclibc編譯,而不是用glibc因?yàn)間libc比較大,busybox在寸土寸金的嵌入式系統(tǒng)中運(yùn)用比較多,所以會(huì)有這樣的要求。
# vi /busybox-1.7.0/applets/applets.c +20
注釋掉20 -- 28行內(nèi)容即可
miscutils/taskset.c:17: error: parse error before '*' token
-----------------------------------------------
最根本的解決辦法是換一個(gè)libc庫(kù),可是現(xiàn)在還不知道哪個(gè)庫(kù)最合適,唯有暫時(shí)將有問題的命令關(guān)掉
Miscellaneous Utilities --->
[ ] taskset
[]各式各樣的
runit/runsv.c: In function `gettimeofday_ns':
-----------------------------------------------
Runit Utilities --->
[ ] runsv
內(nèi)核啟動(dòng)時(shí)遇到的問題:
-----------------------------------------------
“could not run '/bin/sh': No such file or directory”
解決方法:
要這樣配置:
Shells --->
Choose your default shell (ash) --->
如果是這樣配置的話,雖然可以生成ash,但不能生成sh,將會(huì)在內(nèi)核啟動(dòng)時(shí)出現(xiàn)上面出現(xiàn)的問題:
Shells --->
Choose your default shell (none) --->
ash |
|