【引用】Linux-2.6.32.2内核在mini2440上的移植(四)---根文件系统制作(1)

移植环境(红色粗字体字修改后内容,蓝色粗体字为特别注意内容)

1,主机环境:VMare下CentOS 5.5 ,1G内存。

2,集成开发环境:Elipse IDE

3,编译编译环境:arm-linux-gcc v4.4.3,arm-none-linux-gn?i-gcc v4.5.1。

4,开发板:mini2440,2M nor flash,128M nand flash。

5,u-boot版本:u-boot-2009.08

6,linux 版本:linux-2.6.32.2

7,参考文章:

【1】嵌入式linux应用开发完全手册,韦东山,编著。

【2】Mini2440 之Linux 移植开发实战指南

【3】http://linux.chinaunix.net/techdoc/system/2009/08/24/1131864.shtml

4.1,根文件系统制作

在构建文件系统时,建议遵循FHS(Filesystem Hierarchy Standard,文件系统层次标准),它定义了文件系统中目录、文件的分类存放原则,定义了系统运行需要的最小文件目录的集合,FHS文档可以到www.pathname.com/fhs/下载。

【1】下载busybox 源代码

可以从http://www.busybox.net/downloads/,这里下载的是busybox-1.13.3.tar.bz2,友善官方也有提供直接复制过来即可:

[root@localhost linux-test]# ls
busybox-1.13.3-mini2440.tgz   linux-2.6.32.2  linux-2.6.39  yaffs2
[root@localhost linux-test]#

【2】根文件系统目录说明

嵌入式 Linux 中都需要构建根文件系统,构建根文件系统的规则在FHS(FilesystemHierarchy Standard)文档中,下面是根文件系统顶层目录。
目录 内容
bin    存放所有用户都可以使用的、基本的命令。
sbin   存放的是基本的系统命令,它们用于启动系统、修复系统等。
usr    里面存放的是共享、只读的程序和数据。
proc  这是个空目录,常作为proc 文件系统的挂载点。
dev   该目录存放设备文件和其它特殊文件。
etc    存放系统配置文件,包括启动文件。
lib     存放共享库和可加载块(即驱动程序),共享库用于启动系统、运行根文件系统中的可执行程序
boot  引导加载程序使用的静态文件。
home 用户主目录,包括供服务账号锁使用的主目录,如FTP。
mnt    用于临时挂接某个文件系统的挂接点,通常是空目录。也可以在里面创建空的子目录。
opt    给主机额外安装软件所摆放的目录。
root   root 用户的主目录
tmp   存放临时文件,通常是空目录。
var   存放可变的数据,如日志等。

【3】创建系统目录。操作如下:

在与linux内核相同的目录下创建一个目录,此目录名字可以自己指定,这里创建的目录名为myrootfs。

[root@localhost linux-test]# mkdir myrootfs
[root@localhost linux-test]# ls
busybox-1.18.4.tar.bz2  linux-2.6.32.2  linux-2.6.39  myrootfs  yaffs2

进入到/root/linux-test/myrootfs/rootfs 目录,新建一个建立根文件系统目录的脚本文件mkrootfs:

[root@localhost linux-test]# cd myrootfs
[root@localhost myrootfs]# vim mkrootfs

将下列内容复制其中:

#!/bin/sh
echo \"------Create rootfs directons start...--------\"
mkdir rootfs
cd rootfs
echo \"--------Create root,dev....----------\"
mkdir bin boot dev etc home lib mnt proc root sbin sys tmp usr var  www
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 666 dev/console c 5 1
mknod -m 666 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---------\"

然后执行:wq保存退出。

使用命令chmod a+x mkrootfs 改变文件的可执行权限:

[root@localhost myrootfs]# chmod a+x mkrootfs

运行./mkrootfs 脚本:

[root@localhost myrootfs]# ./mkrootfs
------Create rootfs directons start...--------
--------Create root,dev....----------
make node in dev/console dev/null
-------make direction done---------
[root@localhost myrootfs]#

这样就完成了根文件系统目录的创建。在上面脚本执行过程创建的两个设备文件console 和null非常重要,这两文件和控制台设备有关,在前面提到过的在内核挂载文件系统时出现的告警“Warning: unable to open an initial console”与之有关。

其中,mknod命令格式如下:

mknod [OPTION]... NAME TYPE [MAJOR MINOR]

 参数-m, --mode=MODE,表示指定用户操作权限,console和null表示文件名,c 表示是字符设备,后面的两个数字分别表示主设备号和次设备号。

改变了tmp 目录的使用权,让它开启sticky 位,为tmp 目录的使用权开启此位,可确保tmp 目录底下建立的文件,只有建立它的用户有权删除。尽管嵌入式系统多半是单用户,不过有些嵌入式应用不一定用root 的权限来执行,因此需要遵照根文件系统权限位的基本规定来设计。

