|
1 |
| -# Creating UEFI applications |
| 1 | +# Building and running UEFI applications |
| 2 | + |
| 3 | +## UEFI binaries |
2 | 4 |
|
3 | 5 | UEFI applications are simple COFF (Windows) executables, with the special
|
4 | 6 | `EFI_Application` subsystem, and some limitations (such as no dynamic linking).
|
5 |
| -Rust supports building UEFI applications for the |
| 7 | + |
| 8 | +The Rust compiler supports building UEFI applications for the |
6 | 9 | [`aarch64-unknown-uefi`], [`i686-unknown-uefi`], and [`x86_64-unknown-uefi`]
|
7 | 10 | targets.
|
8 | 11 |
|
9 |
| -## Template |
| 12 | +[`aarch64-unknown-uefi`]: https://github.com/rust-lang/rust/blob/HEAD/compiler/rustc_target/src/spec/aarch64_unknown_uefi.rs |
| 13 | +[`i686-unknown-uefi`]: https://github.com/rust-lang/rust/blob/HEAD/compiler/rustc_target/src/spec/i686_unknown_uefi.rs |
| 14 | +[`x86_64-unknown-uefi`]: https://github.com/rust-lang/rust/blob/HEAD/compiler/rustc_target/src/spec/x86_64_unknown_uefi.rs |
| 15 | + |
| 16 | +## Building |
| 17 | + |
| 18 | +- Install a `nightly` version of the Rust [toolchain](https://rust-lang.github.io/rustup/concepts/toolchains.html): |
| 19 | + |
| 20 | + `rustup toolchain install nightly` |
10 | 21 |
|
11 |
| -The [template](template) subdirectory contains a minimal example of a UEFI |
12 |
| -application. Copy it to a new directory to get started. |
| 22 | + It is not currently possible to build the core crate with a stable version of the Rust compiler. |
13 | 23 |
|
14 |
| -- [template/.cargo/config](template/.cargo/config) file sets some `build-std` options. |
15 |
| -- [template/Cargo.toml](template/Cargo.toml) shows the necessary |
16 |
| - dependencies. Note that when creating your project the |
17 |
| - [`uefi`](https://crates.io/crates/uefi) and |
18 |
| - [`uefi-services`](https://crates.io/crates/uefi-services) dependencies should |
19 |
| - be changed to the latest releases on [crates.io](https://crates.io). |
20 |
| -- [template/src/main.rs](template/src/main.rs) has a minimal entry point that |
21 |
| - initializes services and exits successfully. |
| 24 | +- You need to add the `rust-src` toolchain [component](https://rust-lang.github.io/rustup/concepts/components.html) |
| 25 | + (if it's not already installed), which Cargo will use to build the core crates for the UEFI target: |
22 | 26 |
|
23 |
| -## Building and running |
| 27 | + `rustup component add --toolchain nightly rust-src` |
| 28 | + |
| 29 | +- Build this crate using the `nightly` toolchain: |
24 | 30 |
|
25 |
| -- Build using a `nightly` version of the compiler: |
26 | 31 | `cargo +nightly build --target x86_64-unknown-uefi`.
|
27 | 32 |
|
28 | 33 | - The `target` directory will contain a `x86_64-unknown-uefi` subdirectory,
|
29 |
| - where you will find the `uefi_app.efi` file - a normal UEFI executable. |
| 34 | + where you will find a `<crate name>.efi` file - a normal UEFI executable. |
| 35 | + |
| 36 | +## Running |
30 | 37 |
|
31 |
| -- To run this on a real computer: |
| 38 | +- To run an `.efi` executable on a real computer: |
32 | 39 | - Find a USB drive which is FAT12 / FAT16 / FAT32 formatted
|
33 | 40 | - Copy the file to the USB drive, to `/EFI/Boot/Bootx64.efi`
|
34 | 41 | - In the UEFI BIOS, choose "Boot from USB" or similar
|
35 | 42 |
|
36 | 43 | - To run this in QEMU:
|
37 | 44 | - You will need a recent version of QEMU as well as OVMF to provide UEFI support
|
38 | 45 | - Check the [`build.py`](uefi-test-runner/build.py) script for an idea of
|
39 |
| - what arguments to pass to QEMU |
| 46 | + what arguments to pass to QEMU. |
40 | 47 |
|
41 |
| -[`aarch64-unknown-uefi`]: https://github.com/rust-lang/rust/blob/HEAD/compiler/rustc_target/src/spec/aarch64_unknown_uefi.rs |
42 |
| -[`i686-unknown-uefi`]: https://github.com/rust-lang/rust/blob/HEAD/compiler/rustc_target/src/spec/i686_unknown_uefi.rs |
43 |
| -[`x86_64-unknown-uefi`]: https://github.com/rust-lang/rust/blob/HEAD/compiler/rustc_target/src/spec/x86_64_unknown_uefi.rs |
| 48 | + In principle, you need to replicate the file structure described above for an USB drive, |
| 49 | + then [mount the directory as if it were a FAT drive][qemu-vvfat]. |
| 50 | + |
| 51 | +[qemu-vvfat]: https://en.wikibooks.org/wiki/QEMU/Devices/Storage#Virtual_FAT_filesystem_(VVFAT) |
| 52 | + |
| 53 | +## Template |
| 54 | + |
| 55 | +The [template](template) provides a quick way to get started building UEFI applications. |
0 commit comments