busybox编译

BusyBox的交叉编译



开发平台:Ubuntu11.10

    目 标板:ARM体系结构

    编 译器:arm-gcc-4.1.1.tar.bz2 (可从http://download.youkuaiyun.com/detail/npy_lp/3821111上下载)

    源代码:busybox-1.19.2.tar.bz2(可从http://www.busybox.net/上下载)

    帮助文件:http://www.busybox.net/downloads/BusyBox.html

 

    BusyBox - The Swiss Army Knife of EmbeddedLinux.

    BusyBox 是一个集成了一百多个常用Linux命令和工具的应用程序。它不仅包含了一些简单的命令,如 cat 、echo和ls等,而且还包含了一些更大、更复杂的工具,例如 grep、find、mount 以及 telnet等。简单地说,BusyBox就好像是个大工具箱,集成了许多Linux常用的工具和命令。

    BusyBox最初是由Bruce Perens在1996年为DebianGNU/Linux安装盘而编写的。

    1、交叉编译BusyBox的默认配置 

  1. $ tar jvxf busybox-1.19.2.tar.bz2  
  2. $ cd busybox-1.19.2/  
  3. $ make defconfig   //通过执行make help获得帮助  

    设置交叉编译工具链前缀: 

  1. $ make menuconfig  
  2.  Busybox Settings --->  
  3.     Build Options --->  
  4.         () Cross Compiler prefix  

    回车,在弹出的界面中输入交叉编译工具链的前缀:

 

    使用arm-gcc-4.1.1.tar.bz2编译时会发生缺少头文件ubi-user.h的错误: 

  1. miscutils/ubi_tools.c:63:26: error: mtd/ubi-user.h: No such file or directory  
  2. miscutils/ubi_tools.c: In function 'ubi_tools_main':  
  3. miscutils/ubi_tools.c:133: error: 'UBI_DEV_NUM_AUTO' undeclared (first use in this function)  
  4. miscutils/ubi_tools.c:133: error: (Each undeclared identifier is reported only once  
  5. miscutils/ubi_tools.c:133: error: for each function it appears in.)  
  6. miscutils/ubi_tools.c:134: error: 'UBI_VOL_NUM_AUTO' undeclared (first use in this function)  
  7. miscutils/ubi_tools.c:153: error: storage size of 'req' isn't known  
  8. miscutils/ubi_tools.c:161: error: 'UBI_IOCATT' undeclared (first use in this function)  
  9. miscutils/ubi_tools.c:153: warning: unused variable 'req'  
  10. miscutils/ubi_tools.c:167: error: 'UBI_IOCDET' undeclared (first use in this function)  
  11. miscutils/ubi_tools.c:170: error: storage size of 'req' isn't known  
  12. miscutils/ubi_tools.c:177: error: 'UBI_MAX_VOLUME_NAME' undeclared (first use in this function)  
  13. miscutils/ubi_tools.c:184: error: 'UBI_STATIC_VOLUME' undeclared (first use in this function)  
  14. miscutils/ubi_tools.c:186: error: 'UBI_DYNAMIC_VOLUME' undeclared (first use in this function)  
  15. miscutils/ubi_tools.c:195: error: 'UBI_IOCMKVOL' undeclared (first use in this function)  
  16. miscutils/ubi_tools.c:170: warning: unused variable 'req'  
  17. miscutils/ubi_tools.c:201: error: 'UBI_IOCRMVOL' undeclared (first use in this function)  
  18. miscutils/ubi_tools.c:204: error: storage size of 'req' isn't known  
  19. miscutils/ubi_tools.c:214: error: 'UBI_IOCRSVOL' undeclared (first use in this function)  
  20. miscutils/ubi_tools.c:204: warning: unused variable 'req'  
  21. miscutils/ubi_tools.c:222: error: 'UBI_IOCVOLUP' undeclared (first use in this function)  
  22. make[1]: *** [miscutils/ubi_tools.o] Error 1  
  23. make: *** [miscutils] Error 2  

    解决这个问题的方法是从linux-2.6.38.8内核源码的include/mtd/目录下拷贝头文件ubi-user.h到4.1.1/arm-linux-gnu/include/mtd/目录: 

  1. $ cd $HOME/4.1.1/arm-linux-gnu/include  
  2. $ mkdir mtd  
  3. $ cp linux-2.6.38.8/include/mtd/ubi-user.h mtd/  

    执行make和make install即可编译和安装: 

  1. $ make  
  2. $ make install  //默认安装在当前目录的_install目录下。  

    2、根据项目需要适当裁减

    (1)、跟Linux内核类似,BusyBox也可以通过执行make menuconfig命令启动基于ncurses的配置界面,配置界面的操作方法如下:  


     BusyBox中并没有尖括号(< >)的选项,也不会被编译成模块。

    (2)、BusyBox将所有配置进行了分类,可以很方便地根据项目的需要进行裁减。 

  1. Busybox Settings --->        //BusyBox的通用配置,一般采用默认值即可。  
  2.     ---Applets  
  3. Archival Utilities --->      //压缩、解压缩相关工具。  
  4. Coreutils --->           //最基本的命令,如cat、cp、ls等。  
  5. Console Utilities --->       //控制台相关命令。  
  6. Debian Utilities --->        //Debian操作系统相关命令。  
  7. Editors --->         //编辑工具,如vi、awk、sed等。  
  8. Finding Utilities --->       //查找工具,如find、grep、xargs。  
  9. Init Utilities --->      //BusyBox init相关命令。  
  10. Login/Password Management Utilities --->   //登陆、用户账号/密码等方面的命令。  
  11. Linux Ext2 FS Progs ---> //ext2文件系统的一些工具。  
  12. Linux Module Utilities --->  //加载/卸载模块等相关的命令。  
  13. Linux System Utilities --->  //一些系统命令。  
  14. Miscellaneous Utilities ---> //一些不好分类的命令,如crond、crontab。  
  15. Networking Utilities --->    //网络相关的命令和工具。  
  16. Print Utilities --->     //print spool服务及相关工具。  
  17. Mail Utilities --->      //mail相关命令。  
  18. Process Utilities --->       //进程相关命令,如ps、kill等。  
  19. Runit Utilities --->     //runit程序。  
  20. Shells --->              //shell程序。  
  21. System Logging Utilities --->    //系统日志相关工具,如syslogd、klogd。  

    说明:虽然BusyBox被称为嵌入式Linux中的瑞士军刀,但并不是一定非要使用它不可,如果你觉得它的某些功能不能满足你系统的要求,那么你可以毫不犹豫地把这些功能舍弃掉,换用其他相应的程序包。





注:  如果用其它的编译器出现问题很有可能是头文件的版本与编译器的版本不匹配导致的。

以arm-linux-gcc-4.1.1 和uboot-1.19.3为例:

export PATH=/opt/arm-linux-4.1.1/4.1.1/bin:$PATH
make menuconfig
make ARCH=arm CROSS_COMPILE=arm-linux-gnu- -I/opt/arm-linux-4.1.1/4.1.1/arm-linux-gnu/include
make ARCH=arm CROSS_COMPILE=arm-linux-gnu-  install





#########################################################

文件系统制作:

url:   http://hi.baidu.com/zengzhaonong/item/b8fde78ea7e8a3d45e0ec194

BusyBox 是一个集成了一百多个最常用 Linux 命令和工具(如 ash、awk、sed、grep、mount 等)的单一可执行文件。它非常适合用于嵌入式系统,因为它的体积小且功能强大。编译 BusyBox 可以根据需要进行配置和裁剪,以适应特定的需求。以下是编译 BusyBox 的基本步骤: 1. **获取源码**: 首先,从官方网站或 Git 仓库下载 BusyBox 的源码包。 ```bash wget https://busybox.net/downloads/busybox-<version>.tar.bz2 tar -xvjf busybox-<version>.tar.bz2 cd busybox-<version> ``` 2. **配置**: 使用 `make menuconfig` 命令进入配置界面,根据需要进行配置。 ```bash make menuconfig ``` 在配置界面中,可以选择需要编译的命令和功能。 3. **编译**: 配置完成后,使用 `make` 命令进行编译。 ```bash make ``` 编译完成后,会生成一个 `busybox` 可执行文件。 4. **安装**: 将编译好的 `busybox` 文件安装到目标系统的目录中,通常是 `/usr/bin` 或 `/bin`。 ```bash make install ``` 这将把 `busybox` 文件和相关符号链接安装到指定的目录中。 5. **部署**: 将编译好的 BusyBox 部署到目标设备上,可以通过挂载文件系统或使用其他传输方式。 6. **测试**: 在目标设备上测试 BusyBox 的功能,确保所有命令都能正常工作。 ```bash # 示例:编译并安装 BusyBox wget https://busybox.net/downloads/busybox-<version>.tar.bz2 tar -xvjf busybox-<version>.tar.bz2 cd busybox-<version> make menuconfig make make install ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值