在Linux下为嵌入式Linux内核编译busybox

2019-07-13 00:33发布

 笔者所用的是一块ARM9 Atmel 9200的开发板,Linux内核为2.4.27, 交叉编译器为2.95.3,编译环境为RedHat9 Linux下。 1、从http://www.busybox.net/downloads下载到busybox,笔者下载的为busybox1.1.3,下载后解压到一个目录下,如 /tmp 目录下; 2、进入解压后的目录,输入make menuconfig 进行编译配置,基本的配置如下:
Busybox Settings >                                                              
          General Configuration >                                                
                     [*] Support for devfs                                       
          Build Options >                                                        
                     [*] Build BusyBox as a static binary (no shared libs)       
                           /* 将busybox编译为静态连接,少了启动时找动态库的麻烦 */     
                     [*] Do you want to build BusyBox with a Cross Compiler?     
                       (/usr/local/arm/3.3.2/bin/armlinux)                       
                       Cross Compiler prefix                                     
                          /* 指定交叉编译工具路径 */                                
          Init Utilities >                                                       
                    [*] init                                                     
                    [*] Support reading an inittab file                          
                         /* 支持init读取/etc/inittab配置文件,一定要选上 */          
          Shells >                                                               
                    Choose your default shell (ash) >                            
                        /* (X) ash 选中ash,这样生成的时候才会生成bin/sh文件          
                         * 看看我们前头的linuxrc脚本的头一句:                       
                         * #!/bin/sh 是由bin/sh来解释执行的*/                       
                    [*] ash                                                      
          Coreutils >                                                            
                    [*] cp                                                       
                    [*] cat                                                      
                    [*] ls                                                       
                    [*] mkdir                                                    
                    [*] echo (basic SuSv3 version taking no options)             
                    [*] env                                                      
                    [*] mv                                                       
                    [*] pwd                                                      
                    [*] rm                                                       
                    [*] touch                                                    
         Editors >                                                               
                    [*] vi                                                       
         Linux System Utilities >                                                
                    [*] mount                                                     
                    [*] umount                                                   
                    [*] Support loopback mounts                                  
                    [*] Support for the old /etc/mtab file                       
         Networking Utilities >                                                  
                    [*] inetd                                                    
                       /* 支持inetd超级服务器inetd的配置文件为/etc/inetd.conf文件,   
                        * "在该部分的4: 相关配置文件的创建"一节会有说明*/             
3、编译并安装Busybox
[arm@localhost busybox1.1.3]$make TARGET_ARCH=arm CROSS=/usr/local/arm/2.85.3/bin/arm-linux- PREFIX=/root/arm_9200/rdmnt/ all install CROSS 为交叉编译器的路径。
PREFIX指明安装路径:就是我们根文件系统所在路径。
* 这里需要注意一点的是,只要install busybox,我们根文件系统下先前建好的linuxrc就会被覆盖为一同名二进
制文件。所以要事先备份我们自己的linuxrc,在安装完busybox后,将linuxrc复制回去就好。
* 如果在编译的过程中出现错误,这可能是某些支持问题,可以在配置的时候把相关的选项去掉试试。
* 如果出现找不到内核版本号的编译错误,可以有两种方法解决:(1)把你的内核源码中的version.h文件拷贝到交叉编译器的包含文件的linux目录下(该方法笔者试验成功);(2)该方法来源于论坛上面的一位朋友,做法为删掉#include 换成#define UTS_RELEASE "2.4.27"  #define LINUX_VERSION_CODE 132123