1. 程式人生 > >arm-linux移植手記(四)基於busybox1.16.0的根檔案系統製作

arm-linux移植手記(四)基於busybox1.16.0的根檔案系統製作

    參考《Mini2440_Linux移植開發實戰指南.pdf》中的“使用 Busybox 構建檔案系統”,還是有些問題,我自己的為主要原因。詳細的檔案系統的介紹與理解,自己搜尋檢視相關資料吧,我這裡僅是記錄操作步驟與遇到的問題。指南手冊可以在我的資源中下載。

環境介紹:

busybox版本:busybox-1.16.0
Linux平臺:虛擬機器下Fedora 11  自己原來編譯的gcc在debian6下,因此在debian6下也順利
交叉編譯工具:fedora 11 :gcc-4.3.2   debian 6 :gcc 4.4.5  
arm開發板:mini2440(CPU:S3C2440 ,SDRAM:64M,Nor Flash:2M,Nand Flash:256M,網絡卡:DM9000EP)

全部過程主要還是在debian下完成的,在Fedora下僅編譯了busybox1.13。

    基本步驟:建立根檔案系統目錄,安裝busybox,拷貝動態連結庫,建立配置檔案,製作根檔案系統映象
    1.下載原始碼
http://www.busybox.net/downloads/    busybox-1.16.0.tar.bz2
    2.建立系統目錄
通過一個shell指令碼來完成,檔名create_rootfs_sh,內容如下:
#!/bin/sh
echo "------Create rootfs directons start...--------"
mkdir rootfs
cd rootfs
echo "--------Create root,dev....----------"
mkdir root dev etc boot tmp var sys proc lib mnt home usr

mkdir etc/init.d etc/rc.d etc/sysconfig
mkdir usr/sbin usr/bin usr/lib usr/modules
echo "make node in dev/console dev/null"
mknod -m 600 dev/console c 5 1
mknod -m 600 dev/null c 1 3
mkdir mnt/etc mnt/jffs2 mnt/yaffs mnt/data mnt/temp
mkdir var/lib var/lock var/run var/tmp
chmod 1777 tmp
chmod 1777 var/tmp
echo "-------make direction done---------"
與參考文章相比,僅增加了usr目錄,執行#./create_rootfs_sh ,可以看到根目錄資料夾名為rootfs
輸出:
------Create rootfs directons start...--------
--------Create root,dev....----------
make node in dev/console dev/null
-------make direction done--------
    3.安裝busybox
    a.修改Makefile 檔案:
CROSS_COMPILE ?=arm-linux- 
ARCH ?=arm
    b.配置busybox
    輸入 make menuconfig 進行配置:
(1)、Busybox Settings--->
General Configuration--->
[*] 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.config
[*] Suppress warning message if /etc/busybox.conf is not readable
Build Options--->
[*] Build BusyBox as a static binary(no shared libs)
[*] Build with Large File Support(for accessing files>2GB)
Installation Options->
[]Don’t use /usr
Applets links (as soft-links) --->
(./_install) BusyBox installation prefix
Busybox Library Tuning --->
(6)Minimum password legth
(2)MD5:Trade Bytes for Speed
[*]Fsater /proc scanning code(+100bytes)
[*]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
(2)、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 modules.symbols file
Linux System Utilities --->
[*]Support /etc/mdev.conf
[*]Support command execution at device addition/removal

    我這裡直接複製參考手冊上的了,其中有些選項是不太一樣的,自己對應的進入檢視會發現的,例如紅色文字標出的。
    c.編譯安裝busybox
#make CONFIG_PREFIX=/opt/studyarm/rootfs install
在rootfs 目錄下會生成目錄bin、sbin、usr 和檔案linuxrc 的內容。
    4.拷貝動態連結庫
    這裡的動態連結庫主要是生成的busybox使用的,因此可以從你的交叉工具鏈資料夾下拷貝lib目錄中的動態連結庫檔案,例如我的在tools目錄下執行
#cp tools/lib/*.so* /rootfs/lib -d
    很多地方都說這裡的庫檔案不一定都用得到,可以使用arm-linux-readelf命令檢視busybox所需用的庫檔案,並把相關的拷貝進來;例如:
#arm-linux-readelf -a busybox | grep Shared
輸出:
 0x00000001 (NEEDED)                     Shared library: [libcrypt.so.1]
 0x00000001 (NEEDED)                     Shared library: [libm.so.6]
 0x00000001 (NEEDED)                     Shared library: [libc.so.6]
不用看著這三個就直接拷貝就完了,對應的它們還是有需用的連結庫的,可以再使用剛才的命令檢視,有些麻煩。
    5.建立配置檔案
