Android2.2添加busybox 支持——基于Android Bionic库

  Android 的toolbox没有自动补齐,命令少,对于开发人员还是需要busybox,直接移植官方的busybox会有很多问题,这里简单阐述cyanogenmod提供的针对android bionic 库的android源码的移植及添加方法,方便大家开发使用。

Android并没有采用glibc作为C库,而是采用了Google自己开发的Bionic Libc,它的官方Toolchain也是基于Bionic Libc而并非glibc的。与glibc相比,Bionic Libc有如下一些特点:

Ø 采用BSD License,而不是glibc的GPL License;

Ø 大小只有大约200k,比glibc差不多小一半,且比glibc更快;

Ø 实现了一个更小、更快的pthread;

Ø 提供了一些Android所需要的重要函数,如”getprop”, “LOGI”等;

Ø 不完全支持POSIX标准,比如C++ exceptions,wide chars等;

Ø 不提供libthread_db 和 libm的实现

1.      下载cyanogenmod修改过的busybox源码,并解压到源码external/busybox目录

位置:https://github.com/CyanogenMod/android_external_busybox

目录内容如下:

thomas@thomas-TCL:~/tegra2_IAC/tegra2_IAC/external/CyanogenMod-android_external_busybox-995d0d3$ ls

android  AUTHORS Config.in  e2fsprogs  include-full libpwdgrp Makefile.custom networking scripts    TODO  Android.mk  busybox-full.links  console-tools  editors include-minimal  LICENSE Makefile.flags   printutils  selinux  TODO_config_nommu  applets busybox-full.sources coreutils  examples  init  loginutils akefile.help    procps  shell  util-linux  arch  busybox-minimal.links  debianutils  findutils  INSTALL  mailutils  miscutils    README  sysklogd  archival  busybox-minimal.sources  docs  include  libbb  Makefile  modutils   runit    testsuite

2.      编译busybox并修正编译错误:

先在android源码根目录执行:source build/envsetup.sh

进入目录:external/CyanogenMod-android_external_busybox-995d0d3/

执行:mm(单独编译模块)

 

3.      编译过程中遇到一个问题

问题描述:busybox/networking/ntpd.c:1458: undefined reference to `adjtimex'  

出错原因:bionic中没有定义adjtimex,stime,swapon,swapoff,sysinfo,getsid等函数。

解决方法:修改Android.mk,增加 CYANOGEN_BIONIC:=true 

4.      安装、创建busybox shell 链接打包:

编译通过,依据Android.mk中的变量 LOCAL_MODULE_PATH := $(PRODUCT_OUT)/utilities 可知,编译出来目标文件busybox在out/target/product/$(platform_name)/utilities/目录下;

进入out/target/product/$(platform_name)/utilities/目录下,创建链接便于进入busybox  shell环境,执行:ln -s busybox ash,将busybox 和 ash 一起复制到system/bin/目录下,一起打包进文件系统system.img(链接文件和链接目标文件必须一起打包);

5.      烧录到产品板使用:

usb 或网络链接adb 之后,adb shell ,之后执行ash 即可进入busybox shell,操作就和pc的linux环境差不多了,可以使用tab键自动补齐,和其他一些busybox的命令;

 

thomas@thomas-TCL:~/tegra2_IAC/tegra2_IAC$ adb shell

# ash

~ # net

netcfg     netd       netperf    netserver  netstat

~ # netcfg

lo       UP    127.0.0.1       255.0.0.0       0x00000049

eth0     UP    192.168.20.246  255.255.255.0   0x00001043

~ #

另外,有网友在编译过程中出现其它问题,这里也一并列具出来,供参考;

6.      其它编译问题:

问题1描述:In file included from external/busybox/coreutils/df.c:25: bionic/libc/include/mntent.h:48: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'struct'

解决方法:在出错的文件中,包含头文件stdio.h。

            例如在df.c中增加#include <stdio.h>

       类似的编译出错的文件可能会有:coreutile/df.c util-linux/mount.c util-linux/umount.c

问题2描述: external/busybox/shell/ash.c:12714: error: 'rlim_t' undeclared (first use in this function)

原因分析:使用的是早期的Android版本,其中rlim_t没有定义。

解决方法:在bionic/libc/include/sys/resource.h中增加

typedef unsigned long rlim_t;  

       typedef unsigned long rlim_t;

可以参考Froyo bionic/libc/include/sys/resource.h文件。

 

参考:http://www.cublog.cn/u3/95001/showart_2339184.html

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值