2009年11月5日 星期四

建立root fs 系統檔案

製作root.cramfs系统檔案

主機:
ubuntu 8.04 (linux-2.6.24-19)
gcc-4.2

目標板:
s3c2440
linux-2.6.26
cramfs


工具:
busybox-1.9.2
arm-linux-gcc-4.0.3
-------------------------------------------------------------
參考資料:
BusyBox——嵌入式Linux中的瑞士軍刀
使用busybox-1.9.2製作根文件系統
使用Busybox製作CRAMFS文件系統成功
-------------------------------------------------------------
1. 修改Makefile



#ARCH        ?= $(SUBARCH)

#CROSS_COMPILE    ?=
ARCH        := arm
CROSS_COMPILE    :=  /usr/local/arm/4.0.3/bin/arm-linux-


2. 修改applets/applets.c中的警告信息



//#if ENABLE_STATIC && defined(__GLIBC__) && !defined(__UCLIBC__)

#if 0
#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 scripts/trylink and remove this warning.
#error Aborting compilation.
#endif


這段警告的意思是告訴你最好用uclibc編譯,而不是用glibc因為glibc比較大,busybox在嵌入式系統中運用比較多,所以會有這樣的要求。
如果沒有註解掉這段警告或者沒有採用uclibc的話,在make install的時候則會出現如下的錯誤:


applets/applets.c:15:2: warning: #warning Static linking against glibc produces buggy executables

applets/applets.c:16:2: warning: #warning (glibc does not cope well with ld --gc-sections).
applets/applets.c:17:2: warning: #warning See sources.redhat.com/bugzilla/show_bug.cgi?id=3400
applets/applets.c:18:2: warning: #warning Note that glibc is unsuitable for static linking anyway.
applets/applets.c:19:2: warning: #warning If you still want to do it, remove -Wl,--gc-sections
applets/applets.c:20:2: warning: #warning from scripts/trylink and remove this warning.
applets/applets.c:21:2: #error Aborting compilation.
make[1]: *** [applets/applets.o] 錯誤 1
make: *** [applets] 錯誤 2


3. 設定busybox
首先可以先恢復一下預設設定




$ make defconfig

然後,設定busybox可以採用如下命令:


$ make menuconfig





$ make xconfig


配置內容參考
使用busybox-1.9.2製作根文件系統
使用Busybox製作CRAMFS文件系統成功

4. 編譯busybox


$ make install


如果成功,會有如下信息:


--------------------------------------------------

You will probably need to make your busybox binary
setuid root to ensure all configured applets will
work properly.
--------------------------------------------------

並在busybox/_install 目錄下會生成下列文件:

drwxr-xr-x  5 wang wang 4096 2008-09-10 17:32 .

drwxr-xr-x 32 wang wang 4096 2008-09-10 17:32 ..
drwxr-xr-x  2 wang wang 4096 2008-09-10 17:32 bin
lrwxrwxrwx  1 wang wang   11 2008-09-10 17:32 linuxrc -> bin/busybox
drwxr-xr-x  2 wang wang 4096 2008-09-10 17:32 sbin
drwxr-xr-x  4 wang wang 4096 2008-09-10 17:32 usr


5. 修改_install/bin/busybox的屬性


$ chmod 755 ./_install/bin/busybox


必須要要修改屬性,否則在busybox中很多命令會受限制

6. 打包_install文件夾的內容
首先要刪除_install/linuxrc文件,這個文件將在後面重新被創建,這裡先刪除


$ rm ./_install/linuxrc


然後將剩下的三個文件夾打包起來




$ tar cvf 1.tar ./_install/


7. 建立cramfs所需的一些目錄
   首先創建一個文件夾,作為暫時存放cramfs的臨時目錄,以方便在其下建立文件系統。所有命令如下


$ mkdir /opt/rootfs

$ cd /opt/rootfs
$ mkdir bin dev etc home lib mnt proc sbin sys tmp  var usr
$ mkdir etc/init.d


