Crates.io | zfi |
lib.rs | zfi |
version | 0.1.0 |
source | src |
created_at | 2023-08-20 20:55:10.37865 |
updated_at | 2023-08-20 20:55:10.37865 |
description | Zero-cost and safe interface to UEFI firmware |
homepage | |
repository | https://github.com/ultimicro/zfi |
max_upload_size | |
id | 949549 |
size | 53,345 |
ZFI is a Rust crate for writing a UEFI application with the following goals:
ZFI supports only single-thread environment, which is the same as UEFI specifications.
#![no_std]
#![no_main]
use alloc::boxed::Box;
use zfi::{pause, println, DebugFile, Image, Status, SystemTable};
extern crate alloc;
#[no_mangle]
extern "efiapi" fn efi_main(image: &'static Image, st: &'static SystemTable) -> Status {
// This is the only place you need to use unsafe. This must be done immediately after landing
// here.
unsafe {
zfi::init(
image,
st,
Some(|| Box::new(DebugFile::next_to_image("log").unwrap())),
)
};
// Any EFI_HANDLE will be represents by a reference to a Rust type (e.g. image here is a type of
// Image). Each type that represents EFI_HANDLE provides the methods to access any protocols it
// is capable for (e.g. you can do image.proto() here to get an EFI_LOADED_IMAGE_PROTOCOL from
// it). You can download the UEFI specifications for free here: https://uefi.org/specifications
println!("Hello, world!");
pause();
Status::SUCCESS
}
#[cfg(not(test))]
#[panic_handler]
fn panic_handler(info: &core::panic::PanicInfo) -> ! {
zfi::eprintln!("{info}");
loop {}
}
#[cfg(not(test))]
#[global_allocator]
static ALLOCATOR: zfi::PoolAllocator = zfi:PoolAllocator;
To build the above example you need to add a UEFI target to Rust:
rustup target add x86_64-unknown-uefi
Then build with the following command:
cargo build --target x86_64-unknown-uefi
You can grab the EFI file in target/x86_64-unknown-uefi/debug
and boot it on a compatible machine.
Please contact hello@ultima.inc if you need commercial support.
MIT