Skip to content

Commit 5dc4386

Browse files
committed
repo: init uefi-std-example
This is a minimal template to build Rust apps with Rust's std support for UEFI and our additional `uefi` functionality. It isn't build in CI yet, but might serve as a base for now.
1 parent 4b33da6 commit 5dc4386

File tree

6 files changed

+56
-0
lines changed

6 files changed

+56
-0
lines changed

Cargo.lock

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

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
]

uefi-std-example/.cargo/config.toml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[build]
2+
target = "x86_64-unknown-uefi"

uefi-std-example/Cargo.toml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[package]
2+
name = "uefi-std-example"
3+
description = """
4+
5+
"""
6+
version = "0.1.0"
7+
authors = ["The Rust OSDev team"]
8+
publish = false
9+
edition = "2021"
10+
11+
[dependencies]
12+
uefi = { path = "../uefi", features = [], default-features = false }
13+
14+
log.workspace = true

uefi-std-example/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Minimal Rust App using `std` and `uefi`
2+
3+
## Build
4+
5+
Build using `cargo +nightly build` to build an `x86_64-unknown-uefi` app.

uefi-std-example/src/main.rs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#![feature(uefi_std)]
2+
3+
use std::os::uefi as uefi_std;
4+
use uefi::runtime::ResetType;
5+
use uefi::{Handle, Status};
6+
7+
/// Performs the necessary setup code for the `uefi` crate.
8+
fn setup_uefi_crate() {
9+
let st = uefi_std::env::system_table();
10+
let ih = uefi_std::env::image_handle();
11+
12+
// Mandatory setup code for `uefi` crate.
13+
unsafe {
14+
uefi::table::set_system_table(st.as_ptr().cast());
15+
16+
let ih = Handle::from_ptr(ih.as_ptr().cast()).unwrap();
17+
uefi::boot::set_image_handle(ih);
18+
}
19+
}
20+
21+
fn main() {
22+
println!("Hello World from uefi_std");
23+
setup_uefi_crate();
24+
println!("UEFI-Version is {}", uefi::system::uefi_revision());
25+
uefi::runtime::reset(ResetType::SHUTDOWN, Status::SUCCESS, None);
26+
}

0 commit comments

Comments
 (0)