Home

Awesome

The aim is to gather information and patches on how to build busybox using the compilers shipped with the Android NDK.

Currently up-to-date as of busybox 1.36.1, with both NDK API 21 Unified and Deprecated headers.

Building busybox with the standard Android NDK

tias@ulyssis.org discovered that a number [1,2] of upstream changes make it possible to build the latest git version of busybox, without requiring any patches:

# get busybox sources
git clone git://busybox.net/busybox.git
cd busybox
# use default upstream config
cp configs/android_ndk_defconfig .config

# add the target NDK cross-compiler to your exported PATH and CROSS_COMPILE prefix
export PATH="/path/to/your/android-ndk/android-ndk-r15c/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86/bin:$PATH"
export CROSS_COMPILE="/path/to/your/android-ndk/android-ndk-r15c/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86/bin/arm-linux-androideabi-"

# if android-ndk is not installed in /opt/android-ndk, edit SYSROOT= in .config
# (alternately make all but CFLAGS blank if using standalone cross-compiler)
nano .config

# adjust enabled applets/features (optional)
make menuconfig

# build it!
make ARCH=arm CROSS_COMPILE="$CROSS_COMPILE"

These applets are available without any patches:

[, [[, acpid, adjtimex, ar, arp, ascii, ash, awk, base32, base64, basename, bbconfig, beep, blkdiscard, blkid, blockdev, bootchartd, brctl, bunzip2, bzcat, bzip2, cal, cat, catv, chat, chattr, chgrp, chmod, chown, chpst, chroot, chrt, chvt, cksum, clear, cmp, comm, cp, cpio, crc32, crond, crontab, cttyhack, cut, date, dc, dd, deallocvt, depmod, devmem, diff, dirname, dmesg, dnsd, dnsdomainname, dos2unix, dpkg, dpkg-deb, du, dumpkmap, echo, ed, egrep, env, envdir, envuidgid, expand, expr, factor, fakeidentd, false, fbset, fbsplash, fdflush, fdformat, fdisk, fgconsole, fgrep, find, findfs, flashcp, flock, fold, free, freeramdisk, fsfreeze, fsync, fuser, getopt, grep, groups, gunzip, gzip, halt, hd, hdparm, head, hexdump, hostname, httpd, hwclock, id, ifconfig, ifdown, ifenslave, ifplugd, ifup, inetd, init, inotifyd, insmod, install, ionice, iostat, ip, ipaddr, ipcalc, iplink, ipneigh, iproute, iprule, iptunnel, kbd_mode, kill, killall, killall5, klogd, less, link, linuxrc, ln, loadkmap, losetup, lpd, lpq, lpr, ls, lsattr, lsmod, lspci, lsscsi, lsusb, lzcat, lzma, lzop, lzopcat, makedevs, makemime, man, md5sum, mesg, microcom, mim, mkdir, mkdosfs, mkfifo, mkfs.vfat, mknod, mkswap, mktemp, modinfo, modprobe, more, mpstat, mv, nameif, netstat, nice, nl, nmeter, nohup, nologin, od, openvt, partprobe, paste, patch, pidof, pipe_progress, pivot_root, pkill, pmap, popmaildir, poweroff, printenv, printf, ps, pstree, pwd, pwdx, raidautorun, rdate, rdev, readlink, readprofile, realpath, reboot, reformime, renice, reset, resize, rev, rfkill, rm, rmdir, rmmod, rpm, rpm2cpio, rtcwake, run-init, run-parts, runsv, runsvdir, rx, script, scriptreplay, sed, sendmail, seq, setconsole, setkeycodes, setlogcons, setpriv (without capabilities), setserial, setsid, setuidgid, sh, sha1sum, sha256sum, sha512sum, showkey, shred, slattach, sleep, smemcap, softlimit, sort, split, start-stop-daemon, stat, strings, stty, sum, sv, svc, svlogd, switch_root, sync, sysctl, tac, tail, tar, tc, tcpsvd, tee, telnetd, test, tftpd, timeout, top, touch, tr, tree, true, tsort, tty, ttysize, tunctl, tune2fs, udhcpc, udhcpd, udpsvd, uname, uncompress, unexpand, uniq, unix2dos, unlzma, unlzop, unxz, unzip, uptime, usleep, uudecode, uuencode, vconfig, vi, volname, watch, watchdog, wc, which, whoami, xargs, xxd, xz, xzcat, yes, zcat

By applying the included patches to the busybox code-base you additionally get:

arping, conspy, eject, ether-wake, flash_eraseall, flash_lock, flash_unlock, fsck.minix, ftpd, hush, ipcrm, ipcs, loadfont, logread, mkfs.minix, nanddump, nandwrite, nslookup (with own resolver), pgrep, ping6, route, setfont, ssl_client, swapon, swapoff, syslogd, time, traceroute6, ubi*, udhcpc6, unshare, zcip

Also worth noting that while they do build without issue these applets do not entirely work correctly on Android without any patches:

df, fsck, ftpget, ftpput, losetup, mke2fs, mkfs.ext2, mkfs.reiser, mount, mountpoint, nbd-client, nc, ping, poweroff, pscan, reboot, telnet, tftp, traceroute, umount, wget, whois

(when applying certain patches you should include all patches with a lower number as well, there are often dependencies between them).

The remaining config options of 'make defconfig' do not build properly. See below for the list of config options and corresponding error.

Config options that do not build, code error

These errors indicate bugs (usually in the restricted Android libc library, called bionic), and can often be fixed by adding patches to the busybox code.

Config options that do not build, missing header

These errors indicate that the header is missing from Android's libc implementation.

sys/kd.h -- has patch

others

Config options that give a linking error

Android's libc implementation claims to implement the methods in the error, but surprisingly does not.

bit -- has patch

mntopt -- has patch

others