《构建基本的嵌入式Linux根文件系统.doc》由会员分享,可在线阅读,更多相关《构建基本的嵌入式Linux根文件系统.doc(19页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、构建基本的嵌入式Linux根文件系统其实在去年8月份我做系统移植时就构建好了一个可以用的根文件系统,但是那时是跟着别人的Linux全线移植文档做的。有些东西我也不清楚,只是跟着做,做出来能用就了事了,没有深究其中的规范,以及文件系统中哪些要,哪些不要。趁着今年过年的几天假期,我移植重新移植了U-Boot1.3.1和Linux2.6.24到S3C2410及S3C2440后,我想好好的看看有关文件系统构建方法和规范,整理整理构建根文件系统的文档。之后,我用了近一周的时间,慢慢研究构建嵌入式Linux系统这本书有关根文件系统的部分,以及一些网上的参考资料,不断地实验。构建好了一个精简的根文件系统,下
2、面我只介绍构建的过程和方法,至于原理我给出以下参考资料,自己看吧。 1、 Linux系统移植:一个经典的Linux移植文档,共有95页的PDF文档,内容十分详细,里面有根文件系统的创建,还多地方都有下载(有的网站称之为Linux系统全线移植文档等等),很值得参考。在这里感谢文档的作者们。2、 构建嵌入式Linux系统必看!里面对文件系统的构建讲的挺细。3、 Filesystem Hierarchy StandardLinux文件系统的标准规范。我只看到英文的。其他再遇到不懂的就google,基本上都是Linux的相关知识,都是找得到的。 (1)创建根文件系统的基本目录结构。我把这个过程做成了s
3、hell脚本(文件名为mkroot) ,很方便! #! /bin/shecho creatint rootfs dir.mkdir rootfscd rootfsecho making dir : bin dev etc lib proc sbin sys usrmkdir bin dev etc lib proc sbin sys usr #必备的8个目录mkdir usr/bin usr/lib usr/sbin lib/modules# Dont use mknod ,unless you run this Script as root !#mknod -m 600 dev/consol
4、e c 5 1#mknod -m 666 dev/null c 1 3echo making dir : mnt tmp varmkdir mnt tmp varchmod 1777 tmpmkdir mnt/etc mnt/jffs2 mnt/yaffs mnt/data mnt/tempmkdir var/lib var/lock var/log var/run var/tmpchmod 1777 var/tmpecho making dir : home root bootmkdir home root bootecho done在你想要建立根文件系统的地方,运行: tekkamanni
5、njaTekkaman-Ninja nfs$ ./mkrootcreatint rootfs dir.making dir : bin dev etc lib proc sbin sys usrmaking dir : mnt tmp varmaking dir : home root bootdonetekkamanninjaTekkaman-Ninja nfs$ cd rootfs/dev/tekkamanninjaTekkaman-Ninja dev$ su口令:rootTekkaman-Ninja dev# mknod -m 600 console c 5 1;mknod -m 666
6、 null c 1 3;exitexittekkamanninjaTekkaman-Ninja dev$ (2)配置、编译和安装Busybox-1.9.1tekkamanninjaTekkaman-Ninja source$ tar -xjvf busybox-1.9.1.tar.bz2 修改Makefile文件: tekkamanninjaTekkaman-Ninja busybox-1.9.1$ pwd/home/tekkamanninja/working/source/busybox-1.9.1tekkamanninjaTekkaman-Ninja busybox-1.9.1$ kwri
7、te 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 = armCROSS_COMPILE = /home/tekkamanninja/
8、working/gcc4.1.1/gcc-4.1.1-glibc-2.3.2/arm-9tdmi-linux-gnu/bin/arm-9tdmi-linux-gnu-tekkamanninjaTekkaman-Ninja busybox-1.9.1$ make menuconfig在原有的基础上修改如下:Busybox Settings -Installation Options -* Dont use /usr(/home/tekkamanninja/working/nfs/rootfs) BusyBox installation prefix Busybox Library Tuning
9、- * Support for /etc/networks * Additional editing keys * vi-style line editing commands (15) History size * History saving * Tab completion * Username completion * Fancy shell promptsLogin/Password Management Utilities -选项全部N掉,后面单独使用TinyLogin。(因为集成的好像不是很好用,我自己的经验是这样)Linux Module Utilities - N Suppo
10、rt version 2.2.x to 2.4.x Linux kernels Shells - - Ash Shell Options 下的选项全选tekkamanninjaTekkaman-Ninja busybox-1.9.1$ make.LINK busybox_unstrippedTrying libraries: crypt mLibrary crypt is neededLibrary m is neededFinal link with: crypt mtekkamanninjaTekkaman-Ninja busybox-1.9.1$ make install我是动态编译所以
11、查看一下需要的动态库tekkamanninjaTekkaman-Ninja busybox-1.9.1$ /home/tekkamanninja/working/gcc4.1.1/gcc-4.1.1-glibc-2.3.2/arm-9tdmi-linux-gnu/bin/arm-9tdmi-linux-gnu-readelf -d busyboxDynamic section at offset 0xac014 contains 22 entries:Tag Type Name/Value0x00000001 (NEEDED) Shared library: libcrypt.so.10x00
12、000001 (NEEDED) Shared library: libm.so.60x00000001 (NEEDED) Shared library: libc.so.60x0000000c (INIT) 0xc0f00x0000000d (FINI) 0x976080x00000004 (HASH) 0x80e80x00000005 (STRTAB) 0xa3c00x00000006 (SYMTAB) 0x8b300x0000000a (STRSZ) 3371 (bytes)0x0000000b (SYMENT) 16 (bytes)0x00000015 (DEBUG) 0x00x0000
13、0003 (PLTGOT) 0xbc0ec0x00000002 (PLTRELSZ) 2976 (bytes)0x00000014 (PLTREL) REL0x00000017 (JMPREL) 0xb5500x00000011 (REL) 0xb4e00x00000012 (RELSZ) 112 (bytes)0x00000013 (RELENT) 8 (bytes)0x6ffffffe (VERNEED) 0xb4000x6fffffff (VERNEEDNUM) 30x6ffffff0 (VERSYM) 0xb0ec0x00000000 (NULL) 0x0(3)修改和创建必要的文件。
14、tekkamanninjaTekkaman-Ninja busybox-1.9.1$ cp -a examples/bootfloppy/etc/* /home/tekkamanninja/working/nfs/rootfs/etc/tekkamanninjaTekkaman-Ninja busybox-1.9.1$ cd ././nfs/rootfs/etc/1、增加为SHELL导入全局变量的文件/etc/profiletekkamanninjaTekkaman-Ninja etc$ kwrite profile# /etc/profile: system-wide .profile fi
15、le for the Bourne shellsechoecho Processing /etc/profile. # no-op# Set search library pathecho Set search library path in /etc/profileexport LD_LIBRARY_PATH=/lib:/usr/lib# Set user pathecho Set user path in /etc/profilePATH=/bin:/sbin:/usr/bin:/usr/sbinexport PATH# Set PS1 #注意:ash 除了SHELL变量外,支持u、h、W
16、、$、!、n、w 、nnn(ASCII字符对应的八进制数)#以及exx;xxm (彩色特效)等等!#而且前面还要多加一个 !echo Set PS1 in /etc/profileexport PS1=e05;32m$USERwa$e00;34mecho Doneecho2、增加初始化文件tekkamanninjaTekkaman-Ninja etc$ kwrite inittab :sysinit:/etc/init.d/rcS:respawn:-/bin/login:restart:/sbin/init :ctrlaltdel:/sbin/reboot:shutdown:/bin/umou
17、nt -a -r:shutdown:/sbin/swapoff -atekkamanninjaTekkaman-Ninja etc$ kwrite fstab proc /proc proc defaults 0 0none /tmp ramfs defaults 0 0mdev /dev ramfs defaults 0 0sysfs /sys sysfs defaults 0 03、增加初始化脚本tekkamanninjaTekkaman-Ninja etc$ kwrite init.d/rcS#! /bin/shecho -mount all/bin/mount -aecho -Star
18、ting mdev./bin/echo /sbin/mdev /proc/sys/kernel/hotplugmdev -secho *echo Tekkaman Ninja 2440 Rootfs(nfs) 2008.2 echo Love Linux ! ! Love Ke Ke ! ! echo *4、删除备份文件tekkamanninjaTekkaman-Ninja etc$ rm * init.d/*5、为mdev创建配置文件tekkamanninjaTekkaman-Ninja etc$ vi mdev.conf创建一个mdev.conf文件,内容可有可无。 (4)为使用用户登录功
19、能移植TinyLogin1、下载从 下载tinylogin-snapshot.tar.bz2,并解压.tekkamanninjaTekkaman-Ninja source$ tar -xjvf tinylogin-snapshot.tar.bz22、修改tinyLogin的MakefiletekkamanninjaTekkaman-Ninja source$ cd tinylogintekkamanninjaTekkaman-Ninja tinylogin$ kwrite Makefile指明tinyLogin使用自己的算法来处理用户密码 USE_SYSTEM_PWD_GRP = false.
20、 CROSS =/home/tekkamanninja/working/gcc4.1.1/gcc-4.1.1-glibc-2.3.2/arm-9tdmi-linux-gnu/bin/arm-9tdmi-linux-gnu-CC = $(CROSS)gccAR = $(CROSS)arSTRIPTOOL = $(CROSS)strip3、 编译并安装 tekkamanninjaTekkaman-Ninja tinylogin$ make PREFIX=/home/tekkamanninja/working/nfs/rootfs installAborting install - You must
21、 be root, otherwise I cant.make tinylogin be setuid root, which will cause it to fail.make: * install 错误 1tekkamanninjaTekkaman-Ninja tinylogin$su口令:rootTekkaman-Ninja tinylogin# make PREFIX=/home/tekkamanninja/working/nfs/rootfs installrootTekkaman-Ninja tinylogin# exitexit我是动态编译所以查看一下需要的动态库 tekkam
22、anninjaTekkaman-Ninja tinylogin$ /home/tekkamanninja/working/gcc4.1.1/gcc-4.1.1-glibc-2.3.2/arm-9tdmi-linux-gnu/bin/arm-9tdmi-linux-gnu-readelf -d tinyloginDynamic section at offset 0x9670 contains 21 entries:Tag Type Name/Value0x00000001 (NEEDED) Shared library: libcrypt.so.10x00000001 (NEEDED) Sha
23、red library: libc.so.60x0000000c (INIT) 0x9c400x0000000d (FINI) 0x101600x00000004 (HASH) 0x81280x00000005 (STRTAB) 0x90700x00000006 (SYMTAB) 0x85e00x0000000a (STRSZ) 1430 (bytes)0x0000000b (SYMENT) 16 (bytes)0x00000015 (DEBUG) 0x00x00000003 (PLTGOT) 0x197400x00000002 (PLTRELSZ) 1064 (bytes)0x0000001
24、4 (PLTREL) REL0x00000017 (JMPREL) 0x98180x00000011 (REL) 0x97c80x00000012 (RELSZ) 80 (bytes)0x00000013 (RELENT) 8 (bytes)0x6ffffffe (VERNEED) 0x97580x6fffffff (VERNEEDNUM) 20x6ffffff0 (VERSYM) 0x96060x00000000 (NULL) 0x0创建创建帐号及密码文件: tekkamanninjaTekkaman-Ninja tinylogin$ cd ././nfs/rootfs/etc/tekkam
25、anninjaTekkaman-Ninja etc$ su口令:rootTekkaman-Ninja etc# cp /etc/passwd . ;cp /etc/shadow . ;cp /etc/group .rootTekkaman-Ninja etc# kwrite passwdroot:x:0:0:root:/root:/bin/shrootTekkaman-Ninja etc# kwrite grouproot:x:0:rootrootTekkaman-Ninja etc# kwrite shadowroot:$1$N8K8eEQe$.XkJo3xcsjOE6vo1jW9Nk/:1
26、3923:0:99999:7:rootTekkaman-Ninja etc# rm *rm:是否删除 普通文件 “group”? yrm:是否删除 普通文件 “passwd”? yrm:是否删除 普通文件 “shadow”? yrootTekkaman-Ninja etc# exitexittekkamanninjaTekkaman-Ninja etc$ 这 3个文件是从Host中拷贝过来的,只留下root帐号。那么现在 root的登陆密码和Host的登陆口令一致了,可以登录后再修改以及创建新用户。(若使用以上文件,则root密码为tekkaman)拷贝必需的动态库文件 tekkamannin
27、jaTekkaman-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”tekkamanninjaTekkaman-Ninja lib$ cp /home
28、/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 .tekkamanninjaTekkaman-Ninja lib$ cp /home/tekkamanninja/working/gc
29、c4.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* .tekkamanninjaTekkaman-Ninja lib$ cp /home/tekkamanninja/working/gcc4.1.1/gcc-4.1.1-glibc-2.3.2/arm-
30、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* .以上是最基本的文件。一个最基本根文件系统构建完成!未压缩的文件系统总大小不到3M。以下是启动信息: U-Boot 1.3.1 (Feb 18 2008 - 16:04:40)DRAM: 64 MBFlash: 1 MBNAND: NAND flas
31、h probing at 0x4E00000064 MBIn: serialOut: serialErr: serialHit any key to stop autoboot: 0dm9000 i/o: 0x20000300, id: 0x90000a46MAC: 08:08:08:08:12:27operating at 100M full duplex modeFile transfer via NFS from server 192.168.1.22; our IP address is 192.168.1.2Filename /home/tekkamanninja/working/n
32、fs/zImage.img.Load address: 0x30008000Loading: #doneBytes transferred = 1611092 (189554 hex)# Booting image at 30008000 .Image Name: tekkamanninjaCreated: 2008-02-19 0:48:31 UTCImage Type: ARM Linux Kernel Image (uncompressed)Data Size: 1611028 Bytes = 1.5 MBLoad Address: 30008000Entry Point: 300080
33、40Verifying Checksum . OKXIP Kernel Image . OKStarting kernel .Uncompressing Linux. done, booting the kernel.Linux version 2.6.24 (tekkamanninjaTekkaman-Ninja) (gcc version 4.1.1) #4 Tue Feb 19 08:48:15 CST 2008CPU: ARM920T 41129200 revision 0 (ARMv4T), cr=c0007177Machine: Tekkaman2440Memory policy:
34、 ECC disabled, Data cache writebackCPU S3C2440A (id 0x32440001)S3C244X: core 405.000 MHz, memory 101.250 MHz, peripheral 50.625 MHzS3C24XX Clocks, (c) 2004 Simtec ElectronicsCLOCK: Slow mode (1.500 MHz), fast, MPLL on, UPLL onCPU0: D VIVT write-back cacheCPU0: I cache: 16384 bytes, associativity 64,
35、 32 byte lines, 8 setsCPU0: D cache: 16384 bytes, associativity 64, 32 byte lines, 8 setsBuilt 1 zonelists in Zone order, mobility grouping on. Total pages: 16256Kernel 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
36、.255.255.0 console=ttySAC0,115200 init=/linuxrc mem=64Mirq: clearing pending ext status 00000200irq: clearing subpending status 00000002PID hash table entries: 256 (order: 8, 1024 bytes)timer tcon=00500000, tcnt a4ca, tcfg 00000200,00000000, usec 00001e57Console: colour dummy device 80x30console tty
37、SAC0 enabledDentry cache hash table entries: 8192 (order: 3, 32768 bytes)Inode-cache hash table entries: 4096 (order: 2, 16384 bytes)Memory: 64MB = 64MB totalMemory: 61440KB available (2980K code, 309K data, 120K init)Mount-cache hash table entries: 512CPU: Testing write buffer coherency: oknet_name
38、space: 64 bytesNET: Registered protocol family 16S3C2410 Power Management, (c) 2004 Simtec ElectronicsS3C2440: Initialising architectureS3C2440: IRQ SupportS3C2440: Clock Support, DVS offS3C24XX DMA Driver, (c) 2003-2004,2006 Simtec ElectronicsDMA channel 0 at c4800000, irq 33DMA channel 1 at c48000
39、40, irq 34DMA channel 2 at c4800080, irq 35DMA channel 3 at c48000c0, irq 36usbcore: registered new interface driver usbfsusbcore: registered new interface driver hubusbcore: registered new device driver usbNET: Registered protocol family 2IP route cache hash table entries: 1024 (order: 0, 4096 byte
40、s)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 registeredNetWinder Floating Point Emulator V0.97 (double precision)JFFS2 version 2.2. (NAND) © 2001-2006 Re
41、d Hat, Inc.fuse init (API version 7.9)yaffs Feb 15 2008 10:10:34 Installing.io scheduler noop registeredio scheduler anticipatory registered (default)io scheduler deadline registeredio scheduler cfq registeredSerial: 8250/16550 driver $Revision: 1.90 $ 4 ports, IRQ sharing enableds3c2440-uart.0: s3c
42、2410_serial0 at MMIO 0x50000000 (irq = 70) is a S3C2440s3c2440-uart.1: s3c2410_serial1 at MMIO 0x50004000 (irq = 73) is a S3C2440s3c2440-uart.2: s3c2410_serial2 at MMIO 0x50008000 (irq = 76) is a S3C2440RAMDISK driver initialized: 16 RAM disks of 4096K size 1024 blocksizeloop: module loadedusbcore:
43、registered new interface driver ubdm9000 Ethernet Drivereth0: dm9000 at f6100300,f6100304 IRQ 51 MAC: 08:08:08:08:12:27Uniform Multi-Platform E-IDE driver Revision: 7.00alpha2ide: Assuming 50MHz system bus speed for PIO modes; override with idebus=xxS3C24XX NAND Driver, (c) 2004 Simtec Electronicss3c2440-nand s3c2440-nand: Tacls=1, 9ns Twrph