Crate efiloader

Source
Expand description

This crate implements a stripped down EFI runtime that can be used by bootloader implementations to provide the EFI context needed by OS loaders such as EFI stub Linux kernels, systemd-boot UKI images or even GRUB+shim.

The EFI runtime implements the following features/APIs:

  • a memory map and associated page and pool allocation routines, as well as an implementation of the GetMemoryMap() EFI boot service to deliver the final memory map to the OS;
  • a EFI protocol database that supports installing and uninstalling protocols, locating handle and protocol buffers and locating device paths;
  • a EFI configuration table database

The following EFI features are NOT supported:

  • the UEFI driver model
  • asynchronous events and notifications

The runtime services related to timekeeping, the EFI variable store and reset/poweroff are left to the caller to implement, as they cannot be implemented generically. The same applies to the Stall() boot services.

§Example

fn run_efi_image(
    image: impl efiloader::FileLoader + Send + 'static,
    mapper: impl efiloader::MemoryMapper + 'static,
    random: impl efiloader::Random + 'static,
) {
    let ram = 0..0x100_0000;
    let memmap = efiloader::memmap::MemoryMap::new();
    memmap.declare_memory_region(&ram).unwrap();

    let efi = efiloader::init(
        None::<&dyn efiloader::SimpleConsole>,
        memmap,
        mapper,
        Some(random),
    )
    .expect("Failed to init EFI runtime");

    if let Some(mut li) = efi.load_image(&image) {
        let ret = li.start_image();
        println!("EFI app returned {ret:?}\n");
    }
}

Modules§

blockio
bootservices
devicepath
memmap
memorytype
runtimeservices
status

Macros§

guid

Structs§

EfiContext
Event
Guid

Traits§

EfiProtocol
Implementations of EFI protocols must implement this trait in order to be installable into the protocol database managed by the EFI runtime.
FileLoader
Implementations of this trait should be provided for loading kernels, initial ramdisks and potentially other assets (e.g., disk images) that are needed to load the OS.
MemoryMapper
An implementation of this trait must be provided to the EFI runtime at initialization time so that the PE/COFF loader as well as the Memory Attributes Protocol implementation exposed by the EFI runtime are able to manage permission attributes on memory ranges.
Random
An implementation of this trait may be provided to the EFI runtime at initialization time so that the PE/COFF loader and the EFI random number generator protocol have access to a source of random numbers.
SimpleConsole
An implementation of this trait may be provided to the EFI runtime at initialization time, allowing it to print diagnostic messages, and check for key presses.

Functions§

init
Initializes the EFI runtime, and returns a reference to a EfiContext instance that encapsulates its API.

Type Aliases§

Bool
Char16
Handle
Lba