I was following this tutorial on how to make your own basic OS for an x86_64 system in rust, but wanted to do it for an ARM64 target, specifically, the raspberry pi 4. I am at the point where I have compiled an executable with a bare metal arm64 target.

Target-triple used: aarch64-unknown-none

The problem I encountered was creating a boot image. In the tutorial he uses a rust crate called bootloader, but this crate only works for creating bootable images when targeting an x86_64 architecture (I tried anyway and got an error specifying it only works for x86_64 targets)

I learned how the boot process of the raspberry pi works from this post, but I am having trouble making use of that information to actually create a bootable image for the pi.

How do I get my compiled executable to be bootable from the pi AND have the pi boot off of it?

I understand this is a complicated question (it is to me), but at least some pointers would be of great help.

// main.rs

// No std library to compile to a bare metal target

use core::panic::PanicInfo;

// This function is called on panic.
fn panic(_info: &PanicInfo) -> ! {
    loop {}

static HELLO: &[u8] = b"Hello World!";

pub extern "C" fn _start() -> ! {
    let vga_buffer = 0xb8000 as *mut u8;

    for (i, &byte) in HELLO.iter().enumerate() {
        unsafe {
            *vga_buffer.offset(i as isize * 2) = byte;
            *vga_buffer.offset(i as isize * 2 + 1) = 0xb;
    loop {}
  • 1
    Maybe you can find some helpful information from these two tutorials, 1 and 2. Those tutorials are mostly about creating OS for 32-bit Raspberry Pi with C and Rust. However, they do mention something about 64-bit Pi, such as "bootcode.bin: this is the one that's loaded first, executed on the GPU (not needed on RPi4 as that model has bootcode.bin in a ROM)}. They also provide the steps of how to test your kernel by replacing an existing one.
    – Joe_Jingyu
    Nov 30, 2021 at 2:03


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.