I have just ‘finished’ a port of Fuzix, Alan Cox’s lightweight Unix for small machines, to the ESP8266 microcontroller. And: I screen recorded it all, with narration by myself, so if anyone wants to watch the entire process, you now can!

Fuzix is an old-school V7 Unix clone, originally based on Doug Braun’s UZI Unixish for the Z80. Fuzix supports many more architectures, including the 6809, 6502, 68000, MSP430 (I did this one), and some others — it’s pretty easy to port. It’ll run in a tiny amount of space while also scaling up to machines with a reasonable amount of RAM (like a megabyte) while also provided a pretty decent old-school Unix environment, with multiple processes, the classic Bourne shell, init and getty, and so on.

The ESP8266 has ~96kB of RAM (although it’s a bit complicated) and no MMU. While Fuzix does support large flat address spaces, because there’s no MMU you can’t swap processes in and out on such systems as they might end up being loaded at a different address and there’s no way to relocate them; this approach isn’t viable on the ESP8266, so instead it’s using a model where one process lives in memory and all other processes are swapped out. This makes preemptive multitasking a nonstarter but with a fast disk, such as an SD card, the end result is snappy and extremely pleasant to use. Boot time is four seconds. Running a program from the shell takes about 500ms, most of the time spent swapping out the current process (sh is big).

The system supports:

  • user binaries with up to 31.5kB of code and 64kB of data
  • a proper Unix filesystem (files, directories, mostly unlimited sizes, etc)
  • SD card and NAND flash support — the latter via the Dhara FTL library
  • 80MHz clock (can be increased; the ESP8266 can go up to about 350MHz)

I did nearly all the work on video, via screen recorder, with myself talking about what I’m doing. This was partly because my other coding videos are surprisingly popular, including the nine-hour behemoth, which metrics have shown some some strange people have actually watched all the way through.

Here’s the first video (of fifteen). They’ll be released once a day starting on 2021-02-09, to avoid swamping the channel. You can also find them on the playlist.

It’s interesting to break down the full set of videos. The most time consuming part was making the SD card interface work (I still don’t understand what’s going on there). The second most time consuming part was interfacing to the internal NAND flash; I actually went down a couple of blind alleys here, including writing my own FTL (which didn’t work) before finding a preexisting one. The third part was task switchin/switchout/fork. Everything else was trivial by comparison…

Screenshots are kinda meaningless, but here’s a serial terminal dump, complete with the garbage emitted by the boot process:

|�l�c|����{���B�p�n�dNn���cp��cl r$p�N�s����cN�|����B�|�N�l��l`�Nl�d Nr���N��{$`�o�nod���no��rdp�n���l"o�|����p��no�$�$`�no$�{$or���o�` �n�2NNl��|�N��lp�N��d�#n�|���b��Nn�d�l �oo$�{lor���N$�$sےNl��FUZIX version 0.4pre1
Copyright (c) 1988-2002 by H.F.Bower, D.Braun, S.Nitschke, H.Peraza
Copyright (c) 1997-2001 by Arcady Schekochikhin, Adriano C. R. da Cunha
Copyright (c) 2013-2015 Will Sowerbutts <will@sowerbutts.com>
Copyright (c) 2014-2020 Alan Cox <alan@etchedpixels.co.uk>
80kB total RAM, 64kB available to processes (15 processes max)
Enabling interrupts ... ok.
Scanning flash: 2591kB: hda: 
SD drive 0: hdb: hdb1 hdb2 
Mounting root fs (root_dev=18, ro): warning: mounting dirty file system, forcing r/o.
Starting /init
init version 0.9.0ac#1

 ^ ^
 n n   Fuzix 0.3.1
       Welcome to Fuzix
 m m

login: root

Welcome to FUZIX.
# stty erase '^?'
# cd /tmp
# ls
# cd /
# ls
# prtroot
/dev/hdb2 / fuzix rw 0 0
# df
Filesystem       Blocks   Used   Free  %Used Mounted on
/dev/hdb2          4064   3279    785    81% /
# mount /dev/hda1 /mnt
# mount /dev/hda /mnt
warning: mounting dirty file system, forcing r/o.
# df  
Filesystem       Blocks   Used   Free  %Used Mounted on
/dev/hdb2          4064   3279    785    81% /
/dev/hda           2016     20   1996     1% /mnt
# cd /usr/games
# ls
# ./fortune
Breakpoint 1, main (argc=1, argv=0xbffffc40) at main.c:29
29   printf ("Welcome to GNU Hell!\n");
                -- "GNU Libtool documentation"
# ./fortune
On the Internet, nobody knows you're a dog.
                -- Cartoon caption
# ./fortune
The steady state of disks is full.
                -- Ken Thompson
# ./wump
./wump: not found
# ./startrek

 *                                   *
 *                                   *
 *      * * Super Star Trek * *      *
 *                                   *
 *                                   *

Do you need instructions (y/N):

If you’re looking for the source code, I’m upstreaming it piece by piece to the main FUZIX repository. Until that’s done, look in my own fork although there’s no documentation yet.

If you just want a binary to flash and try for yourself, here’s one:

ESP8266 Fuzix binaries

Poorly put-together, bugridden and unsupported Fuzix binaries for the ESP8266. Instructions are enclosed.