-
Notifications
You must be signed in to change notification settings - Fork 113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create a skeleton UEFI app #2605
Changes from all commits
a3ac6a7
825b42b
db7e8e5
14b8d94
6f7b4cc
8b76018
26b0686
80a9d6f
0dff885
3d0c82a
71181e6
72eb725
1e04e06
d82c836
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[build] | ||
target = "x86_64-unknown-uefi" | ||
|
||
[target.x86_64-unknown-uefi] | ||
runner = "qemu-system-x86_64 -nodefaults -nographic -bios /usr/share/OVMF/OVMF_CODE.fd -serial stdio -machine q35 -device isa-debug-exit,iobase=0xf4,iosize=0x04 -kernel" | ||
|
||
[unstable] | ||
build-std = ["core"] | ||
build-std-features = ["compiler-builtins-mem"] |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[package] | ||
name = "uefi-simple" | ||
version = "0.1.0" | ||
authors = ["Andri Saar <[email protected]>"] | ||
edition = "2021" | ||
license = "Apache-2.0" | ||
|
||
[dependencies] | ||
uefi = "*" | ||
uefi-services = "*" | ||
|
||
[dev-dependencies] | ||
uefi-services = { version = "*", features = ["qemu"] } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// | ||
// Copyright 2022 The Project Oak Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
#![no_main] | ||
#![no_std] | ||
#![feature(abi_efiapi)] | ||
#![feature(custom_test_frameworks)] | ||
// As we're in a `no_std` environment, testing requires special handling. This | ||
// approach was inspired by https://os.phil-opp.com/testing/. | ||
#![test_runner(crate::test_runner)] | ||
#![reexport_test_harness_main = "test_main"] | ||
|
||
use uefi::{prelude::*, table::runtime::ResetType, ResultExt}; | ||
|
||
// The main entry point of the UEFI application. | ||
// | ||
// The choice of name (`_start`) is entirely arbitrary; what matters is that | ||
// there's exactly one function with the `#[entry]` attribute in the | ||
// dependency graph. | ||
#[entry] | ||
fn _start(_handle: Handle, mut system_table: SystemTable<Boot>) -> Status { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this need to be named There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just a convention. I've added some comments. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great, thanks! This stuff is pretty new for everyone, including people familiar with "vanilla" Rust, so expect to have to over communicate / document things :)
Comment on lines
+33
to
+34
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I imagine some of this will end up being part of some generic harness library, while some other parts will be Oak-specific. Not in this PR, but it may be worth start thinking about that split going forward. |
||
uefi_services::init(&mut system_table).unwrap_success(); | ||
|
||
// As we're not relying on the normal Rust test harness, we need to call | ||
// the tests ourselves if necessary. | ||
let status = if cfg!(test) { | ||
#[cfg(test)] | ||
test_main(); | ||
Status::SUCCESS | ||
} else { | ||
main(_handle, &mut system_table) | ||
}; | ||
|
||
// After we're done running our code, we also tell the UEFI runtime to shut | ||
// down the machine, otherwise we'd go back to the UEFI shell. | ||
system_table | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add some comment here to explain what's happening (and why)? |
||
.runtime_services() | ||
.reset(ResetType::Shutdown, status, None); | ||
} | ||
|
||
fn main(_handle: Handle, system_table: &mut SystemTable<Boot>) -> Status { | ||
use core::fmt::Write; | ||
|
||
let status = writeln!(system_table.stdout(), "Hello World!"); | ||
|
||
status | ||
.map(|_| Status::SUCCESS) | ||
.unwrap_or(Status::DEVICE_ERROR) | ||
} | ||
|
||
#[cfg(test)] | ||
fn test_runner(tests: &[&dyn Fn()]) { | ||
for test in tests { | ||
test(); | ||
} | ||
} | ||
|
||
// Simple silly test just to prove that the test infrastructure works. | ||
#[test_case] | ||
fn test_simple() { | ||
let x = 1; | ||
assert_eq!(x, 1); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where does the
test_main
string come from? Is it important that it stays like that, or can it be changed? Please add some detailsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume it can be changed; I've added a link to the blog post this code draws upon heavily for the testing infrastructure.