Skip to content

Commit 809128f

Browse files
zyuiopmkroening
authored andcommitted
feat(uefi): add support for bootargs file
1 parent 2bf5334 commit 809128f

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

src/fdt.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ impl Fdt {
4141
self.writer.finish()
4242
}
4343

44-
#[cfg_attr(target_os = "uefi", expect(unused))]
4544
pub fn bootargs(mut self, bootargs: String) -> FdtWriterResult<Self> {
4645
assert!(self.bootargs.is_none());
4746
self.bootargs = Some(bootargs);

src/os/uefi/mod.rs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
mod allocator;
22
mod console;
33

4+
use alloc::string::String;
45
use alloc::vec::Vec;
56
use core::ffi::c_void;
67
use core::mem::MaybeUninit;
@@ -14,7 +15,7 @@ use hermit_entry::elf::{KernelObject, LoadedKernel};
1415
use log::info;
1516
use sptr::Strict;
1617
use uefi::boot::{AllocateType, MemoryType, PAGE_SIZE};
17-
use uefi::fs::{FileSystem, Path};
18+
use uefi::fs::{self, FileSystem, Path};
1819
use uefi::prelude::*;
1920
use uefi::table::cfg;
2021

@@ -40,11 +41,15 @@ fn main() -> Status {
4041

4142
drop(kernel_image);
4243

43-
let fdt = Fdt::new("uefi")
44+
let mut fdt = Fdt::new("uefi")
4445
.unwrap()
4546
.rsdp(u64::try_from(rsdp.expose_addr()).unwrap())
4647
.unwrap();
4748

49+
if let Some(bootargs) = read_bootargs() {
50+
fdt = fdt.bootargs(bootargs).unwrap();
51+
}
52+
4853
allocator::exit_boot_services();
4954
let mut memory_map = unsafe { boot::exit_boot_services(None) };
5055

@@ -69,6 +74,25 @@ fn read_app() -> Vec<u8> {
6974
data
7075
}
7176

77+
fn read_bootargs() -> Option<String> {
78+
let image_handle = boot::image_handle();
79+
let fs = boot::get_image_file_system(image_handle).expect("should open file system");
80+
81+
let path = Path::new(cstr16!(r"\efi\boot\hermit-bootargs"));
82+
83+
match FileSystem::new(fs).read_to_string(path) {
84+
Ok(bootargs) => {
85+
info!("Read Hermit bootargs from from \"{path}\": {bootargs}");
86+
Some(bootargs)
87+
}
88+
Err(fs::Error::Io(err)) if err.uefi_error.status() == Status::NOT_FOUND => {
89+
info!("Hermit bootargs file does not exist: \"{path}\"");
90+
None
91+
}
92+
Err(err) => panic!("{err:?}"),
93+
}
94+
}
95+
7296
pub unsafe fn boot_kernel(kernel_info: LoadedKernel, fdt: Vec<u8>) -> ! {
7397
let LoadedKernel {
7498
load_info,

0 commit comments

Comments
 (0)