Ubuntu 16.04: Build BusyBox

This article will describe building BusyBox for Ubuntu 16.04 and Android. Android version is 5.1.1.

1 Download BusyBox

Download BusyBox 1.25.0.

$ wget http://busybox.net/downloads/busybox-1.25.0.tar.bz2
$ tar jxf busybox-1.25.0.tar.bz2
$ cd busybox-1.25.0

2 Build for Ubuntu 16.04

Build BusyBox with freebsd_defconfig.

$ make freebsd_defconfig
$ make
$ make install

BusyBox is installed to _install directory which include busybox binary and symbolic links.

$ ls _install
bin   sbin  usr
$ ls _install/bin/
ash      dd             grep      mkdir          rev           sync
busybox  dnsdomainname  gunzip    mktemp         rm            tar
cat      echo           gzip      more           rmdir         touch
catv     ed             hostname  mpstat         rpm           true
chattr   egrep          iostat    mv             run-parts     uname
chgrp    false          ipcalc    nice           scriptreplay  uncompress
chmod    fatattr        kill      pipe_progress  sed           usleep
chown    fgrep          ln        printenv       setserial     vi
cp       fsync          ls        ps             sh            watch
cpio     getopt         lzop      pwd            sleep         zcat

Add _install/bin and _install/sbin to PATH.

$ export PATH=$(pwd)/_install/bin:$(pwd)/_install/sbin:${PATH}
$ sh


BusyBox v1.25.0 (2016-09-22 22:56:34 JST) built-in shell (ash)
Enter 'help' for a list of built-in commands.

$ ls --help
BusyBox v1.25.0 (2016-09-22 22:56:34 JST) multi-call binary.

Usage: ls [-1AaCxdLHRFplinsehrSXvctu] [-w WIDTH] [FILE]...

List directory contents

        -1      One column output
        -a      Include entries which start with .
        -A      Like -a, but exclude . and ..
        -C      List by columns
        -x      List by lines
        -d      List directory entries instead of contents
        -L      Follow symlinks
        -H      Follow symlinks on command line
        -R      Recurse
        -p      Append / to dir entries
        -F      Append indicator (one of */=@|) to entries
        -l      Long listing format
        -i      List inode numbers
        -n      List numeric UIDs and GIDs instead of names
        -s      List allocated blocks
        -e      List full date and time
        -h      List sizes in human readable format (1K 243M 2G)
        -r      Sort in reverse order
        -S      Sort by size
        -X      Sort by extension
        -v      Sort by version
        -c      With -l: sort by ctime
        -t      With -l: sort by mtime
        -u      With -l: sort by atime
        -w N    Assume the terminal is N columns wide
        --color[={always,never,auto}]   Control coloring
$

3 Build BusyBox for Android

Download Android NDK for Linux.

$ wget https://dl.google.com/android/repository/android-ndk-r12b-linux-x86_64.zip
$ unzip android-ndk-r12b-linux-x86_64.zip

Set cross toolchain prefix to the variable CROSS_COMPILE and set root filesystem path to the variable SYSROOT (The variable ARMLINUX is temporally variable).

$ ARMLINUX=$(pwd)/android-ndk-r12b/toolchains/arm-linux-androideabi-4.9
$ CROSS_COMPILE=${ARMLINUX}/prebuilt/linux-x86_64/bin/arm-linux-androideabi-
$ SYSROOT=$(pwd)/android-ndk-r12b/platforms/android-24/arch-arm/

Use android_ndk_defconfig for configuration. Change .config as below.

  • Change cross toolchain prefix.
  • Change root filesystem path.
  • Enable PIE for Android 5.1.
  • Disable some commands which will be build error.
$ cd busybox-1.25.0
$ make android_ndk_defconfig
$ sed -i \
-e "s:CONFIG_CROSS_COMPILER_PREFIX=\"[^\"]*\":CONFIG_CROSS_COMPILER_PREFIX=\"${CROSS_COMPILE}\":g" \
-e "s:CONFIG_SYSROOT=\"[^\"]*\":CONFIG_SYSROOT=\"${SYSROOT}\":g" \
-e 's/CONFIG_FLASH_LOCK=y/CONFIG_FLASH_LOCK=n/g' \
-e 's/CONFIG_FLASH_UNLOCK=y/CONFIG_FLASH_UNLOCK=n/g' \
-e 's/CONFIG_FLASHCP=y/CONFIG_FLASHCP=n/g' \
-e 's/CONFIG_NANDDUMP=y/CONFIG_NANDDUMP=n/g' \
-e 's/CONFIG_UBIRENAME=y/CONFIG_UBIRENAME=n/g' \
-e 's/CONFIG_ROUTE=y/CONFIG_ROUTE=n/g' \
-e 's/CONFIG_TIME=y/CONFIG_TIME=n/g' \
-e 's/.*CONFIG_PIE.*/CONFIG_PIE=y/g' .config
$ make
$ make install

