How to cross compile Busybox

BusyBox combines tiny versions of many common UNIX utilities / commands into a single small executable. It provides minimalist replacements for most of the utilities you usually find in GNU coreutils, util-linux, etc. The utilities in BusyBox generally have fewer options than their full-featured GNU cousins.

Following steps helps to cross compile Busybox to a shared executable and also static executable.

Configuration of Busybox ( Dynamic Executable )

$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- menuconfig

If you want to keep everything as default, ( By default busybox create dynamic executable ) then, after you run above command it will open a screen, on which navigate to Exit and click “Yes” when asked as below.

Busybox Menuconfig

This creates a file called “.config”

Configuration of Busybox ( Static Executable )

If you want to create static executable for busybox, so that it can run on any platform ( architecture specific ) independent of libraries, you need to change in menuconfig to select to build as static executable as below,

In menuconfig, Select “Busybox Settings”

Busybox Menuconfig

From settings, Select “Build Busybox as a static binary” as below.

Static Busybox

Compilation of Busybox

For compilation for Dynamic Busybox, once you have configured as above, enter below command to compile.

$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi-

This creates the “busybox” executable

Installation of Busybox

By default Busybox create “./install” directory where your source code is OR you can change the install directory as below,

$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- install

Changing install directory from command line,

$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- CONFIG_PREFIX=/path/from/root install

Changing install directory from menuconfig from “Busybox Settings”

Busybox Install

When Dynamically compiled (This is default compilation)

$ file _install/bin/busybox
_install/bin/busybox: ELF 64-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-, for GNU/Linux 3.2.0, BuildID[sha1]=d16cca32c42da434b296c84f6254e67490a109c5, stripped

When Statically compiled:

If you want to clean the compilation and delete every binaries generated, you can use below command

$ make clean

CLEAN applets
CLEAN busybox busybox_unstripped.map busybox_unstripped.out busybox_unstripped .kernelrelease

Note: you can also download toolchain from https://releases.linaro.org/archive/14.09/components/toolchain/binaries/

$ wget -c https://releases.linaro.org/archive/14.09/components/toolchain/binaries/gcc-linaro-arm-none-eabi-4.9-2014.09_linux.tar.bz2
$ tar xvf gcc-linaro-arm-none-eabi-4.9-2014.09_linux.tar.bz2
$ tar xvf gcc-linaro-arm-none-eabi-4.9-2014.09_linux.tar.bz2
$ export PATH=$PATH:$PWD/gcc-linaro-arm-none-eabi-4.9-2014.09_linux/bin

Leave a Comment