Skip to content

Keeping track of instructions and patches for building busybox with the Android NDK

Notifications You must be signed in to change notification settings

osm0sis/android-busybox-ndk

 
 

Repository files navigation

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.

  • All of Login/Password Management Utilities, CONFIG_USE_BB_PWD_GRP -- error: 'struct passwd' has no member named 'pw_gecos'
    • disables CONFIG_ADD_SHELL, CONFIG_ADDGROUP, CONFIG_ADDUSER, CONFIG_CHPASSWD, CONFIG_CRYPTPW, CONFIG_DELGROUP, CONFIG_DELUSER, CONFIG_GETTY, CONFIG_LOGIN, CONFIG_MKPASSWD, CONFIG_PASSWD, CONFIG_REMOVE_SHELL, CONFIG_SU, CONFIG_SULOGIN, CONFIG_VLOCK
  • CONFIG_ARPING -- has patch -- networking/arping.c:122:4: error: dereferencing pointer to incomplete type
  • CONFIG_BC -- miscutils/bc.c:224:18: error: expected ':', ',', ';', '}' or '__attribute__' before 'num'
  • CONFIG_ETHER_WAKE -- has patch -- networking/ether-wake.c:131:6: warning: assignment makes pointer from integer without a cast
  • CONFIG_FEATURE_IPV6 -- has patch -- networking/ifconfig.c:132:8 error: redefinition of 'struct in6_ifreq'
    • disables CONFIG_FEATURE_IFUPDOWN_IPV6, CONFIG_FEATURE_PREFER_IPV4_ADDRESS, CONFIG_PING6, CONFIG_TRACEROUTE6, CONFIG_UDHCPC6, CONFIG_FEATURE_UDHCPC6_RFC*
  • CONFIG_FEATURE_NSLOOKUP_BIG, CONFIG_FEATURE_NSLOOKUP_LONG_OPTIONS -- networking/nslookup.c:278:4: error: 'ns_t_soa' undeclared here (not in a function)
  • CONFIG_FEATURE_UTMP, CONFIG_FEATURE_WTMP -- init/halt.c:86: error: 'RUN_LVL' undeclared (first use in this function)
    • disables CONFIG_LAST, CONFIG_RUNLEVEL, CONFIG_USERS, CONFIG_WALL, CONFIG_WHO
  • CONFIG_IPCS -- has patch -- util-linux/ipcs.c:79:7: error: redefinition of 'union semun'
  • CONFIG_IPCRM -- has patch -- util-linux/ipcrm.c:35:7: error: redefinition of 'union semun'
  • CONFIG_LFS -- on purpose? -- has patch (experimental) -- include/libbb.h:256: error: size of array 'BUG_off_t_size_is_misdetected' is negative
  • CONFIG_LOGGER -- sysklogd/logger.c:36: error: expected ';', ',' or ')' before '*' token
  • CONFIG_LOGREAD -- has patch -- sysklogd/logread.c:124:8: warning: assignment makes pointer from integer without a cast
  • CONFIG_NSLOOKUP -- has patch (with own resolver) -- networking/nslookup.c:154:27: error: dereferencing pointer to incomplete type
  • CONFIG_POWERTOP -- procps/powertop.c:508:2: error: inconsistent operand constraints in an 'asm'
  • CONFIG_ROUTE -- has patch -- from networking/route.c:46: [...]include/linux/if.h:160:18: error: field 'ifru_addr' has incomplete type
  • CONFIG_SHA1_HWACCEL, CONFIG_SHA256_HWACCEL -- ibbb/hash_md5_sha.c:20:2: error: inconsistent operand constraints in an 'asm'
  • CONFIG_SWAPOFF, CONFIG_SWAPON -- has patch -- util-linux/swaponoff.c:244:35: error: 'MNTOPT_NOAUTO' undeclared (first use in this function)
  • CONFIG_SYSLOGD -- has patch -- sysklogd/syslogd_and_logger.c:53:14: error: unknown type name 'CODE'
  • CONFIG_ZCIP -- has patch -- networking/zcip.c:71:19: error: field 'arp' has incomplete type

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

  • CONFIG_CONSPY -- miscutils/conspy.c:45:20: error: sys/kd.h: No such file or directory
  • CONFIG_LOADFONT, CONFIG_SETFONT -- console-tools/loadfont.c:61:20: error: sys/kd.h: No such file or directory

