现在的位置: 首页 > 综合 > 正文

用busybox打造S3C2410上的文件系统

2013年09月14日 ⁄ 综合 ⁄ 共 4244字 ⁄ 字号 评论关闭
很久以前就用过busybox了, 最近想在自己的这块MC2410板上做自己的文件系统.搜集了一些资料, 遇到了一些困难.  现写出来与大家分享其过程:
 
环境:
 host machine :Fedora 2
 target machine : MC2410 (S3C2410)  上面跑的 Linux version 2.4.18-rmk7-pxa1 (root@Rhvd) (gcc version 2.95.2 20000516 (releas6) 内核.

 安装交叉编译工具链, 我使用的是arm-linux-3.32 ,然后下载busybox-1.2.1,
 
 说明: linux上的软件版本很重要,有时版本不一样,就不能正常编译,经验之谈. 我看了网上的人家做的一般是 arm-linux-3.32 + busybox-1.1.3 ,说是编译没有问题, 但结果我却出了问题,可能我的host OS 不是Rh9吧

 顺便说一句: 不知为何搞嵌入式的公司都用Rh9, 由于在网上现在很难下载到Rh9,就装了Fedora.就不信这个邪.
 
 1: 交叉编译busybox  ,make menuconfig
 这里需要注意的地方:
 
  在Build Options里面
  Build busybox  as  a staic binary (no shared libs) ,我是选yes, 毕竟静态链接比较简单, 先把简单的做成功再做复杂的.
  Build shared libbusybox  没有选
  Do you want to build BusyBox with a Cross Compiler
 填写/usr/local/arm/3.3.2/bin/arm-linux-
 
  在Installation Options里面可以设置安装的路径,即设置为新文件系统的根目录。当然也可以用缺省的 _install目录,安装之后再复制到新文件系统中去。
 
  Shells >                                                               
                    Choose your default shell (ash) >                            
                        /* (X) ash 选中ash,这样生成的时候才会生成bin/sh文件
特别注意这个地方: 刚开始没有选择这个Choose your default shell (none) >为ash, 由于默认是none ,结果做成的文件系统启动后出现: sh: applet not found

其他的配置见文章最后的.config文件内容
                  
  make  TARGET_ARCH=arm all (看到网上的是这样的, 刚开始我一直就是用 make ,没有加参数)
 
  make instll (将在_INSTLL生成 bin,sbin两个文件夹和一个linuxrc文件.

 2: 创建文件系统的启动脚本
  mkdir root_fs
  cp     _INSTLL生成的bin,sbin两个文件夹   .
 
  在这里,我没有要生成的linuxrc, 参考了网上的资料, 写了一个
linuxrc------->
#!/bin/sh
/sbin/insmod -f /lib/yaffs.o 
/bin/mount  -f -t cramfs  -o remount,ro  /dev/mtdblock/3 / 
/bin/mount -t  yaffs /dev/mtdblock/4   /usr 
exec /sbin/init
然后chmod 777 linuxrc  ,因为内核启动参数中init=/linuxrc,可见linuxrc肯定要是可执行的文件. 这个linxurc特别重要, 影响启动是否成功.
 
 由于我这里用到了YAFFS系统, 故将yaffs.o考到root_fs/lib之下 
  
 我自己对照了一下原来板子提供的文件系统里的启动脚本文件,研究发现/etc/下面须有init.d/rcS,
  passwd,  group, fstab
  至于是否是非要这几个文件不可, 还有待考证.
 
  这里只是列出我的过程:
  init.d/rcS ------->
 
 #! /bin/sh
/bin/mount -o remount,rw  /
/bin/mount -a
/bin/hostname  hjembed  (这句很明显配置hostname 的,要不要随你)

fstab ------->
none          /proc           proc      defaults    0   0
none         /dev/pts         devpts    mode=0622     0    0
tmpfs        /dev/shm         tmpfs     defaults      0    0

group------->
root:x:0:root

resolv.conf------->
nameserver  202.114.88.10
nameserver  202.114.160.10 (这里很明显配置DNS的,要不要随你)

3: 试验新的文件系统
./mkcramfs  root_fs  root_fs.cramfs
将root_fs.cramfs烧写进板子,发现启动正常,mount nfs文件系统也没有问题.

另: 在编译busybox-1.1.3时,

用arm-toolchains-3.3.2 编译busybox-1.1.3 ,静态链接, 出现如下问题:
/opt/busybox-1.1.3/util-linux/util-linux.a(mount.o)(.text+0x5fc): In function `singlemount':
: undefined reference to `del_loop'
collect2: ld returned 1 exit status
make[1]: *** [busybox_unstripped] 错误 1
make: *** [all] 错误 2

在busybox 的mail list里面搜到
 http://www.busybox.net/lists/busybox/2006-April/020352.html

[1.1.2] missing build deps for mount
Bernhard Fischer rep.nop at aon.at
Wed Apr 12 01:32:01 PDT 2006

    * Previous message: [1.1.2] missing build deps for mount
    * Next message: [1.1.2] missing build deps for mount
    * Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

On Tue, Apr 11, 2006 at 04:31:12PM -0700, Andre wrote:
>I get the following while trying to build 1.1.2 (and 1.1.1)

>  LINK busybox_unstripped
>/home/andre/busybox-1.1.2/util-linux/util-linux.a(mount.o): In
>function `singlemount':
>mount.c:(.text+0x420): undefined reference to `del_loop'
>collect2: ld returned 1 exit status
>

>CONFIG_MOUNT=y
>CONFIG_UMOUNT=y

what's your gcc -v and version of binutils?

You don't seem to have CONFIG_FEATURE_MOUNT_LOOP nor CONFIG_LOSETUP set,so loopFile should be 0, thus the compiler should have optimized away the call to del_loop()..

AFAICS from a quick glance, all should be well (modulo toolchain surprises), so the snippet below should really not be needed.Alternatively we could stub out the bodies of set_loop and del_loop etal, but i don't like this.

Index: util-linux/mount.c
===================================================================
--- util-linux/mount.c  (revision 14831)
+++ util-linux/mount.c  (working copy)
@@ -351,7 +351,7 @@
 
        // If mount failed, clean up loop file (if any).
 
-       if (rc && loopFile) {
+       if (ENABLE_FEATURE_MOUNT_LOOP && rc && loopFile) {
                del_loop(mp->mnt_fsname);
                if (ENABLE_FEATURE_CLEAN_UP) {
                        free(loopFile);

  故去掉util-linux/mount.c 上面的这么一段, 就编译成功了.
 
在搜索中文网站都没有找到解决办法, 结果却在mail list 中找到答案了, 看来出问题查阅mail list 是一个捷径哦.

  列出busybox  的.config文件内容
 
>>最近在华恒论坛上发现一个帖子:
   
做BUSYBOX的时候,还是获得了一丁点经验:
make menuconfig的时候,有个交叉编译器的选项的,在其config.in文件中可以修改交叉编译器。
BUSYBOX1.2.0好像是不支持LINUX2.4内核的,如果选支持LINUX2.4内核,在选上INSMOD和RMOD的时候,就会编译出错
 
发现的确如此, 去掉了支持2.4内核模块时, 用3.4.1 静态编译busybox 1.2.1 顺利,动态链接编译时也顺利,
但用动态链接做成的文件系统是否能成功   挂载运行, 还没有试

抱歉!评论已关闭.