(1)etc/mdev.conf 檔案,內容為空。
(2)拷貝主機etc 目錄下的passwd、group、shadow 檔案到rootfs/etc 目錄下。
(3)etc/sysconfig 目錄下新建檔案HOSTNAME,內容為”AL-Study”,這個其實沒有什麼關係,就是在板子上執行命令的時候命令前顯示的顯示,類似[root@debian6]。
(4)etc/inittab 檔案:我的前文開機自動設定和這個就有關了。
#etc/inittab
::sysinit:/etc/init.d/rcS
s3c2410_serial0::askfirst:-/bin/sh
::ctrlaltdel:/sbin/reboot
::shutdown:/bin/umount -a –r
(5)etc/init.d/rcS 檔案:
#!/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
runlevel=S
prevlevel=N
umask 022
export PATH runlevel prevlevel
echo "----------mount rootfs success----------------"
mount -a
echo /sbin/mdev>/proc/sys/kernel/hotplug
mdev -s
echo "***********************************************"
echo "**************Studying ARM Linux***************"
echo "Kernel version:linux-2.6.32.2"
echo "Date:2011.10.25"
echo "***********************************************"

/bin/hostname -F /etc/sysconfig/HOSTNAME
(或者直接 /bin/hostname AL-Study )
使用以下命令改變 rcS 的執行許可權:
chmod +x rcS
(6)etc/fstab 檔案:
#device mount-point type option dump fsck order
proc /proc proc defaults 0 0
none /tmp ramfs defaults 0 0
sysfs /sys sysfs defaults 0 0
mdev /dev ramfs defaults 0 0
(7)etc/profile 檔案:
#Ash profile
#vim:syntax=sh
#No core file by defaults
#ulimit -S -c 0>/dev/null 2>&1
USER="id -un"
LOGNAME=$USER
PS1='[\u@\h=W]#'
PATH=$PATH
HOSTNAME='/bin/hostname'
export USER LOGNAME PS1 PATH
    6.製作根檔案系統映象
利用mkyaffs2image-128M,解壓原廠提供的壓縮包,執行命令rootfs為自己製作的根檔案系統目錄
#./usr/sbin/mkyaffs2image-128M rootfs rootfs.bin
    在nor flash下啟動,y命令下載檔案系統,再用b命令引導,檢視。最後輸出有:
yaffs: dev is 32505859 name is "mtdblock3" rw
yaffs: passed flags ""
usb 1-1: new full speed USB device using s3c2410-ohci and address 2
usb 1-1: configuration #1 chosen from 1 choice
hub 1-1:1.0: USB hub found
hub 1-1:1.0: 4 ports detected
VFS: Mounted root (yaffs filesystem) on device 31:3.
Freeing init memory: 132K
----------mount rootfs success----------------
***********************************************
**************Studying ARM Linux***************
Kernel version:linux-2.6.32.2
Date:2011.10.25
***********************************************



Please press Enter to activate this console.


下面補充些遇到的問題:
核心啟動到最後出現:
Kernel panic - not syncing: Attempted to kill init!
Backtrace:
[<c002e270>] (dump_backtrace+0x0/0x10c) from [<c03a600c>] (dump_stack+0x18/0x1c)


 r7:c3820000 r6:c0518450 r5:00000004 r4:00000004
[<c03a5ff4>] (dump_stack+0x0/0x1c) from [<c03a605c>] (panic+0x4c/0x134)
[<c03a6010>] (panic+0x0/0x134) from [<c00466d8>] (do_exit+0x534/0x62c)
沒遇到最後,我是在用自己前面建立的工具鏈編譯的時候出現的問題,由於在Fedora下使用busybox1.13沒有問題,因此初步懷疑是前面的工具鏈問題,因此按照原來的方法,並且再編譯gcc時加上了
--with-arch=armv4t --with-cpu=arm920t --with-tune=arm920t
在編譯busybox1.16時沒有問題了,但是在編譯busybox1.13(原廠提供的)出現瞭如下問題
/linuxrc: error while loading shared libraries: libcrypt.so.1: cannot open share
d object file: No such file or directory
Kernel panic - not syncing: Attempted to kill init!
[<c002fd20>] (unwind_backtrace+0x0/0xd8) from [<c02e7754>] (panic+0x40/0x118)
而且一直沒有解決,唯一的區別就是配置採用的是拷貝原廠提供的配置檔案。


    最後補充一下的是,把前文綜合測試下,構建自己的嵌入式系統。首先肯定是自己的交叉工具鏈,一直在使用,完成對移植好的u-boot編譯,生成u-boot.bin檔案;編譯linux核心生成zImage,再使用u-boot的tools目錄下的工具製作成uImage;最後製作完成的檔案系統,生成rootfs.bin檔案;nor flash啟動板子,選擇a下載u-boot,然後通過nand flash啟動,在3秒內,按任意鍵,進入u-boot命令列,通過nfs下載linux核心;由於我製作的u-boot還不支援對yaffs檔案系統的下載,再通過nor flash啟動,y命令下載檔案系統,最後nand flash啟動,即可完成。啟動資訊如下:
