mirror of
https://github.com/edera-dev/sprout.git
synced 2025-12-19 15:20:17 +00:00
improve error handling of unregistering media loaders
This commit is contained in:
@@ -3,11 +3,10 @@ use crate::utils;
|
|||||||
use crate::utils::media_loader::MediaLoaderHandle;
|
use crate::utils::media_loader::MediaLoaderHandle;
|
||||||
use crate::utils::media_loader::constants::LINUX_EFI_INITRD_MEDIA_GUID;
|
use crate::utils::media_loader::constants::LINUX_EFI_INITRD_MEDIA_GUID;
|
||||||
use anyhow::{Context, Result, bail};
|
use anyhow::{Context, Result, bail};
|
||||||
use log::info;
|
use log::{error, info};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use uefi::CString16;
|
use uefi::CString16;
|
||||||
use uefi::proto::device_path::LoadedImageDevicePath;
|
|
||||||
use uefi::proto::loaded_image::LoadedImage;
|
use uefi::proto::loaded_image::LoadedImage;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Default, Clone)]
|
#[derive(Serialize, Deserialize, Default, Clone)]
|
||||||
@@ -21,9 +20,6 @@ pub struct ChainloadConfiguration {
|
|||||||
|
|
||||||
pub fn chainload(context: Rc<SproutContext>, configuration: &ChainloadConfiguration) -> Result<()> {
|
pub fn chainload(context: Rc<SproutContext>, configuration: &ChainloadConfiguration) -> Result<()> {
|
||||||
let sprout_image = uefi::boot::image_handle();
|
let sprout_image = uefi::boot::image_handle();
|
||||||
let _image_device_path_protocol =
|
|
||||||
uefi::boot::open_protocol_exclusive::<LoadedImageDevicePath>(sprout_image)
|
|
||||||
.context("unable to open loaded image device path protocol")?;
|
|
||||||
|
|
||||||
let resolved = utils::resolve_path(
|
let resolved = utils::resolve_path(
|
||||||
context.root().loaded_image_path()?,
|
context.root().loaded_image_path()?,
|
||||||
@@ -87,10 +83,10 @@ pub fn chainload(context: Rc<SproutContext>, configuration: &ChainloadConfigurat
|
|||||||
let (base, size) = loaded_image_protocol.info();
|
let (base, size) = loaded_image_protocol.info();
|
||||||
info!("loaded image: base={:#x} size={:#x}", base.addr(), size);
|
info!("loaded image: base={:#x} size={:#x}", base.addr(), size);
|
||||||
let result = uefi::boot::start_image(image).context("unable to start image");
|
let result = uefi::boot::start_image(image).context("unable to start image");
|
||||||
if let Some(initrd_handle) = initrd_handle {
|
if let Some(initrd_handle) = initrd_handle
|
||||||
initrd_handle
|
&& let Err(error) = initrd_handle.unregister()
|
||||||
.unregister()
|
{
|
||||||
.context("unable to unregister linux initrd")?;
|
error!("unable to unregister linux initrd: {}", error);
|
||||||
}
|
}
|
||||||
result.context("unable to start image")?;
|
result.context("unable to start image")?;
|
||||||
drop(options_holder);
|
drop(options_holder);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
|
use log::error;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use uefi::Guid;
|
use uefi::Guid;
|
||||||
|
|
||||||
@@ -63,19 +64,22 @@ fn register_media_loader_file(
|
|||||||
|
|
||||||
pub fn edera(context: Rc<SproutContext>, configuration: &EderaConfiguration) -> Result<()> {
|
pub fn edera(context: Rc<SproutContext>, configuration: &EderaConfiguration) -> Result<()> {
|
||||||
let config = build_xen_config(configuration);
|
let config = build_xen_config(configuration);
|
||||||
let config = register_media_loader_text(XEN_EFI_CONFIG_MEDIA_GUID, "config", config)?;
|
let config = register_media_loader_text(XEN_EFI_CONFIG_MEDIA_GUID, "config", config)
|
||||||
|
.context("unable to register config media loader")?;
|
||||||
let kernel = register_media_loader_file(
|
let kernel = register_media_loader_file(
|
||||||
&context,
|
&context,
|
||||||
XEN_EFI_KERNEL_MEDIA_GUID,
|
XEN_EFI_KERNEL_MEDIA_GUID,
|
||||||
"kernel",
|
"kernel",
|
||||||
&configuration.kernel,
|
&configuration.kernel,
|
||||||
)?;
|
)
|
||||||
|
.context("unable to register kernel media loader")?;
|
||||||
|
|
||||||
let mut media_loaders = vec![config, kernel];
|
let mut media_loaders = vec![config, kernel];
|
||||||
|
|
||||||
if let Some(ref initrd) = configuration.initrd {
|
if let Some(ref initrd) = configuration.initrd {
|
||||||
let initrd =
|
let initrd =
|
||||||
register_media_loader_file(&context, XEN_EFI_RAMDISK_MEDIA_GUID, "initrd", initrd)?;
|
register_media_loader_file(&context, XEN_EFI_RAMDISK_MEDIA_GUID, "initrd", initrd)
|
||||||
|
.context("unable to register initrd media loader")?;
|
||||||
media_loaders.push(initrd);
|
media_loaders.push(initrd);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,7 +94,9 @@ pub fn edera(context: Rc<SproutContext>, configuration: &EderaConfiguration) ->
|
|||||||
.context("unable to chainload to xen");
|
.context("unable to chainload to xen");
|
||||||
|
|
||||||
for media_loader in media_loaders {
|
for media_loader in media_loaders {
|
||||||
media_loader.unregister()?;
|
if let Err(error) = media_loader.unregister() {
|
||||||
|
error!("unable to unregister media loader: {}", error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result
|
result
|
||||||
|
|||||||
Reference in New Issue
Block a user