(其中假設你的普通用戶已經取得/opt的操作所有權或者也可以放在用戶目錄下完成; 總之,對於rootfs及其以下目錄,當前用戶必須擁有讀、寫和執行的所有權)

8. 準備啟動所需的文件:linuxrc、rcS、inittab、fstab四個文件
(以下均假定當前路徑在/opt/rootfs)
a. linuxrc

$ vim linuxrc


內容:


#!/bin/sh

echo "mount /etc as ramfs"
/bin/mount -f -t cramfs -o remount,ro /dev/bon/2 /
/bin/mount -t ramfs ramfs /var
/bin/mkdir -p /var/tmp
/bin/mkdir -p /var/run
/bin/mkdir -p /var/log
/bin/mkdir -p /var/lock
/bin/mkdir -p /var/empty
#/bin/mount -t usbdevfs none /proc/bus/usb

exec /sbin/init


更改其所有權:



$ chmod 775 linuxrc



b. rcS


$ vim etc/init.d/rcS


內容:





#!/bin/sh


# mount all filesystem defined in "fstab"
echo "#mount all......."
/bin/mount -a



更改其所有權:


$ chmod 775 etc/init.d/rcS


c. inittab



$ vim etc/inittab

內容:


# This is run first except when booting

::sysinit:/etc/init.d/rcS

# Start an "askfirst" shell on the console
#::askfirst:-/bin/bash
::askfirst:-/bin/sh

# Stuff to do when restarting the init process
::restart:/sbin/init

# Stuff to do before rebooting
::ctrlaltdel:/sbin/reboot
::shutdown:/bin/umount -a -r


d. fstab



$ vim etc/fstab


內容:

none        /proc        proc    defaults    0 0

none        /dev/pts    devpts    mode=0622    0 0
tmpfs        /dev/shm    tmpfs    defaults    0 0


9. 建立節點console、null
否則就會提示「Warning: unable to open an initial console. Kernel panic - not syncing: Attempted to kill init!」的類似錯誤。
創建時,必須以root身份才可以



sudo mknod -m 600 dev/console c 5 1

sudo mknod -m 666 dev/null c 1 3


10. 使用之前打包的_install
將剛才在busybox的_install下的三個文件夾的打包文件複製到rootfs目錄,解壓後刪除打包文件。


$ tar xvf 1.tar

$ rm 1.tar


11. 複製常用的lib文件
我用的是開發板的文件系統中的lib/下的文件,直接拷貝過來用

12. 建立cramfs


$ cd /opt

$ mkcramfs rootfs s3c2440.cramfs


如果沒有mkcramfs命令,請執行下面指令安裝



$sudo apt-get install cramfsprogs


13. 燒錄文件系統到開發板並啟動

啟動信息:


Read chip id = ec76

