参考 《Mini2440_Linux移植开发实战指南.pdf》中的“使用 Busybox 构建文件系统”,还是有些问题,我自己的为主要原因。详细的文件系统的介绍与理解,自己搜索查看相关资料吧,我这里仅是记录操作步骤与遇到的问题。指南手册可以在我的资源中下载。

环境介绍:

busybox版本:busybox-1.16.0
Linux平台:虚拟机下Fedora 11  自己原来编译的gcc在debian6下,因此在debian6下也顺利
交叉编译工具:fedora 11 :gcc-4.3.2   debian 6 :gcc 4.4.5  
arm开发板:mini2440(CPU:S3C2440 ,SDRAM:64M,Nor Flash:2M,Nand Flash:256M,网卡:DM9000EP)

全部过程主要还是在debian下完成的,在Fedora下仅编译了busybox1.13。

    基本步骤:建立根文件系统目录,安装busybox,拷贝动态链接库,建立配置文件,制作根文件系统镜像
    1.下载源码
http://www.busybox.net/downloads/    busybox-1.16.0.tar.bz2
    2.建立系统目录
通过一个shell脚本来完成,文件名create_rootfs_sh,内容如下:
#!/bin/sh
echo "------Create rootfs directons start...--------"
mkdir rootfs
cd rootfs
echo "--------Create root,dev....----------"
mkdir root dev etc boot tmp var sys proc lib mnt home usr
mkdir etc/init.d etc/rc.d etc/sysconfig
mkdir usr/sbin usr/bin usr/lib usr/modules
echo "make node in dev/console dev/null"
mknod -m 600 dev/console c 5 1
mknod -m 600 dev/null c 1 3
mkdir mnt/etc mnt/jffs2 mnt/yaffs mnt/data mnt/temp
mkdir var/lib var/lock var/run var/tmp
chmod 1777 tmp
chmod 1777 var/tmp
echo "-------make direction done---------"
与参考文章相比,仅增加了usr目录,执行#./create_rootfs_sh ,可以看到根目录文件夹名为rootfs
输出:
------Create rootfs directons start...--------
--------Create root,dev....----------
make node in dev/console dev/null
-------make direction done--------
    3.安装busybox
    a.修改Makefile 文件:
CROSS_COMPILE ?=arm-linux- 
ARCH ?=arm
    b.配置busybox
    输入 make menuconfig 进行配置:
(1)、Busybox Settings--->
General Configuration--->
[*] Show verbose applet usage messages
[*] Store applet usage messages in compressed form
[*] Support –install [-s] to install applet links at runtime
[*] Enable locale support(system needs locale for this to work)
[*] Support for –long-options
[*] Use the devpts filesystem for unix98 PTYs
[*] Support writing pidfiles
[*] Runtime SUID/SGID configuration via /etc/busybox.config
[*] Suppress warning message if /etc/busybox.conf is not readable
Build Options--->
[*] Build BusyBox as a static binary(no shared libs)
[*] Build with Large File Support(for accessing files>2GB)
Installation Options->
[]Don’t use /usr
Applets links (as soft-links) --->
(./_install) BusyBox installation prefix
Busybox Library Tuning --->
(6)Minimum password legth
(2)MD5:Trade Bytes for Speed
[*]Fsater /proc scanning code(+100bytes)
[*]Command line editing
(1024)Maximum length of input
[*] vi-style line editing commands
(15) History size
[*] History saving
[*] Tab completion
[*]Fancy shell prompts
(4) Copy buffer size ,in kilobytes
[*]Use ioctl names rather than hex values in error messages
[*]Support infiniband HW
(2)、Linux Module Utilities--->
(/lib/modules)Default directory containing modules
(modules.dep)Default name of modules.dep
[*] insmod
[*] rmmod
[*] lsmod
[*] modprobe
-----options common to multiple modutils
[ ] support version 2.2/2.4 Linux kernels
[*]Support tainted module checking with new kernels
[*]Support for module .aliases file
[*] support for modules.symbols file
Linux System Utilities --->
[*]Support /etc/mdev.conf
[*]Support command execution at device addition/removal

    我这里直接复制参考手册上的了,其中有些选项是不太一样的,自己对应的进入查看会发现的,例如红色文字标出的。
    c.编译安装busybox
