blob: 4b3dee0097f62dd67e40a5eb2e7d5435b7f28e89 [file] [log] [blame]
Rob Landley09e8bde2012-02-04 12:20:39 -06001Toybox: all-in-one Linux command line.
2
Rob Landley0b87b2e2013-05-07 22:50:33 -05003--- Getting started
4
5You can download static binaries for various targets from:
6
7 http://landley.net/toybox/bin
8
9The special name "." indicates the current directory (just like ".." means
10the parent directory), and you can run a program that isn't in the $PATH by
11specifying a path to it, so this should work:
12
Rob Landley5acc6f42016-04-09 11:04:16 -050013 wget http://landley.net/toybox/bin/toybox-x86_64
Rob Landley0b87b2e2013-05-07 22:50:33 -050014 chmod +x toybox-x86_64
15 ./toybox-x86_64 echo hello world
16
17--- Building toybox
Rob Landley09e8bde2012-02-04 12:20:39 -060018
19Type "make help" for build instructions.
20
Rob Landley1cbc2832015-10-28 21:41:45 -050021Toybox uses the "make menuconfig; make; make install" idiom same as
22the Linux kernel. Usually you want something like:
Rob Landley09e8bde2012-02-04 12:20:39 -060023
Rob Landley0b87b2e2013-05-07 22:50:33 -050024 make defconfig
Rob Landley1cbc2832015-10-28 21:41:45 -050025 make
26 make install
Rob Landley09e8bde2012-02-04 12:20:39 -060027
Rob Landley1cbc2832015-10-28 21:41:45 -050028Or maybe:
29
30 LDFLAGS="--static" CROSS_COMPILE=armv5l- make defconfig toybox
31 PREFIX=/path/to/root/filesystem/bin make install_flat
32
33The file "configure" defines default values for many environment
34variables that control the toybox build; if you set a value for any of
35these, your value is used instead of the default in that file.
36
37The CROSS_COMPILE argument above is optional, the default builds a version of
Rob Landley0b87b2e2013-05-07 22:50:33 -050038toybox to run on the current machine. Cross compiling requires an appropriately
39prefixed cross compiler toolchain, several example toolchains are available at:
40
Zach Riggled3e68142017-09-13 12:15:45 -050041 http://landley.net/aboriginal/bin
Rob Landley0b87b2e2013-05-07 22:50:33 -050042
43For the "CROSS_COMPILE=armv5l-" example above, download
44cross-compiler-armv5l.tar.bz2, extract it, and add its "bin" subdirectory to
45your $PATH. (And yes, the trailing - is significant, because the prefix
46includes a dash.)
47
48For more about cross compiling, see:
49
50 http://landley.net/writing/docs/cross-compiling.html
51 http://landley.net/aboriginal/architectures.html
Rob Landley09e8bde2012-02-04 12:20:39 -060052
Rob Landley1cbc2832015-10-28 21:41:45 -050053For a more thorough description of the toybox build process, see
54http://landley.net/toybox/code.html#building
55
Rob Landley09e8bde2012-02-04 12:20:39 -060056--- Using toybox
57
Rob Landley0b87b2e2013-05-07 22:50:33 -050058The toybox build produces a multicall binary, a "swiss-army-knife" program
59that acts differently depending on the name it was called by (cp, mv, cat...).
60Installing toybox adds symlinks for each command name to the $PATH.
Rob Landley09e8bde2012-02-04 12:20:39 -060061
Rob Landley0b87b2e2013-05-07 22:50:33 -050062The special "toybox" command treats its first argument as the command to run.
63With no arguments, it lists available commands. This allows you to use toybox
64without installing it. This is the only command that can have an arbitrary
65suffix (hence "toybox-armv5l").
Rob Landley09e8bde2012-02-04 12:20:39 -060066
67The "help" command provides information about each command (ala "help cat").
68
Rob Landley0b87b2e2013-05-07 22:50:33 -050069--- Configuring toybox
Rob Landley09e8bde2012-02-04 12:20:39 -060070
Rob Landley0b87b2e2013-05-07 22:50:33 -050071It works like the Linux kernel: allnoconfig, defconfig, and menuconfig edit
72a ".config" file that selects which features to include in the resulting
Rob Landleye8bd47b2016-05-02 18:59:57 -050073binary. You can save and re-use your .config file, although may want to
74run "make oldconfig" to re-run the dependency resolver when migrating to
75new versions.
Rob Landley09e8bde2012-02-04 12:20:39 -060076
Rob Landley0b87b2e2013-05-07 22:50:33 -050077The maximum sane configuration is "make defconfig": allyesconfig isn't
78recommended for toybox because it enables unfinished commands and debug code.
79
80--- Creating a Toybox-based Linux system
81
82Toybox is not a complete operating system, it's a program that runs under
83an operating system. Booting a simple system to a shell prompt requires
Rob Landleye8bd47b2016-05-02 18:59:57 -050084three packages: an operating system kernel (Linux*) to drive the hardware,
85one or more programs for the system to run (toybox), and a C library ("libc")
86to tie them together (toybox has been tested with musl, uClibc, glibc,
87and bionic).
Rob Landley0b87b2e2013-05-07 22:50:33 -050088
Rob Landleya7c3e292014-01-01 13:24:03 -060089The C library is part of a "toolchain", which is an integrated suite
Rob Landley0b87b2e2013-05-07 22:50:33 -050090of compiler, assembler, and linker, plus the standard headers and libraries
Rob Landleye8bd47b2016-05-02 18:59:57 -050091necessary to build C programs. (And miscellaneous binaries like nm and objdump.)
Rob Landley0b87b2e2013-05-07 22:50:33 -050092
Rob Landleya7c3e292014-01-01 13:24:03 -060093Static linking (with the --static option) copies the shared library contents
94into the program, resulting in larger but more portable programs, which
Rob Landleya6916cd2015-04-07 14:59:32 -050095can run even if they're the only file in the filesystem. Otherwise,
Rob Landleya7c3e292014-01-01 13:24:03 -060096the "dynamically" linked programs require the library files to be present on
97the target system ("man ldd" and "man ld.so" for details).
Rob Landley0b87b2e2013-05-07 22:50:33 -050098
Rob Landley0b87b2e2013-05-07 22:50:33 -050099An example toybox-based system is Aboriginal Linux:
100
Rob Landleya6916cd2015-04-07 14:59:32 -0500101 http://landley.net/aboriginal/about.html
102
103That's designed to run under qemu, emulating several different hardware
104architectures (x86, x86-64, arm, mips, sparc, powerpc, sh4). Each toybox
105release is regression tested by building Linux From Scratch under this
106toybox-based system on each supported architecture, using QEMU to emulate
107big and little endian systems with different word size and alignment
Rob Landleye8bd47b2016-05-02 18:59:57 -0500108requirements. (The eventual goal is to replace Linux From Scratch with
109the Android Open Source Project.)
110
111* Or something providing the same API such as FreeBSD's Linux emulation layer.
Rob Landleya6916cd2015-04-07 14:59:32 -0500112
113--- Presentations
114
Rob Landleye8bd47b2016-05-02 18:59:57 -05001151) "Why Toybox?" talk at the Embedded Linux Conference in 2013
Rob Landleya6916cd2015-04-07 14:59:32 -0500116
117 video: http://youtu.be/SGmtP5Lg_t0
118 outline: http://landley.net/talks/celf-2013.txt
119 linked from http://landley.net/toybox/ in nav bar on left as "Why is it?"
120 - march 21, 2013 entry has section links.
121
1222) "Why Public Domain?" The rise and fall of copyleft, Ohio LinuxFest 2013
123
124 audio: https://archive.org/download/OhioLinuxfest2013/24-Rob_Landley-The_Rise_and_Fall_of_Copyleft.mp3
125 outline: http://landley.net/talks/ohio-2013.txt
126
1273) Why did I do Aboriginal Linux (which led me here)
128
129 260 slide presentation:
130 https://speakerdeck.com/landley/developing-for-non-x86-targets-using-qemu
131
132 How and why to make android self-hosting:
133 http://landley.net/aboriginal/about.html#selfhost
134
1354) What's new with toybox (ELC 2015 status update):
136
137 video: http://elinux.org/ELC_2015_Presentations
138 outline: http://landley.net/talks/celf-2015.txt
Rob Landleyb057bac2015-12-01 11:13:08 -0600139
Rob Landleye8bd47b2016-05-02 18:59:57 -0500140--- Contributing
141
142The three important URLs for communicating with the toybox project are:
143
144 web page: http://landley.net/toybox
145
146 mailing list: http://lists.landley.net/listinfo.cgi/toybox-landley.net
147
148 git repo: http://github.com/landley/toybox
149
150The maintainer prefers patches be sent to the mailing list. If you use git,
151the easy thing to do is:
152
153 git format-patch -1 $HASH
154
155Then send a file attachment. The list holds messages from non-subscribers
156for moderation, but I usually get to them in a day or two.
157
158Although I do accept pull requests on github, I download the patches and
159apply them with "git am" (which avoids gratuitous merge commits). Closing
160the pull request is then the submitter's responsibility.
161
162If I haven't responded to your patch after one week, feel free to remind
163me of it.
164
165Android's policy for toybox patches is that non-build patches should go
166upstream first (into vanilla toybox, with discussion on the toybox mailing
167list) and then be pulled into android's toybox repo from there. (They
168generally resync on fridays). The exception is patches to their build scripts
169(Android.mk and the checked-in generated/* files) which go directly to AOSP.