blob: bb6f8f1ca4dd86e7a1337f8300a5cc90a7f81750 [file] [log] [blame]
#![no_std]
use matcha_hal::dprintf;
use matcha_hal::mailbox_hal::MailboxHAL;
pub mod elf_loader;
pub mod tar_loader;
pub const SMC_CONTROL_BLOCK: *mut u32 = 0x54020000 as *mut u32;
fn round_up_to_page(addr: u32) -> u32 {
return (addr + 4095) & !4095;
}
// TODO(aappleby): Break this down into smaller pieces and move into app/main
pub fn load_sel4(mailbox : &'static dyn MailboxHAL) {
unsafe {
// Look in our tar file for the ELFs we need to boot Shodan.
let sel4_elf = elf_loader::find_elf("kernel");
let capdl_elf = elf_loader::find_elf("capdl-loader");
if sel4_elf.is_null() {
dprintf!("Boot failure, seL4 kernel ELF missing.\n");
return;
}
if capdl_elf.is_null() {
dprintf!("Boot failure seL4 CapDL ELF missing.\n");
return;
}
// If we found all of them, boot in Shodan mode.
dprintf!("Loading seL4 kernel elf\n");
elf_loader::load_elf_segments(sel4_elf.as_ref().unwrap(), 0);
let sel4_segments = elf_loader::elf_get_segments(sel4_elf);
let capdl_segments = elf_loader::elf_get_segments(capdl_elf);
let sel4_pend = round_up_to_page(elf_loader::elf_phys_max(sel4_segments));
dprintf!("Loading capdl-loader to the page after seL4\n");
elf_loader::load_elf_segments(
capdl_elf.as_ref().unwrap(),
sel4_pend - elf_loader::elf_phys_min(capdl_segments),
);
dprintf!("Starting management core\n");
let entry_point: u32 = (*sel4_elf).e_entry
- (elf_loader::elf_virt_min(sel4_segments)
- elf_loader::elf_phys_min(sel4_segments));
let message : [u32; 4] = [
sel4_pend,
sel4_pend + round_up_to_page(elf_loader::elf_phys_max(capdl_segments) - elf_loader::elf_phys_min(capdl_segments)),
sel4_pend - elf_loader::elf_phys_min(capdl_segments),
(*capdl_elf).e_entry,
];
let _ = mailbox.send_message_sync(16, core::mem::transmute(message.as_ref()));
dprintf!("seL4 boot message posted\n");
SMC_CONTROL_BLOCK.write_volatile(entry_point);
// This message is checked in shodan_boot.robot - keep in sync.
dprintf!("load_sel4() completed successfully\n");
}
}