Ubuntu 16.04でBusyBox 1.25.0をUbuntu 16.04とAndroid向けにビルドします。Anroid向けにビルドしたBusyBoxはAndroid 5.1.1で動作させています。
Table of Contents
Ubuntu 16.04: BusyBoxをビルドする
1 BusyBoxのダウンロード
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 Ubuntu 16.04向けにビルド
freebsd_defconfigを用いてUbuntu 16.04向けにbusyboxをビルドします。
$ make freebsd_defconfig $ make $ make install
_installディレクトリにbusyboxのバイナリと各コマンドのシンボリックリンクが作成されます。
$ 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
_install/binと_install/sbinにパスを通してbusyboxのshとlsを実行します。
$ 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 Android向けにビルド
Linux向けのAndroid NDKをダウンロードします。
$ wget https://dl.google.com/android/repository/android-ndk-r12b-linux-x86_64.zip $ unzip android-ndk-r12b-linux-x86_64.zip
クロスツールチェインのプレフィックスとルートファイルシステムのパスを変数CROSS_COMPILEとSYSROOTに格納します(変数ARMLINUXは一時的な変数で意味は無いです)。
$ 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/
android_ndk_defconfigを使います。作成された.configに対して以下の変更を加えます。
- クロスツールチェインのプレフィクスを変更します。
- ルートファイルシステムのパスを変更します。
- Android 5.1の為にPIEを有効にします。
- ビルドエラーとなるコマンドを除外します。
$ 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
_installをAndroid 5.1.1へpushしてAndroid 5.1.1上で実行します。
$ 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>
Android 5.1上でNDKアプリケーションを動作させると以下の警告が出ます。BusyBox以外のプログラムでも警告が出るようなので、Anroid 5.1の問題のようです。
$ ./busybox WARNING: linker: ./busybox: unused DT entry: type 0x6ffffffe arg 0x2d10 WARNING: linker: ./busybox: unused DT entry: type 0x6fffffff arg 0x2