#make CONFIG_PREFIX=/opt/studyarm/rootfs install
在rootfs 目录下会生成目录bin、sbin、usr 和文件linuxrc 的内容。
    4.拷贝动态链接库
    这里的动态链接库主要是生成的busybox使用的,因此可以从你的交叉工具链文件夹下拷贝lib目录中的动态链接库文件,例如我的在tools目录下执行
#cp tools/lib/*.so* /rootfs/lib -d
    很多地方都说这里的库文件不一定都用得到,可以使用arm-linux-readelf命令查看busybox所需用的库文件,并把相关的拷贝进来;例如:
#arm-linux-readelf -a busybox | grep Shared
输出:
 0x00000001 (NEEDED)                     Shared library: [libcrypt.so.1]
 0x00000001 (NEEDED)                     Shared library: [libm.so.6]
 0x00000001 (NEEDED)                     Shared library: [libc.so.6]
不用看着这三个就直接拷贝就完了,对应的它们还是有需用的链接库的,可以再使用刚才的命令查看,有些麻烦。
    5.建立配置文件
(1)etc/mdev.conf 文件,内容为空。
(2)拷贝主机etc 目录下的passwd、group、shadow 文件到rootfs/etc 目录下。
(3)etc/sysconfig 目录下新建文件HOSTNAME,内容为”AL-Study”,这个其实没有什么关系,就是在板子上运行命令的时候命令前显示的显示,类似[root@debian6]。
(4)etc/inittab 文件:我的前文开机自动设置和这个就有关了。
#etc/inittab
::sysinit:/etc/init.d/rcS
s3c2410_serial0::askfirst:-/bin/sh
::ctrlaltdel:/sbin/reboot
::shutdown:/bin/umount -a –r
(5)etc/init.d/rcS 文件:
#!/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
runlevel=S
prevlevel=N
umask 022
export PATH runlevel prevlevel
echo "----------mount rootfs success----------------"
mount -a
echo /sbin/mdev>/proc/sys/kernel/hotplug
mdev -s
echo "***********************************************"
echo "**************Studying ARM Linux***************"
echo "Kernel version:linux-2.6.32.2"
echo "Date:2011.10.25"
echo "***********************************************"

/bin/hostname -F /etc/sysconfig/HOSTNAME
(或者直接 /bin/hostname AL-Study )
使用以下命令改变 rcS 的执行权限:
chmod +x rcS
(6)etc/fstab 文件:
#device mount-point type option dump fsck order
proc /proc proc defaults 0 0
none /tmp ramfs defaults 0 0
sysfs /sys sysfs defaults 0 0
mdev /dev ramfs defaults 0 0
(7)etc/profile 文件:
#Ash profile
#vim:syntax=sh
#No core file by defaults
#ulimit -S -c 0>/dev/null 2>&1
USER="id -un"
LOGNAME=$USER
PS1='[\u@\h=W]#'
PATH=$PATH
HOSTNAME='/bin/hostname'
export USER LOGNAME PS1 PATH
    6.制作根文件系统镜像
利用mkyaffs2image-128M,解压原厂提供的压缩包,执行命令rootfs为自己制作的根文件系统目录
#./usr/sbin/mkyaffs2image-128M rootfs rootfs.bin
    在nor flash下启动,y命令下载文件系统,再用b命令引导,查看。最后输出有:
yaffs: dev is 32505859 name is "mtdblock3" rw
yaffs: passed flags ""
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
VFS: Mounted root (yaffs filesystem) on device 31:3.
Freeing init memory: 132K
----------mount rootfs success----------------
***********************************************
**************Studying ARM Linux***************
Kernel version:linux-2.6.32.2
Date:2011.10.25
***********************************************



Please press Enter to activate this console.


下面补充些遇到的问题:
内核启动到最后出现:
Kernel panic - not syncing: Attempted to kill init!
Backtrace:
[<c002e270>] (dump_backtrace+0x0/0x10c) from [<c03a600c>] (dump_stack+0x18/0x1c)


 r7:c3820000 r6:c0518450 r5:00000004 r4:00000004
