Chinaunix首页 | 论坛 | 博客
  • 博客访问: 28499
  • 博文数量: 14
  • 博客积分: 772
  • 博客等级: 军士长
  • 技术积分: 125
  • 用 户 组: 普通用户
  • 注册时间: 2008-11-07 17:27
文章分类

全部博文(14)

文章存档

2010年(7)

2009年(6)

2008年(1)

我的朋友

分类: LINUX

2010-01-13 16:37:47

 此文仅介绍busybox生成根文件系统的步骤和方法.对生成后的文件是否运行未做验证.


 一  修改busybox中的 Makefile文件 
 找到  ARCH  和 CROSS_COMPILE 修改成如下
 ARCH            ?= arm
 CROSS_COMPILE   ?= /usr/local/arm/3.3.2/bin/arm-linux-

 二  配置busybox(不同的busybox采用不同的配置方案,此外仅供参考)

 [root@localhost busybox]# make defconfig
 [root@localhost busybox]# make xconfig
 =============================================
 修改配置 主要修改如下
 =============================================
 Busybox Settings
     Build Options
   [*]Build BusyBox as a static binary    
      //选此项静态编译。

 Miscellaneous Utilities
     []taskset    //选了就会出错

 -------------------------------------------------
 三  编译
 [root@localhost busybox-1.5.1]# make all install
 -----------------------------------------------------------------
 最后会在  busybox-1.5.1/_install/目录生成你要的 bin sbin  usr 目录
 ------------------------------------------------------------------
 
