分类:
2011-05-23 18:12:00
原文地址:构建基本的嵌入式Linux根文件系统 作者:tekkamanninja
构建基本的嵌入式Linux根文件系统
其实在去年8月份我做系统移植时就构建好了一个可以用的根文件系统,但是那时是跟着别人的《Linux全线移植文档》做的。有些东西我也不清楚,只是跟着做,做出来能用就了事了,没有深究其中的规范,以及文件系统中哪些要,哪些不要。
趁着今年过年的几天假期,我移植重新移植了U-Boot1.3.1和Linux2.6.24到S3C2410及S3C2440后,我想好好的看看有关文件系统构建方法和规范,整理整理构建根文件系统的文档。之后,我用了近一周的时间,慢慢研究《构建嵌入式Linux系统》这本书有关根文件系统的部分,以及一些网上的参考资料,不断地实验。构建好了一个精简的根文件系统,下面我只介绍构建的过程和方法,至于原理我给出以下参考资料,自己看吧。
1、 《Linux系统移植》:一个经典的Linux移植文档,共有95页的PDF文档,内容十分详细,里面有根文件系统的创建,还多地方都有下载(有的网站称之为《Linux系统全线移植文档》等等),很值得参考。在这里感谢文档的作者们。
2、 《构建嵌入式Linux系统》必看!里面对文件系统的构建讲的挺细。
3、 《Filesystem Hierarchy Standard》Linux文件系统的标准规范。我只看到英文的。
其他再遇到不懂的就google,基本上都是Linux的相关知识,都是找得到的。
|
在你想要建立根文件系统的地方,运行:
|
(2)配置、编译和安装Busybox-
|
修改Makefile文件:
[tekkamanninja@Tekkaman-Ninja busybox-1.9.1]$ pwd
/home/tekkamanninja/working/source/busybox-1.9.1
[tekkamanninja@Tekkaman-Ninja busybox-1.9.1]$ kwrite Makefile
......(第151-154行)
#SUBARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \
# -e s/arm.*/arm/ -e s/sa110/arm/ \
# -e s/s390x/s390/ -e s/parisc64/parisc/ \
# -e s/ppc.*/powerpc/ -e s/mips.*/mips/ )
......(第174行附近)
#ARCH ?= $(SUBARCH)
#CROSS_COMPILE ?=
ARCH = arm
CROSS_COMPILE = /home/tekkamanninja/working/gcc4.1.1/gcc-4.1.1-glibc-2.3.2/arm-9tdmi-linux-gnu/bin/arm-9tdmi-linux-gnu-
[tekkamanninja@Tekkaman-Ninja busybox-1.9.1]$ make menuconfig
在原有的基础上修改如下:
Busybox Settings --->
Installation Options --->
[*] Don't use /usr
(/home/tekkamanninja/working/nfs/rootfs) BusyBox installation prefix
Busybox Library Tuning --->
[*] Support for /etc/networks
[*] Additional editing keys
[*] vi-style line editing commands
(15) History size
[*] History saving
[*] Tab completion
[*] Username completion
[*] Fancy shell prompts
Login/Password Management Utilities --->选项全部N掉,后面单独使用TinyLogin。(因为集成的好像不是很好用,我自己的经验是这样)
Linux Module Utilities --->
[N] Support version 2.2.x to 2.4.x Linux kernels
Shells --->
--- Ash Shell Options 下的选项全选
|
我是动态编译所以查看一下需要的动态库
|
(3)修改和创建必要的文件。
|
1、增加为SHELL导入全局变量的文件/etc/profile
[tekkamanninja@Tekkaman-Ninja etc]$ kwrite profile
echo "Set PS export PS1="\\e[05; echo "Done" echo
# /etc/profile: system-wide .profile file for the Bourne shells
echoecho "Processing /etc/profile... "
# no-op
# Set search library path
echo "Set search library path in /etc/profile"
export LD_LIBRARY_PATH=/lib:/usr/lib
# Set user path
echo "Set user path in /etc/profile"
PATH=/bin:/sbin:/usr/bin:/usr/sbin
export PATH
# Set PS1
#注意:ash 除了SHELL变量外,支持\u、\h、\W、\$、\!、\n、\w 、\nnn(ASCII字符对应的八进制数)
#以及\e[xx;xxm (彩色特效)等等!
#而且前面还要多加一个 '\'!
2、增加初始化文件
[tekkamanninja@Tekkaman-Ninja etc]$ kwrite inittab
::sysinit:/etc/init.d/rcS
::respawn:-/bin/login
::restart:/sbin/init
::ctrlaltdel:/sbin/reboot
::shutdown:/bin/umount -a -r
::shutdown:/sbin/swapoff -a
[tekkamanninja@Tekkaman-Ninja etc]$ kwrite fstab
proc /proc proc defaults 0 0
none /tmp ramfs defaults 0 0
mdev /dev ramfs defaults 0 0
sysfs /sys sysfs defaults 0 0
3、增加初始化脚本
[tekkamanninja@Tekkaman-Ninja etc]$ kwrite init.d/rcS
|
4、删除备份文件
[tekkamanninja@Tekkaman-Ninja etc]$ rm *~ init.d/*~
5、为mdev创建配置文件
[tekkamanninja@Tekkaman-Ninja etc]$ vi mdev.conf
创建一个mdev.conf文件,内容可有可无。
(4)为使用用户登录功能移植TinyLogin
1、下载
从 下载tinylogin-snapshot.tar.bz2,并解压.
[tekkamanninja@Tekkaman-Ninja source]$ tar -xjvf tinylogin-snapshot.tar.bz2
[tekkamanninja@Tekkaman-Ninja source]$ cd tinylogin
[tekkamanninja@Tekkaman-Ninja tinylogin]$ kwrite Makefile
|
make: *** [install] 错误 1 [tekkamanninja@Tekkaman-Ninja tinylogin]$su 口令: [root@Tekkaman-Ninja tinylogin]# make PREFIX=/home/tekkamanninja/working/nfs/rootfs install [root@Tekkaman-Ninja tinylogin]# exit exit |
|
创建创建帐号及密码文件:
[tekkamanninja@Tekkaman-Ninja tinylogin]$ cd ../../nfs/rootfs/etc/
[tekkamanninja@Tekkaman-Ninja etc]$ su
口令:
[root@Tekkaman-Ninja etc]# cp /etc/passwd . ;cp /etc/shadow . ;cp /etc/group .
[root@Tekkaman-Ninja etc]# kwrite passwd
root:x:0:0:root:/root:/bin/sh
[root@Tekkaman-Ninja etc]# kwrite grouproot:x:0:root
[root@Tekkaman-Ninja etc]# kwrite shadow
root:$1$N8K8eEQe$.XkJo3xcsjOE6vo1jW9Nk/:13923:0:99999:7:::
[root@Tekkaman-Ninja etc]# rm *~
rm:是否删除 普通文件 “group~”? y
rm:是否删除 普通文件 “passwd~”? y
rm:是否删除 普通文件 “shadow~”? y
[root@Tekkaman-Ninja etc]# exit
exit
[tekkamanninja@Tekkaman-Ninja etc]$
这 3个文件是从Host中拷贝过来的,只留下root帐号。
那么现在 root的登陆密码和Host的登陆口令一致了,可以登录后再修改以及创建新用户。( 若使用以上文件,则root密码为tekkaman)
拷贝必需的动态库文件
[tekkamanninja@Tekkaman-Ninja lib]$ cp -d /home/tekkamanninja/working/gcc4.1.1/gcc-4.1.1-glibc-2.3.2/arm-9tdmi-linux-gnu/arm-9tdmi-linux-gnu/lib/ld* .
cp: 略过目录 “/home/tekkamanninja/working/gcc4.1.1/gcc-4.1.1-glibc-2.3.2/arm-9tdmi-linux-gnu/arm-9tdmi-linux-gnu/lib/ldscripts”
[tekkamanninja@Tekkaman-Ninja lib]$ cp /home/tekkamanninja/working/gcc4.1.1/gcc-4.1.1-glibc-2.3.2/arm-9tdmi-linux-gnu/arm-9tdmi-linux-gnu/lib/libc-2.3.2.so .;cp -d /home/tekkamanninja/working/gcc4.1.1/gcc-4.1.1-glibc-2.3.2/arm-9tdmi-linux-gnu/arm-9tdmi-linux-gnu/lib/libc.so.6 .
[tekkamanninja@Tekkaman-Ninja lib]$ cp /home/tekkamanninja/working/gcc4.1.1/gcc-4.1.1-glibc-2.3.2/arm-9tdmi-linux-gnu/arm-9tdmi-linux-gnu/lib/libm-* . ;cp -d /home/tekkamanninja/working/gcc4.1.1/gcc-4.1.1-glibc-2.3.2/arm-9tdmi-linux-gnu/arm-9tdmi-linux-gnu/lib/libm.s* .
[tekkamanninja@Tekkaman-Ninja lib]$ cp /home/tekkamanninja/working/gcc4.1.1/gcc-4.1.1-glibc-2.3.2/arm-9tdmi-linux-gnu/arm-9tdmi-linux-gnu/lib/libcrypt-* . ;cp -d /home/tekkamanninja/working/gcc4.1.1/gcc-4.1.1-glibc-2.3.2/arm-9tdmi-linux-gnu/arm-9tdmi-linux-gnu/lib/libcrypt.s* .
以上是最基本的文件。
一个最基本根文件系统构建完成!未压缩的文件系统总大小不到
以下是启动信息:
Processing /etc/profile... Set search library path in /etc/profile Set user path in /etc/profile Set PS Done [root@/root]#
U-Boot 1.3.1 (Feb 18 2008 - 16:04:40)
DRAM: 64 MB
Flash: 1 MB
NAND: NAND flash probing at 0x4E000000
64 MB
In: serial
Out: serial
Err: serial
Hit any key to stop autoboot: 0
dm9000 i/o: 0x20000300, id: 0x90000a46
MAC: 08:08:08:08:12:27
operating at 100M full duplex mode
File transfer via NFS from server 192.168.1.22; our IP address is 192.168.1.2
Filename '/home/tekkamanninja/working/nfs/zImage.img'.
Load address: 0x30008000
Loading: #################################################################
#################################################################
#################################################################
#################################################################
#######################################################
done
Bytes transferred = 1611092 (189554 hex)
## Booting image at 30008000 ...
Image Name: tekkamanninja
Created: 2008-02-19 0:48:31 UTC
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 1611028 Bytes = 1.5 MB
Load Address: 30008000
Entry Point: 30008040
Verifying Checksum ... OK
XIP Kernel Image ... OK
Starting kernel ...
Uncompressing Linux........................................................................................................ done, booting the kernel.
Linux version 2.6.24 (tekkamanninja@Tekkaman-Ninja) (gcc version 4.1.1) #4 Tue Feb 19 08:48:15 CST 2008
CPU: ARM920T [41129200] revision 0 (ARMv4T), cr=c0007177
Machine: Tekkaman2440
Memory policy: ECC disabled, Data cache writeback
CPU S3C2440A (id 0x32440001)
S3C244X: core 405.000 MHz, memory 101.250 MHz, peripheral 50.625 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: noinitrd root=/dev/nfs rw nfsroot=192.168.1.22:/home/tekkamanninja/working/nfs/rootfs ip=192.168.1.2:192.168.1.22::255.255.255.0 console=ttySAC0,115200 init=/linuxrc mem=64M
irq: clearing pending ext status 00000200
irq: clearing subpending status 00000002
PID hash table entries: 256 (order: 8, 1024 bytes)
timer tcon=00500000, tcnt a4ca, tcfg 00000200,00000000, usec 00001e57
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: 61440KB available (2980K code, 309K data, 120K 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) 2004 Simtec Electronics
S3C2440: Initialising architecture
S3C2440: IRQ Support
S3C2440: Clock Support, DVS off
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
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
NetWinder Floating Point Emulator V0.97 (double precision)
JFFS2 version 2.2. (NAND) © 2001-2006 Red Hat, Inc.
fuse init (API version 7.9)
yaffs Feb 15 2008 10:10:34 Installing.
io scheduler noop registered
io scheduler anticipatory registered (default)
io scheduler deadline registered
io scheduler cfq registered
Serial: 8250/16550 driver $Revision: 1.90 $ 4 ports, IRQ sharing enabled
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
RAMDISK driver initialized: 16 RAM disks of 4096K size 1024 blocksize
loop: module loaded
usbcore: registered new interface driver ub
dm9000 Ethernet Driver
eth0: dm9000 at f6100300,f6100304 IRQ 51 MAC: 08:08:08:08:12:27
Uniform Multi-Platform E-IDE driver Revision: 7.00alpha2
ide: Assuming 50MHz system bus speed for PIO modes; override with idebus=xx
S3C24XX NAND Driver, (c) 2004 Simtec Electronics
s3c2440-nand s3c2440-nand: Tacls=1, 9ns Twrph0=4 39ns, Twrph1=1 9ns
NAND device: Manufacturer ID: 0xec, Chip ID: 0x76 (Samsung NAND 64MiB 3,3V 8-bit)
Scanning device for bad blocks
Bad eraseblock 3579 at 0x037ec000
Creating 7 MTD partitions on "NAND 64MiB 3,3V 8-bit":
0x00000000-0x00030000 : "U-Boot-1.3.1"
0x00030000-0x00040000 : "U-Boot-1.3.1 Parameter"
0x00040000-0x00500000 : "Linux2.6.24 Kernel(JFFS2)"
0x00500000-0x00a00000 : "Root(cramfs)"
0x00a00000-0x00f00000 : "Root(JFFS2)"
0x00f00000-0x01400000 : "Root(YAFFS)"
0x01400000-0x04000000 : "DATA"
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 ohci_hcd
usb usb1: SerialNumber: s3c24xx
usbcore: registered new interface driver libusual
mice: PS/2 mouse device common for all mice
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
s3c2440-i2c s3c2440-i2c: slave address 0x10
s3c2440-i2c s3c2440-i2c: bus frequency set to 98 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
TCP cubic registered
NET: Registered protocol family 1
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
s3c2410-rtc s3c2410-rtc: setting system clock to 2008-02-20 16:01:20 UTC (1203523280)
eth0: link down
IP-Config: Complete:
device=eth0, addr=192.168.1.2, mask=255.255.255.0, gw=255.255.255.255,
host=192.168.1.2, domain=, nis-domain=(none),
bootserver=192.168.1.22, rootserver=192.168.1.22, rootpath=
Looking up port of RPC 100003/2 on 192.168.1.22
eth0: link up, 100Mbps, full-duplex, lpa 0x45E1
Looking up port of RPC 100005/1 on 192.168.1.22
VFS: Mounted root (nfs filesystem).
Freeing init memory: 120K
init started: BusyBox v1.9.1 (2008-02-20 14:54:41 CST)
starting pid 781, tty '': '/etc/init.d/rcS'
----------mount all
----------Starting mdev......
*********************************************************
Tekkaman Ninja 2440 Rootfs(nfs) 2008.2
Love Linux ! ! @@ Love Ke Ke ! !
********************************************************
starting pid 785, tty '': '/bin/login'
192.168.1.2 login: root
Password:
login[785]: root login on `console
以上我使用nfs挂载的,后面我会介绍如何挂载jffs2、cramfs以及yaffs文件系统,有了这个基本的文件系统以后,其他就好办了!以下是这个文件系统,编译器是gcc4.1.2(制作编译器所用内核为2.6.24)。
文件:
rootfs.tar.bz2
大小:
1218KB
下载:
下载