busybox-1.20.2 交叉编译 并构建最小根文件系统

来源:互联网 发布:软件测试好学吗 编辑:程序博客网 时间:2024/06/05 18:58

1 导出交叉编译器路径:

export PATH=$PATH:/opt/freescale/usr/local/gcc-4.6.2-glibc-2.13-linaro-multilib-2011.12/fsl-linaro-toolchain/bin/


2 进入busybox-1.20.2目录执行make menuconfig

Busybox Settings  ---> 

Build Options  --->  

[ ] Build BusyBox as a static binary (no shared libs) 

( ) Cross Compiler prefix 

Cross Compiler prefix 输入交叉编译器前缀:arm-none-linux-gnueabi-

如果需要静态编译busybox,可以选上以下这一项:Build BusyBox as a static binary (no shared libs) 

Installation Options ("make install" behavior)  --->  

( ) BusyBox installation prefix 

BusyBox installation prefix 输入.bin,即make install后安装到.bin目录下


3 建立安装目录:mkdir bin

4 编译:make 

5 安装:make install

到此,busybox已经全部编译结束。


进入安装bin目录下,建立最小根文件系统所需其他目录:mkdir dev  etc  lib  mnt  proc  sbin  sys  tmp  usr

进入etc下,建立以下两个文件:inittab  rcS

inittab文件内容:

# /etc/inittab
#
# Copyright (C) 2001 Erik Andersen <andersen@codepoet.org>
#
# Note: BusyBox init doesn't support runlevels.  The runlevels field is
# completely ignored by BusyBox init. If you want runlevels, use
# sysvinit.
#
# Format for each entry: <id>:<runlevels>:<action>:<process>
#
# id        == tty to run on, or empty for /dev/console
# runlevels == ignored
# action    == one of sysinit, respawn, askfirst, wait, and once
# process   == program to run


# Startup the system
::sysinit:/etc/rcS


# Set up a couple of getty's
# Put a getty on the serial port
ttymxc0::askfirst:/bin/sh
#ttymxc0::respawn:/bin/sh 


# Logging junk


# Stuff to do before rebooting
#null::shutdown:/bin/umount -a -r


rcS文件内容:

#!/bin/sh
mount -t proc /proc /proc
mount -t sysfs /sys /sys
#busybox --install -s
mount tmpfs /tmp -t tmpfs -o size=80%
echo /sbin/mdev > /proc/sys/kernel/hotplug
mdev -s

ifconfig eth0 192.168.1.11 up
ifconfig lo up &


进入dev下建立两个设备文件:console  null

mknod console c 5 1

mknod null c 1 3


由于我用来做initramfs,所以把linuxrc改为init:mv linuxrc init

接下来就是把busybox所需动态库拷贝到lib下,首先查看一下所需动态库: arm-none-linux-gnueabi-readelf -d bin/busybox  

Dynamic section at offset 0xe400c contains 25 entries:
  Tag        Type                         Name/Value
 0x00000001 (NEEDED)                     Shared library: [libm.so.6]
 0x00000001 (NEEDED)                     Shared library: [libc.so.6]
 0x0000000c (INIT)                       0xbfbc
 0x0000000d (FINI)                       0xca524
 0x00000019 (INIT_ARRAY)                 0xf4000
 0x0000001b (INIT_ARRAYSZ)               4 (bytes)
 0x0000001a (FINI_ARRAY)                 0xf4004
 0x0000001c (FINI_ARRAYSZ)               4 (bytes)
 0x00000004 (HASH)                       0x8168
 0x00000005 (STRTAB)                     0xa3dc
 0x00000006 (SYMTAB)                     0x8b9c
 0x0000000a (STRSZ)                      3232 (bytes)
 0x0000000b (SYMENT)                     16 (bytes)
 0x00000015 (DEBUG)                      0x0
 0x00000003 (PLTGOT)                     0xf40fc
 0x00000002 (PLTRELSZ)                   2968 (bytes)
 0x00000014 (PLTREL)                     REL
 0x00000017 (JMPREL)                     0xb424
 0x00000011 (REL)                        0xb3c4
 0x00000012 (RELSZ)                      96 (bytes)
 0x00000013 (RELENT)                     8 (bytes)
 0x6ffffffe (VERNEED)                    0xb384
 0x6fffffff (VERNEEDNUM)                 2
 0x6ffffff0 (VERSYM)                     0xb07c
 0x00000000 (NULL)                       0x0


一般只需要拷贝以上两个红色标注的动态库,但是为了以后开发不需要重修拷贝,把整个交叉编译器的库都拷到lib下。


至此,最小根文件系统已经构建完成。


0 0
原创粉丝点击