1*cf5a6c84SAndroid Build Coastguard WorkerToybox: all-in-one Linux command line. 2*cf5a6c84SAndroid Build Coastguard Worker 3*cf5a6c84SAndroid Build Coastguard Worker--- Getting started 4*cf5a6c84SAndroid Build Coastguard Worker 5*cf5a6c84SAndroid Build Coastguard WorkerYou can download static binaries for various targets from: 6*cf5a6c84SAndroid Build Coastguard Worker 7*cf5a6c84SAndroid Build Coastguard Worker http://landley.net/toybox/bin 8*cf5a6c84SAndroid Build Coastguard Worker 9*cf5a6c84SAndroid Build Coastguard WorkerThe special name "." indicates the current directory (just like ".." means 10*cf5a6c84SAndroid Build Coastguard Workerthe parent directory), and you can run a program that isn't in the $PATH by 11*cf5a6c84SAndroid Build Coastguard Workerspecifying a path to it, so this should work: 12*cf5a6c84SAndroid Build Coastguard Worker 13*cf5a6c84SAndroid Build Coastguard Worker wget http://landley.net/toybox/bin/toybox-x86_64 14*cf5a6c84SAndroid Build Coastguard Worker chmod +x toybox-x86_64 15*cf5a6c84SAndroid Build Coastguard Worker ./toybox-x86_64 echo hello world 16*cf5a6c84SAndroid Build Coastguard Worker 17*cf5a6c84SAndroid Build Coastguard Worker--- Building toybox 18*cf5a6c84SAndroid Build Coastguard Worker 19*cf5a6c84SAndroid Build Coastguard WorkerType "make help" for build instructions. 20*cf5a6c84SAndroid Build Coastguard Worker 21*cf5a6c84SAndroid Build Coastguard WorkerToybox uses the "make menuconfig; make; make install" idiom same as 22*cf5a6c84SAndroid Build Coastguard Workerthe Linux kernel. Usually you want something like: 23*cf5a6c84SAndroid Build Coastguard Worker 24*cf5a6c84SAndroid Build Coastguard Worker make defconfig 25*cf5a6c84SAndroid Build Coastguard Worker make 26*cf5a6c84SAndroid Build Coastguard Worker make install 27*cf5a6c84SAndroid Build Coastguard Worker 28*cf5a6c84SAndroid Build Coastguard WorkerOr maybe: 29*cf5a6c84SAndroid Build Coastguard Worker 30*cf5a6c84SAndroid Build Coastguard Worker LDFLAGS="--static" CROSS_COMPILE=armv5l- make defconfig toybox 31*cf5a6c84SAndroid Build Coastguard Worker PREFIX=/path/to/root/filesystem/bin make install_flat 32*cf5a6c84SAndroid Build Coastguard Worker 33*cf5a6c84SAndroid Build Coastguard WorkerThe file "configure" defines default values for many environment variables 34*cf5a6c84SAndroid Build Coastguard Workerthat control the toybox build; if you export any of these variables into your 35*cf5a6c84SAndroid Build Coastguard Workerenvironment, your value is used instead of the default in that file. 36*cf5a6c84SAndroid Build Coastguard Worker 37*cf5a6c84SAndroid Build Coastguard WorkerThe CROSS_COMPILE argument above is optional, the default builds a version of 38*cf5a6c84SAndroid Build Coastguard Workertoybox to run on the current machine. Cross compiling requires an appropriately 39*cf5a6c84SAndroid Build Coastguard Workerprefixed cross compiler toolchain, several example toolchains (built using 40*cf5a6c84SAndroid Build Coastguard Workerthe file "scripts/mcm-buildall.sh" in the toybox source) are available at: 41*cf5a6c84SAndroid Build Coastguard Worker 42*cf5a6c84SAndroid Build Coastguard Worker https://landley.net/toybox/downloads/binaries/toolchains/latest 43*cf5a6c84SAndroid Build Coastguard Worker 44*cf5a6c84SAndroid Build Coastguard WorkerFor the "CROSS_COMPILE=armv5l-" example above, download 45*cf5a6c84SAndroid Build Coastguard Workerarmv5l-linux-musleabihf-cross.tar.xz, extract it, and add its "bin" 46*cf5a6c84SAndroid Build Coastguard Workersubdirectory to your $PATH. (And yes, the trailing - is significant, 47*cf5a6c84SAndroid Build Coastguard Workerbecause the prefix includes a dash.) 48*cf5a6c84SAndroid Build Coastguard Worker 49*cf5a6c84SAndroid Build Coastguard WorkerFor more about cross compiling, see: 50*cf5a6c84SAndroid Build Coastguard Worker 51*cf5a6c84SAndroid Build Coastguard Worker https://landley.net/toybox/faq.html#cross 52*cf5a6c84SAndroid Build Coastguard Worker http://landley.net/writing/docs/cross-compiling.html 53*cf5a6c84SAndroid Build Coastguard Worker http://landley.net/aboriginal/architectures.html 54*cf5a6c84SAndroid Build Coastguard Worker 55*cf5a6c84SAndroid Build Coastguard WorkerFor a more thorough description of the toybox build process, see: 56*cf5a6c84SAndroid Build Coastguard Worker 57*cf5a6c84SAndroid Build Coastguard Worker http://landley.net/toybox/code.html#building 58*cf5a6c84SAndroid Build Coastguard Worker 59*cf5a6c84SAndroid Build Coastguard Worker--- Using toybox 60*cf5a6c84SAndroid Build Coastguard Worker 61*cf5a6c84SAndroid Build Coastguard WorkerThe toybox build produces a multicall binary, a "swiss-army-knife" program 62*cf5a6c84SAndroid Build Coastguard Workerthat acts differently depending on the name it was called by (cp, mv, cat...). 63*cf5a6c84SAndroid Build Coastguard WorkerInstalling toybox adds symlinks for each command name to the $PATH. 64*cf5a6c84SAndroid Build Coastguard Worker 65*cf5a6c84SAndroid Build Coastguard WorkerThe special "toybox" command treats its first argument as the command to run. 66*cf5a6c84SAndroid Build Coastguard WorkerWith no arguments, it lists available commands. This allows you to use toybox 67*cf5a6c84SAndroid Build Coastguard Workerwithout installing it, and is the only command that can have an arbitrary 68*cf5a6c84SAndroid Build Coastguard Workersuffix (hence "toybox-armv5l"). 69*cf5a6c84SAndroid Build Coastguard Worker 70*cf5a6c84SAndroid Build Coastguard WorkerThe "help" command provides information about each command (ala "help cat"), 71*cf5a6c84SAndroid Build Coastguard Workerand "help toybox" provides general information about toybox. 72*cf5a6c84SAndroid Build Coastguard Worker 73*cf5a6c84SAndroid Build Coastguard Worker--- Configuring toybox 74*cf5a6c84SAndroid Build Coastguard Worker 75*cf5a6c84SAndroid Build Coastguard WorkerIt works like the Linux kernel: allnoconfig, defconfig, and menuconfig edit 76*cf5a6c84SAndroid Build Coastguard Workera ".config" file that selects which features to include in the resulting 77*cf5a6c84SAndroid Build Coastguard Workerbinary. You can save and re-use your .config file, but may want to 78*cf5a6c84SAndroid Build Coastguard Workerrun "make oldconfig" to re-run the dependency resolver when migrating to 79*cf5a6c84SAndroid Build Coastguard Workernew versions. 80*cf5a6c84SAndroid Build Coastguard Worker 81*cf5a6c84SAndroid Build Coastguard WorkerThe maximum sane configuration is "make defconfig": allyesconfig isn't 82*cf5a6c84SAndroid Build Coastguard Workerrecommended as a starting point for toybox because it enables unfinished 83*cf5a6c84SAndroid Build Coastguard Workercommands, debug code, and optional dependencies your build environment may 84*cf5a6c84SAndroid Build Coastguard Workernot provide. 85*cf5a6c84SAndroid Build Coastguard Worker 86*cf5a6c84SAndroid Build Coastguard Worker--- Creating a Toybox-based Linux system 87*cf5a6c84SAndroid Build Coastguard Worker 88*cf5a6c84SAndroid Build Coastguard WorkerToybox has a built-in simple system builder (scripts/mkroot.sh) with a 89*cf5a6c84SAndroid Build Coastguard WorkerMakefile target: 90*cf5a6c84SAndroid Build Coastguard Worker 91*cf5a6c84SAndroid Build Coastguard Worker make root 92*cf5a6c84SAndroid Build Coastguard Worker sudo chroot root/host/fs /init 93*cf5a6c84SAndroid Build Coastguard Worker 94*cf5a6c84SAndroid Build Coastguard WorkerType "exit" to get back out. If you install appropriate cross compilers and 95*cf5a6c84SAndroid Build Coastguard Workerpoint it at Linux source code, it can build simple three-package systems 96*cf5a6c84SAndroid Build Coastguard Workerthat boot to a shell prompt under qemu: 97*cf5a6c84SAndroid Build Coastguard Worker 98*cf5a6c84SAndroid Build Coastguard Worker make root CROSS_COMPILE=sh4-linux-musl- LINUX=~/linux 99*cf5a6c84SAndroid Build Coastguard Worker cd root/sh4 100*cf5a6c84SAndroid Build Coastguard Worker ./qemu-sh4.sh 101*cf5a6c84SAndroid Build Coastguard Worker 102*cf5a6c84SAndroid Build Coastguard WorkerBy calling scripts/mkroot.sh directly you can add additional packages 103*cf5a6c84SAndroid Build Coastguard Workerto the build, see scripts/root/dropbear as an example. 104*cf5a6c84SAndroid Build Coastguard Worker 105*cf5a6c84SAndroid Build Coastguard WorkerThe FAQ explains this in a lot more detail: 106*cf5a6c84SAndroid Build Coastguard Worker 107*cf5a6c84SAndroid Build Coastguard Worker https://landley.net/toybox/faq.html#system 108*cf5a6c84SAndroid Build Coastguard Worker https://landley.net/toybox/faq.html#mkroot 109*cf5a6c84SAndroid Build Coastguard Worker 110*cf5a6c84SAndroid Build Coastguard Worker--- Presentations 111*cf5a6c84SAndroid Build Coastguard Worker 112*cf5a6c84SAndroid Build Coastguard Worker1) "Why Toybox?" talk at the Embedded Linux Conference in 2013 113*cf5a6c84SAndroid Build Coastguard Worker 114*cf5a6c84SAndroid Build Coastguard Worker outline: http://landley.net/talks/celf-2013.txt 115*cf5a6c84SAndroid Build Coastguard Worker video: http://youtu.be/SGmtP5Lg_t0 116*cf5a6c84SAndroid Build Coastguard Worker 117*cf5a6c84SAndroid Build Coastguard Worker The https://landley.net/toybox/about.html page has nav links breaking that 118*cf5a6c84SAndroid Build Coastguard Worker talk down into sections. 119*cf5a6c84SAndroid Build Coastguard Worker 120*cf5a6c84SAndroid Build Coastguard Worker2) "Why Public Domain?" The rise and fall of copyleft, Ohio LinuxFest 2013 121*cf5a6c84SAndroid Build Coastguard Worker 122*cf5a6c84SAndroid Build Coastguard Worker outline: http://landley.net/talks/ohio-2013.txt 123*cf5a6c84SAndroid Build Coastguard Worker audio: https://archive.org/download/OhioLinuxfest2013/24-Rob_Landley-The_Rise_and_Fall_of_Copyleft.mp3 124*cf5a6c84SAndroid Build Coastguard Worker 125*cf5a6c84SAndroid Build Coastguard Worker3) Why did I do Aboriginal Linux (which led me here) 126*cf5a6c84SAndroid Build Coastguard Worker 127*cf5a6c84SAndroid Build Coastguard Worker 260 slide presentation: 128*cf5a6c84SAndroid Build Coastguard Worker https://speakerdeck.com/landley/developing-for-non-x86-targets-using-qemu 129*cf5a6c84SAndroid Build Coastguard Worker 130*cf5a6c84SAndroid Build Coastguard Worker How and why to make android self-hosting: 131*cf5a6c84SAndroid Build Coastguard Worker http://landley.net/aboriginal/about.html#selfhost 132*cf5a6c84SAndroid Build Coastguard Worker 133*cf5a6c84SAndroid Build Coastguard Worker More backstory than strictly necessary: 134*cf5a6c84SAndroid Build Coastguard Worker https://landley.net/aboriginal/history.html 135*cf5a6c84SAndroid Build Coastguard Worker 136*cf5a6c84SAndroid Build Coastguard Worker4) What's new with toybox (ELC 2015 status update): 137*cf5a6c84SAndroid Build Coastguard Worker 138*cf5a6c84SAndroid Build Coastguard Worker video: http://elinux.org/ELC_2015_Presentations 139*cf5a6c84SAndroid Build Coastguard Worker outline: http://landley.net/talks/celf-2015.txt 140*cf5a6c84SAndroid Build Coastguard Worker 141*cf5a6c84SAndroid Build Coastguard Worker5) Toybox vs BusyBox (2019 ELC talk): 142*cf5a6c84SAndroid Build Coastguard Worker 143*cf5a6c84SAndroid Build Coastguard Worker outline: http://landley.net/talks/elc-2019.txt 144*cf5a6c84SAndroid Build Coastguard Worker video: https://www.youtube.com/watch?v=MkJkyMuBm3g 145*cf5a6c84SAndroid Build Coastguard Worker 146*cf5a6c84SAndroid Build Coastguard Worker--- Contributing 147*cf5a6c84SAndroid Build Coastguard Worker 148*cf5a6c84SAndroid Build Coastguard WorkerThe three important URLs for communicating with the toybox project are: 149*cf5a6c84SAndroid Build Coastguard Worker 150*cf5a6c84SAndroid Build Coastguard Worker web page: http://landley.net/toybox 151*cf5a6c84SAndroid Build Coastguard Worker 152*cf5a6c84SAndroid Build Coastguard Worker mailing list: http://lists.landley.net/listinfo.cgi/toybox-landley.net 153*cf5a6c84SAndroid Build Coastguard Worker 154*cf5a6c84SAndroid Build Coastguard Worker git repo: http://github.com/landley/toybox 155*cf5a6c84SAndroid Build Coastguard Worker 156*cf5a6c84SAndroid Build Coastguard WorkerThe maintainer prefers patches be sent to the mailing list. If you use git, 157*cf5a6c84SAndroid Build Coastguard Workerthe easy thing to do is: 158*cf5a6c84SAndroid Build Coastguard Worker 159*cf5a6c84SAndroid Build Coastguard Worker git format-patch -1 $HASH 160*cf5a6c84SAndroid Build Coastguard Worker 161*cf5a6c84SAndroid Build Coastguard WorkerThen send a file attachment. The list holds messages from non-subscribers 162*cf5a6c84SAndroid Build Coastguard Workerfor moderation, but I usually get to them in a day or two. 163*cf5a6c84SAndroid Build Coastguard Worker 164*cf5a6c84SAndroid Build Coastguard WorkerI download github pull requests as patches and apply them with "git am" 165*cf5a6c84SAndroid Build Coastguard Worker(which avoids gratuitous merge commits). Sometimes I even remember to close 166*cf5a6c84SAndroid Build Coastguard Workerthe pull request. 167*cf5a6c84SAndroid Build Coastguard Worker 168*cf5a6c84SAndroid Build Coastguard WorkerIf I haven't responded to your patch after one week, feel free to remind 169*cf5a6c84SAndroid Build Coastguard Workerme of it. 170*cf5a6c84SAndroid Build Coastguard Worker 171*cf5a6c84SAndroid Build Coastguard WorkerAndroid's policy for toybox patches is that non-build patches should go 172*cf5a6c84SAndroid Build Coastguard Workerupstream first (into vanilla toybox, with discussion on the toybox mailing 173*cf5a6c84SAndroid Build Coastguard Workerlist) and then be pulled into android's toybox repo from there. (They 174*cf5a6c84SAndroid Build Coastguard Workergenerally resync on fridays). The exception is patches to their build scripts 175*cf5a6c84SAndroid Build Coastguard Worker(Android.mk and the checked-in generated/* files) which go directly to AOSP. 176*cf5a6c84SAndroid Build Coastguard Worker 177*cf5a6c84SAndroid Build Coastguard Worker(As for the other meaning of "contributing", https://patreon.com/landley is 178*cf5a6c84SAndroid Build Coastguard Workeralways welcome but I warn you up front I'm terrible about updating it.) 179