用busybox打造S3C2410上的檔案系統

來源:互聯網
上載者:User
很久以前就用過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 順利,動態連結編譯時間也順利,
但用動態連結做成的檔案系統是否能成功   掛載運行, 還沒有試

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.