Push _install to Android 5.1.1 and run.

$ adb push _install /data/local/tmp/busybox
$ adb shell
$ cd /data/local/tmp/busybox/bin
$ ./busybox
WARNING: linker: ./busybox: unused DT entry: type 0x6ffffffe arg 0x2ce8
WARNING: linker: ./busybox: unused DT entry: type 0x6fffffff arg 0x2
BusyBox v1.25.0 (2016-09-23 00:44:45 JST) multi-call binary.
BusyBox is copyrighted by many authors between 1998-2015.
Licensed under GPLv2. See source distribution for detailed
copyright notices.

Usage: busybox [function [arguments]...]
   or: busybox --list[-full]
   or: busybox --install [-s] [DIR]
   or: function [arguments]...

        BusyBox is a multi-call binary that combines many common Unix
        utilities into a single executable.  Most people will create a
        link to busybox for each function they wish to use and BusyBox
        will act like whatever it was invoked as.

Currently defined functions:
        [, [[, ar, arp, awk, base64, basename, bbconfig, beep, blkdiscard,
        blkid, blockdev, bootchartd, bunzip2, bzcat, bzip2, cal, cat, catv,
        chat, chattr, chgrp, chmod, chown, chpst, chroot, chrt, chvt, cksum,
        clear, cmp, comm, cp, cpio, crond, crontab, cttyhack, cut, dc, dd,
        deallocvt, depmod, devmem, diff, dirname, dmesg, dnsd, dos2unix, dpkg,
        dpkg-deb, du, dumpkmap, echo, ed, egrep, env, envdir, envuidgid,
        expand, expr, fakeidentd, false, fatattr, fbset, fbsplash, fdflush,
        fdformat, fdisk, fgconsole, fgrep, find, findfs, flock, fold, free,
        freeramdisk, fstrim, fsync, ftpd, ftpget, ftpput, fuser, getopt, grep,
        gunzip, gzip, halt, hd, hdparm, head, hexdump, httpd, hwclock,
        i2cdetect, i2cdump, i2cget, i2cset, ifconfig, ifdown, ifup, init,
        inotifyd, insmod, install, iostat, ip, ipaddr, ipcalc, iplink, iproute,
        iprule, iptunnel, klogd, less, linuxrc, ln, loadkmap, losetup, lpd,
        lpq, lpr, ls, lsattr, lsmod, lsof, lspci, lsusb, lzcat, lzma, lzop,
        lzopcat, makedevs, makemime, man, md5sum, mesg, mkdir, mkfifo, mknod,
        mkpasswd, mkswap, mktemp, modinfo, modprobe, more, mpstat, mv,
        nbd-client, nc, netstat, nice, nmeter, nohup, nsenter, od, openvt,
        patch, pidof, ping, pipe_progress, pmap, popmaildir, poweroff,
        powertop, printenv, printf, ps, pscan, pstree, pwd, pwdx, raidautorun,
        rdev, readlink, readprofile, realpath, reboot, reformime, renice,
        reset, resize, rev, rm, rmdir, rmmod, rpm, rpm2cpio, rtcwake,
        run-parts, runsv, runsvdir, rx, script, scriptreplay, sed, sendmail,
        seq, setconsole, setkeycodes, setlogcons, setserial, setsid, setuidgid,
        sha1sum, sha256sum, sha3sum, sha512sum, showkey, shuf, sleep, smemcap,
        softlimit, sort, split, start-stop-daemon, strings, stty, sum, sv,
        svlogd, switch_root, sync, sysctl, tac, tail, tar, tcpsvd, tee, telnet,
        telnetd, test, tftp, tftpd, timeout, top, touch, tr, traceroute, true,
        truncate, ttysize, tunctl, tune2fs, udhcpc, udpsvd, uevent, uname,
        uncompress, unexpand, uniq, unix2dos, unlink, unlzma, unlzop, unshare,
        unxz, unzip, uptime, usleep, uudecode, uuencode, vconfig, vi, volname,
        watch, wc, wget, which, whoami, whois, xargs, xz, xzcat, yes, zcat

shell@tilapia:/data/local/tmp/busybox/bin $

3.1 WARNING: linker: <prog> unused DT entry: <entry> arg <value>

Running NDK application will output warning as below. This may be Android 5.1 problem.

$ ./busybox
WARNING: linker: ./busybox: unused DT entry: type 0x6ffffffe arg 0x2d10
WARNING: linker: ./busybox: unused DT entry: type 0x6fffffff arg 0x2