【4】编译并安装内核模块

首先就进入到内核顶级目录下,并确认内核顶层目录下的Makefile中的ARCH=arm,CROSS_COMPILE=arm-linux- ,然后执行编译:

[root@localhost linux-test]# cd linux-2.6.32.2
[root@localhost linux-2.6.32.2]# make modules

等到编译完成后,安装编译好的模块:

[root@localhost linux-2.6.32.2]# make modules_install ARCH=arm INSTALL_MOD_PATH=/root/linux-test/myrootfs/rootfs

等到模块安装完成后可以看到

[root@localhost linux-2.6.32.2]# cd ../myrootfs/rootfs
[root@localhost rootfs]# ls ./lib/modules
2.6.32.2  2.6.32.2-FriendlyARM
[root@localhost rootfs]# ls ./lib/modules/2.6.32.2
build           modules.dep          modules.ofmap     modules.symbols
kernel          modules.ieee1394map  modules.order     modules.usbmap
modules.alias   modules.inputmap     modules.pcimap    source
modules.ccwmap  modules.isapnpmap    modules.seriomap

[root@localhost rootfs]# ls ./lib/modules/2.6.32.2/kernel
crypto  drivers  fs  lib  net  sound
[root@localhost rootfs]#
上面的目录中有make modules_install安装的模块。

【5】建立动态链接库

这里的动态链接库直接用友善之臂的,可以从其官方光盘映像/linux目录下rootfs_qtopia_qt4-20110304.tar.gz,先解压友善之臂的根文件包:

[root@localhost myrootfs]# cd ../
[root@localhost linux-test]# ls
busybox-1.13.3-mini2440.tgz  linux-2.6.39  rootfs_qtopia_qt4-20110304.tar.gz
linux-2.6.32.2          myrootfs      yaffs2
[root@localhost linux-test]# tar -zxf rootfs_qtopia_qt4-20110304.tar.gz -C ./
[root@localhost linux-test]# ls
busybox-1.13.3-mini2440.tgz  linux-2.6.39  rootfs_qtopia_qt4                  yaffs2
linux-2.6.32.2          myrootfs      rootfs_qtopia_qt4-20110304.tar.gz
[root@localhost linux-test]#

拷贝其lib 的内容到新建的根文件目录lib 内:

[root@localhost linux-test]# cp -rfd ./rootfs_qtopia_qt4/lib/* ./myrootfs/rootfs/lib/
[root@localhost linux-test]#

还有一种做法:

对于\"lib\"目录:这个里面放的都是库文件,直接从交叉编译器的库文件目录中拷贝过来:
#cp -f /usr/local/arm/4.4.3/arm-none-linux-gneabi/libc/armv4t/lib/*so* lib/ -a

【5】交叉编译Bosybox

Bosybox 是一个遵循GPL v2 协议的开源项目,它在编写过程总对文件大小进行优化,并考虑了系统资源有限(比如内存等)的情况,使用Busybox 可以自动生成根文件系统所需的bin、sbin、usr 目录和linuxrc 文件。

(1)解压busybox

[root@localhost linux-test]# ls
busybox-1.13.3-mini2440.tgz  linux-2.6.39  rootfs_qtopia_qt4                  yaffs2
linux-2.6.32.2          myrootfs      rootfs_qtopia_qt4-20110304.tar.gz
[root@localhost linux-test]# tar -zxf busybox-1.13.3-mini2440.tgz 
[root@localhost linux-test]# ls
busybox-1.13.3          linux-2.6.39       rootfs_qtopia_qt4-20110304.tar.gz
busybox-1.13.3-mini2440.tgz    myrootfs           yaffs2
linux-2.6.32.2          rootfs_qtopia_qt4
[root@localhost linux-test]#

(2)进入busybox的顶层目录,修改Makefile

[root@localhost linux-test]# cd busybox-1.13.3
[root@localhost busybox-1.13.3]# gedit Makefile
在gedit打开的Makefile中,定位到164行附近,修改如下:

# Note: Some architectures assign CROSS_COMPILE in their arch/*/Makefile

CROSS_COMPILE ?= arm-linux-
# bbox: we may have CONFIG_CROSS_COMPILER_PREFIX in .config,
# and it has not been incl? yet... thus using an awkward syntax.

... ...

定位到189行附近,修改如下:
ARCH ?= arm

# Architecture as present in compile.h
UTS_MACHINE := $(ARCH)

然后保存。

(3)配置busybox

在busybox顶层目录下执行make menconfig 进行配置

[root@localhost busybox-1.13.3]# make menconfig

出现如下图配置菜单

\"Linux-2.6.32.2内核在mini2440上的移植(三)---根文件系统制作

 

下面只列出了要注意的地方,没有列出的默认即可。  

<1>、Busybox Settings--->

    Build Options--->
