RaspberryPi 4B Bare Metal Development - silasmue/project_aarch64 GitHub Wiki
Testing on real Hardware (RaspberryPi 4B)
To test on real hardware, it is neccessary to format the microSD card with FAT32. To make that step easier it is recommended to just install a version of Raspbian and modify the boot
partition.
On the boot
partition the following files are needed:
- bcm2711-rpi-4-b.dtb
- overlays/miniuart-bt.dtbo
- config.txt
- start4.elf The files can be downloaded here.
PL011 UART0
If you use UART0 for your kernel, as described in OSDevWiki you have to extend the config.txt
with the following content to switch Pin 14/15 to the UART0 (from miniUART) and switch the miniUART to Bluetooth (you can also just disable Bluetooth, be aware that you will nee the file overlays/disable-bt.dtbo
from the firmware repository), see the RaspberryPi Docs for that. Be careful with changes to the config.txt
if your overlay folder is not present or not complete!!! the changes may not be effective.
miniUART UART1
If you use the miniUART not extra configuration is necessary you can just boot up your kernel, as long, as the files from above are present. Be aware that if you use QEMU for testing you need the option -serial none -serial mon:stdio
to interact with the virtual miniUART.
RaspberryPi 4B Emulation with QEMU
QEMU 9 supports emulating the RaspberryPi4B. To make QEMU useful for bare metal development, we need it to output miniUART (UART1), if we do not want to change our code to support QEMU emulation.
The file confix.txt
should be empty.
To do so we need to start the QEMU with the following command.
$ qemu-system-aarch64 -machine raspi4b -serial none -serial mon:stdio -display none -kernel kernel8.img
-serial none -serial mon:stdio
has to be used when the miniUART (UART1) is used. If you use PL011 (UART0, UART2...UART5) you have to use just -serial stdio
.
kernel8.img
represents our binary that we compiled and object copied in the steps before. Be aware that only QEMU version 9+ supports the emulation of the RaspberryPi4B. A list with supported devices can be found here.