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 {}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.