Skip to content

Commit

Permalink
Use x86_64-unknown-uefi target
Browse files Browse the repository at this point in the history
Rust now supports uefi as a build target: rust-lang/rust#56769

This change mainly eliminates references to the custom JSON target
file. It also requires that the entry point's name be changed to
`efi_main`.

Note that the "C" abi is now correct for EFI applications, but will
still be incorrect when uefi-rs is brought in as an external dependancy
for a different target. This means the entry point should always be
`extern "C"` while the table of function pointers should be `extern
"win64"`.
  • Loading branch information
josephlr committed Feb 6, 2019
1 parent 954a359 commit cd02b2f
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 40 deletions.
13 changes: 5 additions & 8 deletions BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

UEFI applications are simple COFF (Windows) executables, with the special
`EFI_Application` subsystem, and some limitations (such as no dynamic linking).

The `x86_64-uefi.json` file describes a custom target for building UEFI apps.
[Rust supports building UEFI applications](https://github.com/rust-lang/rust/pull/56769)
though the `x86_64-unknown-uefi` target.

## Prerequisites

Expand All @@ -19,15 +19,12 @@ The following steps allow you to build a simple UEFI app.

```rust
#[no_mangle]
pub extern "win64" fn uefi_start(handle: Handle, system_table: SystemTable<Boot>) -> Status;
pub extern "C" fn efi_main(handle: Handle, system_table: SystemTable<Boot>) -> Status;
```

- Copy the `uefi-test-runner/x86_64-uefi.json` target file to your project's root.
You can customize it.

- Build using `cargo xbuild --target x86_64-uefi`.
- Build using `cargo xbuild --target x86_64-unknown-uefi`.

- The `target` directory will contain a `x86_64-uefi` subdirectory,
- The `target` directory will contain a `x86_64-unknown-uefi` subdirectory,
where you will find the `uefi_app.efi` file - a normal UEFI executable.

- To run this on a real computer:
Expand Down
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
OS loaders, hypervisors and other low-level applications. While it started out
as x86-specific, it has been adopted on other platforms, such as ARM.

This crates makes it easy to write UEFI applications in Rust.
This crate makes it easy to both:
- Write UEFI applications in Rust (via the [`x86_64-unknown-uefi`][rustc-uefi] target)
- Call UEFI functions from an OS (usually built with a [custom target][rustc-custom])

The objective is to provide **safe** and **performant** wrappers for UEFI interfaces,
and allow developers to write idiomatic Rust code.
Expand All @@ -20,6 +22,8 @@ and has been tested _only_ with **64-bit** UEFI.

[UEFI]: https://en.wikipedia.org/wiki/Unified_Extensible_Firmware_Interface
[gm-blog]: https://medium.com/@gil0mendes/an-efi-app-a-bit-rusty-82c36b745f49
[rustc-uefi]: https://github.com/rust-lang/rust/pull/56769
[rustc-custom]: https://doc.rust-lang.org/rustc/targets/custom.html

![uefi-rs running in QEMU](https://imgur.com/SFPSVuO.png)

Expand Down Expand Up @@ -49,7 +53,7 @@ This project contains multiple sub-crates:

## Building kernels which use UEFI

This crate makes it easy to start buildimg simple applications with UEFI.
This crate makes it easy to start building simple applications with UEFI.
However, there are some limitations you should be aware of:

- The global logger / allocator **can only be set once** per binary.
Expand Down Expand Up @@ -92,8 +96,6 @@ An example UEFI app is built in the `uefi-test-runner` directory.

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

This repo also contains a `x86_64-uefi.json` file, which is a custom Rust target for 64-bit UEFI applications.

## Building UEFI programs

For instructions on how to create your own UEFI apps, see the [BUILDING.md](BUILDING.md) file.
Expand Down
2 changes: 1 addition & 1 deletion uefi-test-runner/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
# Run QEMU without showing GUI
'headless': False,
# Target to build for.
'target': 'x86_64-uefi',
'target': 'x86_64-unknown-uefi',
# Configuration to build.
'config': 'debug',
# QEMU executable to use
Expand Down
2 changes: 1 addition & 1 deletion uefi-test-runner/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ mod boot;
mod proto;

#[no_mangle]
pub extern "win64" fn uefi_start(image: uefi::Handle, st: SystemTable<Boot>) -> Status {
pub extern "C" fn efi_main(image: uefi::Handle, st: SystemTable<Boot>) -> Status {
// Initialize utilities (logging, memory allocation...)
uefi_services::init(&st).expect_success("Failed to initialize utilities");

Expand Down
26 changes: 0 additions & 26 deletions uefi-test-runner/x86_64-uefi.json

This file was deleted.

0 comments on commit cd02b2f

Please sign in to comment.