嵌入式根文件系统实验指导
实验环境:
宿主机:RHEL4(Linux vm-dev 2.6.9-42.ELsmp)
目标机:博创经典S2410平台
交叉编译器:arm-linux-gcc V3.4.1
本次实验目录下存放着已经修改好的博创经典2410平台的文件系统源码包,将该源码包拷贝到宿主机LINUX系统中,解压至本次实验目录,配置编译生成映像文件烧写到ARM设备中。
前提是:通过samba服务器把实验源码包拷贝到了虚拟机的共享目录。
一、使用busybox工具创建文件系统
1、创建实验目录rootfs
[root@vm-dev ~]# cd /root/
[root@vm-dev ~]# mkdir rootfs
2、解压实验压缩包
[root@vm-dev ~]# cd rootfs/
[root@vm-dev rootfs]# ls
busybox-1.12.2.tar.bz2 mkcramfs rootfs.tar.bz2
[root@vm-dev rootfs]# tar xjvf busybox-1.12.2.tar.bz2
[root@vm-dev rootfs]# ls
busybox-1.12.2 busybox-1.12.2.tar.bz2 mkcramfs rootfs.tar.bz2
[root@vm-dev rootfs]#
3、编译busybox工具集
3.1进入busybox源码目录
[root@vm-dev rootfs]# cd busybox-1.12.2
修改该目录下Makefile文件中的ARCH和CROSS_COMPIL,指定交叉编译器和目标系统,与本机的路径一致:
CROSS_COMPILE ?= arm-linux-
...
ARCH ?= arm
3.2编译busybox。先make menuconfig,修改以下:
[root@vm-dev busybox-1.12.2]# make menuconfig
Busybox Settings --->
Build Options --->
[*] Build BusyBox as a static binary (no shared libs)
//直接编译成静态库,简单方便
(/opt/crosstools/gcc-3.4.6-glibc-2.3.6/bin/arm-linux-) Cross Compiler prefix
//这里和Makefile里保持一致,应该写一处就行了
Installation Options --->
[ ] Don't use /usr
//使用usr目录
Busybox Library Tuning --->
[*] Fancy shell prompts
//一定要选上,否则很多转意字符无法识别
Miscellaneous Utilities --->
[ ] inotifyd
//不选
保存退出,直接make,make install。
[root@vm-dev busybox-1.12.2]# make
[root@vm-dev busybox-1.12.2]# make install
可以看到如下生成的目录_install
[root@vm-dev busybox-1.12.2]# ls _install/
bin linuxrc sbin usr
[root@vm-dev busybox-1.12.2]#
至此busybox工具编译完成,生成了文件系统需要的相关命令和工具在_install目录下。用户也可以根据需要,在busybox中添加删除相关命令和工具。
4、手动创建根文件系统的基本目录树,如usr、bin、lib、mnt等,并添加相关配置文件与设备节点。
该步骤用户可以省略,直接使用实验目录中解压出来的rootfs目录即可,如有兴趣可以仔细分析rootfs目录下的相关配置文件。
解压rootfs压缩包:
[root@vm-dev rootfs]# tar xjvf rootfs.tar.bz2
生成rootfs根目录树
5、把busybox编译后默认安装目录_install中需要的命令工具复制到这里的rootfs相关目录中。
此步骤可以省略,我们提供的rootfs目录内容已经比较完善,无需增加内容。
6、使用mkcramfs工具将rootfs文件系统目录制作成CRAMFS根文件系统映像
[root@vm-dev rootfs]# mkcramfs rootfs root.cramfs
[root@vm-dev rootfs]# ls
busybox-1.12.2 busybox-1.12.2.tar.bz2 mkcramfs root.cramfs rootfs rootfs.tar.bz2
[root@vm-dev rootfs]#
生成root.cramfs根文件系统文件。
二、烧写根文件系统
注意:前提是已烧写好uboot和内核镜像
1、拷贝刚刚生生成的根文件系统文件root.cramfs到本机(宿主机)TFTP服务器下载目录/tftpboot;
[root@vm-dev rootfs]# cp root.cramfs /tftpboot/
2、启动ARM设备,进入U-BOOT控制台,配置网络IP,下载内核。
2.1 设置网络IP:
U-Boot 1.3.2 (Dec 8 20## - 11:37:21)
DRAM: 64 MB
Flash: 512 kB
NAND: 64 MiB
In: serial
Out: serial
Err: serial
Found DM9000 ID:90000a46 at address 10000000 !
DM9000 work in 16 bus width
bd->bi_entaddr: 08:00:3e:26:0a:5b
[eth_init]MAC:8:0:3e:26:a:5b:
Hit any key to stop autoboot: 0
[up-class2410 #] setenv serverip 192.168.1.140
[up-class2410 #] setenv ipaddr 192.168.1.199
[up-class2410 #] saveenv
Saving Environment to NAND...
Erasing Nand...Writing to Nand... done
[up-class2410 #]
setenv serverip 192.168.1.140 :设置宿主机IP地址,即TFTP服务器端机器IP
setenv ipaddr 192.168.1.199 :设置ARM端U-BOOT中网络设备IP地址(与服务器IP同一网段任意非冲突IP地址即可)
2.2 烧写文件系统,并固化到NANDFLASH中:
下载到SDRAM:
[up-class2410 #] tftp 30008000 root.cramfs
Found DM9000 ID:90000a46 at address 10000000 !
DM9000 work in 16 bus width
bd->bi_entaddr: 08:00:3e:26:0a:5b
[eth_init]MAC:8:0:3e:26:a:5b:
TFTP from server 192.168.1.140; our IP address is 192.168.1.199
Filename 'root.cramfs'.
Load address: 0x30008000
Loading: T #################################################################
#################################################################
#################################################################
#############################################################
done
Bytes transferred = 3743744 (392000 hex)
[up-class2410 #]
擦除NANDFLASH空间:
[up-class2410 #] nand erase 280000 400000
NAND erase: device 0 offset 0x280000, size 0x400000
Erasing at 0x67c000 -- 100% complete.
OK
[up-class2410 #]
写入NANDFLASH:
[up-class2410 #] nand write 30008000 280000 400000
NAND write: device 0 offset 0x280000, size 0x400000
4194304 bytes written: OK
[up-class2410 #]
固化到FLASH中后,ARM设备掉电内核不会丢失!
三、启动LINUX系统,挂载根文件系统
在U-BOOT中输入boot目录引导系统。
[up-class2410 #] boot
NAND read: device 0 offset 0x80000, size 0x380000
3670016 bytes read: OK
## Booting image at 30008000 ...
Image Name: Linux-2.6.24.4
Created: 20##-03-29 4:56:17 UTC
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 1814044 Bytes = 1.7 MB
Load Address: 30008000
Entry Point: 30008040
Verifying Checksum ... OK
test:hdr->ih_type:2
test:hdr->ih_comp:0
XIP Kernel Image ... OK
test:hdr->ih_type:2
test:hdr->ih_os:5
Starting kernel ...
test:machid:805306624
test: bi_boot_params:0x33f5bfb8
test:starting 1
Uncompressing Linux...................................................................................................................... done, booting the kernel.
Linux version 2.6.24.4 (root@vm-dev) (gcc version 3.4.6) #128 Mon Mar 29 12:55:10 CST 2010
CPU: ARM920T [41129200] revision 0 (ARMv4T), cr=00007177
Machine: SMDK2410
Memory policy: ECC disabled, Data cache writeback
CPU S3C2410A (id 0x32410002)
S3C2410: core 202.800 MHz, memory 101.400 MHz, peripheral 50.700 MHz
S3C24XX Clocks, (c) 20## 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 noinitrd console=ttySAC0,115200
irq: clearing pending ext status 00080000
irq: clearing subpending status 00000002
PID hash table entries: 256 (order: 8, 1024 bytes)
timer tcon=00500000, tcnt a509, tcfg 00000200,00000000, usec 00001e4c
Console: colour dummy device 80x30
console [ttySAC0] 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: 60672KB available (3316K code, 744K data, 132K init)
Mount-cache hash table entries: 512
CPU: Testing write buffer coherency: ok
net_namespace: 64 bytes
NET: Registered protocol family 16
S3C2410 Power Management, (c) 20## Simtec Electronics
S3C2410: Initialising architecture
S3C24XX DMA Driver, (c) 20##-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
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: 20## (order: 2, 16384 bytes)
TCP bind hash table entries: 20## (order: 1, 8192 bytes)
TCP: Hash tables configured (established 20## bind 2048)
TCP reno registered
NetWinder Floating Point Emulator V0.97 (double precision)
yaffs Mar 29 20## 10:08:47 Installing.
io scheduler noop registered
io scheduler anticipatory registered (default)
io scheduler deadline registered
io scheduler cfq registered
Console: switching to colour frame buffer device 80x30
fb0: s3c2410fb frame buffer device
lp: driver loaded but no devices found
ppdev: user-space parallel port driver
Serial: 8250/16550 driver $Revision: 1.90 $ 4 ports, IRQ sharing enabled
s3c2410-uart.0: s3c2410_serial0 at MMIO 0x50000000 (irq = 70) is a S3C2410
s3c2410-uart.1: s3c2410_serial1 at MMIO 0x50004000 (irq = 73) is a S3C2410
s3c2410-uart.2: s3c2410_serial2 at MMIO 0x50008000 (irq = 76) is a S3C2410
RAMDISK driver initialized: 16 RAM disks of 4096K size 1024 blocksize
loop: module loaded
DM9000: dm9k_init_module
Board init for dm9000a finished!
<DM9KS> I/O: c480e000, VID: 90000a46
eth0: at 0xc480e000 IRQ 18
eth0: Ethernet addr: 08:00:3e:26:0a:5b
Linux video capture interface: v2.00
Uniform Multi-Platform E-IDE driver Revision: 7.00alpha2
ide: Assuming 50MHz system bus speed for PIO modes; override with idebus=xx
Driver 'sd' needs updating - please use bus_type methods
S3C24XX NAND Driver, (c) 20## Simtec Electronics
s3c2410-nand s3c2410-nand: Tacls=3, 29ns Twrph0=7 69ns, Twrph1=3 29ns
NAND device: Manufacturer ID: 0xec, Chip ID: 0x76 (Samsung NAND 64MiB 3,3V 8-bit)
NAND_ECC_NONE selected by board driver. This is not recommended !!
Scanning device for bad blocks
Creating 4 MTD partitions on "NAND 64MiB 3,3V 8-bit":
0x00000000-0x00080000 : "Boot Agent"
0x00080000-0x00280000 : "S3C2410 kernel"
0x00280000-0x00680000 : "S3C2410 rootfs"
0x00680000-0x04000000 : "user"
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
usb usb1: Product: S3C24XX OHCI
usb usb1: Manufacturer: Linux 2.6.24.4 ohci_hcd
usb usb1: SerialNumber: s3c24xx
Initializing USB Mass Storage driver...
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
usb 1-1: Product: Standard USB Hub
usbcore: registered new interface driver usb-storage
USB Mass Storage support registered.
usbcore: registered new interface driver microtekX6
usbcore: registered new interface driver gspca
drivers/usb/media/gspcav1-20071224/gspca_core.c: gspca driver 00.60.00 registered
mice: PS/2 mouse device common for all mice
s3c2410 TouchScreen successfully loaded
input: s3c2410 TouchScreen as /class/input/input0
S3C24XX RTC, (c) 2004,2006 Simtec Electronics
s3c2410-rtc s3c2410-rtc: rtc disabled, re-enabling
s3c2410-rtc s3c2410-rtc: rtc core: registered s3c as rtc0
i2c /dev entries driver
s3c2410-i2c s3c2410-i2c: slave address 0x10
s3c2410-i2c s3c2410-i2c: bus frequency set to 99 KHz
s3c2410-i2c s3c2410-i2c: i2c-0: S3C I2C adapter
S3C2410 Watchdog Timer, (c) 20## Simtec Electronics
s3c2410-wdt s3c2410-wdt: watchdog inactive, reset disabled, irq enabled
TCP cubic registered
NET: Registered protocol family 1
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
s3c2410-rtc s3c2410-rtc: hctosys: invalid date/time
VFS: Mounted root (cramfs filesystem) readonly.
Freeing init memory: 132K
init started: BusyBox v1.12.2 (20##-03-29 13:05:22 CST)
Bad inittab entry at line 5
starting pid 796, tty '': '/etc/rc.d/rc.sysinit'
Setting system clock: hwclock: settimeofday() failed: Invalid argument
fail
Remounting root rw: done
Mounting devpts: done
Mounting tmpfs: done
Mounting applications on /root: yaffs: dev is 32505859 name is "mtdblock3"
yaffs: passed flags ""
yaffs: Attempting MTD mount on 31.3, "mtdblock3"
done
Setting hostname: done
Backup last logfiles: done
Cleaning up system: done
Setting up interface lo: done
Running start scripts.
Starting syslogd: done
Starting klogd: done
fail
[dmfe_tx_done] tx_pkt_cnt ERROR!!
Starting custom devices initing: done
Running vsftpd server.
starting pid 865, tty '': '/sbin/getty -L s3c2410_serial0 115200 vt100'
up-tech login: root
up-tech:~ #
输入root用户名称,系统顺利引导运行起来了。