Micro Code

Michael's blog about teaching, hardware, software and the things inbetween

Tiny Unix on a tiny microcontroller

January 01, 2018 — Michael Engel

There is one quite nice thing I (re)discovered over the Christmas break. At a MIPS FPGA workshop in Munich last January, I was given a ChipKit Wi-Fire board. This board is based on a Microchip PIC32MZ microcontroller, which includes a MIPS M14k CPU core with MMU and FPU, 2 MB of flash memory, 512 kB RAM and a number of peripherals.

This board is not only capable of running typical embedded operating systems, but is probably one of the tiniest platforms capable of running real Unix - namely the last BSD Unix version from UC Berkeley, 4.4BSD-Lite2. This final version from the CSRG research group came out in 1995 after a lengthy litigation in which AT&T (back then the owner of Unix copyrights) tried to hinder the publication of the BSD source code due to allegations of illegaly copied AT&T proprietary source code - luckily, this trial resulted in only six files which had to be removed from the BSD source code base; the 4.4BSD source code without the infringing files was then published as 4.4BSD-Lite2 and formed the basis for subsequent open source BSD projects, including 386BSD, FreeBSD, NetBSD, OpenBSD and DragonFly BSD.

Serge Vakulenko has worked on liteBSD, a port of 4.4BSD-Lite2 to the PIC32MZ MIPS-based microcontrollers for a number of years and managed to get it to work with the rather puny hardware resources of that controller (the MIPS architecture itself was supported by 4.4BSD in DECstation and SONY MIPS machines).

I got it to run on the Wi-Fire board (which is one of the boards supported out of the box by LiteBSD); it is quite an impressive achievement and, despite the minimal hardware resources, feels familiar to people used to modern Unix or Linux systems.

So far, I have fixed two bugs in the litebsd kernel source.

One was missing support for the execution of so-called shebang interpreted executables, i.e. shell scripts or similar (Perl, Python, awk, etc.), which start with the character sequence "#!" followed by the name of the interpreter, such as "#!/bin/sh".

The other was a bug in the memory allocation code for ktrace, which resulted in a kernel panic during execution tracing when tracing was enabled in the kernel.

There is also RetroBSD, an even smaller version of BSD for very tiny microcontrollers, derived from the last PDP11 BSD Unix version, 2.11BSD.

Some links:

Wi-Fire board litebsd screen shot

Tags: mips, pic32, BSD, unix, litebsd