-Boot 2010.06 (Oct 17 2011 - 21:01:36)


DRAM:  64 MiB
Flash: 512 KiB
NAND:  256 MiB
In:    serial
Out:   serial
Err:   serial
Net:   dm9000
Hit any key to stop autoboot:  0


NAND read: device 0 offset 0x60000, size 0x500000
 5242880 bytes read: OK
## Booting kernel from Legacy Image at 30008000 ...
   Image Name:   micro_linux
   Created:      2011-10-25   5:47:30 UTC
   Image Type:   ARM Linux Kernel Image (uncompressed)
   Data Size:    2119664 Bytes = 2 MiB
   Load Address: 30008000
   Entry Point:  30008040
   Verifying Checksum ... OK
   XIP Kernel Image ... OK
OK


Starting kernel ...


Uncompressing Linux.............................................................
...................................................................... done, boo
ting the kernel.
Linux version 2.6.32.2 (root@debian6) (gcc version 4.4.5 (GCC) ) #18 Mon Oct 24
15:45:06 CST 2011
CPU: ARM920T [41129200] revision 0 (ARMv4T), cr=00007177
CPU: VIVT data cache, VIVT instruction cache
Machine: micro2440 board test
Memory policy: ECC disabled, Data cache writeback
CPU S3C2440A (id 0x32440001)
S3C24XX Clocks, (c) 2004 Simtec Electronics
S3C244X: core 405.000 MHz, memory 101.250 MHz, peripheral 50.625 MHz
CLOCK: Slow mode (1.500 MHz), fast, MPLL on, UPLL on
Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 16256
Kernel command line: noinitrd console=ttySAC0,115200  init=/linuxrc mem=64M root
=/dev/mtdblock3 rw rootfstype=yaffs ip=10.1.0.129:10.1.0.128:10.1.0.1:255.255.25
5.0::eth0:off
PID hash table entries: 256 (order: -2, 1024 bytes)
Dentry cache hash table entries: 8192 (order: 3, 32768 bytes)
Inode-cache hash table entries: 4096 (order: 2, 16384 bytes)
Memory: 64MB = 64MB total
Memory: 60512KB available (3696K code, 418K data, 132K init, 0K highmem)
SLUB: Genslabs=11, HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
Hierarchical RCU implementation.
NR_IRQS:85
irq: clearing subpending status 00000002
Console: colour dummy device 80x30
console [ttySAC0] enabled
Calibrating delay loop... 50.38 BogoMIPS (lpj=125952)
Mount-cache hash table entries: 512
CPU: Testing write buffer coherency: ok
NET: Registered protocol family 16
S3C2440: Initialising architecture
S3C2440: IRQ Support
S3C24XX DMA Driver, (c) 2003-2004,2006 Simtec Electronics
DMA channel 0 at c4808000, irq 33
DMA channel 1 at c4808040, irq 34
DMA channel 2 at c4808080, irq 35
DMA channel 3 at c48080c0, irq 36
S3C244X: Clock Support, DVS off
bio: create slab <bio-0> at 0
usbcore: registered new interface driver usbfs
usbcore: registered new interface driver hub
usbcore: registered new device driver usb
s3c-i2c s3c2440-i2c: slave address 0x10
s3c-i2c s3c2440-i2c: bus frequency set to 98 KHz
s3c-i2c s3c2440-i2c: i2c-0: S3C I2C adapter
NET: Registered protocol family 2
IP route cache hash table entries: 1024 (order: 0, 4096 bytes)
TCP established hash table entries: 2048 (order: 2, 16384 bytes)
TCP bind hash table entries: 2048 (order: 1, 8192 bytes)
TCP: Hash tables configured (established 2048 bind 2048)
TCP reno registered
NET: Registered protocol family 1
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
RPC: Registered tcp NFSv4.1 backchannel transport module.
JFFS2 version 2.2. (NAND) ? 2001-2006 Red Hat, Inc.
ROMFS MTD (C) 2007 Red Hat, Inc.
msgmni has been set to 118
alg: No test for stdrng (krng)
io scheduler noop registered
io scheduler anticipatory registered (default)
io scheduler deadline registered
io scheduler cfq registered
Console: switching to colour frame buffer device 60x53
fb0: s3c2410fb frame buffer device
s3c2440-uart.0: s3c2410_serial0 at MMIO 0x50000000 (irq = 70) is a S3C2440
s3c2440-uart.1: s3c2410_serial1 at MMIO 0x50004000 (irq = 73) is a S3C2440
s3c2440-uart.2: s3c2410_serial2 at MMIO 0x50008000 (irq = 76) is a S3C2440
brd: module loaded
S3C24XX NAND Driver, (c) 2004 Simtec Electronics
s3c24xx-nand s3c2440-nand: Tacls=3, 29ns Twrph0=7 69ns, Twrph1=3 29ns
s3c24xx-nand s3c2440-nand: NAND soft ECC
NAND device: Manufacturer ID: 0xec, Chip ID: 0xda (Samsung NAND 256MiB 3,3V 8-bi
t)
Scanning device for bad blocks
Bad eraseblock 384 at 0x000003000000
Bad eraseblock 385 at 0x000003020000
Bad eraseblock 431 at 0x0000035e0000
Bad eraseblock 447 at 0x0000037e0000
Bad eraseblock 950 at 0x0000076c0000
Bad eraseblock 1098 at 0x000008940000
Creating 5 MTD partitions on "NAND 256MiB 3,3V 8-bit":
0x000000000000-0x000000040000 : "u-boot"
0x000000040000-0x000000060000 : "param"
ftl_cs: FTL header not found.
0x000000060000-0x000000560000 : "kernel"
ftl_cs: FTL header not found.
0x000000560000-0x000040560000 : "root"

