Hello! I am one of Embox RTOS developers. People often ask us whether Raspberry Pi is supported in Embox. The answer is “yes”, and in this article, I want to tell you a little about it.
We had Raspberry Pi Model B rev 2.0 (that is rpi1) for a long time, and some drivers were successfully implemented: UART, interrupt controller, system timer and framebuffer. But the knowledge about how to run these things has been lost, so we started with QEMU. At first, there is no support for old rpi1 in QEMU mainstream, but we have qemu rpi branch in our repository, which supports RPi1 — “-M raspi” (how to run Embox on qemu raspi you can read here ).
After launching on QEMU we were aimed to run the same binary on a real board. But it was unclear where to start, so we decided to try Raspbian first. We download 2020–02–13-raspbian-buster-lite.img here. Then flash it to micro SD card (by the way, on rpi1 is only SD adapter, not microSD):
dd bs=4M if=2020–02–13-raspbian-buster-lite.img of=/dev/sdb conv=fsync
where “/dev/sdb” is your microSD card. Let’s take a look at what lsblk says:
sdb 8:16 1 14,6G 0 disk├─sdb1 8:17 1 256M 0 part└─sdb2 8:18 1 14,3G 0 part
Let’s mount sdb1 and see what it contains:
$ sudo mount /dev/sdb1 /mnt$ ls /mnt/bcm2708-rpi-b.dtb bcm2710-rpi-3-b.dtb COPYING.linux fixup_db.dat start_db.elfbcm2708-rpi-b-plus.dtb bcm2710-rpi-3-b-plus.dtb fixup4cd.dat fixup_x.dat start.elfbcm2708-rpi-cm.dtb bcm2710-rpi-cm3.dtb fixup4.dat issue.txt start_x.elfbcm2708-rpi-zero.dtb bcm2711-rpi-4-b.dtb fixup4db.dat kernel.imgbcm2708-rpi-zero-w.dtb bootcode.bin fixup4x.dat LICENCE.broadcombcm2709-rpi-2-b.dtb cmdline.txt fixup_cd.dat overlaysbcm2710-rpi-2-b.dtb config.txt fixup.dat start_cd.elf
As we can see there is a bunch of *.dts for different Rpi versions, bootcode.bin is a bootloader (it is not open source), and kernel.img is a Linux kernel (zImage format).
We connect the HDMI cable to the board and to monitor, insert an SD card and power the board on. Raspbian successfully loaded. Then we should copy Embox binary instead of kernel.img to make bootcode.bin load our system. Build Embox:
Copy resulting binary to SD card: “cp build/base/bin/embox.bin /mnt/kernel.img”.
Then insert the SD card back in RPi and power it on. But nothing happens. Well, it’s difficult to debug something without uart, let’s connect RDC1-USB-UART to the board.
RDC1 RapiGND <---> GND5V <---> 5VRX <---> TXD0/GPIO14TX <---> RXD0/GPIO15
Here you can see the corresponding pinout to make it even simpler. Now power the adapter from PC USB hub and power Rpi from the adapter.
Power the adapter and connect with minicom:
sudo minicom -d /dev/ttyUSB0
Hmm, no output in minicom... Most probably some problem with the uart driver under Embox. We disable uart initialization and leave only read/write function, that is we hope the bootloader configured uart well. Yes, it helped! Then we fixed the driver, but I don’t want to tell a lot about this, you can just look at the final init code -
I would like to mention that Raspberry Pi has Linux port maintained it their Github repository — minicom. I helped us to get an actual value of UARTCLK which is used to program baud rate. From the documentation, it has a very non-trivial configuration so we decided to rely here on the value that Linux uses. It’s enough to insert printk() in drivers/tty/serial/amba-pl011.c, build the kernel and copy zImage to kernel.img.
Finally, we launched the same Embox binary as it was compiled for QEMU.
I got the impression that there are a few ports of RTOSes to RPi if any. For example, as far as I can see there is no official support from FreeRTOS (only some repository on Github), no support for Nuttx or something similar, bare metal example for Rpi1 on osdev is not working. Moreover, discussions on RPi forums tell us the same, and people advise you to try Arduino if you need RTOS.
Partial support for Rpi2/3/4 is delayed for the future, nevertheless, some work is planned to be completed during GSoC 2020. That’s why we got Embox on Rpi1 back to life.
If someone has thoughts about whether RTOS is useful on RPi boards you are welcome in the comments to discuss :)
- Mailing-list: firstname.lastname@example.org
- Telegram chat: https://t.me/embox_chat_en