Skip to the content.

Writing a “bare metal” operating system for Raspberry Pi 4

Building on the RPi4 itself

It’s possible (but not super-simple) to follow this tutorial on the Raspberry Pi without need for an additional build device.

Perhaps the easiest route is to firstly re-image your Pi to use the 64-bit Raspberry Pi OS (Beta), and then use a pre-built cross-compiler:

You’ll then need to download a cross-compiler from the Arm website.

What you’re looking for is the current AArch64 ELF bare-metal target (aarch64-none-elf). If this link is somehow broken, you can use Google to search for “Arm GNU-A linux hosted cross compilers”.

Then unpack the archive using tar -xf <filename>. You’ll end up with a gcc directory (albeit with a slightly longer name), which itself contains a bin subdirectory, wherein you’ll find the gcc executable (again - with a longer name!). Remember this path.

Note: you can avoid re-imaging the Pi, by instead building a cross-compiler yourself.

Now let’s build something:

If you want to then boot with this, you’ll need to copy the kernel8.img file to a prepped SD card as the tutorial discusses. For the purposes of testing this process, I did the following (NOTE: it will trash your OS install unless you backup the old files so you can move them back later):


Reboot and you should see the part5-framebuffer demo firing up!

Go to part1-bootstrapping >