Fuzix port for the MSP430
a possible record for the smallest Unix ever
Over the past couple of months I've been spending some time porting Alan Cox's Fuzix operating system to a random microcontroller I have on my desk. It's working really rather well.
The MSP430FR5969 is an ultra-low-power embedded microcontroller made by Texas Instruments. It's unusual for a modern microcontroller in that it's got quite a lot of RAM; a whole 64kB! And the architecture allows you to run programs out of RAM. (Most common microcontrollers, like the AVR32 or PIC, store your program in a different address space to your data which isn't easily accessible by programs.) It's a system-on-chip device, so you can build an entire functioning computer out of a single IC with no other components. (Although Fuzix does require an external SD card to put the file system on.)
The specs are quite minimal:
- 66kB RAM (mostly FRAM; this is really neat stuff --- behaves and performs like SRAM, but the data doesn't go away when the power dies)
- 16MHz MSP430 processor core (although I'm running it at 8MHz)
- 20-bit registers
- A billion on-chip peripherals, including SPI (used for the SD card interface) and a serial port (for the console)
- Runs at ~1mA flat out
Here is a picture of TI's MSP430FR5969 development board.
You see that little square chip all by itself on the left-hand board? That's the processor. All the rest of the electronics on that board, including the bigger chip at the top containing a much more powerfull microcontroller, is the USB debugger interface. (The board on the right is the plug-in SD card adaptor.)
Fuzix is a very, very small Unixish operating system, originally intended to run on Z80 platforms. It's a fork of Uzi, which in turn dates back to the 1980s. It supports most System V Unix functionality, including a proper unixy virtual file system, swap, multiple processes, pipes, the V7 Bourne shell, device nodes, multiple groups and users, etc.
How well does Fuzix work? Really well. Here's a log from my serial terminal.
FUZIX version 0.1 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 <firstname.lastname@example.org> Copyright (c) 2014-2015 Alan Cox <email@example.com> Devboot 64kB total RAM, 25kB available to processes (6 processes max) Enabling interrupts ... ok. SD drive 0: hda: hda1 hda2 hda3 Mounting root fs (root_dev=1): OK Starting /init init version 0.9.0ac#1 # stty erase '^?' # ls bin dev etc init tmp usr # prtroot /dev/hda1 / fuzix rw # prtroot > /etc/mtab # df Filesystem Blocks Used Free %Used Mounted on /dev/hda1 20480 1240 18600 6% / # ls -l drwxr-xr-x 2 root 0 3584 Oct 24 19:21 bin drwxr-xr-x 3 root 0 3072 Oct 24 19:21 dev drwxr-xr-x 3 root 0 512 Jan 01 00:01 etc -rwxr-xr-x 1 root 0 7973 Oct 24 19:21 init drwxrwxrwt 2 root 0 512 Oct 24 19:21 tmp drwxr-xr-x 2 root 0 512 Oct 24 19:21 usr # ls /bin | wc 100 100 511 # cal January 1970 Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 # ls -l /bin/cal -rwxr-xr-x 1 root 0 10689 Oct 24 19:21 /bin/cal # cd /tmp # touch a # echo "foo" > b # cat a b > c # cat c foo # cat c c c > d # cat d foo foo foo # echo "bar" >> b # echo "baz" >> b # cat b foo bar baz # ed b "b", 3 lines, 12 chars : p foo : p foo : n Unimplemented command : 3 baz : 2 bar : i inserted line . : w "b", 4 lines, 22 chars : # cat b inserted line bar baz # ls -l -rw-rw-rw- 1 root 0 0 Jan 01 00:07 a -rw-rw-rw- 1 root 0 22 Jan 01 00:09 b -rw-rw-rw- 1 root 0 4 Jan 01 00:07 c -rw-rw-rw- 1 root 0 12 Jan 01 00:07 d # ls -l -rw-rw-rw- 1 root 0 0 Jan 01 00:07 a -rw-rw-rw- 1 root 0 22 Jan 01 00:09 b -rw-rw-rw- 1 root 0 4 Jan 01 00:07 c -rw-rw-rw- 2 root 0 12 Jan 01 00:07 d -rw-rw-rw- 2 root 0 12 Jan 01 00:07 e # cd /usr/games # ls -l -rwxr-xr-x 1 root 0 5540 Oct 24 19:21 arithmetic -rwxr-xr-x 1 root 0 10859 Oct 24 19:21 backgammon -rwxr-xr-x 1 root 0 7062 Oct 24 19:21 fish -rwxr-xr-x 1 root 0 8393 Oct 24 19:21 wump # ./wump Instructions? (y-n) y Welcome to 'Hunt the Wumpus.' The Wumpus lives in a cave of 20 rooms. Each room has 3 tunnels leading to other rooms.
That's not bad for a device half the size of my little fingernail and with 25kB of userspace RAM! (And I have a strong suspicion that I am the only person ever to have lost a game of Go Fish against an MSP430.)
It can't run multiple processes simultaneously, as it's only got space for one process in-memory at once, and so it swaps to SD card. Those pipes above will typically involve about four context switches. Despite this, performance is pretty snappy; it's disturbingly comfortable to use. Alas, it doesn't have enough memory to run Fuzix's vi clone, so the only real editor is ed.
You could probably hook up both MSP430 serial ports to terminals and have multiple people logged in at once, although it would probably be a fairly miserable experience due to constant swapping.
It's currently a bit buggy; some of the commands fail, some hang, some print gibberish --- I suspect alignment issues (the Z80 doesn't care about alignment. The MSP430 does). But I still think it's pretty cool.
Main Fuzix page
The main (external) Fuzix github site. For MSP430 information, see Documentation/MSP430FR5969.md.