One of the items I discussed in my last post on bare metal Raspberry Pi development is the need for a convenient way to load program binaries onto the Pi. For a while I’ve been using Etherboot to do this, however it no longer does everything I need. One of the main problems is that it basically requires a LAN Ethernet connection — this makes it harder to use my Pi at the real-time OS lab on campus, for example. After using Etherboot for a few weeks, I realized that the ideal solution for me would be to load program binaries over a serial connection instead. I decided to write my own bootloader, Raspboot, to do so.
Right now Raspboot is very basic — its only function is to load a program and transfer it over a serial port to a Raspberry Pi. The binary is loaded into the Pi’s main memory at a memory address specified as part of the command line arguments. After the transfer is complete Raspboot executes the uploaded code. Raspboot runs in an infinite loop, so if the loaded program returns properly it’ll branch back into the loop when it terminates. At this point another program can be loaded and run, without needing to reset the Pi.
I’m actively working on a few more features that improve the usefulness of Raspboot, particularly in the context of systems development. The most significant of these is an “interactive mode” with commands that can be used to query device state. Whenever the Pi is running the device side of the bootloader, it will be able to respond to requests for memory dumps, register state, etc. It’s also worth noting that interactive mode will also display any serial port output from the Pi.
There isn’t a whole lot to say about the design of Raspboot yet. The system uses a client/server model; a client application on a Linux machine communicates with the server application running on the device itself. Originally I hoped to be able to use a standard terminal emulator like GNU Screen to communicate with Raspberry Pi, however the client application is needed to load program data and enforce command formatting.
At the moment the Raspboot server only works on the Raspberry Pi Model 1B; it may work on other Pi versions, however the UART pin layout may have changed in Model 2. Porting the code to another Pi version, or another platform for that matter, should be relatively easy as the only hardware feature used is UART IO. So far I’ve only tested the client code on Linux Mint, but I expect it’ll work on pretty much any Linux variant. It definitely won’t work on Windows because of the serial communication dependencies (termios.h and fcntl.h) — Windows will have its own implementation of these. I’m fairly certain that OS X has the termios API, but some tweaking might be needed to get everything working.