Skip to content

Commit 8aeac23

Browse files
GabrielMajerinicholasbishop
authored andcommitted
Update and reorganize documentation
1 parent 5be61ad commit 8aeac23

File tree

5 files changed

+84
-53
lines changed

5 files changed

+84
-53
lines changed

BUILDING.md

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,55 @@
1-
# Creating UEFI applications
1+
# Building and running UEFI applications
2+
3+
## UEFI binaries
24

35
UEFI applications are simple COFF (Windows) executables, with the special
46
`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
69
[`aarch64-unknown-uefi`], [`i686-unknown-uefi`], and [`x86_64-unknown-uefi`]
710
targets.
811

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`
1021

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.
1323

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:
2226

23-
## Building and running
27+
`rustup component add --toolchain nightly rust-src`
28+
29+
- Build this crate using the `nightly` toolchain:
2430

25-
- Build using a `nightly` version of the compiler:
2631
`cargo +nightly build --target x86_64-unknown-uefi`.
2732

2833
- 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
3037

31-
- To run this on a real computer:
38+
- To run an `.efi` executable on a real computer:
3239
- Find a USB drive which is FAT12 / FAT16 / FAT32 formatted
3340
- Copy the file to the USB drive, to `/EFI/Boot/Bootx64.efi`
3441
- In the UEFI BIOS, choose "Boot from USB" or similar
3542

3643
- To run this in QEMU:
3744
- You will need a recent version of QEMU as well as OVMF to provide UEFI support
3845
- 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.
4047

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.

