Dynamically compile busybox Based on Android bionic Library

Source: Internet
Author: User

Recently, Android-based IPv6 development and testing require tools such as ping, ping6, NSlookup, and traceroute6 provided in busybox. After tests, we found that there are many articles on cross-compiling busybox and putting it into Android. You can also download the cross-compiled busybox directly. However, because both of them are statically compiled busybox and linked to the standard glibc, some functions cannot run normally in Android. For example: # busybox Ping www.baidu.com

 

Android does not use glibc as the C library, but uses bionic libc developed by Google. Its official toolchain is based on Bionic libc rather than glibc. Compared with glibc, bionic libc has the following features:

  • Use BSD license instead of glibc GPL license;
  • The size is only about 200 K, half smaller than glibc, and faster than glibc;
  • Implements a smaller and faster pthread;
  • Provides important functions required by Android, such as "getprop" and "logi;
  • POSIX standards are not fully supported, such as C ++ exceptions and wide chars;
  • Libthread_db and libm implementations are not provided

What I want to do here is compile busybox Based on Bionic libc to provide better support for network-related tools. Internet search found that some people have done a lot of work on the transplantation of busybox and have done their own work, such:

  • Cyanogenmod has provided the modified busybox source code download, but it is based on froyo and has not enabled IPv6 settings.
  • Http://lazyhack.net/compile-busybox-linked-bionic/

    This article describes how to dynamically compile busybox for milestone/droid and connect it to Bionic, but you need to modify bionic and replace libc. So

Their articles and source code have been studied and tried. We can easily port busybox to Android based on the cyanogenmod source code, enable IPv6-related functions, and do not need to replace libc. So. The following is a summary of my porting steps and experience:

 

1. Download the modified busybox source code of cyanogenmod and decompress it to the <SRC>/external/busybox directory.

: Http://github.com/CyanogenMod/android_external_busybox

 

2. Compile busybox and correct compilation errors

Run # Make-J4 busybox in the root directory of the andorid source code.

 

Possible first-class compilation errors are as follows:

In file encoded ded from external/busybox/coreutils/DF. c: 25: <br/> bionic/libc/include/mntent. h: 48: Error: Expected '=', ';', 'asm 'or' _ attribute _ 'before 'struct '<br/>

The solution is to include the header file stdio. h In the error file. For example, add

# Include <stdio. h>

Files with similar compilation errors may be:

Coreutile/DF. C <br/> util-Linux/mount. C <br/> util-Linux/umount. c

 

The second possible compilation error is as follows:

External/busybox/Shell/ash. C: 12714: Error: 'rlim _ t' undeclared (first use in this function)

The error occurs because you are using an earlier Android version, which is not defined by rlim_t. The solution is to add <SRC>/bionic/libc/include/sys/resource. h

Typedef unsigned long rlim_t;

See <SRC>/bionic/libc/include/sys/resource. h file in froyo.

 

The third possible compilation error is as follows:

Busybox/networking/ntpd. C: 1458: Undefined reference to 'adjtimex'

The error occurs because the adjtimex, stime, Swapon, swapoff, sysinfo, and getsid functions are not defined in bionic. The solution is to modify Android. mk and add

Cyanogen_bionic: = true

 

3. Copy the compiled busybox to the mobile phone/system/xbin/directory for testing.

# ADB push busybox/system/xbin/

 

Appendix: compiled busybox binary (IPv6 supported)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.