[*] Build BusyBox as a static binary (no shared libs)                 
[ ] Force NOMMU build                                                  
[*] Build with Large File Support (for accessing files > 2 GB)      
(arm-linux-) Cross Compiler prefix   //指定编译前缀,按回车就可进行修改

    Installation Options  ---> 
[*] Don\'t use /usr  
    //选中该项可以避免buysbox被安装到宿主机系统的/usr目录下,破坏宿主机系统。 
    Applets links (as soft-links)  ---> 
(/root/linux-test/myrootfs/rootfs) BusyBox installation prefix    //这里需要指定busybox的安装路径,按回车即可输入。

    Busybox Library Tuning --->
[*] Support for /etc/networks   
[*] Command line editing  
(1024) Maximum length of input 
[*] vi-style line editing commands
(15)  History size         
 [*]   History saving            
 [*]   Tab completion    
 [*]     Username completion     
 
[*]   Fancy shell prompts 

<2>Linux Module Utilities--->

(/lib/modules)Default directory containing modules
(modules.dep)Default name of modules.dep

下面是在busybox 中配置对dev 下设备类型的支持,dev 的创建有手动创建、使用devfs 文件系统创建和?v创建三种方法,而?v的一个简化版是busybox 自带的mdev ,适合于嵌入式的应用埸合。其具有使用简单的特点。它的作用,就是在系统启动和热插拔或动态加载驱动程序时,自动产生驱动程序所需的节点文件。在以busybox 为基础构建嵌入式linux 的根文件系统时,使用它是最优的选择。

<3>Linux System Utilities --->
[*]Support /etc/mdev.conf
[*]Support command execution at device addition/removal

<4>Init Utilities --->

“Support reading an inittab file”应该选中,这样可以根据自己编写的inittab文件初始化;“Support running commands with a controlling-tty”应该选中,否则会提示非常困扰的“/bin/sh: can\'t access tty; job control turned off”的提示,尽管可以进入控制台命令行。

(4)编译busybox

编译busybox 到指定目录,在busybox-1.13.3的根目录下执行
make CONFIG_PREFIX=/root/linux-test/myrootfs/rootfs install
在rootfs 目录下会生成目录bin、sbin、usr 和文件linuxrc 的内容。

[root@localhost busybox-1.13.3]# make CONFIG_PREFIX=/root/linux-test/myrootfs/rootfs install
... ...

--------------------------------------------------
You will probably need to make your busybox binary
setuid root to ensure all configured applets will
work properly.
--------------------------------------------------

[root@localhost busybox-1.13.3]#

[root@localhost busybox-1.13.3]# ls ../myrootfs/rootfs
bin   dev  home  linuxrc  proc  sbin  tmp  var
boot  etc  lib   mnt      root  sys   usr  www
[root@localhost busybox-1.13.3]#

【6】建立etc 目录下的配置文件

(1) 建立/etc/group系统用户组配置文件,内容如下:

root:*:0:
daemon:*:1:
bin:*:2:
sys:*:3:
adm:*:4:
tty:*:5:
disk:*:6:
lp:*:7:lp
mail:*:8:
news:*:9:
u p:*:10:
proxy:*:13:
kmem:*:15:
dialout:*:20:
fax:*:21:
voice:*:22:
cdrom:*:24:
floppy:*:25:
tape:*:26:
s o:*:27:
a io:*:29:
ppp:x:99:
500:x:500:plg
501:x:501:fa

(2)建立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

[root@localhost rootfs]# ls ./etc
group  init.d  passwd  rc.d   sysconfig
[root@localhost rootfs]#

(3) 在etc/sysconfig 目录下新建主机文件名HOSTNAME,内容为\"mini2440\"。

[root@localhost rootfs]# cat >>./etc/sysconfig/HOSTNAME
mini2440

[root@localhost rootfs]#
当录入完文件内容“mini2440”并回车后需要按下Ctrl+C组合键结束录入状态。此时该文件内容为:“mini2440\",这句话就是我们在文件系统里面看到那个“[root@ mini2440 /]”。

(4)新建etc/inittab 系统init进程配置文件,将下面内容复制并粘贴其中:

#etc/inittab
::sysinit:/etc/init.d/rcS
console::askfirst:-/bin/sh
::ctrlaltdel:/sbin/reboot
::shutdown:/bin/umount -a –r

要记住赋予其可执行属性

[root@localhost rootfs]# chmod a+x ./etc/inittab

