mirror of
https://github.com/edera-dev/sprout.git
synced 2025-12-19 17:10:17 +00:00
move some code to utils and move around functions
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
use crate::utils;
|
||||
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 {
|
||||
@@ -21,13 +19,6 @@ pub struct ChainloaderConfiguration {
|
||||
}
|
||||
|
||||
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");
|
||||
let content = utils::read_file_contents("sprout.toml");
|
||||
toml::from_slice(&content).expect("unable to parse sprout.toml file")
|
||||
}
|
||||
|
||||
@@ -2,10 +2,13 @@
|
||||
pub mod config;
|
||||
pub mod modules;
|
||||
pub mod setup;
|
||||
pub mod utils;
|
||||
|
||||
fn main() {
|
||||
setup::init();
|
||||
|
||||
let config = config::load();
|
||||
modules::execute(config.modules);
|
||||
for module in config.modules {
|
||||
modules::execute(module);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,12 +2,10 @@ 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");
|
||||
}
|
||||
pub fn execute(module: ModuleConfiguration) {
|
||||
if let Some(chainloader) = module.chainloader {
|
||||
chainloader::chainloader(chainloader);
|
||||
} else {
|
||||
panic!("unknown module configuration");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,26 +1,11 @@
|
||||
use crate::config::ChainloaderConfiguration;
|
||||
use crate::utils::text_to_device_path;
|
||||
use log::info;
|
||||
use uefi::proto::loaded_image::LoadedImage;
|
||||
use uefi::{
|
||||
CString16,
|
||||
proto::device_path::{
|
||||
DevicePath, LoadedImageDevicePath, PoolDevicePath,
|
||||
text::{AllowShortcuts, DevicePathFromText, DisplayOnly},
|
||||
},
|
||||
use uefi::proto::device_path::{
|
||||
DevicePath, LoadedImageDevicePath,
|
||||
text::{AllowShortcuts, DisplayOnly},
|
||||
};
|
||||
|
||||
fn text_to_device_path(path: &str) -> PoolDevicePath {
|
||||
let path = CString16::try_from(path).expect("unable to convert path to CString16");
|
||||
let device_path_from_text = uefi::boot::open_protocol_exclusive::<DevicePathFromText>(
|
||||
uefi::boot::get_handle_for_protocol::<DevicePathFromText>()
|
||||
.expect("no device path from text protocol"),
|
||||
)
|
||||
.expect("unable to open device path from text protocol");
|
||||
|
||||
device_path_from_text
|
||||
.convert_text_to_device_path(&path)
|
||||
.expect("unable to convert text to device path")
|
||||
}
|
||||
use uefi::proto::loaded_image::LoadedImage;
|
||||
|
||||
pub fn chainloader(configuration: ChainloaderConfiguration) {
|
||||
let sprout_image = uefi::boot::image_handle();
|
||||
|
||||
29
src/utils.rs
Normal file
29
src/utils.rs
Normal file
@@ -0,0 +1,29 @@
|
||||
use uefi::CString16;
|
||||
use uefi::fs::{FileSystem, Path};
|
||||
use uefi::proto::device_path::PoolDevicePath;
|
||||
use uefi::proto::device_path::text::DevicePathFromText;
|
||||
use uefi::proto::media::fs::SimpleFileSystem;
|
||||
|
||||
pub fn text_to_device_path(path: &str) -> PoolDevicePath {
|
||||
let path = CString16::try_from(path).expect("unable to convert path to CString16");
|
||||
let device_path_from_text = uefi::boot::open_protocol_exclusive::<DevicePathFromText>(
|
||||
uefi::boot::get_handle_for_protocol::<DevicePathFromText>()
|
||||
.expect("no device path from text protocol"),
|
||||
)
|
||||
.expect("unable to open device path from text protocol");
|
||||
|
||||
device_path_from_text
|
||||
.convert_text_to_device_path(&path)
|
||||
.expect("unable to convert text to device path")
|
||||
}
|
||||
|
||||
pub fn read_file_contents(path: &str) -> Vec<u8> {
|
||||
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 path = CString16::try_from(path).expect("unable to convert path to CString16");
|
||||
let content = fs.read(Path::new(&path));
|
||||
content.expect("unable to read file contents")
|
||||
}
|
||||
Reference in New Issue
Block a user