Function load_boot_option

Source
pub fn load_boot_option(config: &Config) -> BootResult<Handle>
Expand description

Loads a boot option given a Config.

It simply delegates to BootAction::run.

§Errors

May return an Error if any of the actions fail.

§Example

// this example starts the fallback boot loader on the same partition as the image handle.

use bootmgr_rs_core::{boot::loader::load_boot_option, config::builder::ConfigBuilder};
use uefi::{
    boot,
    proto::{
        device_path::DevicePath,
        loaded_image::LoadedImage,
        media::fs::SimpleFileSystem
    }
};

let handle = {
    let loaded_image =
        boot::open_protocol_exclusive::<LoadedImage>(boot::image_handle()).expect("Failed to open LoadedImage protocol on image");
    let device_handle = loaded_image.device().expect("Image was not loaded from a filesystem");
    let device_path = boot::open_protocol_exclusive::<DevicePath>(device_handle).expect("Failed to get device path from image filesystem");
    boot::locate_device_path::<SimpleFileSystem>(&mut &*device_path).expect("Failed to get SimpleFileSystem protocol from image filesystem")
}; // so that the handle will be able to be opened for loading the boot option

let config = ConfigBuilder::new("foo.bar", ".bar").efi_path("/efi/boot/bootx64.efi").fs_handle(handle).build();

let image = load_boot_option(&config).expect("Failed to load boot option");

boot::start_image(image).expect("Failed to start image");