Skip to content

Commit f7a76a9

Browse files
authored
Rollup merge of #119937 - nicholasbishop:bishop-uefi-doc-improve, r=ehuss
Improve UEFI target docs * Add a section showing exactly how to build a driver instead of an application * Add links to the crates mentioned in the doc CC `@dvdhrm`
2 parents 3a33a4b + 3402f07 commit f7a76a9

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

src/doc/rustc/src/platform-support/unknown-uefi.md

+27-5
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,29 @@ rustup target add x86_64-unknown-uefi
8282
cargo build --target x86_64-unknown-uefi
8383
```
8484

85+
### Building a driver
86+
87+
There are three types of UEFI executables: application, boot service
88+
driver, and runtime driver. All of Rust's UEFI targets default to
89+
producing applications. To build a driver instead, pass a
90+
[`subsystem`][linker-subsystem] linker flag with a value of
91+
`efi_boot_service_driver` or `efi_runtime_driver`.
92+
93+
Example:
94+
95+
```toml
96+
# In .cargo/config.toml:
97+
[build]
98+
rustflags = ["-C", "link-args=/subsystem:efi_runtime_driver"]
99+
```
100+
85101
## Testing
86102

87103
UEFI applications can be copied into the ESP on any UEFI system and executed
88104
via the firmware boot menu. The qemu suite allows emulating UEFI systems and
89105
executing UEFI applications as well. See its documentation for details.
90106

91-
The [uefi-run](https://github.com/Richard-W/uefi-run) rust tool is a simple
107+
The [uefi-run] rust tool is a simple
92108
wrapper around `qemu` that can spawn UEFI applications in qemu. You can install
93109
it via `cargo install uefi-run` and execute qemu applications as
94110
`uefi-run ./application.efi`.
@@ -132,19 +148,19 @@ have been developed to provide access to UEFI protocols and make UEFI
132148
programming more ergonomic in rust. The following list is a short overview (in
133149
alphabetical ordering):
134150

135-
- **efi**: *Ergonomic Rust bindings for writing UEFI applications*. Provides
151+
- **[efi][efi-crate]**: *Ergonomic Rust bindings for writing UEFI applications*. Provides
136152
_rustified_ access to UEFI protocols, implements allocators and a safe
137153
environment to write UEFI applications.
138-
- **r-efi**: *UEFI Reference Specification Protocol Constants and Definitions*.
154+
- **[r-efi]**: *UEFI Reference Specification Protocol Constants and Definitions*.
139155
A pure transpose of the UEFI specification into rust. This provides the raw
140156
definitions from the specification, without any extended helpers or
141157
_rustification_. It serves as baseline to implement any more elaborate rust
142158
UEFI layers.
143-
- **uefi-rs**: *Safe and easy-to-use wrapper for building UEFI apps*. An
159+
- **[uefi-rs]**: *Safe and easy-to-use wrapper for building UEFI apps*. An
144160
elaborate library providing safe abstractions for UEFI protocols and
145161
features. It implements allocators and provides an execution environment to
146162
UEFI applications written in rust.
147-
- **uefi-run**: *Run UEFI applications*. A small wrapper around _qemu_ to spawn
163+
- **[uefi-run]**: *Run UEFI applications*. A small wrapper around _qemu_ to spawn
148164
UEFI applications in an emulated `x86_64` machine.
149165

150166
## Example: Freestanding
@@ -311,3 +327,9 @@ pub fn main() {
311327
The current implementation of std makes `BootServices` unavailable once `ExitBootServices` is called. Refer to [Runtime Drivers](https://edk2-docs.gitbook.io/edk-ii-uefi-driver-writer-s-guide/7_driver_entry_point/711_runtime_drivers) for more information regarding how to handle switching from using physical addresses to using virtual addresses.
312328

313329
Note: It should be noted that it is up to the user to drop all allocated memory before `ExitBootServices` is called.
330+
331+
[efi-crate]: https://github.com/gurry/efi
332+
[linker-subsystem]: https://learn.microsoft.com/en-us/cpp/build/reference/subsystem
333+
[r-efi]: https://github.com/r-efi/r-efi
334+
[uefi-rs]: https://github.com/rust-osdev/uefi-rs
335+
[uefi-run]: https://github.com/Richard-W/uefi-run

0 commit comments

Comments
 (0)