lanzaboote: add error handling strings

This commit is contained in:
Julian Stecklina 2022-11-26 02:47:21 +01:00
parent 95a03d69bb
commit 1f0f349559
1 changed files with 30 additions and 23 deletions

View File

@ -82,15 +82,17 @@ fn main(handle: Handle, mut system_table: SystemTable<Boot>) -> Status {
let config: EmbeddedConfiguration = let config: EmbeddedConfiguration =
EmbeddedConfiguration::new(&mut booted_image_file(system_table.boot_services()).unwrap()) EmbeddedConfiguration::new(&mut booted_image_file(system_table.boot_services()).unwrap())
.unwrap(); .expect("Failed to extract configuration from binary. Did you run lanzatool?");
let mut kernel_file; let mut kernel_file;
let initrd = { let initrd = {
let mut file_system = system_table let mut file_system = system_table
.boot_services() .boot_services()
.get_image_file_system(handle) .get_image_file_system(handle)
.unwrap(); .expect("Failed to get file system handle");
let mut root = file_system.open_volume().unwrap(); let mut root = file_system
.open_volume()
.expect("Failed to find ESP root directory");
kernel_file = root kernel_file = root
.open( .open(
@ -98,38 +100,43 @@ fn main(handle: Handle, mut system_table: SystemTable<Boot>) -> Status {
FileMode::Read, FileMode::Read,
FileAttribute::empty(), FileAttribute::empty(),
) )
.unwrap() .expect("Failed to open kernel file for reading")
.into_regular_file() .into_regular_file()
.unwrap(); .expect("Kernel is not a regular file");
root.open( root.open(
&config.initrd_filename, &config.initrd_filename,
FileMode::Read, FileMode::Read,
FileAttribute::empty(), FileAttribute::empty(),
) )
.unwrap() .expect("Failed to open initrd for reading")
.into_regular_file() .into_regular_file()
.unwrap() .expect("Initrd is not a regular file")
}; };
let kernel_cmdline = booted_image_cmdline(system_table.boot_services()).unwrap(); let kernel_cmdline =
booted_image_cmdline(system_table.boot_services()).expect("Failed to fetch command line");
let kernel_data = read_all(&mut kernel_file).unwrap(); let kernel_handle = {
let kernel_handle = system_table let kernel_data =
.boot_services() read_all(&mut kernel_file).expect("Failed to read kernel file into memory");
.load_image(
handle, system_table
uefi::table::boot::LoadImageSource::FromBuffer { .boot_services()
buffer: &kernel_data, .load_image(
file_path: None, handle,
}, uefi::table::boot::LoadImageSource::FromBuffer {
) buffer: &kernel_data,
.unwrap(); file_path: None,
},
)
.expect("UEFI refused to load the kernel image. It may not be signed or it may not have an EFI stub.")
};
let mut kernel_image = system_table let mut kernel_image = system_table
.boot_services() .boot_services()
.open_protocol_exclusive::<LoadedImage>(kernel_handle) .open_protocol_exclusive::<LoadedImage>(kernel_handle)
.unwrap(); .expect("Failed to open the LoadedImage protocol");
unsafe { unsafe {
kernel_image.set_load_options( kernel_image.set_load_options(
@ -138,8 +145,8 @@ fn main(handle: Handle, mut system_table: SystemTable<Boot>) -> Status {
); );
} }
let mut initrd_loader = let mut initrd_loader = InitrdLoader::new(system_table.boot_services(), handle, initrd)
InitrdLoader::new(system_table.boot_services(), handle, initrd).unwrap(); .expect("Failed to load the initrd. It may not be there or it is not signed");
let status = system_table let status = system_table
.boot_services() .boot_services()
.start_image(kernel_handle) .start_image(kernel_handle)
@ -147,6 +154,6 @@ fn main(handle: Handle, mut system_table: SystemTable<Boot>) -> Status {
initrd_loader initrd_loader
.uninstall(system_table.boot_services()) .uninstall(system_table.boot_services())
.unwrap(); .expect("Failed to uninstall the initrd protocols");
status status
} }