UEFI Rust bootloader used to load CoonOS kernel into memory, collect all information about system and give control to the kernel.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

85 lines
2.2 KiB

#![no_std]
#![no_main]
#![feature(alloc)]
extern crate uefi;
extern crate uefi_alloc;
extern crate uefi_exts;
extern crate uefi_logger;
extern crate uefi_services;
#[macro_use]
extern crate log;
extern crate alloc;
extern crate serde;
#[macro_use]
extern crate serde_derive;
extern crate serde_json_core;
use serde_json_core::de::from_slice;
use uefi::prelude::*;
use uefi::proto::media::file::{FileAttribute, FileMode};
use uefi::proto::media::fs::SimpleFileSystem;
use uefi_exts::BootServicesExt;
#[derive(Deserialize, Serialize)]
struct Configuration<'a> {
pub kernel_location: &'a str,
pub load_modules: bool,
}
impl<'a> Default for Configuration<'a> {
fn default() -> Configuration<'a> {
Configuration {
kernel_location: "\\EFI\\COONBOOT\\CoonKRNL",
load_modules: false,
}
}
}
#[no_mangle]
pub extern "win64" fn uefi_start(_image: uefi::Handle, table: SystemTable<Boot>) -> Status {
let mut buf: [u8; 8000] = [0; 8000];
uefi_services::init(&table).expect_success("Failed to initialize utilities");
table
.stdout()
.reset(false)
.expect_success("Failed to reset stdout");
let mut config: Configuration = Default::default();
let fs = table
.boot_services()
.find_protocol::<SimpleFileSystem>()
.expect("Failed to resolve filesystem")
.get();
unsafe {
let mut file = (*fs).open_volume().expect("Failed to open root").unwrap();
let result = file.open(
"\\EFI\\COONBOOT\\boot.json",
FileMode::READ,
FileAttribute::empty(),
);
match result {
Ok(file) => {
let mut file = file.unwrap();
// TODO: Don't panic here
let size = file.read(&mut buf).unwrap().unwrap();
// TODO: Don't panic here too
config = from_slice(&buf[..size]).unwrap();
}
Err(_) => {
warn!("\\EFI\\COONBOOT\\boot.json not found, using default configuration");
}
}
}
if config.load_modules {
error!("Can't load kernel modules, not supported yet");
}
info!("Loading kernel from {}", config.kernel_location);
Status::SUCCESS
}