Nand flash status = c0
Set boot params = root=/dev/mtdblock2 init=/linuxrc load_ramdisk=0 console=ttySAC1,115200 mem=65536K devfs=mount display=shp480
Load Kernel...
Linux version 2.6.26 (wang@wang-desktop) (gcc version 4.1.0) #7 Thu Sep 4 17:18:03 CST 2008
CPU: ARM920T [41129200] revision 0 (ARMv4T), cr=c0007177
Machine: SMDK2440
ATAG_INITRD is deprecated; please update your bootloader.
Memory policy: ECC disabled, Data cache writeback
CPU S3C2440A (id 0x32440001)
S3C244X: core 400.000 MHz, memory 100.000 MHz, peripheral 50.000 MHz
S3C24XX Clocks, (c) 2004 Simtec Electronics
CLOCK: Slow mode (1.500 MHz), fast, MPLL on, UPLL on
CPU0: D VIVT write-back cache
CPU0: I cache: 16384 bytes, associativity 64, 32 byte lines, 8 sets
CPU0: D cache: 16384 bytes, associativity 64, 32 byte lines, 8 sets
Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 16256
Kernel command line: root=/dev/mtdblock2 init=/linuxrc load_ramdisk=0 console=ttySAC1,115200 mem=65536K devfs=mount display=shp480
irq: clearing pending ext status 00056200
irq: clearing pending ext status 00000200
irq: clearing subpending status 00000092
PID hash table entries: 256 (order: 8, 1024 bytes)
timer tcon=00590000, tcnt a2c1, tcfg 00000200,00000000, usec 00001eb8
Console: colour dummy device 80x30
console [ttySAC1] enabled
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: 61708KB available (2732K code, 277K data, 124K init)
Mount-cache hash table entries: 512
CPU: Testing write buffer coherency: ok
net_namespace: 192 bytes
NET: Registered protocol family 16
S3C2440: Initialising architecture
S3C2440: IRQ Support
S3C24XX DMA Driver, (c) 2003-2004,2006 Simtec Electronics
DMA channel 0 at c4800000, irq 33
DMA channel 1 at c4800040, irq 34
DMA channel 2 at c4800080, irq 35
DMA channel 3 at c48000c0, irq 36
S3C244X: Clock Support, DVS off
SCSI subsystem initialized
usbcore: registered new interface driver usbfs
usbcore: registered new interface driver hub
usbcore: registered new device driver usb
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
NetWinder Floating Point Emulator V0.97 (double precision)
msgmni has been set to 120
io scheduler noop registered
io scheduler anticipatory registered (default)
io scheduler deadline registered
io scheduler cfq registered
Console: switching to colour frame buffer device 30x40
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
usbcore: registered new interface driver ub
dm9000 Ethernet Driver, V1.30
Linux video capture interface: v2.00
NFTL driver: nftlcore.c $Revision: 1.98 $, nftlmount.c $Revision: 1.41 $
S3C24XX NAND Driver, (c) 2004 Simtec Electronics
s3c2440-nand s3c2440-nand: Tacls=1, 10ns Twrph0=4 40ns, Twrph1=1 10ns
NAND device: Manufacturer ID: 0xec, Chip ID: 0x76 (Samsung NAND 64MiB 3,3V 8-bit)
s3c2410_nand_update_chip: chip c3d784bc: 9
NAND_ECC_NONE selected by board driver. This is not recommended !!
Scanning device for bad blocks
Bad eraseblock 357 at 0x00594000
Bad eraseblock 3335 at 0x0341c000
Bad eraseblock 3995 at 0x03e6c000
Creating 4 MTD partitions on "NAND 64MiB 3,3V 8-bit":
0x00000000-0x00030000 : "boot"
0x00030000-0x00200000 : "kernel"
0x00200000-0x02000000 : "rootfs"
0x02000000-0x04000000 : "ext-fs1"
usbmon: debugfs is not available
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
Initializing USB Mass Storage driver...
usbcore: registered new interface driver usb-storage
USB Mass Storage support registered.
mice: PS/2 mouse device common for all mice
i2c /dev entries driver
s3c2440-i2c s3c2440-i2c: slave address 0x10
s3c2440-i2c s3c2440-i2c: bus frequency set to 390 KHz
s3c2440-i2c s3c2440-i2c: i2c-0: S3C I2C adapter
S3C2410 Watchdog Timer, (c) 2004 Simtec Electronics
s3c2410-wdt s3c2410-wdt: watchdog inactive, reset disabled, irq enabled
Registered led device: led4
Registered led device: led5
Registered led device: led6
Registered led device: led7
TCP cubic registered
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
VFS: Mounted root (cramfs filesystem) readonly.
Freeing init memory: 124K
mount /etc as ramfs
init started: BusyBox v1.9.2 (2008-09-05 13:54:16 CST)
starting pid 813, tty '': '/etc/init.d/rcS'
#mount all.......
mount: mounting none on /dev/pts failed: No such file or directory
mount: mounting tmpfs on /dev/shm failed: No such file or directory
# starting mdev....
******************************************
 linux-2.6.26 boot           
 2008-9-5            
                      
******************************************

Please press Enter to activate this console.
starting pid 815, tty '': '/bin/sh'
/ #
/ #


就可以進入console了~~!!