The typical development cycle of a kernel on the Raspberry Pi requires the constant update of a kernel.img file on the microSD card. This can become tedious as every time the kernel is updated, the physical process becomes:
- power down the Raspberry Pi
- eject and remove the microSD card from the Raspberry Pi
- insert the microSD card into the host environment (e.g. a laptop)
- copy the latest kernel.img onto the microSD card
- eject and remove the micro SD card from the host environment
- insert the microSD card into the Raspberry Pi
- power up the Raspberry Pi
Rather than continue this constant swapping of the microSD card, something different is needed. Luckily, such a thing was found during early development of the IMP OS kernel: “bootloader07”.
What is bootloader07?
bootloader07 is, itself, a kernel for the Raspberry Pi. By uploading it onto the microSD card, bootloader07 – upon launch – will await a kernel image to be delivered to it over a serial connection, at which point it will install the kernel into memory and boot from there. It is, in effect, a kind of “proto-kernel” that both loads and boots the wanted kernel.
There were a handful of minor amendments made to the code, hence it has been branched and is maintained within the IMP OS repository set (here). Notably, it loads the supplied kernel image (which must be provided in IHEX format) at the top of the Raspberry Pi memory area (for 1Gb systems) at 0x3b000000 (944MB marker), as this is where the kernel is built to run from. (For more details on the memory aspects of IMP OS with respect to the Raspberry Pi, please refer to the (upcoming!) Memory section).
IMP OS is currently developed using a Linux distribution. When IMP OS is built, both the official binary image and an IHEX image are available (e.g. “kernel8.img” and “kernel8.hex” respectively). The IHEX image file is then transferred over to the Raspberry Pi using two things: a USB to UART serial console cable, and a simple terminal emulator program.
The cable being used came from the nice people at Pimoroni, and can be purchased here if required: Pimoroni USB to UART Serial Console Cable. (Note, this site is not affiliated in any way with suppliers, this information is provided with no reward).
The Terminal Emulator
The terminal emulator program used is “picocom”. Individual circumstances may differ, but by way of reference the command used to launch picocom is:
picocom -b 115200 -l -r /dev/ttyUSB0 --send-cmd "ascii-xfr -s"
This connects picocom to the USB device at a baud rate (transfer rate) of 115,200bps. When the Raspberry Pi is plugged in, bootloader07 sends over some initial data for picocom to display, which should look something like this:
12345678 3B1F8358 IHEX
picocom can be made to select the kernel to transfer by pressing CTRL-A, CTRL-S. Upon entering the name of the kernel, picocom will then send the IHEX kernel image over to bootloader07, which will install it into the Raspberry Pi RAM and, upon finishing, launch the freshly-installed kernel by jumping to the first RAM location (typically 0x3b000000).
In summary: by compiling the kernel, using a relevant cable to connect the host with the Raspberry Pi, running bootloader07, and using a simple terminal emulator, a more rapid deployment cycle can be achieved for kernel development.
One question that arises is “can the IMP OS kernel be launched directly on the Raspberry Pi, or is bootloader07 a necessary requirement?
The answer is that the IMP OS kernel can be launched directly on the microSD card. Despite bootloader07 being used for the development, the ultimate aim is for IMP OS to be able to launch entirely under its own volition.
To achieve this on the Raspberry Pi, there are only two steps required to eradicate the requirement for bootloader07, and make IMP OS standalone:
- copy the IMP OS kernel directly onto the microSD card (removing the bootloader07 kernel)
- add a line to the Raspberry Pi config.txt file (on the microSD card) to tell the Raspberry Pi where to load the kernel image in memory
With (1), what this means is to delete the bootloader07 kernel image file from the microSD card, and replace it directly with the kernel image file for IMP OS.
With (2), the line that needs to exist in the Raspberry Pi config.txt file is this:
It is worth understanding here that the Raspberry Pi will, by default, install a 32-bit kernel at memory location 0x8000, whilst a 64-bit kernel will be installed at memory location 0x80000. However, the IMP OS kernel is installed much higher up in memory, and luckily the Raspberry Pi allows the default location to be overridden using the above line in the config.txt file.
Do note that when placing the IMP OS kernel onto the microSD card, the binary version of the kernel image should be used, not the IHEX version. (bootloader07 installs kernels using the IHEX format of their image, but the Raspberry Pi - when launching directly - requires the binary image).
Credit must go to dwelch67 for this extremely helpful utility. There are potentially other ways of achieving this ability to reboot the Raspberry Pi with a fresh kernel efficiently, however at the time of writing, bootloader07 is doing the job well.