Skip to content

Commit 47aaec7

Browse files
committed
workspace: add uefi-std-example member
1 parent ff34fcb commit 47aaec7

File tree

6 files changed

+70
-0
lines changed

6 files changed

+70
-0
lines changed

Diff for: Cargo.lock

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ members = [
55
"uefi",
66
"uefi-macros",
77
"uefi-raw",
8+
"uefi-std-example",
89
"uefi-test-runner",
910
"xtask",
1011
]

Diff for: README.md

+2
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ This project contains multiple sub-crates:
7777
Specification. Safe wrappers for these types are provided by the `uefi`
7878
crate. The raw types are suitable for implementing UEFI firmware.
7979

80+
- `uefi-std-example`: Example UEFI app but as Rust standard binary.
81+
8082
- `uefi-test-runner`: a UEFI application that runs unit / integration tests.
8183

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

Diff for: uefi-std-example/Cargo.toml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[package]
2+
name = "uefi-std-example"
3+
version = "0.1.0"
4+
authors = ["The Rust OSDev team"]
5+
publish = false
6+
edition = "2021"
7+
8+
[dependencies]
9+
# Attention: Don't activate the panic_handler feature, as it will clash with
10+
# the one coming from `std`.
11+
uefi = { path = "../uefi", features = ["alloc"], default-features = false }

Diff for: uefi-std-example/README.md

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Minimal Rust App using `std` and `uefi`
2+
3+
Minimal example of a "standard Rust application" that showcases how `uefi` can
4+
be utilized and enhance the developers experience, when `std` is available.
5+
6+
For simplicity, this example is minimal and the documentation is focused on
7+
`x86_64-unknown-uefi`. However, it works similar for other supported UEFI
8+
platforms.
9+
10+
## Build
11+
12+
Build the app using
13+
`$ cargo +nightly build --target x86_64-unknown-uefi`. To build it from the root
14+
directory (the Cargo workspace), append `-p uefi-std-example`.
15+
16+
## Run
17+
18+
The resulting `.efi` file can be found in `target/x86_64-unknown-uefi/<debug|release>/uefi-std-example.efi`.

Diff for: uefi-std-example/src/main.rs

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Note: In Rust 1.82.0-nightly and before, the `uefi_std` feature is
2+
// required for accessing `std::os::uefi::env::*`. The other default
3+
// functionality doesn't need a nightly toolchain (with Rust 1.80 and later),
4+
// but with that limited functionality you - currently - also can't integrate
5+
// the `uefi` crate.
6+
#![feature(uefi_std)]
7+
8+
use std::os::uefi as uefi_std;
9+
use uefi::runtime::ResetType;
10+
use uefi::{Handle, Status};
11+
12+
/// Performs the necessary setup code for the `uefi` crate.
13+
fn setup_uefi_crate() {
14+
let st = uefi_std::env::system_table();
15+
let ih = uefi_std::env::image_handle();
16+
17+
// Mandatory setup code for `uefi` crate.
18+
unsafe {
19+
uefi::table::set_system_table(st.as_ptr().cast());
20+
21+
let ih = Handle::from_ptr(ih.as_ptr().cast()).unwrap();
22+
uefi::boot::set_image_handle(ih);
23+
}
24+
}
25+
26+
fn main() {
27+
println!("Hello World from uefi_std");
28+
setup_uefi_crate();
29+
println!("UEFI-Version is {}", uefi::system::uefi_revision());
30+
uefi::runtime::reset(ResetType::SHUTDOWN, Status::SUCCESS, None);
31+
}

0 commit comments

Comments
 (0)