BusyBox Compiling

BusyBox, the Swiss Army Knife of Embedded Linux, it can be compiled into a single binary for different architectures.

Before compiling software, we must get a compiler and the corresponding libraries, a build host and a target platform, the build host is the one running the compiler, the target platform is the one running the target binary. Herein, the desktop development system is a 64 bit X86 Ubuntu systems, it will be used as our build host, and an ARM Android system will be used as our target platform.

To compile BusyBox on X86-64 Ubuntu system for ARM, we need a cross compiler.

The gcc-arm-linux-gnueabi cross compiler can be installed directly on Ubuntu:

$ sudo apt-get install gcc-arm-linux-gnueabi

On the other Linux distributions, Google's official NDK is a good choice if want to share Android's Bionic C library, but since Bionic C library lacks lots of POSIX C header files, if want to get most of BusyBox applets building, the prebuilt version of Linaro GCC with Glibc is preferable, we can download it from http://www.linaro.org/downloads/, for example:

BusyBox Installation

This section shows how to install the above compiled BusyBox binaries on an ARM Android system.

The installation of BusyBox means to create soft links for all of its built-in applets, use wc applet as an example:

$ ln -s busybox wc$ echo "Hello, Busybox." ./wc -w|2

BusyBox can be installed at the earlier compiling stage or at run-time.

To build a minimal embedded file system with BusyBox, we'd better install it at the compiling stage with 'make install' for it helps to create the basic directory architecture of a standard Linux root file system and create soft links to BusyBox under the corresponding directories. With this installation method, we need to configure the target installation directory as following, use ~/busybox-ramdisk/ directory as an example:

After installation, we may get such a list of the file and directories:

$ ls ~/busybox-ramdisk/bin linuxrc sbin usr

But to install it on an existing ARM Android system, it may be easier to install BusyBox at run-time with its --install option.

With --install, by default, hard links will be created, to create soft links (symbolic links), -s option should be appended. If want to create links across different file systems (E.g. in Android system, to install BusyBox to /system/bin but BusyBox itself is put in the /data directory), -s must be used.

Now, let's assume a rooted Android system is already running there with the USB debugging option enabled for Android Debug Bridge (adb, http://developer.android.com/tools/help/adb.html) support, for example, to check if such a device is started, we can run:

$ adb devicesList of devices attachedemulator-5554 device

As we can see, a virtual Android device running on Android emulator: emulator-5554 is there.

Now, we are able to show how to install the BusyBox binaries on the existing Android system. Since the dynamically linked and statically linked BusyBox binaries are different, we will introduce how to install them respectively.

Install the statically linked Busybox binary

To install the statically installed Busybox binary, we only need to upload the BusyBox binary itself:

$ adb push busybox /data/

Afterwards, install it with the --install option, for example, install it to the /bin directory of the Andriod system:

To run the applets without the full path, the /bin directory should be appended to the PATH variable:

$ export PATH=$PATH:/bin

Then, all of the BusyBox applets can be executed directly, that means we have installed Busybox successfully.

To make the settings permanently, the above commands can be added to a script and such a script can be run as an Android service.

Install the dynamically linked BusyBox binary

For a dynamically linked BusyBox, to install it, besides the installation of the BusyBox binary itself, the required dynamic linker/loader (ld-linux.so) and the dependent shared libraries (libc.so and libm.so) should be installed too. For the basic installation procedure are the same as the one for statically linked BusyBox, herein, we only introduce how to install the required ld-linux.so.3, libc.so.6 and libm.so.6.

Without the above dynamic linker/loader and libraries, we may get such error while running the dynamically linked BusyBox:

With the above installation, the dynamically linked BusyBox binary should also be able to run and we are able to install and execute its applets as before:

$ /data/busybox --install -s /bin

As we can see, the installation of the dynamically linked BusyBox binary requires extra installation of the dependent linker/loader and libraries.

For real embedded system development, if only the BusyBox binary itself uses the shared libraries, the static linking should be used instead at compiling to avoid the extra installation and the time-cost run-time linking, otherwise, if many binaries share the same libraries, to reduce the total size cost for the size critical embedded systems, dynamic linking may be preferable.

Summary

In this article we learned about BusyBox compiling and its installation. BusyBox is a free GPL-licensed toolbox aimed at the embedded world. It is a collection of the tiny versions of many common Unix utilities.

Alerts & Offers

Series & Level

We understand your time is important. Uniquely amongst the major publishers, we seek to develop and publish the broadest range of learning and information products on each technology. Every Packt product delivers a specific learning pathway, broadly defined by the Series type. This structured approach enables you to select the pathway which best suits your knowledge level, learning style and task objectives.

Learning

As a new user, these step-by-step tutorial guides will give you all the practical skills necessary to become competent and efficient.

Beginner's Guide

Friendly, informal tutorials that provide a practical introduction using examples, activities, and challenges.

Essentials

Fast paced, concentrated introductions showing the quickest way to put the tool to work in the real world.

Cookbook

A collection of practical self-contained recipes that all users of the technology will find useful for building more powerful and reliable systems.

Blueprints

Guides you through the most common types of project you'll encounter, giving you end-to-end guidance on how to build your specific solution quickly and reliably.

Mastering

Take your skills to the next level with advanced tutorials that will give you confidence to master the tool's most powerful features.

Starting

Accessible to readers adopting the topic, these titles get you into the tool or technology so that you can become an effective user.

Progressing

Building on core skills you already have, these titles share solutions and expertise so you become a highly productive power user.