Initramfs的製作和移植
———————————————————————————————————————
機作業系統:Centos 6.7交叉編譯器環境:arm-linux-gcc-4.5.4 交叉編譯器:buildroot-2012.08開發板平臺: FL2440 Linux核心版本: linux-3.0 除錯終端:SECURE-CRT Bootloader:U-boot-2010.09
郵箱:[email protected]
———————————————————————————————————————
1.瞭解initramfs檔案系統
initramfs在編譯核心的同時被編譯並與核心生成一個映像檔案,可以壓縮也可以不壓縮,但是目前只支援cpio包格式。它是根檔案系統製作和製作的一種非常簡單的方法,也可以通過執行這個檔案系統中的程式引導真正的檔案系統,這樣載入根檔案系統的工作就不是核心的工作,而是initramfs的工作。由於initramfs使用cpio包格式,所以很容易將一個單一的檔案、目錄、node編譯連結到系統中去,這樣很簡單的系統中使用起來很方便,不需要另外掛接檔案系統。
2.對根檔案系統進行修改
[[email protected] rootfs]$ ln -s bin/busybox init
[[email protected] rootfs]$ ll
total 60
drwxr-xr-x 2 lingyun trainning 4096 Apr 25 20:15 apps
drwxr-xr-x 2 lingyun trainning 4096 Apr 26 15:16 bin
drwxr-xr-x 2 lingyun trainning 4096 Apr 25 20:15 data
drwxr-xr-x 2 lingyun trainning 4096 Apr 25 20:51 dev
drwxr-xr-x 4 lingyun trainning 4096 Apr 26 14:16 etc
drwxr-xr-x 2 lingyun trainning 4096 Apr 25 20:15 info
lrwxrwxrwx 1 lingyun trainning 11 Apr 27 21:19 init -> bin/busybox
drwxr-xr-x 3 lingyun trainning 4096 Apr 25 21:17 lib
lrwxrwxrwx 1 root root 11 Apr 26 15:16 linuxrc -> bin/busybox
drwxr-xr-x 6 lingyun trainning 4096 Apr 25 20:15 mnt
drwxr-xr-x 2 lingyun trainning 4096 Apr 25 20:15 proc
drwxr-xr-x 2 lingyun trainning 4096 Apr 25 20:15 root
drwxr-xr-x 2 lingyun trainning 4096 Apr 26 15:16 sbin
drwxr-xr-x 2 lingyun trainning 4096 Apr 25 20:15 sys
drwxr-xr-x 2 lingyun trainning 4096 Apr 25 20:15 tmp
drwxr-xr-x 6 lingyun trainning 4096 Apr 25 20:15 usr
drwxr-xr-x 2 lingyun trainning 4096 Apr 25 20:57 var
3. 新增核心對initramfs的支援
[[email protected] kernel]$ ls
linux-3.0 linux-3.0.tar.bz2
[[email protected] kernel]$ cd linux-3.0
[[email protected] linux-3.0]$ export TERM=vt100
[[email protected] linux-3.0]$ make menuconfig
。 。 。 。 。 。
General setup --->
[*] Initial RAM filesystem and RAM disk (initramfs/initrd) support
(/home/hongfuhao/fl2440/rootfs/rootfs) Initramfs source file(s) #輸入根檔案系統的所在目錄
。 。 。 。 。 。
[[email protected] linux-3.0]$ ls
arch fs linuxrom-s3c2440.bin README usr
block include MAINTAINERS REPORTING-BUGS virt
COPYING init Makefile samples vmlinux
CREDITS ipc mm scripts vmlinux.o
crypto Kbuild modules.builtin security
Documentation Kconfig modules.order sound
drivers kernel Module.symvers System.map
firmware lib net tools
[[email protected] linux-3.0]$ du -h linuxrom-s3c2440.bin
6.8M linuxrom-s3c2440.bin
4.製作映像檔案
因為檔案系統和核心是整合在一起的,所以不需要製作檔案系統映像5.新增uboot對initramfs支援
U-Boot 2010.09 (Jul 15 2016 - 21:57:32)
DRAM: 64 MiB
NAND: 256 MiB
In: serial
Out: serial
Err: serial
Net: dm9000
Hit any key to stop autoboot: 0
[[email protected]]# set bkr 'tftp 30008000 linuxrom-s3c2440.bin;nand erase 100000 8000000;nand write 30008000 100000 800000'
[[email protected]]# set bootcmd_initramdisk 'nand read 30008000 100000 800000;bootm 30008000'
[[email protected]]# set bootargs 'console=ttyS0,115200 mem=64M init=/linuxrc rw loglevel=7'
[[email protected]]# set bootcmd 'run bootcmd_initramdisk'
[[email protected]]# save
Saving Environment to NAND...
Erasing Nand...
Erasing at 0x60000 -- 100% complete.
Writing to Nand... done
[[email protected]]# run bkr
dm9000 i/o: 0x20000300, id: 0x90000a46
DM9000: running in 16 bit mode
MAC: 08:00:3e:26:0a:5b
could not establish link
Using dm9000 device
TFTP from server 192.168.1.2; our IP address is 192.168.1.168
Filename 'linuxrom-s3c2440.bin'.
Load address: 0x30008000
Loading: T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T
Retry count exceeded; starting again
dm9000 i/o: 0x20000300, id: 0x90000a46
DM9000: running in 16 bit mode
MAC: 08:00:3e:26:0a:5b
could not establish link
Using dm9000 device
TFTP from server 192.168.1.2; our IP address is 192.168.1.168
Filename 'linuxrom-s3c2440.bin'.
Load address: 0x30008000
Loading: T T T T T T T T T T T T T T #################################################################
#################################################################
#################################################################
#################################################################
#################################################################
##
done
Bytes transferred = 4797912 (4935d8 hex)
NAND erase: device 0 offset 0x100000, size 0x8000000
Skipping bad block at 0x00700000
Skipping bad block at 0x053a0000
Erasing at 0x80e0000 -- 100% complete.
OK
NAND write: device 0 offset 0x100000, size 0x800000
Skip bad block 0x00700000
8388608 bytes written: OK
6. 啟動引導
[[email protected]]# boot
啟動過程省略。。。。