others

  • CONFIG_EJECT -- has patch -- util-linux/eject.c:49:22: error: scsi/sg.h: No such file or directory
  • CONFIG_FEATURE_INETD_RPC -- networking/inetd.c:176:22: error: rpc/rpc.h: No such file or directory
  • CONFIG_FEATURE_SHADOWPASSWDS -- include/libbb.h:61:22: error: shadow.h: No such file or directory
    • CONFIG_USE_BB_PWD_GRP, CONFIG_USE_BB_SHADOW would potentially work around, but there is a code error as listed above
  • CONFIG_HUSH -- has patch -- shell/hush.c:342:18: error: glob.h: No such file or directory
  • CONFIG_I2C* -- miscutils/i2c_tools.c:65:27: error: linux/i2c-dev.h: No such file or directory
    • disables CONFIG_I2CDETECT, CONFIG_I2CDUMP, CONFIG_I2CGET, CONFIG_I2CSET
  • CONFIG_LINUX32, CONFIG_LINUX64, CONFIG_SETARCH -- util-linux/setarch.c:23:29: error: sys/personality.h: No such file or directory
  • CONFIG_MT -- miscutils/mt.c:19:22: error: sys/mtio.h: No such file or directory
  • CONFIG_NANDDUMP, CONFIG_NANDWRITE -- has patch -- miscutils/nandwrite.c:54:26: error: mtd/mtd-user.h: No such file or directory
  • CONFIG_NTPD -- networking/ntpd.c:49:23: error: sys/timex.h: No such file or directory
  • CONFIG_SEEDRNG -- miscutils/seedrng.c:45:24: error: sys/random.h: No such file or directory
  • CONFIG_UDHCPC6 -- has patch -- networking/udhcp/d6_socket.c:10:21: error: ifaddrs.h: No such file or directory
  • CONFIG_UBI* -- has patch -- miscutils/ubi_tools.c:69:26: error: mtd/ubi-user.h: No such file or directory
    • disables CONFIG_UBIATTACH, CONFIG_UBIDETACH, CONFIG_UBIMKVOL, CONFIG_UBIRENAME, CONFIG_UBIRMVOL, CONFIG_UBIRSVOL, CONFIG_UBIUPDATEVOL

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

  • CONFIG_FSCK_MINIX -- undefined reference to 'setbit', 'clrbit'
  • CONFIG_MKFS_MINIX -- undefined reference to 'setbit', 'clrbit'

mntopt -- has patch

  • CONFIG_SWAPOFF -- undefined reference to 'hasmntopt'
  • CONFIG_SWAPON -- undefined reference to 'hasmntopt'

others

  • CONFIG_ETHER_WAKE -- has patch -- undefined reference to 'ether_hostton'
  • CONFIG_FALLOCATE -- undefined reference to 'posix_fallocate'
  • CONFIG_FEATURE_HTTPD_AUTH_MD5 -- undefined reference to 'crypt'
  • CONFIG_FEATURE_SYNC_FANCY -- undefined reference to 'syncfs'
  • CONFIG_HOSTID -- undefined reference to 'gethostid'
  • CONFIG_LOGNAME -- undefined reference to 'getlogin_r'
  • CONFIG_MDEV -- undefined reference to 'sigtimedwait'
  • CONFIG_NPROC -- undefined reference to 'sched_getaffinity'
  • CONFIG_NSENTER -- undefined reference to 'setns'
  • CONFIG_UDHCPC6 -- has patch -- undefined reference to 'getifaddrs', 'freeifaddrs'
  • CONFIG_UNSHARE -- undefined reference to 'unshare'

About

Keeping track of instructions and patches for building busybox with the Android NDK

Resources

Stars

Watchers

Forks