UEFI applications are simple COFF (Windows) executables, with the special
EFI_Application
subsystem, and some limitations (such as no dynamic linking).
The Rust compiler supports building UEFI applications for the
aarch64-unknown-uefi
, i686-unknown-uefi
, and x86_64-unknown-uefi
targets.
For instructions on building the uefi-rs
crates, see the
README. This section is for building your own crates,
outside of the uefi-rs
repo.
-
Install a
nightly
version of the Rust toolchain and include therust-src
component. The easiest way to do this is with arust-toolchain.toml
file, for example:[toolchain] channel = "nightly" components = ["rust-src"]
-
Build the crate:
cargo build --target x86_64-unknown-uefi
. -
The
target
directory will contain ax86_64-unknown-uefi
subdirectory, where you will find a<crate name>.efi
file - a normal UEFI executable.
-
To run an
.efi
executable on a real computer:- Find a USB drive which is FAT12 / FAT16 / FAT32 formatted
- Copy the file to the USB drive, to
/EFI/Boot/Bootx64.efi
- In the UEFI BIOS, choose "Boot from USB" or similar
-
To run this in QEMU:
-
You will need a recent version of QEMU as well as OVMF to provide UEFI support
-
Check the
qemu.rs
module for an idea of what arguments to pass to QEMU.In principle, you need to replicate the file structure described above for an USB drive, then mount the directory as if it were a FAT drive.
-
The template provides a quick way to get started building UEFI applications.