[<c03a5ff4>] (dump_stack+0x0/0x1c) from [<c03a605c>] (panic+0x4c/0x134)
[<c03a6010>] (panic+0x0/0x134) from [<c00466d8>] (do_exit+0x534/0x62c)
没遇到最后,我是在用自己前面建立的工具链编译的时候出现的问题,由于在Fedora下使用busybox1.13没有问题,因此初步怀疑是前面的工具链问题,因此按照原来的方法,并且再编译gcc时加上了
--with-arch=armv4t --with-cpu=arm920t --with-tune=arm920t
在编译busybox1.16时没有问题了,但是在编译busybox1.13(原厂提供的)出现了如下问题
/linuxrc: error while loading shared libraries: libcrypt.so.1: cannot open share
d object file: No such file or directory
Kernel panic - not syncing: Attempted to kill init!
[<c002fd20>] (unwind_backtrace+0x0/0xd8) from [<c02e7754>] (panic+0x40/0x118)
而且一直没有解决,唯一的区别就是配置采用的是拷贝原厂提供的配置文件。


    最后补充一下的是,把前文综合测试下,构建自己的嵌入式系统。首先肯定是自己的交叉工具链,一直在使用,完成对移植好的u-boot编译,生成u-boot.bin文件;编译linux内核生成zImage,再使用u-boot的tools目录下的工具制作成uImage;最后制作完成的文件系统,生成rootfs.bin文件;nor flash启动板子,选择a下载u-boot,然后通过nand flash启动,在3秒内,按任意键,进入u-boot命令行,通过nfs下载linux内核;由于我制作的u-boot还不支持对yaffs文件系统的下载,再通过nor flash启动,y命令下载文件系统,最后nand flash启动,即可完成。启动信息如下:
-Boot 2010.06 (Oct 17 2011 - 21:01:36)


DRAM:  64 MiB
Flash: 512 KiB
NAND:  256 MiB
In:    serial
Out:   serial
Err:   serial
Net:   dm9000
Hit any key to stop autoboot:  0


NAND read: device 0 offset 0x60000, size 0x500000
 5242880 bytes read: OK
## Booting kernel from Legacy Image at 30008000 ...
   Image Name:   micro_linux
   Created:      2011-10-25   5:47:30 UTC
   Image Type:   ARM Linux Kernel Image (uncompressed)
   Data Size:    2119664 Bytes = 2 MiB
   Load Address: 30008000
   Entry Point:  30008040
   Verifying Checksum ... OK
   XIP Kernel Image ... OK
OK


Starting kernel ...


Uncompressing Linux.............................................................
...................................................................... done, boo
ting the kernel.
Linux version 2.6.32.2 (root@debian6) (gcc version 4.4.5 (GCC) ) #18 Mon Oct 24
15:45:06 CST 2011
CPU: ARM920T [41129200] revision 0 (ARMv4T), cr=00007177
CPU: VIVT data cache, VIVT instruction cache
Machine: micro2440 board test
Memory policy: ECC disabled, Data cache writeback
CPU S3C2440A (id 0x32440001)
S3C24XX Clocks, (c) 2004 Simtec Electronics
S3C244X: core 405.000 MHz, memory 101.250 MHz, peripheral 50.625 MHz
CLOCK: Slow mode (1.500 MHz), fast, MPLL on, UPLL on
Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 16256
Kernel command line: noinitrd console=ttySAC0,115200  init=/linuxrc mem=64M root
=/dev/mtdblock3 rw rootfstype=yaffs ip=10.1.0.129:10.1.0.128:10.1.0.1:255.255.25
5.0::eth0:off
PID hash table entries: 256 (order: -2, 1024 bytes)
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: 60512KB available (3696K code, 418K data, 132K init, 0K highmem)
SLUB: Genslabs=11, HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
Hierarchical RCU implementation.
NR_IRQS:85
irq: clearing subpending status 00000002
Console: colour dummy device 80x30
console [ttySAC0] enabled
Calibrating delay loop... 50.38 BogoMIPS (lpj=125952)
Mount-cache hash table entries: 512
CPU: Testing write buffer coherency: ok
NET: Registered protocol family 16
S3C2440: Initialising architecture
S3C2440: IRQ Support
S3C24XX DMA Driver, (c) 2003-2004,2006 Simtec Electronics
DMA channel 0 at c4808000, irq 33
DMA channel 1 at c4808040, irq 34
DMA channel 2 at c4808080, irq 35
DMA channel 3 at c48080c0, irq 36
S3C244X: Clock Support, DVS off
bio: create slab <bio-0> at 0
usbcore: registered new interface driver usbfs
usbcore: registered new interface driver hub
usbcore: registered new device driver usb
s3c-i2c s3c2440-i2c: slave address 0x10
s3c-i2c s3c2440-i2c: bus frequency set to 98 KHz
s3c-i2c s3c2440-i2c: i2c-0: S3C I2C adapter
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
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
RPC: Registered tcp NFSv4.1 backchannel transport module.
JFFS2 version 2.2. (NAND) ? 2001-2006 Red Hat, Inc.
ROMFS MTD (C) 2007 Red Hat, Inc.
msgmni has been set to 118
alg: No test for stdrng (krng)
io scheduler noop registered
io scheduler anticipatory registered (default)
io scheduler deadline registered
io scheduler cfq registered
Console: switching to colour frame buffer device 60x53
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
S3C24XX NAND Driver, (c) 2004 Simtec Electronics
s3c24xx-nand s3c2440-nand: Tacls=3, 29ns Twrph0=7 69ns, Twrph1=3 29ns
s3c24xx-nand s3c2440-nand: NAND soft ECC
NAND device: Manufacturer ID: 0xec, Chip ID: 0xda (Samsung NAND 256MiB 3,3V 8-bi
t)
Scanning device for bad blocks
Bad eraseblock 384 at 0x000003000000
Bad eraseblock 385 at 0x000003020000
Bad eraseblock 431 at 0x0000035e0000
Bad eraseblock 447 at 0x0000037e0000
Bad eraseblock 950 at 0x0000076c0000
Bad eraseblock 1098 at 0x000008940000
Creating 5 MTD partitions on "NAND 256MiB 3,3V 8-bit":
0x000000000000-0x000000040000 : "u-boot"
0x000000040000-0x000000060000 : "param"
ftl_cs: FTL header not found.
0x000000060000-0x000000560000 : "kernel"
ftl_cs: FTL header not found.
0x000000560000-0x000040560000 : "root"