CONTRIBUTING.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ First, change to the `uefi-test-runner` directory:
1313
cd 'uefi-test-runner'
1414
```
1515

16-
Please take a quick look at the README for an overview of the system requirements
17-
of the test runner.
16+
Please take a quick look at the test runner project's [`README`](uefi-test-runner/README.md)
17+
for an overview of the required dependencies. In addition, the [`BUILDING`](BUILDING.md)
18+
document is useful if it's your first time building and running an UEFI executable.
1819

1920
Make some changes in your favourite editor / IDE:
2021
I use [VS Code][code] with the [RLS][rls] extension.

README.md

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,11 @@ This crate makes it easy to both:
1919
The objective is to provide **safe** and **performant** wrappers for UEFI interfaces,
2020
and allow developers to write idiomatic Rust code.
2121

22-
Check out @gil0mendes [blog post on getting started with UEFI in Rust][gm-blog].
22+
Check out [the UEFI application template](template) for a quick start.
2323

2424
**Note**: this crate currently has only been tested with **64-bit** UEFI on x86/ARM.
2525

2626
[UEFI]: https://en.wikipedia.org/wiki/Unified_Extensible_Firmware_Interface
27-
[gm-blog]: https://gil0mendes.io/blog/an-efi-app-a-bit-rusty/
2827
[rustc-custom]: https://doc.rust-lang.org/rustc/targets/custom.html
2928

3029
![uefi-rs running in QEMU](https://imgur.com/SFPSVuO.png)
@@ -54,30 +53,6 @@ This project contains multiple sub-crates:
5453

5554
[log]: https://github.com/rust-lang-nursery/log
5655

57-
## Building kernels which use UEFI
58-
59-
This crate makes it easy to start building simple applications with UEFI.
60-
However, there are some limitations you should be aware of:
61-
62-
- The global logger / allocator **can only be set once** per binary.
63-
It is useful when just starting out, but if you're building a real OS you will
64-
want to write your own specific kernel logger and memory allocator.
65-
66-
- To support advanced features such as [higher half kernel] and [linker scripts]
67-
you will want to build your kernel as an ELF binary.
68-
69-
In other words, the best way to use this crate is to create a small binary which
70-
wraps your actual kernel, and then use UEFI's convenient functions for loading
71-
it from disk and booting it.
72-
73-
This is similar to what the Linux kernel's [EFI stub] does: the compressed kernel
74-
is an ELF binary which has little knowledge of how it's booted, and the boot loader
75-
uses UEFI to set up an environment for it.
76-
77-
[higher half kernel]: https://wiki.osdev.org/Higher_Half_Kernel
78-
[linker scripts]: https://sourceware.org/binutils/docs/ld/Scripts.html
79-
[EFI stub]: https://www.kernel.org/doc/Documentation/efi-stub.txt
80-
8156
## Documentation
8257

8358
The docs for the latest published crate version can be found at
@@ -88,11 +63,12 @@ the [UEFI specification][spec] for detailed information.
8863

8964
[spec]: http://www.uefi.org/specifications
9065

91-
## Sample code
66+
## Tests
9267

93-
An example UEFI app is built in the `uefi-test-runner` directory.
68+
The `uefi-test-runner` directory contains a sample UEFI app which exercises
69+
most of the library's functionality.
9470

95-
Check out the testing [README.md](uefi-test-runner/README.md) for instructions on how to run the crate's tests.
71+
Check out the testing project's [`README.md`](uefi-test-runner/README.md) for instructions on how to run the tests.
9672

9773
## Building UEFI programs
9874

template/README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# UEFI application template
2+
3+
This directory contains a minimal example of a UEFI application.
4+
Copy it to a new directory to get started.
5+
6+
Check out the [`BUILDING.md`](../BUILDING.md) document for more instructions on
7+
how to build and run a UEFI application developed using `uefi-rs`.
8+
9+
## File structure
10+
11+
- [`template/.cargo/config`](template/.cargo/config) file sets some `build-std` options.
12+
- [`template/Cargo.toml`](template/Cargo.toml) shows the necessary
13+
dependencies. Note that when creating your project the
14+
[`uefi`](https://crates.io/crates/uefi) and
15+
[`uefi-services`](https://crates.io/crates/uefi-services) dependencies should
16+
be changed to the latest releases on [crates.io](https://crates.io).
17+
- [`template/src/main.rs`](template/src/main.rs) has a minimal entry point that
18+
initializes the `uefi-services` crate and exits successfully.
19+
20+
## Building kernels which use UEFI
21+
22+
This template makes it easy to start building simple applications with UEFI.
23+
However, there are some limitations you should be aware of:
24+
25+
- The global logger / allocator **can only be set once** per binary.
26+
It is useful when just starting out, but if you're building a real OS you will
27+
want to write your own specific kernel logger and memory allocator.
28+
29+
- To support advanced features such as [higher half kernel] and [linker scripts]
30+
you will want to build your kernel as an ELF binary.
31+
32+
In other words, the best way to use this crate is to create a small binary which
33+
wraps your actual kernel, and then use UEFI's convenient functions for loading
34+
it from disk and booting it.
35+
36+
This is similar to what the Linux kernel's [EFI stub] does: the compressed kernel
37+
is an ELF binary which has little knowledge of how it's booted, and the boot loader
38+
uses UEFI to set up an environment for it.
39+
40+
[higher half kernel]: https://wiki.osdev.org/Higher_Half_Kernel
41+
[linker scripts]: https://sourceware.org/binutils/docs/ld/Scripts.html
42+
[EFI stub]: https://www.kernel.org/doc/Documentation/efi-stub.txt

uefi-test-runner/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This file documents the process of building and running the test suite.
44

55
## Prerequisites
66

7-
Besides all the [core library requirements](https://github.com/rust-osdev/uefi-rs/blob/master/BUILDING.md#Prerequisites) for building a UEFI app, the tests have additional requirements:
7+
Besides all the [core library requirements](../BUILDING.md) for building a UEFI app, the tests have additional requirements:
88

99
- [QEMU](https://www.qemu.org/): the most recent version of QEMU is recommended.
1010
- [Python 3](https://www.python.org): at least version 3.6 is required.

0 commit comments

Comments
 (0)