-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds a simple Rust based DXE driver to demonstrate how to structure a DXE driver that only has Rust crate dependencies. Within the firmware build framework, this is considered a "pure Rust" DXE driver in that it only has a `Cargo.toml` file in the `[Sources]` section of the INF with no EDK II library dependencies. The module uses the `RustAdvancedLoggerDxe` crate (which is a wrapper around the Advanced Logger protocol) to write debug messages and the `RustBootServicesAllocatorDxe`. Co-authored-by: John Schock <[email protected]> Signed-off-by: Michael Kubacki <[email protected]>
- Loading branch information
Showing
7 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/target | ||
**/*.rs.bk | ||
Cargo.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[package] | ||
name = "HelloWorldRustDxe" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[[bin]] | ||
name = "HelloWorldRustDxe" | ||
path = "src/main.rs" | ||
test = false | ||
|
||
[dependencies] | ||
r-efi = {workspace=true} | ||
RustAdvancedLoggerDxe = {workspace=true} | ||
RustBootServicesAllocatorDxe = {workspace=true} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
### @file | ||
# Hello World DXE Rust driver. | ||
# | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# SPDX-License-Identifier: BSD-2-Clause-Patent | ||
# | ||
### | ||
|
||
[Defines] | ||
INF_VERSION = 1.27 | ||
BASE_NAME = HelloWorldRustDxe | ||
FILE_GUID = A14E35E2-BB32-4446-8622-C1874B8284E4 | ||
MODULE_TYPE = DXE_DRIVER | ||
RUST_MODULE = TRUE | ||
|
||
[Sources] | ||
Cargo.toml | ||
|
||
[Depex] | ||
TRUE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
//! Hello World Rust DXE Driver | ||
//! | ||
//! Demonstrates how to build a DXE driver written in Rust. | ||
//! | ||
//! ## License | ||
//! | ||
//! Copyright (c) Microsoft Corporation. All rights reserved. | ||
//! | ||
//! SPDX-License-Identifier: BSD-2-Clause-Patent | ||
//! | ||
#![no_std] | ||
#![no_main] | ||
#![allow(non_snake_case)] | ||
|
||
extern crate alloc; | ||
|
||
use alloc::vec; | ||
use core::panic::PanicInfo; | ||
use r_efi::efi::Status; | ||
use rust_advanced_logger_dxe::{debugln, init_debug, DEBUG_INFO}; | ||
|
||
#[no_mangle] | ||
pub extern "efiapi" fn efi_main( | ||
_image_handle: *const core::ffi::c_void, | ||
_system_table: *const r_efi::system::SystemTable, | ||
) -> u64 { | ||
rust_boot_services_allocator_dxe::GLOBAL_ALLOCATOR.init(unsafe { (*_system_table).boot_services }); | ||
init_debug(unsafe { (*_system_table).boot_services }); | ||
|
||
debugln!(DEBUG_INFO, "Hello, World. This is Rust in UEFI."); | ||
|
||
debugln!(DEBUG_INFO, "file: {:} line: {:} as hex: {:x}", file!(), line!(), line!()); | ||
|
||
let mut foo = vec!["asdf", "xyzpdq", "abcdefg", "thxyzb"]; | ||
|
||
debugln!(DEBUG_INFO, "Unsorted vec: {:?}", foo); | ||
foo.sort(); | ||
debugln!(DEBUG_INFO, "Sorted vec: {:?}", foo); | ||
|
||
Status::SUCCESS.as_usize() as u64 | ||
} | ||
|
||
#[panic_handler] | ||
fn panic(_info: &PanicInfo) -> ! { | ||
loop {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters