首先說(shuō)一下各個(gè)知識(shí)點(diǎn): 使用的busybox是1.15.0。什么是busybox呢,busybox是很多標(biāo)準(zhǔn)linux一個(gè)單個(gè)可執(zhí)行實(shí)現(xiàn),很多標(biāo)準(zhǔn)linux工具都可以共享很多共同的元素。例如,很多基于文件的元素(比如grep和find)都需要在文件中搜索文件的代碼。當(dāng)這些工具被合并到一個(gè)可執(zhí)行程序中時(shí),他們就可以共享這些相同的元素,這樣可以產(chǎn)生更小的可執(zhí)行程序。實(shí)際上,busybox可以將大約3.5M的工具包裝成大約200KB大小。這就為引導(dǎo)盤(pán)和嵌入式linux設(shè)備提供了更多的工具。我們可以對(duì)2.4或2.6版本的linux內(nèi)核使用這個(gè)工具。 幾個(gè)常用的make選項(xiàng): make clean 清除源代碼樹(shù) make distclean 徹底清除源代碼樹(shù) make menuconfig N-curses(基于菜單的)配置工具 make defconfig 啟用默認(rèn)的(通用)配置 make config 基于菜單的配置工具 uClibc與glibc。CC的標(biāo)準(zhǔn)就是glibc這個(gè)庫(kù),里邊有GCC各種標(biāo)準(zhǔn)函數(shù)的實(shí)現(xiàn),使用uClibc,這是一個(gè)對(duì)大小進(jìn)行優(yōu)化過(guò)的C庫(kù),它為嵌入式系統(tǒng)開(kāi)發(fā)。 根文件系統(tǒng)前面加一個(gè)“根”字,說(shuō)明它是加載其他文件系統(tǒng)的根,既然是根,那么如果沒(méi)有這個(gè)根,其他文件系統(tǒng)就沒(méi)法加載。他包括系統(tǒng)引導(dǎo)和其他文件系統(tǒng)掛載所必須的文件,根文件系統(tǒng)包括Linux啟動(dòng)所必須的目錄和關(guān)鍵性的文件,例如Linux啟動(dòng)時(shí)都需要有init目錄下的相關(guān)文件,在Linux掛載分區(qū)時(shí)Linux一定會(huì)找到/etc/fstab這個(gè)掛載文件等,根文件系統(tǒng)還包括了應(yīng)用程序bin目錄等。 1)Jffs2 JFFS嵌入式系統(tǒng)文件系統(tǒng)最早是由瑞典 Axis Communications公司基于Linux2.0的內(nèi)核為嵌入式系統(tǒng)開(kāi)發(fā)的文件系統(tǒng)。JFFS2是RedHat公司基于JFFS開(kāi)發(fā)的閃存文件系統(tǒng),最初是針對(duì)RedHat公司的嵌入式產(chǎn)品eCos開(kāi)發(fā)的嵌入式文件系統(tǒng),所以JFFS也可以用于Linux,uCLinux中。 Jffs2:日志閃存嵌入式系統(tǒng)文件系統(tǒng)版本2(Journalling Flash FileSystem v2)主要用于NOR型閃存,基于MTD驅(qū)動(dòng)層,特點(diǎn)是,可讀寫(xiě)的,支持?jǐn)?shù)據(jù)壓縮的,基于哈希表的日志型文件系統(tǒng),并提供了崩潰/掉電安全保護(hù),提供“寫(xiě)平衡”支持等。缺點(diǎn)主要是當(dāng)文件系統(tǒng)已經(jīng)滿或接近滿時(shí),因?yàn)槔占年P(guān)系而使jffs2的運(yùn)行速度大大放慢。 2)Yaffs Yet Another Flash File System Yaffs/yaffs2是專(zhuān)門(mén)為嵌入式系統(tǒng)使用NAND型閃存而設(shè)計(jì)的一種日志型文件系統(tǒng)。與jffs2相比,它減少一些功能(例如不支持?jǐn)?shù)據(jù)壓縮),所以速度更快,掛載時(shí)間更短,對(duì)內(nèi)存的占用較小。另外他是跨平臺(tái)的文件系統(tǒng),除了Linux和eCos,還支持WinCE,pSOS和ThreadX等。 Yaffs/yaffs自帶NAND芯片驅(qū)動(dòng),并且為嵌入式提供了直接訪問(wèn)文件系統(tǒng)的API,用于可以不使用Linux中的MTD與VFS,直接對(duì)文件系統(tǒng)操作。 3)Cramfs Cramfs是Linux的創(chuàng)始人Linux Torvalds參與開(kāi)發(fā)的一種只讀的壓縮文件系統(tǒng)。他也基于MTD驅(qū)動(dòng)程序。在cramfs文件系統(tǒng)中,每一頁(yè)(4KB)被壓縮,可以隨機(jī)頁(yè)訪問(wèn),其壓縮比高達(dá)2:1,為嵌入式系統(tǒng)節(jié)省了大量的Flash存儲(chǔ)空間,使系統(tǒng)可通過(guò)更低容量的FLASH存儲(chǔ)相同的文件,從而降低系統(tǒng)成本。Cramfs文件系統(tǒng)以壓縮方式存儲(chǔ),在運(yùn)行時(shí)解壓縮。 4)NFS NFS是由Sun開(kāi)發(fā)并發(fā)展起來(lái)的一項(xiàng)不同機(jī)器,不同操作系統(tǒng)之間通過(guò)網(wǎng)絡(luò)共享文件的技術(shù) 然后開(kāi)始操作: 一. 給內(nèi)核打上補(bǔ)丁,使內(nèi)核對(duì)yaffs2文件系統(tǒng)支持。 下載最新的驅(qū)動(dòng)http://www.aleph1.co.uk/cgi-bin/ ... fs2.tar.gz?view=tar 解壓: tar zxvf yaffs2.tar.gz cd yaffs2 ./patch-ker.shc/home/hacker/linux-2.6.30.4 成功后打印信息: 1. Updating /file/fl/linux-2.6.33/fs/Kconfig 2. Updating /file/fl/linux-2.6.33/fs/Makefile 進(jìn)入linux-2.6.30.4目錄,把s3c2410的默認(rèn)配置寫(xiě)入config文件。 1. make s3c2410_defconfig 配置文件系統(tǒng)選項(xiàng) 配置yaffs2文件系統(tǒng) 修改配置如下: 1. File systems---> 2. Miscellaneous filesystems---> 3. <*> YAFFS2 file system support 4. -*- 512 byte / page devices 5. -*- 2048 byte (or larger) / page devices 6. Autoselect yaffs2 format 7. Cache short names in RAM 二: 編譯busybox生成文件系統(tǒng)所需要的應(yīng)用程序 1.解壓busybox源碼,修改Makefile使之編譯成ARM平臺(tái): #tar-jxvf busybox-1.15.0.tar.tar #cdbusybox-1.15.0 #gedit Makefile 修改CROSS_COMPILE ?= arm-linux- ARCH = arm 2.配置busybox,下面是一個(gè)人配置的busybox 1.13.0,借來(lái)參考,基本差不多。 make menuconfig Busybox Settings ---> General Configuration ---> Buffer allocation policy (Allocate with Malloc) ---> Show verbose applet usage messages Store applet usage messages in compressed form Support --install [-s] to install applet links at runtime Enable locale support (system needs locale for this to work) Support for --long-options Use the devpts filesystem for Unix98 PTYs Support writing pidfiles Runtime SUID/SGID configuration via /etc/busybox.conf Suppress warning message if /etc/busybox.conf is not readable (/proc/self/exe) Path to BusyBox executable Build Options ---> Build BusyBox as a static binary (no shared libs) Build with Large File Support (for accessingfiles> 2 GB) Installation Options ---> [ ] Don't use /usr Applets links (as soft-links) ---> (./_install) BusyBox installation prefix Busybox Library Tuning ---> (6) Minimum password length (2) MD5: Trade Bytes for Speed Faster /proc scanning code (+100 bytes) Command line editing (1024) Maximum length of input vi-style line editing commands (15) History size History saving Tab completion Fancy shell prompts (4) Copy buffer size, in kilobytes Use ioctl names rather than hex values in error messages Support infiniband HW Linux Module Utilities ---> (/lib/modules) Default directory containing modules (modules.dep) Default name of modules.dep insmod rmmod lsmod modprobe --- Options common to multiple modutils [ ] Support version 2.2/2.4 Linux kernels Support tainted module checking with new kernels Support for module.aliases file Support for module.symbols fileLinux System Utilities ---> 3.編譯和安裝busybox: make;make install 安裝好后會(huì)在busybox-1.15.0/_install/目錄下生成:bin,linuxrc,sbin,usr。 4.開(kāi)始構(gòu)建文件系統(tǒng) 1)創(chuàng)建一個(gè)root_2.6.30.4目錄,把busybox-1.15.0/_install/目錄下的復(fù)制過(guò)來(lái),并在該目錄下創(chuàng)建文件系統(tǒng)所需要的其他目錄。 #mkdir root-2.6.30.4 #cp-rf busybox-1.15.0/_install/*root-2.6.30.4/ #cdroot-2.6.30.4/ #mkdir dev etc home lib mnt opt proc tmp var 2)添加必須的文件,文件和文件夾都用chmod 777 xxx,修改權(quán)限 "dev"目錄,創(chuàng)建兩個(gè)設(shè)備文件: #mknodconsolec 5 1 #mknod null c 1 3 etc"目錄,創(chuàng)建各種配置文件并向里面添加內(nèi)容,沒(méi)有列出的就不用添加: group: 系統(tǒng)用戶組配置文件,內(nèi)容如下: root:*:0: daemon:*:1: bin:*:2: sys:*:3: adm:*:4: tty:*:5: disk:*:6: lp:*:7:lp mail:*:8: news:*:9: uucp:*:10: proxy:*:13: kmem:*:15: dialout:*:20: fax:*:21: voice:*:22: cdrom:*:24: floppy:*:25: tape:*:26: sudo:*:27: audio:*:29: ppp:x:99: 500:x:500:plg 501:x:501:fa inittab: 系統(tǒng)init進(jìn)程配置文件,內(nèi)容如下: # /etc/inittab ::sysinit:/etc/init.d/rcS console::askfirst:-/bin/sh ::ctrlaltdel:/sbin/reboot ::shutdown:/bin/umount -a –r passwd: 系統(tǒng)密碼文件,內(nèi)容如下: root::0:0:root:/:/bin/sh ftp::14:50:FTP User:/var/ftp: bin:*:1:1:bin:/bin: daemon:*:2:2:daemon:/sbin: nobody:*:99:99:Nobody:/: hacker::502:502 ![]() sysconfig/HOSTNAME: 主機(jī)名稱(chēng)文件,內(nèi)容如下: TE2440II 注意HOSTNAME是文件名,TE2440II是文件中的內(nèi)容。 fstab: 系統(tǒng)掛載文件系統(tǒng)列表,內(nèi)容如下: # device mount-point type options dump fsck order none/proc proc defaults0 0 none/dev/pts devptsmode=06220 0 tmpfs/dev/shm tmpfsdefaults0 0
profile: 用戶環(huán)境配置文件,內(nèi)容如下: # Ash profile # vim: syntax=sh # No corefilesby default #ulimit -S -c 0 > /dev/null 2>&1 USER="`id -un`" LOGNAME=$USER PS1='[\u@\h \W]\# ' PATH=$PATH:/usr/local/bin LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib HOSTNAME=`/bin/hostname` export USER LOGNAME PS1 PATHLD_LIBRARY_PATH resolv.conf: DNS配置文件,內(nèi)容如下: nameserver 61.144.56.100 "home"目錄:創(chuàng)建一個(gè)hacker目錄,與etc目錄passwd文件中的hacker相對(duì)應(yīng) "lib"目錄:這個(gè)里面放的都是庫(kù)文件,直接從交叉編譯器的庫(kù)文件目錄中拷貝過(guò)來(lái): #cp -f /usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/armv4t/lib/*so* lib/ -a 6. 使用yaffs制作工具編譯構(gòu)建好的文件系統(tǒng)。使用mkyaffs2image,復(fù)制到/usr/sbin/目錄下,給予777權(quán)限。 然后mkyaffs2image root-2.6.30.4 root-2.6.30.4.bin 注意一個(gè)路徑是這樣的 /etc/init.d/rcS, rcS是文件 Kernel panic - not syncing: Attempted to kill init! 上網(wǎng)搜索了一些相關(guān)信息,找到了解決問(wèn)題的途徑。 原因在于:編譯內(nèi)核和busybox使用的編譯器是arm-linux-gcc 4.3.2,而這個(gè)編譯器默認(rèn)是打開(kāi)“EABI選項(xiàng)”的,這樣編譯出來(lái)的busybox就是EABI的。但是內(nèi)核編譯的時(shí)候,默認(rèn)是把“EABI選項(xiàng)”關(guān)掉的。所以busybox和內(nèi)核無(wú)法正常配合。把“EABI選項(xiàng)”打開(kāi),重新編譯內(nèi)核后,一切正常。 Kernel Features ---> Use the ARM EABI to compile the kernel Allow old ABI binaries to run with this kernel (EXPERIMENTAL) (NEW) 這樣就搞定了,嘿嘿。 李萬(wàn)鵬 |