(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 \"----------munt all----------------\"
mount -a 
//挂载/etc/fstab/文件指定的所有的文件系统
echo /sbin/mdev>/proc/sys/kernel/hotplug
mdev -s
echo \"***********************************************\"
echo \"************booting to mini2440 *****************\"
echo \"Kernel version:linux-2.6.32.2\"
echo \"the fans:singleboy\"
echo \"Date:2011.5.30\"
echo \"***********************************************\"
/bin/hostname -F /etc/sysconfig/HOSTNAME

然后使用以下命令改变 rcS 的执行权限:
Chmod +x rcS

[root@localhost rootfs]# chmod +x ./etc/init.d/rcS
[root@localhost rootfs]#

(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

修改环境变量PS1(命令行提示符),可以使用vi编辑/etc/profile文件,在最后加上:
export PS1=\'[\\u@\\h \\W]\\$ \'
即可,其中\\u显示当前用户账号,\\h显示当前主机名,\\W显示当前路径,\\$显示\'$\'符号
\\W 代替 \\w 就可以实现绝对路径到相对路径的转换

下面简单说说环境下默认的特殊符号所代表的意义:
\\d :代表日期,格式为weekday month date,例如:\"Mon Aug 1\"
\\H :完整的主机名称。例如:我的机器名称为:fc4.linux,则这个名称就是fc4.linux
\\h :仅取主机的第一个名字,如上例,则为fc4,.linux则被省略
\\t :显示时间为24小时格式,如:HH:MM:SS
\\T :显示时间为12小时格式
\\A :显示时间为24小时格式:HH:MM
\\u :当前用户的账号名称
\\v :BASH的版本信息
\\w :完整的工作目录名称。家目录会以 ~代替
\\W :利用basename取得工作目录名称,所以只会列出最后一个目录
\\# :下达的第几个命令
\\$ :提示字符,如果是root时,提示符为:# ,普通用户则为:$

(8) 建立etc/mdev.conf (mdev设备配置文件)、 net.conf (网络配置文件件),mime.types: MIME(Multipurpose Internet Mail Extensions) 内容均为空。

[root@localhost rootfs]# to h ./etc/mdev.conf
[root@localhost rootfs]# to h ./etc/net.conf
[root@localhost rootfs]# to h ./etc/mine.types

(9)建立boa WEB服务器文件配置文件

在etc/boa目录,并在boa目录中建立boa.conf文件,内容为空。

[root@localhost rootfs]# mkdir ./etc/boa
[root@localhost rootfs]# to h ./etc/boa/boa.conf
[root@localhost rootfs]#

(10)先建立etc/rc.d/init.d目录

[root@localhost rootfs]# mkdir ./etc/rc.d/init.d

然后建立etc/rc.d/init.d/httpd文件
[root@localhost rootfs]# gedit ./etc/rc.d/init.d/httpd
[root@localhost rootfs]#

将下面内容复制并粘贴:

#!/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

(11)新建etc/resolv.conf,DNS配置文件,存放访问外网时需要DNS 的信息,内容如下:

nameserver 61.144.56.100

 (12)在/home/sky目录,与etc目录passwd文件中的sky相对应

[root@localhost rootfs]# mkdir ./home/sky
[root@localhost rootfs]#

3.2,根文件系统测试

将制作的文件系统通过下面三种方法测试

【1】将nfs文件系统作为根文件系统进行测试

(1) 将制作好的根文件系统rootfs复制到/nfsboot目录下作为mini2440的根文件系统

[root@localhost myrootfs]# cp -drf ./rootfs /nfsboot/
[root@localhost myrootfs]#  cd /nfsboot
[root@localhost nfsboot]#

复制时需要加上drf参数,d表示文件的链接关系不变。r表示递归复制此目录下所有的子目录和文件。

(2)确保rootfs目录可读写

[root@localhost nfsboot]# ls -l
总计 63216
drwxr-xr-x 17 root root     4096 06-01 07:14 rootfs
-rwxrw-rw-  1 root root 58487616 2009-07-18 root_qtopia-128M.img
-rw-r--r--  1 root root  2114212 05-27 11:45 uImage
[root@localhost nfsboot]#  

进入到内核目录下,执行:

[root@localhost myrootfs]# cd ../linux-2.6.32.2
[root@localhost linux-2.6.32.2]# vim .config

在打开的配置文件中在命令模式下:/CMD,会自动定位到340行,对照上面CONFIG_CMDLINE参数修改成如下:

#
# Boot options
#
CONFIG_ZBOOT_ROM_TEXT=0
CONFIG_ZBOOT_ROM_BSS=0
CONFIG_CMDLINE=\"root=/dev/nfs rw nfsroot=10.1.0.128:/nfsboot/rootfs ip=10.1.0.129 console=ttySAC0 mem=64M\"
# CONFIG_XIP_KERNEL is not set
CONFIG_KEXEC=y
CONFIG_ATAGS_PROC=y

在内核目录下命令终端中执行

[root@localhost linux-2.6.32.2]# make men onfig
在打开的配置菜单-> Boot options --->回车可以看到刚才的修改结果,如下图:

\"Linux-2.6.32.2内核在mini2440上的移植(四)---根文件系统制作

 当然上图高亮的菜单选项上按回车也可以进行修改,但没有在vim编辑器中修改方便。

(5)确保内核提供nfs boot支持

在刚才的配置菜单中定位到 

      Device Drivers  ---> 

    <*> Memory Technology Device (MTD) support  --->

    <*>   Caching block device access to MTD devices

      [*] Network device support  --->

      [*]   Ethernet (10 or 100Mbit)  ---> 

      <*>   DM9000 support 

     File systems  --->

     [*] Network File Systems  ---> 

     --- Network File Systems                                   
     <*>   NFS client support                                         
      [*]     NFS client support for NFS version 3                     
      [*]       NFS client support for the NFSv3 ACL protocol extension
      [*]     NFS client support for NFS version 4 (EXPERIMENTAL)      
      [ ]       NFS client support for NFSv4.1 (DEVELOPER ONLY)        
      [*]     Root file system on NFS                                  
     < >   NFS server support 

要确保上面蓝色高亮部分的选项被选上。

(6)重新编译内核,将生成的uImage和zImage文件复制到/nfsboot/目录下

[root@localhost nfsboot]# ls
rootfs  root_qtopia-128M.img  uImage  uImage_T35  zImage  zImage_T35
[root@localhost nfsboot]#
(7)给开发板上电,启动u-boot

I2C:   ready
DRAM:  64 MB
Flash:  2 MB
NAND:  128 MiB
Video: 240x320x16 20kHz 62Hz
In:    serial
Out:   serial
Err:   serial
Net:   dm9000
U-Boot 2009.08
modified by singleboy(singleboy@163.com)
Love Linux forever!!!
Hit any key to stop autoboot:  0
dm9000 i/o: 0x20000300, id: 0x90000a46
DM9000: running in 16 bit mode
MAC: 08:00:3e:26:0a:5b
operating at 100M full duplex mode
Using dm9000 device
File transfer via NFS from server 10.1.0.128; our IP address is 10.1.0.129
Filename \'/nfsboot/uImage\'.
Load address: 0x31000000
Loading: #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #######################
done
Bytes transferred = 2110772 (203534 hex)
## Booting kernel from Legacy Image at 31000000 ...
   Image Name:   Linux-2.6.32.2
   Created:      2011-06-01  11:10:24 UTC
   Image Type:   ARM Linux Kernel Image (uncompressed)
   Data Size:    2110708 Bytes =  2 MB
   Load Address: 30008000
   Entry Point:  30008000
   Verifying Checksum ... OK
   Loading Kernel Image ... OK
OK

Starting kernel ...

Uncompressing Linux.............................................................
...................................................................... done, boo
ting the kernel.
Linux version 2.6.32.2 (root@localhost.localdomain) (gcc version 4.4.3 (ctng-1.6
.1) ) #11 Wed Jun 1 19:10:07 CST 2011
CPU: ARM920T [41129200] revision 0 (ARMv4T), cr=00007177
CPU: VIVT data cache, VIVT instr tion cache
Machine: my mini2440 devolopment board singleboy@163.com
... ...

Kernel command line: noinitrd console=ttySAC0,115200 init=/linuxrc mem=64M root=
/dev/nfs rw nfsroot=10.1.0.128:/nfsboot/rootfs ip=10.1.0.129:10.1.0.128:10.1.0.1
:255.255.255.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
... ...

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: Man?turer ID: 0xec, Chip ID: 0xf1 (Samsung NAND 128MiB 3,3V 8-bit)
Scanning device for bad blocks
Creating 5 MTD partitions on \"NAND 128MiB 3,3V 8-bit\":
0x000000000000-0x000000040000 : \"boot\"
0x000000040000-0x000000060000 : \"param\"
0x000000060000-0x000000560000 : \"kernel\"
0x000000560000-0x000008000000 : \"rootfs\"
0x000000000000-0x000008000000 : \"nand\"
dm9000 Ethernet Driver, V1.31
eth0: dm9000e at c486e300,c4872304 IRQ 51 MAC: 08:90:90:90:90:90 (chip)
... ...

eth0: link up, 100Mbps, full-duplex, lpa 0x45E1
IP-Config: Complete:
     device=eth0, addr=10.1.0.129, mask=255.255.255.0, gw=10.1.0.1,
     host=10.1.0.129, domain=, nis-domain=(none),
     bootserver=10.1.0.128, rootserver=10.1.0.128, rootpath=
Looking up port of RPC 100003/2 on 10.1.0.128
Looking up port of RPC 100005/1 on 10.1.0.128
VFS: Mounted root (nfs filesystem) on device 0:14.
Freeing init memory: 132K
----------munt all----------------
***********************************************
************booting to mini2440 *****************
Kernel version:linux-2.6.32.2
the fans:singelboy
Date:2011.5.30
***********************************************

Please press Enter to activate this console.
[root@mini2440 /]#ls
bin      dev      home     linuxrc  proc     sbin     tmp      var
boot     etc      lib      mnt      root     sys      usr      www
[root@mini2440 /]#

可以看到制作的根文件系统内核成功地引导起来了。


【2】将制作根文件系统编译进内核,并制作成initramfs文件系统

 现在基于Linux的发行版通常采用initramfs代替initrd,架构更简单,应用也更灵活一些,不需要创建内存设备块,能根据文件的大小自动申请或释放内存。

(1) 配置linux内核,支持initramfs

在命令终端的linux-2.6.32.2内核目录下

[root@localhost ~]# cd linux-test/linux-2.6.32.2

然后执行
[root@localhost linux-2.6.32.2]# make menconfig

General setup  --->

[*] Initial RAM filesystem and RAM disk (initramfs/initrd) suppor
(/root/linux-test/myrootfs/rootfs) Initramfs source file(s) //填写你要制作成initramfs格式的根文件系统目录。

原因很简单,我们使用的是initramfs,而不是ramdisk,所以不用配置ramdisk的驱动支持项Device Drivers-->Block devices-->RAM block device support 项。相应的之后的(4096)Default RAM disk size kbytes等相关默认配置选项就不会再出现了。
另外initramfs技术和ramdisk技术的另一个重要的区别就是initramfs并不是在内存中模拟出一个磁盘,所以也就不在需要ramdisk中所需的ext2驱动支持。所以,File systems菜单下的ext2文件系统支持< > Second extended fs support选项就可以取消了。

(2) 进入制作好的根文件系统rootfs

[root@localhost linux-2.6.32.2]# cd ../myrootfs/rootfs
[root@localhost rootfs]#

因为initramfs根文件系统启动时执行的第一个程序是init,而不是linuxrc,所以在此,我们制作的根文件系统需要添加一个init文件,相应的linuxrc文件就不再需要了。于是执行

[root@localhost rootfs]# ln -s ./bin/busybox init
这样就为busybox创建了一个软链接init,这个文件就是我们要创建的init文件。

(3)修改内核的命令行参数

[root@localhost rootfs]# cd ../../linux-2.6.32.2
[root@localhost linux-2.6.32.2]# vim .config
用/CMD 定位到CONFIG_CMDLINE处,修改如下:

CONFIG_CMDLINE=\"console=ttySAC0 mem=64M\"

(4)重新编译内核

[root@localhost linux-2.6.32.2]# make uImage

按照上面的配置,经过重新编译的内核后将initramfs根文件系统直接合并到内核镜像里边了。这样,合二为一的镜像就不再需要单独烧写根文件系统镜像了,相应的,启动内核时的参数就不需要添加initrd=……来指定initramfs的位置了。

(4)启动u-boot下载测试

Hit any key to stop autoboot:  0
[u-boot@MINI2440]# usbslave
USB host is connected. Waiting a download.

Now, Downloading [ADDRESS:31000000h,TOTAL:24052958]
RECEIVED FILE SIZE:24052958 (618KB/S, 38S)
[u-boot@MINI2440]# bootm 31000000

... ...

NET: Registered protocol family 1
RPC: Registered p transport module.
RPC: Registered tcp transport module.
RPC: Registered tcp NFSv4.1 backchannel transport module.
Kernel panic - not syncing: Out of memory and no killable processes...

... ...

发现确实是小内存的问题,参照文章

http://www.dbanotes.net/database/linux_outofmemory_oom_killer.html

这里需要将rootfs/lib/modules目录下的模块文件移除,然后重新编译

[root@localhost ~]# cd linux-test/myrootfs
[root@localhost myrootfs]# ls
mkrootfs  rootfs
[root@localhost myrootfs]# mv ./rootfs/lib/modules/* ./
[root@localhost myrootfs]# cd ../linux-2.6.32.2
[root@localhost linux-2.6.32.2]# make uImage

编译完成后生成uImage文件,启动u-boot下载

[u-boot@MINI2440]# tftp 31000000 uImage
dm9000 i/o: 0x20000300, id: 0x90000a46
DM9000: running in 16 bit mode
MAC: 08:00:3e:26:0a:5b
operating at 100M full duplex mode
Using dm9000 device
TFTP from server 10.1.0.128; our IP address is 10.1.0.129
Filename \'uImage\'.
Load address: 0x31000000
Loading: #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         ###############
done
Bytes transferred = 6895692 (69384c hex)
[u-boot@MINI2440]# bootm 31000000
## Booting kernel from Legacy Image at 31000000 ...
   Image Name:   Linux-2.6.32.2
   Created:      2011-06-07   7:00:10 UTC
   Image Type:   ARM Linux Kernel Image (uncompressed)
   Data Size:    6895628 Bytes =  6.6 MB
   Load Address: 30008000
   Entry Point:  30008000
   Verifying Checksum ... OK
   Loading Kernel Image ... OK
OK

Starting kernel ...

Uncompressing Linux.............................................................
................................................................................
................................................................................
........................................................ done, booting the kernel.
Linux version 2.6.32.2 (root@localhost.localdomain) (gcc version 4.4.3 (ctng-1.6
.1) ) #16 T Jun 7 14:59:55 CST 2011
CPU: ARM920T [41129200] revision 0 (ARMv4T), cr=00007177
CPU: VIVT data cache, VIVT instr tion cache
Machine: my mini2440 devolopment board singleboy@163.com
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/nfs rw nfsroot=10.1.0.128:/nfsboot/rootfs ip=10.1.0.129:10.1.0.128:10.1.0.1
:255.255.255.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: 55836KB available (3680K code, 418K data, 4828K init, 0K highmem)
SL : Genslabs=11, HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
Hierarchical RCU implementation.
NR_IRQS:85
irq: clearing s pending status 00000003
irq: clearing s pending 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 b?r 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 h
usbcore: registered new device driver usb
s3c-i2c s3c2440-i2c: slave address 0x10
s3c-i2c s3c2440-i2c: bus freqncy 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 p 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 109
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 b?r device 60x53
fb0: s3c2410fb frame b?r device
s3c2440- rt.0: s3c2410_serial0 at MMIO 0x50000000 (irq = 70) is a S3C2440
s3c2440- rt.1: s3c2410_serial1 at MMIO 0x50004000 (irq = 73) is a S3C2440
s3c2440- rt.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: Man?turer ID: 0xec, Chip ID: 0xf1 (Samsung NAND 128MiB 3,3V 8-bit)
Scanning device for bad blocks
Creating 5 MTD partitions on \"NAND 128MiB 3,3V 8-bit\":
0x000000000000-0x000000040000 : \"boot\"
0x000000040000-0x000000060000 : \"param\"
0x000000060000-0x000000560000 : \"kernel\"
0x000000560000-0x000008000000 : \"rootfs\"
0x000000000000-0x000008000000 : \"nand\"
dm9000 Ethernet Driver, V1.31
eth0: dm9000e at c486e300,c4872304 IRQ 51 MAC: 08:90:90:90:90:90 (chip)
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
h 1-0:1.0: USB h found
h 1-0:1.0: 2 ports detected
usbcore: registered new interface driver libus l
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 A134X
No device for DAI s3c24xx-i2s
ALSA device list:
  No soundcards found.
TCP c ic registered
NET: Registered protocol family 17
drivers/rtc/hctosys.c: unable to open rtc device (rtc0)
eth0: link up, 100Mbps, full-duplex, lpa 0x45E1
IP-Config: Complete:
     device=eth0, addr=10.1.0.129, mask=255.255.255.0, gw=10.1.0.1,
     host=10.1.0.129, domain=, nis-domain=(none),
     bootserver=10.1.0.128, rootserver=10.1.0.128, rootpath=
Freeing init memory: 4828K
----------munt all----------------
***********************************************
************booting to mini2440 *****************
Kernel version:linux-2.6.32.2
the fans:singleboy
Date:2011.5.30
***********************************************

Please press Enter to activate this console.

为了与后续生成的uImage文件区别,将这次生成的uImage文件备份到myrootfs目录下,重命名为uImag_initramfs

[root@localhost linux-2.6.32.2]# cp ./arch/arm/boot/uImage ../myrootfs/uImage_initramfs
[root@localhost linux-2.6.32.2]# ls ../myrootfs
2.6.32.2  2.6.32.2-FriendlyARM  mkrootfs  rootfs  uImage_initramfs
为了方便后面的操作,现将之前移除的rootfs/lib/modules目录下的文件还原

[root@localhost myrootfs]# ls
2.6.32.2  2.6.32.2-FriendlyARM  mkrootfs  rootfs  uImage_initramfs
[root@localhost myrootfs]# mv 2.6.32.2 ./rootfs/lib/modules/2.6.32.2
[root@localhost myrootfs]# mv 2.6.32.2-FriendlyARM ./rootfs/lib/modules/2.6.32.2-FriendlyARM
[root@localhost myrootfs]#

然后需要执行
[root@localhost linux-2.6.32.2]# make menconfig

General setup  --->

[*] Initial RAM filesystem and RAM disk (initramfs/initrd) suppor
按空格键将“[*] Initial RAM filesystem and RAM disk (initramfs/initrd) suppor”选项关闭。

[ ] Initial RAM filesystem and RAM disk (initramfs/initrd) suppor
然后重新编译。

【3】将制作根文件系统通过mkyaffs2image工具制作成yaffs文件系统映像文件,然后烧录到nand flash中。

(1) 将友善提供的mkyaffs2image.tgz包进行解压,即可使用:

[root@localhost linux-test]# ls
busybox-1.13.3          linux-2.6.39       rootfs_qtopia_qt4
busybox-1.18.4.tar.bz2  mkyaffs2image.tgz  rootfs_qtopia_qt4-20110304.tar.gz
linux-2.6.32.2          myrootfs           yaffs2
然后在myrootfs 目录下,使用命令mkyaffs2image rootfs rootfs.img 生成根文件系统映像文件。

[root@localhost linux-test]# tar -vxzf mkyaffs2image.tgz -C /
usr/sbin/mkyaffs2image
usr/sbin/mkyaffs2image-128M
[root@localhost linux-test]#
[root@localhost myrootfs]# cd myrootfs
[root@localhost myrootfs]# mkyaffs2image-128M rootfs rootfs-128M

[root@localhost myrootfs]# ls
mkrootfs  rootfs  rootfs-128M  uImage_initramfs
[root@localhost myrootfs]#
其中mkyaffs2image-128M是用于128M及以上的nand flash。

(2)确认其是否有执行权限

[root@localhost myrootfs]# ll
总计 62760
-rwxr-xr-x  1 root root      554 05-30 14:40 mkrootfs
drwxr-xr-x 17 root root     4096 06-02 10:41 rootfs
-rw-------  1 root root 57285888 06-07 16:32 rootfs-128M
-rw-r--r--  1 root root  6895692 06-07 16:07 uImage_initramfs
赋予其执行权限

[root@localhost myrootfs]# chmod a+rwx rootfs-128M
[root@localhost myrootfs]# ll
总计 62760
-rwxr-xr-x  1 root root      554 05-30 14:40 mkrootfs
drwxr-xr-x 17 root root     4096 06-02 10:41 rootfs
-rwxrwxrwx  1 root root 57285888 06-07 16:32 rootfs-128M
-rw-r--r--  1 root root  6895692 06-07 16:07 uImage_initramfs
[root@localhost myrootfs]#

否则会产生\'Permission denied\' (0) 错误。

(2) 下载测试

将生成的rootfs.img文件复制到主机的/tftpboot目录下

[root@localhost myrootfs]# cp -drf rootfs-128M /tftpboot/
[root@localhost myrootfs]#

参数d表示保持与库文件的链接关系

(3) 给开发板上电,启动u-boot后用tftp下载rootfs根文件系统

U-Boot 2009.08

 modified by singleboy (singleboy@163.com)
 Love Linux forever!!

I2C:   ready
DRAM:  64 MB
Flash:  2 MB
NAND:  128 MiB
Video: 240x320x16 20kHz 62Hz
In:    serial
Out:   serial
Err:   serial
Net:   dm9000
U-Boot 2009.08
modified by singleboy(singleboy@163.com)
Love Linux forever!!!
Hit any key to stop autoboot:  0
[u-boot@MINI2440]# tftp 30008000 rootfs-128M
dm9000 i/o: 0x20000300, id: 0x90000a46
DM9000: running in 16 bit mode
MAC: 08:00:3e:26:0a:5b
operating at 100M full duplex mode
Using dm9000 device
TFTP from server 10.1.0.128; our IP address is 10.1.0.129
Filename \'rootfs-128M\'.
Load address: 0x30008000
Loading: #################################################################
              #################################################################         

              ......        

               #################################################################
              #######################################################
done
Bytes transferred = 55678656 (35196c0 hex)
[u-boot@MINI2440]#

OK!下载成功。将其烧录到nand flash,注意,nand flash分区表

Creating 5 MTD partitions on \"NAND 128MiB 3,3V 8-bit\":
0x000000000000-0x000000040000 : \"boot\"
0x000000040000-0x000000060000 : \"param\"
0x000000060000-0x000000560000 : \"kernel\"
0x000000560000-0x000008000000 : \"rootfs\"
0x000000000000-0x000008000000 : \"nand\"
rootfs起始地址是560000。

[u-boot@MINI2440]# nand erase 0x560000 0x3600000

NAND erase: device 0 offset 0x560000, size 0x3600000
Erasing at 0x3b4000000000000 --   0% complete.
OK

[u-boot@MINI2440]# nand write 0x30008000 0x560000 0x3600000

NAND write: device 0 offset 0x560000, size 0x3600000
Writing at 0x3b4000000020000 -- 100% is complete. 56623104 bytes written: OK

 重启开发板

... ...

VFS: Mounted root (yaffs filesystem) on device 31:3.
Freeing init memory: 132K
Warning: unable to open an initial console.
Failed to execute /linuxrc.
  Attempting defaults...
Kernel panic - not syncing: No init found. 

问题分析:rootfs能够在nfs根文件系统中启动,nfs只能验证文件系统本身,而不能验证yaffs2格式的支持,重新设定引导参数从nfs启动,然后进入控制台将分别挂载/dev/mtdbolck0~3分区。

接下来,要解决nand flash 的mtd 分区的操作工具问题

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值