2. 编写linuxrc 文件
 -----------------------------------------------------------------
 #!/bin/sh
 #echo "mount /etc as ramfs"
 /bin/mount -n -t ramfs ramfs /etc
 /bin/cp -a /mnt/etc/* /etc

 echo "re-create the /etc/mtab entries"
 # re-create the /etc/mtab entries
 /bin/mount -f -t cramfs -o remount,ro /dev/mtdblock/3  /

 #mount some file system
 echo "mount  /dev/shm as tmpfs"
 /bin/mount -n -t  tmpfs tmpfs /dev/shm


 #挂载/procproc文件系统
 echo "mount /proc as proc"
 /bin/mount -n -t  proc none /proc

 #挂载/syssysfs文件系统
 echo "mount  /sys as sysfs"  
 /bin/mount -n -t  sysfs none /sys

 /bin/mount -f -t ramfs ramfs /etc

 echo "yaffs is mounted"
 /bin/mount -t yaffs /dev/mtdblock/1 /mnt/yaffs
 exec /sbin/init 
 ---------------------------------------------------------------------
3. 权限修改
 chmod  chmod 775 linuxrc

4.  编写 inittab文件
 
 ---------------------------------------------------------------------
 ::sysinit:/etc/init.d/rc
 
 ::askfirst:-/bin/sh
 tty2::askfirst:-/bin/sh
 tty3::askfirst:-/bin/sh
 tty4::askfirst:-/bin/sh
 tty0::askfirst:-/bin/sh
   
 ::restart:/sbin/init
        
 ::ctrlaltdel:/sbin/reboot
 ::shutdown:/bin/umount -a -r
 ::shutdown:/sbin/swapoff -a
 ----------------------------------------------------------------------

5. rc文件
 ----------------------------------------------------------------------
 #!/bin/sh

 /bin/mount -a
 -----------------------------------------------------------------------

6. fastab 文件
 ----------------------------------------------------------------------
 none  /proc  proc defaults 0 0
 none  /dev/pts devpts mode=0622 0 0
 tmpfs  /dev/shm tmpfs defaults 0 0
 ----------------------------------------------------------------------


7. 各文件的关系
 ----------------------------------------------------------------------
 7.1 建立一个目标板的空根目录
 我们将在这里构建构建根文件系统,创建基础目录结构存放交叉编译后生成的目标应用程序
 (BUSYBOXTINYLOGIN),存放库文件等。
 [root@localhost rootfs]# mkdir my_rootfs
 [root@localhost rootfs]# pwd
 /home/arm/dev_home/rootfs/my_rootfs
 [root@localhost rootfs]# cd my_rootfs
 [root@localhost my_rootfs]#
 7.2 my_rootfs中建立Linux目录树
 [root@localhost my_rootfs]#mkdir bin dev etc home lib mnt proc sbin sys tmp root usr
 [root@localhost my_rootfs]#mkdir mnt/etc
 [root@localhost my_rootfs]#mkdir usr/bin usr/lib usr/sbin
 [root@localhost my_rootfs]#touch linuxrc
 [root@localhost my_rootfs]#tree
 |bin
 |dev
 |etc
 |home
 |lib
 |linuxrc
 /* 此文件为启动脚本,是一shell脚本文件。本文后面有专门介绍 */
 |mnt
 | `etc   
 |proc
 |sbin
 |sys
 |tmp
 |root
 `usr
 |bin
 |lib
 `sbin

8. 把上面编译出来的 busybox文件拷贝到 my_rootfs 文件系统 
 ---------------------------------------------------------------
 把 busybox1.5.1/_install/目录下的 bin  sbin  usr 覆盖 my_rootfs
 文件夹里的空文件夹。
 --------------------------------------------------------------

9. 把 生成的文件(rc)拷贝到 /mnt/etc/init.d/目录(先在/mnt/etc/目录新建格init.d目录)
 把 46生成的文件(inittab和 fastab )放到 /mnt/etc/目录
 把 生成的文件linuxrc 放到/目录 
         这里所提到的 /目录即my_rootfs目录。
10. 新建/dev设备,/dev目录(即my_rootfs/dev/.
 mknod console c 5 1

非常重要之/lib,务必重视(此处对lib的添加的前提是对busybox的编译采用的是动态的编译方式,如果一天开始采用的是静态的编译方式,则没有必要对lib目录的文件拷贝   
    找到你编译环境的target目录,把需要的lib文件先用strip压縮(非target目录下的,而已编译环境提供的strip),先把最基本的libc, ld等等,必须同样做跟target/lib里面一样的link
    然后根据特定的应用加相应的lib,不要把不用的加进去,lib比较占空间

采用动态方式的拷贝方法如下:

/*****

[root@localhost bin]# file busybox
busybox: elf 32-bit lsb executable, arm, version 1, dynamically linked (uses shared libs), for gnu/linux 2.0.0, stripped
四 查看共享了哪些库文件
用命令 arm-linux-readelf -a ${program} | grep "shared library"
---------------------------------------------------------------
[root@localhost bin]# pwd
/root/maoyong/busybox-1.4.2/_install/bin
[root@localhost bin]# arm-linux-readelf -a busybox | grep "shared library"
0x00000001 (needed) shared library: [libcrypt.so.1]
0x00000001 (needed) shared library: [libm.so.6]
0x00000001 (needed) shared library: [libc.so.6]
------------------------------------------------------------------
如上所示 要把 /usr/local/arm/3.3.2/arm-linux/lib目录下的
libcrypt.so.1
libm.so.6
libc.so.6
文件是busybox所需的共享库文件,要把它以及和他相关的链接文件拷贝到
你新建的文件系统的 lib 目录。
(注意: libcrypt.so.1 libm.so.6 libc.so.6相关的链接文件也要拷贝到lib目录)

*****/

8. 生成cramfs文件
 
 ----------------------------------------------------------------
 下载mkfs.cramfs工具,然后用下面命令生成你要的cramfs文件系统
 ./mkcramfs  ./my_rootfs    ./root.cramfs

在ubuntu系统,mkfs.cramfs工具可以直接apt-get 获取。

Mkfs.cramfs 工具由util-linux-2.12r.tar.bz2产生(./configure  make  makeinstall)

阅读(364) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~