一、移植环境
主 机:Fedora 14 (kernel-2.6.33.7)
开发板:FL2440( nandflash:K9F1G08 128MB)
开发板:FL2440( nandflash:K9F1G08 128MB)
编译器:arm-linux-gcc-4.3.2
二、移植步骤
FL2440开发板自带的是带有集成了QT的文件系统,本身大小也较大,启动的时候需要加载的模块也比较多,所以导致开机时间比较慢。由于目前阶段我暂时不需要用到QT,所以就想为FL2440移植一个比较简单的文件系统,减少开机时间。具体移植步骤如下。
1. 移植前的准备。为了进行本次文件系统移植,需要准备三个工具:
busybox-1.13.1.tar.bz2,用于生成linux所需要的命令和工具,
mkyaffs2image,用于制作yaffs2文件系统。
yaffs2补丁,用于给配置内核,使内核支持yaffs2文件系统。
2. 准备工作目录,进入工作目录,打上yaffs2补丁。
- #mkdir rootfs
- #cd rootfs
- #tar -xzvf yaffs2.tar.gz
- #cd yaffs2
- #./patch-ker.sh c /home/skywalker/linux-2.6.33/
- Updating ../linux-2.6.33.7//fs/Kconfig
- Updating ../linux-2.6.33.7
出现上述两行字样,则表示已经打好补丁
3. 配置内核如下,使内核支持yaffs2文件系统。配置完成后重新编译内核,下载。(如果在移植内核的时候已经加入对yaffs2的支持,yaffs2补丁和这一步可以省略)。
- File systems --->
- < > Second extended fs support
- < > Ext3 journalling file system support
- < > The Extended 4 (ext4) filesystem
- < > Reiserfs support
- < > JFS filesystem support
- < > XFS filesystem support
- < > OCFS2 file system support
- < > Btrfs filesystem (EXPERIMENTAL) Unstable disk format
- [*] Enable POSIX file locking API
- [*] Dnotify support
- [*] Inotify file change notification support
- [*] Inotify support for userspace
- [ ] Quota support
- Kernel automounter support
- Kernel automounter version 4 support (also supports v3)
- FUSE (Filesystem in Userspace) support
- Caches --->
- CD-ROM/DVD Filesystems --->
- <*> ISO 9660 CDROM file system support
- [ ] Microsoft Joliet CDROM extensions
- [ ] Transparent decompression extension
- < > UDF file system support
- DOS/FAT/NT Filesystems --->
- <*> MSDOS fs support
- <*> VFAT (Windows-95) fs support
- (437) Default codepage for FAT
- (iso8859-1) Default iocharset for FAT
- < > NTFS file system support
- Pseudo filesystems --->
- [*] Miscellaneous filesystems --->
- --- Miscellaneous filesystems
- < > ADFS file system support (EXPERIMENTAL)
- < > Amiga FFS file system support (EXPERIMENTAL)
- < > Apple Macintosh file system support (EXPERIMENTAL)
- < > Apple Extended HFS file system support
- < > BeOS file system (BeFS) support (read only) (EXPERIMENTAL)
- < > BFS file system support (EXPERIMENTAL)
- < > EFS file system support (read only) (EXPERIMENTAL)
- <*> YAFFS2 file system support
- -*- 512 byte / page devices
- [ ] Use older-style on-NAND data format with pageStatus byte
- [ ] Lets Yaffs do its own ECC
- -*- 2048 byte (or larger) / page devices
- [*] Autoselect yaffs2 format
- [ ] Disable lazy loading
- [ ] Turn off wide tnodes
- [ ] Force chunk erase check
- [*] Cache short names in RAM
- <*> Journalling Flash File System v2 (JFFS2) support
- (0) JFFS2 debugging verbosity (0 = quiet, 2 = noisy)
- [*] JFFS2 write-buffering support
- [ ] Verify JFFS2 write-buffer reads
- [*] JFFS2 summary support (EXPERIMENTAL)
- [ ] JFFS2 XATTR support (EXPERIMENTAL)
- [ ] Advanced compression options for JFFS2
- <*> Compressed ROM file system support (cramfs)
- SquashFS 4.0 - Squashed file system support
- [ ] Additional option for memory-constrained systems
- < > FreeVxFS file system support (VERITAS VxFS(TM) compatible)
- < > Minix file system support
- < > SonicBlue Optimized MPEG File System support
- < > OS/2 HPFS file system support
- < > QNX4 file system support (read only)
- <*> ROM file system support
- RomFS backing stores (Block device-backed ROM file system support) --
- < > System V/Xenix/V7/Coherent file system support
- < > UFS file system support (read only)
- < > NILFS2 file system support (EXPERIMENTAL)
- [*] Network File Systems --->
- Partition Types --->
- -*- Native language support --->
- < > Distributed Lock Manager (DLM) --->
4. 修改busybox顶层Makefile,使busybox支持适应arm平台,并配置busybox,加入或减少必要的参数。
- #tar -xjvf busybox-1.13.1.tar.bz2
- #cd busybox-1.13.1
- #vim Makefile
- CROSS_COMPILE ?= /usr/local/arm/3.4.1/bin/arm-linux- (164行左右)
- ARCH ?= arm (189行左右)
配置busybox选项,下面只列出了要注意的地方,没有列出的默认即可
- #make menuconfig
- Makefile:422: *** Mixed implicit and normal rules. stop
- Makefile:1270: *** Mixed implicit and normal rules. stop
在make menuconfig的时候出现了上述两个错误,意思是混合隐式和普通的规则。以前并未见过类似的错误,所以看着这两个错误也云里雾里,上百度也找不到解决的办法。最后在一个国外的嵌入式论坛找到原因:是make版本差异导致的,我的fedora14上的make版本是3.82,而这busybox适应的make版本是3.81,所以规则存在差异。解决办法就是打补丁,或者手动修改如下:
把422行
- config %config: scripts_basic outputmakefile FORCE
- $(Q)mkdir -p include
- $(Q)$(MAKE) $(build)=scripts/kconfig $@
- $(Q)$(MAKE) -C $(srctree) KBUILD_SRC= .kernelrelease
改为
- %config: scripts_basic outputmakefile FORCE
- $(Q)mkdir -p include
- $(Q)$(MAKE) $(build)=scripts/kconfig $@
- $(Q)$(MAKE) -C $(srctree) KBUILD_SRC= .kernelrelease
把1270行
- / %/: prepare scripts FORCE
- $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
- $(build)=$(build-dir)
改为
- %/: prepare scripts FORCE
- $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
- $(build)=$(build-dir)
修改完毕后便可以进行busybox的配置
- Busybox Settings --->
- General Configuration --->
- Buffer allocation policy (Allocate with Malloc) --->
- [*] 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.conf
- [*] Suppress warning message if /etc/busybox.conf is not readable
- (/proc/self/exe) Path to BusyBox executable
- Build Options --->
- [*] Build BusyBox as a static binary (no shared libs)
- [*] Build with Large File Support (for accessing files > 2 GB)
- Installation Options --->
- [ ] Don't use /usr
- Applets links (as soft-links) --->
- (./_install) BusyBox installation prefix
- Busybox Library Tuning --->
- (6) Minimum password length
- (2) MD5: Trade Bytes for Speed
- [*] Faster /proc scanning code (+100 bytes)
- [*] 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
- 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 module.symbols fileLinux System Utilities --->
编译make之后,出现如下错误
- [skywalker@localhost busybox-1.13.1]$make
- CC networking/interface.o
- networking/interface.c:818: error: `ARPHRD_INFINIBAND' undeclared here (not in a function)
- networking/interface.c:818: error: initializer element is not constant
- networking/interface.c:818: error: (near initialization for `ib_hwtype.type')
- make[1]: *** [networking/interface.o] 错误 1
- make: *** [networking] 错误 2
- [skywalker@localhost busybox-1.13.1]$
通过查看内核源代码目录中的“include/linux/ifarp.h”文件可得知“ARPHRDINFINIBAND”的值为“32”,然后修改“networking/interface.c”文件,在其中添加如下定义,再重新编译即可通过。
- #vim networking/interface.c
- #define ARPHRD_INFINIBAND 32 /* InfiniBand */
- #make
- #make install
5. 开始构建文件系统
1). 新建一个目录root_2.6.33,吧busybox-1.13.1/_install目录下生成bin、linuxrc、sbin、usr全部复制到这个目录,并且在该目录下创建文件系统所需要的其他目录。
#mkdir root-2.6.33
#cp -rf busybox-1.13.1/_install/* root-2.6.33/
#cd root-2.6.33/
#mkdir dev etc home lib mnt opt proc tmp var www sys
2).向各目录中添加文件系统所需要的目录或文件,没有提到的就不用添加。这里要注意各种文件的权限,建议都改为777,命令:#chmod 777 文件名。
"dev"目录,创建两个设备文件:
- #mknod console c 5 1
- #mknod null c 1 3
"etc"目录,创建各种配置文件并向里面添加内容,没有列出的就不用添加:
boa/boa.conf: boa WEB服务器配置文件,暂时为空。
group: 系统用户组配置文件,内容如下:
- root:*:0:
- daemon:*:1:
- bin:*:2:
- sys:*:3:
- adm:*:4:
- tty:*:5:
- disk:*:6:
- lp:*:7:lp
- mail:*:8:
- news:*:9:
- uucp:*:10:
- proxy:*:13:
- kmem:*:15:
- dialout:*:20:
- fax:*:21:
- voice:*:22:
- cdrom:*:24:
- floppy:*:25:
- tape:*:26:
- sudo:*:27:
- audio:*:29:
- ppp:x:99:
- 500:x:500:plg
- 501:x:501:fa
inittab: 系统init进程配置文件,内容如下:
- # /etc/inittab
- ::sysinit:/etc/init.d/rcS
- console::askfirst:-/bin/sh
- ::ctrlaltdel:/sbin/reboot
- ::shutdown:/bin/umount -a -r
另一选择:
- # /etc/inittab
- #Startup the system
- null::sysinit:/bin/mount -o remount, rw /
- null::sysinit:/bin/mount -t proc proc /proc
- null::sysinit:/bin/mount -a
- #null::sysinit:/bin/hostname -F /etc/sysconfig/HOSTNAME
- #now run any rc srcipts
- ::sysinit:/etc/init.d/rcS
- #now invoke shell
- ::askfirst:/bin/sh
- #logging junk
- null::sysinit:/bin/touch /var/log/messages
- null::respawn:/sbin/syslogd -n -m 0
- null::respawn:/sbin/klogd -n
- #stuff to do for the 3-finger salute
- ::ctrlaltdel:/sbin/reboot
- #stuff to do before rebooting
- null::shutdown:/bin/killall klogd
- null::shutdown:/bin/killall syslogd
- null::shutdown:/bin/umount -a -r
- null::shutdown:/sbin/swapoff -a
mime.types: 暂时为空。
passwd: 系统密码文件,内容如下:
- root::0:0:root:/:/bin/sh
- ftp::14:50:FTP User:/var/ftp:
- bin:*:1:1:bin:/bin:
- daemon:*:2:2:daemon:/sbin:
- nobody:*:99:99:Nobody:/:
- sky::502:502:Linux User,,,:/home/sky:/bin/sh
rc.d/init.d/httpd: 内容如下:
- #!/bin/sh
- base=boa
- # See how we were called.
- case "$1" in
- start)
- /usr/sbin/$base
- ;;
- stop)
- pid=`/bin/pidof $base`
- if [ -n "$pid" ]; then
- kill -9 $pid
- fi
- ;;
- esac
- exit 0
sysconfig/HOSTNAME: 主机名称文件,内容如下:
- yyq2440
fstab: 系统挂载文件系统列表,内容如下:
- # device mount-point type options dump fsck order
- none /proc proc defaults 0 0
- none /dev/pts devpts mode=0622 0 0
- tmpfs /dev/shm tmpfs defaults 0 0
另一选择:
- #<file system> <mount pt> <type> <option> <dump> <pass>
- /dev/root / ext2 rw.noauto 0 1
- proc /proc proc defaults 0 0
- devpts /dev/pts devpts defaults 0 0
- tmpfs /tmp tmpfs defaults 0 0
- sysfs /sys sysfs defaults 0 0
init.d/rcS: 系统启动加载项,内容如下:
- #!/bin/sh
- PATH=/sbin:/bin:/usr/sbin:/usr/bin
- runlevel=S
- prevlevel=N
- umask 022
- export PATH runlevel prevlevel
- #
- # Trap CTRL-C &c only in this shell so we can interrupt subprocesses.
- #
- /bin/mount -t proc none /proc
- /bin/mount -t tmpfs none /tmp
- /bin/mount -t tmpfs none /var
- /bin/mkdir -p /var/log
- /bin/hostname -F /etc/sysconfig/HOSTNAME
- mdev.conf: mdev设备配置文件,暂时为空。
- net.conf: 网络配置文件,暂时为空。
- profile: 用户环境配置文件,内容如下:
- # Ash profile
- # vim: syntax=sh
- # No core files by default
- #ulimit -S -c 0 > /dev/null 2>&1
- USER="`id -un`"
- LOGNAME=$USER
- PS1='[\u@\h \W]\# '
- PATH=$PATH:/usr/local/bin
- LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
- HOSTNAME=`/bin/hostname`
- export USER LOGNAME PS1 PATH LD_LIBRARY_PATH
resolv.conf: DNS配置文件,内容如下:
- nameserver 61.144.56.100
"home"目录:创建一个sky目录,与etc目录passwd文件中的sky相对应
"lib"目录:这个里面放的都是库文件,直接从交叉编译器的库文件目录中拷贝过来,并删除不必要的符号信息,以减小所占容量:
#cp -f /usr/local/arm/3.4.1/arm-linux/lib/*so* lib/ -a
#arm-linux-strip lib/*
6. 使用mkyaffs2image工具生成yaffs2文件系统。先把mkyaffs2image解压出来并复制到/usr/sbin/目录下,然后执行:
- #mkyaffs2image root-2.6.33/ root-2.6.33.bin
即可生成yaffs2文件系统,下载到开发板启动,这时却出现一个比较烦人的错误。
- List of all partitions:
- 1f00 128 mtdblock0 (driver?)
- 1f01 384 mtdblock1 (driver?)
- 1f02 3072 mtdblock2 (driver?)
- 1f03 61440 mtdblock3 (driver?)
- 1f04 512 mtdblock4 (driver?)
- 1f05 60928 mtdblock5 (driver?)
- No filesystem could mount root, tried: ext3 ext2 cramfs vfat msdos iso9660 romfs yaffs yaffs2
- Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(31,3)
- Backtrace:
- [<c00309bc>] (dump_backtrace+0x0/0x104) from [<c0030ad8>] (dump_stack+0x18/0x1c)
- r7:c388c000 r6:c388c037 r5:00000000 r4:c381bf5c
- [<c0030ac0>] (dump_stack+0x0/0x1c) from [<c004d008>] (panic+0x3c/0x124)
- [<c004cfcc>] (panic+0x0/0x124) from [<c0009044>] (mount_block_root+0x1d8/0x21c)
- r3:00000003 r2:c381bf6f r1:c381bf5c r0:c03a39ac
- [<c0008e6c>] (mount_block_root+0x0/0x21c) from [<c0009254>] (mount_root+0xd0/0xf0)
- [<c0009184>] (mount_root+0x0/0xf0) from [<c00093e4>] (prepare_namespace+0x170/0x1d0)
- r6:00000000 r5:c0024a0c r4:c042ca54
- [<c0009274>] (prepare_namespace+0x0/0x1d0) from [<c0008c1c>] (kernel_init+0xd8/0x10c)
- r5:c00238e8 r4:c042c838
- [<c0008b44>] (kernel_init+0x0/0x10c) from [<c004f814>] (do_exit+0x0/0x5a4)
- r5:00000000 r4:00000000
找了一些资料,这个错误时跟arm-linux-gcc版本有关。原来是我刚才把arm-linux-gcc换成了4.3.2惹的祸,4.*的版本编译出来的内核+yaffs2文件系统一般都会报错:Kernel panic - not syncing: Attempted to kill init!解决办法有两个。
a. 重新配置内核,选上以下参数:
- Kernel Features --->
- [*] Use the ARM EABI to compile the kernel
- [*] Allow old ABI binaries to run with this kernel (EXPERIMENTA)
b. 把编译器换成3.*。
我当然会选择第二种了,于是乎又把编译器换回3.4.1版本。再次重重新编译下载启动,从终端的启动信息可以看到。2.6.33.7内核+yaffs2文件系统顺利启动:
- yaffs: dev is 32505859 name is "mtdblock3"
- yaffs: passed flags ""
- yaffs: Attempting MTD mount on 31.3, "mtdblock3"
- yaffs: auto selecting yaffs2
- block 122 is bad
- block 342 is bad
- usb 1-1: new full speed USB device using s3c2410-ohci and address 2
- yaffs_read_super: isCheckpointed 0
- VFS: Mounted root (yaffs filesystem) on device 31:3.
- Freeing init memory: 144K
- hub 1-1:1.0: USB hub found
- hub 1-1:1.0: 4 ports detected
- Please press Enter to activate this console.
- [root@yyq2440 /]#
但这时使用ls命令却又有了新问题。
[root@yyq2440 /]# ls
[1;34mbin[0m [1;34mhome[0m [1;34mlost+found[0m [1;34mproc[0m [1;34musr[0m
[1;34mdev[0m [1;34mlib[0m [1;34mmnt[0m [1;34msbin[0m [1;34mvar[0m
[1;34metc[0m [1;36mlinuxrc[0m [1;34mopt[0m [1;34mtmp[0m [1;34mwww[0m
造成这样的原因是,busybox配置的时候默认选上了支持色彩附加信息,而DNW不支持色彩信息,所以会显示乱码。如果换成超级终端或者PUTTY就会显示正常,但我用习惯了DNW,还是重新配置以下吧。配置busybox时把下面两项N掉就可解决这个bug。
- Coreutils --->
- [*] ls
- [ ] Allow use of color to identify file types
- [ ] Produce colored ls output by default (NEW)
最后文件系统终于正常工作了,被各种问题折腾的不轻啊。还好耐心地慢慢摸索把问题解决,编译出一个可以运行的文件系统。明天可以安心回家过年了,希望过个好年,好想念家里人和家里的美食啊。O(∩_∩)O哈哈~
2011-1-30