Book Image

Instant Optimizing Embedded Systems Using BusyBox

By : Wu Zhangjin, Cao Ziqiang
Book Image

Instant Optimizing Embedded Systems Using BusyBox

By: Wu Zhangjin, Cao Ziqiang

Overview of this book

As hundreds of millions of people have started using Android smartphones, embedded Linux systems are becoming more and more popular. To get more market share, not only for hardware and function piling up, smartphone manufacturers gradually realized the importance of user experience. To improve user experience, the back-end Linux system must be optimized in many ways. Instant Optimizing Embedded System Using BusyBox is a practical, hands-on guide that provides you with a number of clear, step-by-step exercises to help you take advantage of the real power behind Busybox, and give you a good grounding for using it to optimize your embedded (Android Linux) systems. Moving on from the basics, this book will teach you how to configure and compile it from source code, including cross-compiling it with static linking and dynamic linking. You will also learn how to install and use Busybox on the Android emulator. You will learn to replace the simple Android mksh console with Busybox ash console and start a telnet and HTTP service provided by Busybox. You will also build embedded Linux file system from scratch and start it on Android emulator. We will take a look at how to add functionality to Busybox based system, including adding external applets to Busybox, as well as building development environments (like Bash and C) for it manually or with the automatic Buildroot system. If want to learn how to take advantage of using Busybox applets to optimize your embedded system, then this is the book for you for it will also show you how to use the powerful applets to optimize multiple aspects of an embedded (Android Linux) system.This book will teach you how to build an embedded (Android Linux) system with Busybox, enhance its functionality to meet diverse system requirements, and optimize it to provide a better user experience for embedded products.
Table of Contents (8 chapters)

Configuring BusyBox (Simple)

In this recipe, we'll download BusyBox and configure it using defconfig, xxx_defconfig, oldconfig, allyesconfig/allnoconfig, menuconfig, and randconfig.

Getting ready

BusyBox was designed for Linux in early 1996, originally as a Debian GNU/Linux installer and rescue system. With about 18 years of development, the latest 1.21.0 (at the time of this writing) release has more than 380 applets and about 100 projects claimed using it. The projects embrace Linux, Android, FreeBSD, and others.

It integrates a set of stripped-down Unix tools, including simple ones, such as echo and ls, as well as the larger ones, such as grep, awk, find, mount, and modprobe and other functional utilities; for example, ifconfig, route, dmesg, tar, wget, and even a tiny shell interpreter called ash.

It is modular, and can be customized to meet different requirements. To discuss and demonstrate its configuration system, first download its source code. It is maintained at and released with .tar packages at If you want a stable release, download the .tar packages or clone the Git repository with the latest (but perhaps not stable) features. At the time of this writing, we used the stable version busybox-1.21.0.tar.bz2; download it and decompress it.

$ wget
$ tar jxvf busybox-1.20.0.tar.bz2
$ cd busybox-1.20.0/

To simplify the command-line output, all command-line prompts in the desktop development system is prefixed with the $ symbol; ones that need root permission will follow a sudo command.

Before configuring, make sure the ncurses library required by the graphic configurator is installed on the development system.

$ sudo apt-get install libncurses5-dev


Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at If you purchased this book elsewhere, you can visit and register to have the files e-mailed directly to you.

How to do it...

The friendliest way to configure BusyBox will be using make menuconfig. Issue the command to launch a graphic interface, configure the features, and exit to save them.

  1. Issue the following command in a graphic configurator:

    $ make menuconfig
  2. It starts the graphic interface.

  3. Configure the features with hotkeys. It allows us to enable, disable, exit, get help, and search with hotkeys. The primary hotkeys include:

    • <Enter> selects submenus

    • <Y> includes

    • <N> excludes

    • <Space> Switch <Y> and <N>

    • <Esc><Esc> to exit

    • <?> for Help

    • </> for Search

  4. Most configuration options are Boolean type. Use the ash shell applet as an example. Press Enter on the shell's submenu. Enable with Y and disable with N.

    Shells  --->
    [*] ash
  5. Some configuration options are strings and may require input. Use the cross-compiler arm-linux-gnueabi-gcc (see the Compiling Busybox recipe) configuration as an example. Press Enter on BusyBox Settings and on Build Options and then press Enter on (arm-linux-gnueabi-) Cross Compiler prefix.

           Busybox Settings  --->
                   Build Options  --->
                        (arm-linux-gnueabi-) Cross Compiler prefix
  6. Save the configuration.

After configuring, Press Esc + Esc to exit, and the configuration will be saved to a file named .config.

With the previous configuration, we should be able to start the compiling process in the next recipe, but we still need to learn more details about the principle and the other methods of configuration.

How it works...

BusyBox can be flexibly customized; the main configurable features include Busybox Settings and Applets. The former allows us to configure build/compiling and installation features. The latter allows us to configure all of the built-in applets and their features. Both of them will be introduced in the following recipes.

To configure them in fine detail, the Config.src files (for example, networking/Config.src) provide configure options for the features, and every option should have a default setting.

Hotkeys are provided to enable, disable, or set the option; the option's value will be converted to symbols prefixed with CONFIG_ and saved into the .config file, and meanwhile some C headers will be generated.

There's more...

Besides graphic configuration with make menuconfig, some other configuration techniques you might want to run with the BusyBox make tool include:

  • make config: Similar to make menuconfig, this is a text-based interactive configurator. It does not contain the dependency of the ncurses library, and is not that friendly.

  • make oldconfig: Resolve any unresolved symbols and regenerate C header files with the old configuration, .config; it is often executed after make clean. make clean allows us to delete temporary files created by an old configuration or building. It is often used to get a clean environment for a new configuration or building.

  • make xxx_defconfig: Some old configurations, such as .config are renamed and saved to the configs/ directory of the BusyBox source code. To re-use them, just run make with their names; for example:

    $ make android2_defconfig
  • make defconfig: It uses the option's default setting and generates .config to the largest generic configuration. This is often used by a newcomer as the base of a new configuration. Based on this default configuration, disable the unnecessary features and reserve only the necessary features and get a minimal configuration eventually.

  • make allyesconfig/allnoconfig: They don't use the default settings, but rather enable or disable the features and generate a .config file accordingly. Some options may still be disabled even with allyesconfig. If they conflict with the already enabled ones (for example, the CONFIG_NOMMU configure option is enabled by default), the other features, such as ash, will be disabled. make allyesconfig will generate the largest BusyBox binary. It should not be used to build a size-critical embedded system, but it may be a good configuration base for a rich-function system. make allnoconfig provides a clean configuration base. It may be good to get a clean configuration for a size-critical embedded system, but it requires a good understanding of the configuration options.

  • make randconfig: It generates a configuration with random settings. We don't need it since our real requirement is often deterministic, but BusyBox developers may need it for building tests.