mtd: partition "root" extends beyond the end of device "NAND 256MiB 3,3V 8-bit"
-- size truncated to 0xfaa0000
ftl_cs: FTL header not found.
0x000000000000-0x000040000000 : "nand"
mtd: partition "nand" extends beyond the end of device "NAND 256MiB 3,3V 8-bit"
-- size truncated to 0x10000000
dm9000 Ethernet Driver, V1.31
ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver
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
usbcore: registered new interface driver libusual
mice: PS/2 mouse device common for all mice
S3C24XX RTC, (c) 2004,2006 Simtec Electronics
i2c /dev entries driver
S3C2410 Watchdog Timer, (c) 2004 Simtec Electronics
s3c2410-wdt s3c2410-wdt: watchdog inactive, reset disabled, irq enabled
cpuidle: using governor ladder
sdhci: Secure Digital Host Controller Interface driver
sdhci: Copyright(c) Pierre Ossman
usbcore: registered new interface driver hiddev
usbcore: registered new interface driver usbhid
usbhid: v2.6:USB HID core driver
Advanced Linux Sound Architecture Driver Version 1.0.21.
No device for DAI UDA134X
No device for DAI s3c24xx-i2s
ALSA device list:
  No soundcards found.
TCP cubic registered
NET: Registered protocol family 17
drivers/rtc/hctosys.c: unable to open rtc device (rtc0)
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
IP-Config: Device `eth0' not found.
yaffs: dev is 32505859 name is "mtdblock3" rw
yaffs: passed flags ""
VFS: Mounted root (yaffs filesystem) on device 31:3.
Freeing init memory: 132K
----------mount rootfs success----------------
***********************************************
**************Studying ARM Linux***************
Kernel version:linux-2.6.32.2
Date:2011.10.25
***********************************************



Please press Enter to activate this console.


    好了,应该勉强看上去可以了。以后可以增加各种驱动支持,功能丰富了。发现自己写得越来越不清晰了,可能觉得很多步骤都不用写那么详细了,所以有些混乱的感觉。以上这些全是自己操作的记录,现在突然明白有时候为什么和别人一样的环境却总是成功不了,因为自己在记录的时候或多或少的忘了步骤(自己重做的时候发现了些问题),还希望参考的人能告知,最后还是那句老话了,行家多多指点,有问题请留言。
Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