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

busybox 交叉编译

2013年10月19日 ⁄ 综合 ⁄ 共 3762字 ⁄ 字号 评论关闭

1, 下载busybox,http://www.busybox.net/  

2, 下载arm-linux  交叉编译工具链arm-linux-gcc-3.4.5

3,进入busybox文件夹,makemenuconfig

Busybox Settings  ---> 

              Build Options  --->

                     [*] BuildBusyBox as a static binary (no shared libs)

                     [ ] ForceNOMMU build

                     [ ] Buildwith Large File Support (for accessing files > 2 GB)

                     (arm-softfloat-linux-gnu-)Cross Compiler prefix

                     ()  Additional CFLAGS

选中“Cross Compiler prefix”,回车,然后输入交叉编译工具链地址, 可以使用export PATH=$PATH:$(your cross compiler path)

注意: 这里选择的是静态编译busybox  ,  所以自己的程序交叉编译的时候也需要静态编译。否则无法运行。

动态编译操作:

1).BusyBox-1.10.1的配置中将如下选项勾上:

Busybox settings->

Build Options->

Build shared bosybox->

将如下两项去掉勾(不去掉编译通不过,具体愿因还未研究):

Produce a binary for each applet,linked against libbusybox.

Produce a additional busybox binary linked against libbusybox.


2).在建立文件系统时将交叉编译器的lib库全部复制到文件系统的ib库中,一般可以运行起来,如果还差其它动态库,则找到后放在文件系统的lib库下即可.如我的4.0版本的交叉编译器lib库为../arm-9tdmi-linux-gnu/arm-9tdmi-linux-gnu/lib下面,复制到文件系统的lib目录中,并在etc目录下建立一个ld.so.conf配置文件,将动态库的路径加入其中,usr/local/lib,保存.然事在PC上对文件系统根目录运行配置命令:如根目录为netfs,则如下:

ldconfig –r netfs

之后在etc下生成一个ld.so.cache的文件,这样启动后即可加载动态编译的文件系统了,自己的编译的程序也不用静态编译了.

4, make

出错: #1  

       miscutils/ionice.c:16:error: `SYS_ioprio_set' undeclared (first use in this function)

       miscutils/ionice.c:16:error: (Each undeclared identifier is reported only once

       miscutils/ionice.c:16:error: for each function it appears in.)

解决:

miscutils/ionice.c添加如下内容:

       #define SYS_ioprio_set 289

       #define SYS_ioprio_get 290

       (这个宏可以在主机的/usr/include下查到)

       重新编译:

出错: #2

miscutils/nandwrite.c:49:26: mtd/mtd-user.h: No such file or directory

解决:

cp /usr/include/mtd/  ./include/mtd/  -a

出错:  #3

networking/interface.c:818: error: `ARPHRD_INFINIBAND’ undeclared here(not in a function)

解决:

修改networking/interface.c
vim networking/interface.c
添加define ARPHRD_INFINIBAND 32 /* InfiniBand */

出错: #4

错误4:
util-linux/acpid.c: In function `acpid_main’:
util-linux/acpid.c:146: error: `EV_SW’ undeclared (first use in thisfunction)
util-linux/acpid.c:146: error: (Each undeclared identifier is reportedonly once
util-linux/acpid.c:146: error: for each function it appears in.)
util-linux/acpid.c:147: error: `SW_LID’ undeclared (first use in thisfunction)

解决:
cp /opt/linuxcore/linux-2.6.33.3/include/linux/ ./include/ -a

5,make install

生成   _install 文件夹

6, 配置文件系统

mkdir dev etc lib mnt proc var tmp sys root

建立初始化启动所需文件

Ø  创建inittab文件

       进入_install/etc目录,建立inittab文件,文件内容:

       #this is run first except when booting insingle-user mode.

       :: sysinit:/etc/init.d/rcS

          # /bin/sh invocations on selected ttys

       # Start an "askfirst" shell on theconsole (whatever that may be)

          ::askfirst:-/bin/sh

          # Stuff to do when restarting the init process

          ::restart:/sbin/init

          # Stuff to do before rebooting

          ::ctrlaltdel:/sbin/reboot

Ø  创建fstab文件

       进入_install/etc下面,创建fstab文件,添加如下内容

       #device 
     mount-point     type   options              dump             fsckorder

       proc           /proc              proc     defaults           0           0

       tmpfs        /tmp                  tmpfs   defaults              0                 0

       sysfs         /sys                    sysfs    defaults        0                   0

       tmpfs          /dev                   tmpfs   defaults              0                 0

Ø  创建init.d/rcS

进入_install/etc下创建init.d/rcS文件,添加如下内容

             
#!/bin/sh

          # This is the first script called by init process

          /bin/mount –a

Ø  创建profile文件

进入_install/etc下创建profile文件,添加如下内容:

#!/bin/sh

export HOSTNAME=mylinux

export USER=root

export HOME=root

#export PS1="\[\u@\h \W\]\$ "

cd root

export PS1="[$USER@$HOSTNAME \W]\# "

PATH=/bin:/sbin:/usr/bin:/usr/sbin

LD_LIBRARY_PATH=/lib:/usr/lib:$LD_LIBRARY_PATH

export PATH LD_LIBRARY_PATH

Ø  dev下创建终端设备节点console

进入_install/dev创建设备节点console

mknod console        c    5   1

Ø  建立嵌入式系统库

cp gcc-3.4.5-glibc-2.3.6/arm-linux/lib_install/lib/ -a

cd_install/lib

删除所又无用的目录和静态库 (所有的目录和.a文件)

然后剥除库文件中的调试段等信息,从而减小库的体积。运行:

arm-softfloat-linux-gnu-strip *.so

抱歉!评论已关闭.