mtd: partition "root" extends beyond the end of device "NAND 256MiB 3,3V 8-bit"
-- size truncated to 0xfaa0000
ftl_cs: FTL header not found.
0x000000000000-0x000040000000 : "nand"
mtd: partition "nand" extends beyond the end of device "NAND 256MiB 3,3V 8-bit"
-- size truncated to 0x10000000
dm9000 Ethernet Driver, V1.31
ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver
s3c2410-ohci s3c2410-ohci: S3C24XX OHCI
s3c2410-ohci s3c2410-ohci: new USB bus registered, assigned bus number 1
s3c2410-ohci s3c2410-ohci: irq 42, io mem 0x49000000
usb usb1: configuration #1 chosen from 1 choice
hub 1-0:1.0: USB hub found
hub 1-0:1.0: 2 ports detected
usbcore: registered new interface driver libusual
mice: PS/2 mouse device common for all mice
S3C24XX RTC, (c) 2004,2006 Simtec Electronics
i2c /dev entries driver
S3C2410 Watchdog Timer, (c) 2004 Simtec Electronics
s3c2410-wdt s3c2410-wdt: watchdog inactive, reset disabled, irq enabled
cpuidle: using governor ladder
sdhci: Secure Digital Host Controller Interface driver
sdhci: Copyright(c) Pierre Ossman
usbcore: registered new interface driver hiddev
usbcore: registered new interface driver usbhid
usbhid: v2.6:USB HID core driver
Advanced Linux Sound Architecture Driver Version 1.0.21.
No device for DAI UDA134X
No device for DAI s3c24xx-i2s
ALSA device list:
  No soundcards found.
TCP cubic registered
NET: Registered protocol family 17
drivers/rtc/hctosys.c: unable to open rtc device (rtc0)
usb 1-1: new full speed USB device using s3c2410-ohci and address 2
usb 1-1: configuration #1 chosen from 1 choice
hub 1-1:1.0: USB hub found
hub 1-1:1.0: 4 ports detected
IP-Config: Device `eth0' not found.
yaffs: dev is 32505859 name is "mtdblock3" rw
yaffs: passed flags ""
VFS: Mounted root (yaffs filesystem) on device 31:3.
Freeing init memory: 132K
----------mount rootfs success----------------
***********************************************
**************Studying ARM Linux***************
Kernel version:linux-2.6.32.2
Date:2011.10.25
***********************************************



Please press Enter to activate this console.


    好了,應該勉強看上去可以了。以後可以增加各種驅動支援,功能豐富了。發現自己寫得越來越不清晰了,可能覺得很多步驟都不用寫那麼詳細了,所以有些混亂的感覺。以上這些全是自己操作的記錄,現在突然明白有時候為什麼和別人一樣的環境卻總是成功不了,因為自己在記錄的時候或多或少的忘了步驟(自己重做的時候發現了些問題),還希望參考的人能告知,最後還是那句老話了,行家多多指點,有問題請留言。