1

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
#![no_std]
#![no_main]

use core::panic::PanicInfo;

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

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

#[no_mangle]
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 {}
}
  • Maybe you can find some helpful information from these two tutorials, [1](https://wiki.osdev.org/Raspberry_Pi_Bare_Bones) and [2](https://wiki.osdev.org/Raspberry_Pi_Bare_Bones_Rust). 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 '21 at 02:03

0 Answers0