support for configuration files

This commit is contained in:
2025-10-01 18:25:49 -07:00
parent 17ca11f239
commit 3fdaad42ad
9 changed files with 176 additions and 8 deletions

33
src/config.rs Normal file
View File

@@ -0,0 +1,33 @@
use serde::{Deserialize, Serialize};
use uefi::cstr16;
use uefi::fs::{FileSystem, Path};
use uefi::proto::media::fs::SimpleFileSystem;
#[derive(Serialize, Deserialize, Default)]
pub struct RootConfiguration {
#[serde(default)]
pub modules: Vec<ModuleConfiguration>,
}
#[derive(Serialize, Deserialize, Default)]
pub struct ModuleConfiguration {
#[serde(default)]
pub chainloader: Option<ChainloaderConfiguration>,
}
#[derive(Serialize, Deserialize, Default)]
pub struct ChainloaderConfiguration {
pub path: String,
}
pub fn load() -> RootConfiguration {
let fs = uefi::boot::open_protocol_exclusive::<SimpleFileSystem>(
uefi::boot::get_handle_for_protocol::<SimpleFileSystem>().expect("no filesystem protocol"),
)
.expect("unable to open filesystem protocol");
let mut fs = FileSystem::new(fs);
let content = fs
.read(Path::new(cstr16!("sprout.toml")))
.expect("unable to read sprout.toml file");
toml::from_slice(&content).expect("unable to parse sprout.toml file")
}

View File

@@ -1,10 +1,11 @@
#![feature(uefi_std)]
pub mod chainload;
pub mod config;
pub mod modules;
pub mod setup;
const CHAINLOADER_TARGET: &str = "\\EFI\\BOOT\\KERNEL.efi";
fn main() {
setup::init();
chainload::chainload(CHAINLOADER_TARGET);
let config = config::load();
modules::execute(config.modules);
}

13
src/modules.rs Normal file
View File

@@ -0,0 +1,13 @@
use crate::config::ModuleConfiguration;
pub mod chainloader;
pub fn execute(modules: Vec<ModuleConfiguration>) {
for module in modules {
if let Some(chainloader) = module.chainloader {
chainloader::chainloader(chainloader);
} else {
panic!("unknown module configuration");
}
}
}

View File

@@ -1,3 +1,4 @@
use crate::config::ChainloaderConfiguration;
use uefi::{
CString16,
proto::device_path::{
@@ -19,7 +20,7 @@ fn text_to_device_path(path: &str) -> PoolDevicePath {
.expect("unable to convert text to device path")
}
pub fn chainload(path: &str) {
pub fn chainloader(configuration: ChainloaderConfiguration) {
let sprout_image = uefi::boot::image_handle();
let image_device_path_protocol =
uefi::boot::open_protocol_exclusive::<LoadedImageDevicePath>(sprout_image)
@@ -42,9 +43,9 @@ pub fn chainload(path: &str) {
.collect::<Vec<_>>()
.join("/");
full_path.push('/');
full_path.push_str(path);
full_path.push_str(&configuration.path);
println!("chainload: {}", full_path);
println!("chainloader: path={}", full_path);
let device_path = text_to_device_path(&full_path);
@@ -57,5 +58,4 @@ pub fn chainload(path: &str) {
)
.expect("failed to load image");
uefi::boot::start_image(image).expect("failed to start image");
panic!("chainloaded image exited");
}