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:
- Download a zipped .img image file from the 64-bit image list, picking the newest update
- Unzip it and use the Raspberry Pi Imager to write it to your SD card, selecting "Use custom" from the options and pointing it at your downloaded .img file
- Boot the Pi and follow the setup wizard to ensure you have a working Internet connection
- Just for luck, run
sudo apt update
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:
- Use
git
to clone this repo:git clone https://github.com/isometimes/rpi4-osdev.git
- Decide which part you want to build - I like testing with part5-framebuffer (it's visual, so you'll know when it works!)
- Copy the Makefile.gcc to Makefile
- Edit the Makefile and ensure the
GCCPATH
variable points to the bin subdirectory where your cross-compiler is to be found - Type
make
at the command line and it should build without errors
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):
sudo cp kernel8.img /boot
- Then edit /boot/config.txt to include only these lines (for part5-framebuffer anyway, otherwise read the tutorial in full for any necessary config changes for other parts...):
hdmi_group=1
hdmi_mode=16
core_freq_min=500
Reboot and you should see the part5-framebuffer demo firing up!