[Toybox] Building Linux with Toybox

Rob Landley rob at landley.net
Sat Aug 29 02:14:43 PDT 2020


On 8/28/20 11:56 AM, Porter, Jeremy wrote:
> I have RISC-V based cross compiled Linux running busybox. I have a very simple
> /etc/inittab file like this:
> 
>   1 ::sysinit:/bin/busybox mount -t proc proc /proc
>   2 ::sysinit:/bin/busybox mount -t tmpfs tmpfs /tmp
>   3 ::sysinit:/bin/busybox mount -o remount,rw /dev/htifbd0 /
>   4 ::sysinit:/bin/busybox --install -s
>   5 /dev/console::sysinit:-/bin/ash
> 
> How can I translate this to something toybox can use? I've tried this:
> 
>   1 mount -t proc proc /proc
>   2 mount -t tmpfs tmpfs /tmp
>   3 mount -o remount,rw /dev/htifbd0 /
>   4 #::sysinit:/bin/toybox --install -s
>   5 #/dev/console::sysinit:-/bin/sh
>   6 exec toybox init

And when you tried it, you saw what output?

Toybox init is still in pending, and thus isn't in the defconfig build. It
hasn't undergone the full https://landley.net/toybox/cleanup.html review yet, so
I couldn't tell you what it does. (I'm told it worked for the people who
submitted it...)

Toybox has a built-in system builder:

  https://landley.net/toybox/faq.html#mkroot

And the init script it uses starts at:

  https://github.com/landley/toybox/blob/master/scripts/mkroot.sh#L73

Which ends by calling "oneit", a very simple init program that runs a single
child process (with /dev/console pointing to a proper tty with signal support),
and reboots the system when that child exits.

Unfortunately the systems created by that system builder use 2 commands out of
pending (sh and route), and sh is under active development which means I broke
it recently. I added proper ${var:thingy} parsing, but haven't implemented
${var/search/replace} yet, which that init script uses. The current shell parses
it properly, but throws an error when it tries to _do_ it, because:

https://github.com/landley/toybox/blob/master/toys/pending/sh.c#L1205

Which means the make root init script won't currently work as is, but I plan to
fix it up before cutting the next release. At the moment implementing "case"
statements and wildcard support, need to cycle back around to finishing the
variable expansion...

The downside of the project not being to 1.0 yet. :)

> It's starting partially (I think) but I'm not quite sure how to troubleshoot
> this.

Without seeing what it produced, I can't either.

> My goal is to have a very small Linux. It's around 3 MB file size right
> now and takes about 5 MB of memory when booted. It looks like toybox might go a
> little smaller if I can get it working.

Try running /bin/sh as pid 1, and run your statements from the command line to
see what they do?

You can also stick in "echo" statements to see what's being output, although if
your initramfs hasn't got a /dev/console entry you won't have a stdout until you
mount devtmpfs and redirect it yourself, but it looks like you're using
/dev/htifbd0 as your root so presumably you're using the root= fallback logic
which creates a temporary /dev/console node to attach PID 1's stdin/out/err to,
so this doesn't apply to that case...

> Thanks,
> 
> Jeremy

Rob



More information about the Toybox mailing list