原创 嵌入式linux根目录制作

2008-7-22 10:42 3119 3 3 分类: MCU/ 嵌入式
(1)创建根文件系统的基本目录结构。
把这个过程做成shell脚本(红色部分) ,在要建立根目录的地方运行即可。?
#! /bin/sh
? echo "creatint rootfs dir......"
? mkdir rootfs
? cd rootfs

? echo "making dir : bin dev etc lib proc sbin sys usr"
? mkdir bin dev etc lib proc sbin sys usr #必备的8个目录
? mkdir usr/bin usr/lib usr/sbin lib/modules

? echo "making dir : mnt tmp var"
? mkdir mnt tmp var
? chmod 1777 tmp
? mkdir mnt/etc mnt/jffs2 mnt/yaffs mnt/data mnt/temp
? mkdir var/lib var/lock var/log var/run var/tmp?
? chmod 1777 var/tmp?

? echo "making dir : home root boot"
? mkdir home root boot

? echo "done"

在你想要建立根文件系统的地方,运行上面建立的脚本:?
$ ./mkroot
creatint rootfs dir......
making dir : bin dev etc lib proc sbin sys usr
making dir : mnt tmp var
making dir : home root boot
done
$ cd rootfs/dev/
$ su
口令:
# mknod -m 600 console c 5 1;mknod -m 666 null c 1 3;exit
Exit

(2)配置busybox
$ tar -xjvf busybox-1.9.1.tar.bz2
修改Makefile
kwrite Makefile

......(第174行附近)
#ARCH ?= $(SUBARCH)
#CROSS_COMPILE ?=
......(修改为)
ARCH = arm
CROSS_COMPILE = arm-linux-

使用menuconfig配置
$ make menuconfig

在原有的基础上修改如下:
Busybox Settings --->
? Build Options --->
?
  • build busybox as a static binary (no share libs) //(1)
    ? Installation Options --->
    ?
  • Don't use /usr //(2)
    ? (/home/linux/rootfs) BusyBox installation prefix?
    ? Busybox Library Tuning --->?
    ?
  • Support for /etc/networks?
    ?
  • Additional editing keys ?
    ?
  • vi-style line editing commands ?
    ? (15) History size ?
    ?
  • History saving ?
    ?
  • Tab completion?
    ?
  • Username completion ?

    ?

  • Fancy shell prompts

    Linux System Utilities --->?
    ?

  • mdev //(3)
    ?
  • Support /etc/mdev.conf
    ?
  • Support command execution at device addition/removal
    Linux Module Utilities ---> ?

    ? [N] Support version 2.2.x to 2.4.x Linux kernels?
    Shells --->?
    ? --- Ash Shell Options 下的选项全选

    编译安装
    .1]$ make
    ......
    ?Library crypt is needed
    ?Library m is needed
    Final link with: crypt m
    $ make install

    为mdev的运行准备环境
    -----------------------------------------------
    ? mdev需要改写/dev和/sys两个目录。所以必须保证这两个目录是可写的(一般会用到sysfs,tmpfs。所以要重新编译内核)。然后在你的启动脚本文件中加入/sbin/mdev -s

    linux-2.6.19 -- make menuconfig
    File systems --->
    ? Pseudo filesystems --->?
    ?
  • sysfs file system support ?
    ?
  • Virtual memory file system support (former shm fs)?
    ?
  • Tmpfs POSIX Access Control Lists



    常见问题
    (1)因为busybox主要应用于对空间要求非常严格的嵌入式系统,所以它推荐使用uclibc而不鼓励使用glibc,如果你没有安装uclibc,而且在 build Options也选择了Build BusyBox as a static binary(no shared libs),
    Busybox Settings --->
    ? Build Options --->
    ?
  • build busybox as a static binary (no share libs)
    那肯定无法编译通过的,当然如果你之前build Options选择的是动态编译的话就不会有这样的问题出现了。假设你是第一种情况,编译的时候将会遇到下面问题:
    applets/applets.c:20:2: error: #warning Static linking against glibc produces buggy executables
    applets/applets.c:21:2: error: #warning (glibc does not cope well with ld --gc-sections).
    applets/applets.c:22:2: error: #warning See sources.redhat.com/bugzilla/show_bug.cgi?id=3400
    applets/applets.c:23:2: error: #warning Note that glibc is unsuitable for static linking anyway.
    applets/applets.c:24:2: error: #warning If you still want to do it, remove -Wl,--gc-sections
    applets/applets.c:25:2: error: #warning from top-level Makefile and remove this warning.
    make[1]: *** [applets/applets.o] Error 1

    这段警告的意思是告诉你最好用uclibc编译,而不是用glibc因为glibc比较大,busybox在寸土寸金的嵌入式系统中运用比较多,所以会有这样的要求。
    -----------------------------------------------
    我们可以这样解决:把applets/applets.c开头的几行 warning注释掉

    # vi applets/applets.c
    /*
    #if ENABLE_STATIC && defined(__GLIBC__) && !defined(__UCLIBC__)
    #warning Static linking against glibc produces buggy executables
    #warning (glibc does not cope well with ld --gc-sections).
    #warning See sources.redhat.com/bugzilla/show_bug.cgi?id=3400
    #warning Note that glibc is unsuitable for static linking anyway.
    #warning If you still want to do it, remove -Wl,--gc-sections
    #warning from top-level Makefile and remove this warning.
    #error Aborting compilation.
    #endif
    */
    该情况在使用1.10.4版本时未出现

    (2)miscutils/taskset.c:17: error: parse error before '*' token
    -----------------------------------------------
    最根本的解决办法是换一个libc库,可是现在还不知道哪个库最合适,唯有暂时将有问题的命令关掉
    Miscellaneous Utilities --->
    [ ] taskset

    (3)runit/runsv.c: In function `gettimeofday_ns':
    -----------------------------------------------

    Runit Utilities --->
    ? [ ] runsv ?

    (4)内核启动时遇到的问题:
    -----------------------------------------------
    “could not run '/bin/sh': No such file or directory”

    解决方法:
    要这样配置:
    Shells ---> ?
    ? Choose your default shell (ash) ---> ?

    如果是这样配置的话,虽然可以生成ash,但不能生成sh,将会在内核启动时出现上面出现的问题:
    Shells ---> ?
    ? Choose your default shell (none) --->
  • ash?




  • PARTNER CONTENT

    文章评论0条评论)

    登录后参与讨论
    我要评论
    0
    3
    关闭 站长推荐上一条 /4 下一条