Skip to content

Commit 1d68de8

Browse files
authored
Migrate mu_plus from mu_uefi_boot_services crate to patina crate (#881)
## Description - `mu_uefi_boot_services` is not maintained and its functionality is moved into patina. - The [mu_uefi_boot_services's crates.io](https://crates.io/crates/mu_uefi_boot_services) point to non-existent repo. - This cleanup is needed to move mu_plus's r-efi dependency to 6.0 Next, Once Patina is updated to r-efi 6.0 we can migrate mu_plus to patina vnext and r-efi to 6.0 - [ ] Impacts functionality? - [ ] Impacts security? - [ ] Breaking change? - [ ] Includes tests? - [ ] Includes documentation? ## How This Was Tested `cargo make all` worked. Will be tested in internal repos once r-efi 6.0 migration is done. ## Integration Instructions NA Signed-off-by: Vineel Kovvuri[MSFT] <vineelko@microsoft.com>
1 parent 1d1b4db commit 1d68de8

6 files changed

Lines changed: 46 additions & 141 deletions

File tree

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "RustAdvancedLoggerDxe"
33
version = "0.1.0"
4-
edition = "2021"
4+
edition = "2024"
55

66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
77
[lib]
@@ -10,7 +10,7 @@ path = "src/lib.rs"
1010

1111
[dependencies]
1212
r-efi = { workspace = true }
13-
mu_uefi_boot_services = { workspace = true }
13+
patina = { workspace = true }
1414

1515
[dev-dependencies]
16-
mu_uefi_boot_services = { workspace = true, features = ["mockall"] }
16+
patina = { workspace = true, features = ["mockall"] }

AdvLoggerPkg/Crates/RustAdvancedLoggerDxe/src/lib.rs

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ use core::{
3939
ptr,
4040
sync::atomic::{AtomicPtr, Ordering},
4141
};
42+
use patina::BinaryGuid;
43+
use patina::{boot_services, uefi_protocol::ProtocolInterface};
4244
use r_efi::efi;
4345

44-
use boot_services::{self, protocol_handler::Protocol};
45-
4646
//Global static logger instance - this is a singleton.
4747
static LOGGER: AdvancedLogger = AdvancedLogger::new();
4848

@@ -58,34 +58,25 @@ pub const DEBUG_VERBOSE: usize = 0x00400000;
5858
pub const DEBUG_ERROR: usize = 0x80000000;
5959

6060
// AdvancedLogger protocol definition. Mirrors C definition in AdvLoggerPkg/Include/Protocol/AdvancedLogger.h
61-
const ADVANCED_LOGGER_PROTOCOL_GUID: efi::Guid =
62-
efi::Guid::from_fields(0x434f695c, 0xef26, 0x4a12, 0x9e, 0xba, &[0xdd, 0xef, 0x00, 0x97, 0x49, 0x7c]);
63-
61+
const ADVANCED_LOGGER_PROTOCOL_GUID: BinaryGuid = BinaryGuid::from_string("434f695c-ef26-4a12-9eba-ddef0097497c");
6462
type AdvancedLoggerWriteProtocol = extern "efiapi" fn(*const AdvancedLoggerProtocolInterface, usize, *const u8, usize);
6563

66-
const ADVANCED_LOGGER_PROTOCOL: AdvancedLoggerProtocol = AdvancedLoggerProtocol {};
67-
6864
#[repr(C)]
6965
struct AdvancedLoggerProtocolInterface {
7066
signature: u32,
7167
version: u32,
7268
write_log: AdvancedLoggerWriteProtocol,
7369
}
7470

75-
struct AdvancedLoggerProtocol;
76-
77-
unsafe impl Protocol for AdvancedLoggerProtocol {
78-
type Interface = AdvancedLoggerProtocolInterface;
79-
fn protocol_guid(&self) -> &'static efi::Guid {
80-
&ADVANCED_LOGGER_PROTOCOL_GUID
81-
}
71+
unsafe impl ProtocolInterface for AdvancedLoggerProtocolInterface {
72+
const PROTOCOL_GUID: BinaryGuid = ADVANCED_LOGGER_PROTOCOL_GUID;
8273
}
8374

84-
impl Deref for AdvancedLoggerProtocol {
75+
impl Deref for AdvancedLoggerProtocolInterface {
8576
type Target = efi::Guid;
8677

8778
fn deref(&self) -> &Self::Target {
88-
self.protocol_guid()
79+
&ADVANCED_LOGGER_PROTOCOL_GUID
8980
}
9081
}
9182

@@ -103,7 +94,8 @@ impl AdvancedLogger {
10394

10495
// initialize the AdvancedLogger by acquiring a pointer to the AdvancedLogger protocol.
10596
fn init(&self, boot_services_impl: &impl boot_services::BootServices) {
106-
let protocol_ptr = match unsafe { boot_services_impl.locate_protocol(&ADVANCED_LOGGER_PROTOCOL, None) } {
97+
let protocol_ptr = match unsafe { boot_services_impl.locate_protocol::<AdvancedLoggerProtocolInterface>(None) }
98+
{
10799
Ok(interface) => interface as *mut AdvancedLoggerProtocolInterface,
108100
Err(_status) => ptr::null_mut(),
109101
};
@@ -143,7 +135,7 @@ impl fmt::Write for LogTransactor<'_> {
143135
/// # Safety
144136
/// Parameter `efi_boot_services` should be a valid pointer of [`efi::BootServices`] with a static lifetime.
145137
pub unsafe fn init_debug(efi_boot_services: *mut efi::BootServices) {
146-
let standard_boot_services = unsafe { boot_services::StandardBootServices::new(&*efi_boot_services) };
138+
let standard_boot_services = boot_services::StandardBootServices::new(efi_boot_services);
147139
LOGGER.init(&standard_boot_services);
148140
}
149141

@@ -252,12 +244,12 @@ macro_rules! debugln {
252244
mod tests {
253245
extern crate std;
254246
use crate::{
255-
debug, AdvancedLogger, AdvancedLoggerProtocol, AdvancedLoggerProtocolInterface, DEBUG_ERROR, DEBUG_INFO,
256-
DEBUG_INIT, DEBUG_VERBOSE, DEBUG_WARN, LOGGER,
247+
AdvancedLogger, AdvancedLoggerProtocolInterface, DEBUG_ERROR, DEBUG_INFO, DEBUG_INIT, DEBUG_VERBOSE,
248+
DEBUG_WARN, LOGGER, debug,
257249
};
258250
use core::{slice::from_raw_parts, sync::atomic::Ordering};
251+
use patina::boot_services::MockBootServices;
259252
use std::{println, str};
260-
261253
static ADVANCED_LOGGER_INSTANCE: AdvancedLoggerProtocolInterface =
262254
AdvancedLoggerProtocolInterface { signature: 0, version: 0, write_log: mock_advanced_logger_write };
263255

@@ -287,8 +279,8 @@ mod tests {
287279

288280
#[test]
289281
fn init_should_initialize_logger() {
290-
let mut mock_boot_services = boot_services::MockBootServices::new();
291-
mock_boot_services.expect_locate_protocol().returning(|_: &AdvancedLoggerProtocol, registration| unsafe {
282+
let mut mock_boot_services = MockBootServices::new();
283+
mock_boot_services.expect_locate_protocol().returning(|registration| unsafe {
292284
assert_eq!(registration, None);
293285
Ok((&ADVANCED_LOGGER_INSTANCE as *const AdvancedLoggerProtocolInterface
294286
as *mut AdvancedLoggerProtocolInterface)
@@ -305,8 +297,8 @@ mod tests {
305297

306298
#[test]
307299
fn debug_macro_should_log_things() {
308-
let mut mock_boot_services = boot_services::MockBootServices::new();
309-
mock_boot_services.expect_locate_protocol().returning(|_: &AdvancedLoggerProtocol, registration| unsafe {
300+
let mut mock_boot_services = MockBootServices::new();
301+
mock_boot_services.expect_locate_protocol().returning(|registration| unsafe {
310302
assert_eq!(registration, None);
311303
Ok((&ADVANCED_LOGGER_INSTANCE as *const AdvancedLoggerProtocolInterface
312304
as *mut AdvancedLoggerProtocolInterface)

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ mu_rust_helpers = { version = "3" }
2020
MuTelemetryHelperLib = { path = "MsWheaPkg/Crates/MuTelemetryHelperLib" }
2121
RustAdvancedLoggerDxe = { path = "AdvLoggerPkg/Crates/RustAdvancedLoggerDxe" }
2222
RustBootServicesAllocatorDxe = { path = "MsCorePkg/Crates/RustBootServicesAllocatorDxe" }
23-
mu_uefi_boot_services = { version = "2" }
23+
patina = { version = "21" }
2424
mockall = {version = "0.14.0"}
2525

2626
memoffset = "0.9.0"

MsWheaPkg/Crates/MuTelemetryHelperLib/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "MuTelemetryHelperLib"
33
version = "0.1.0"
4-
edition = "2021"
4+
edition = "2024"
55

66
[lib]
77
name = "mu_telemetry_helper_lib"
@@ -11,11 +11,11 @@ path = "src/lib.rs"
1111
mu_pi = { workspace = true }
1212
mu_rust_helpers = { workspace = true }
1313
r-efi = { workspace = true }
14-
mu_uefi_boot_services = { workspace = true }
14+
patina = { workspace = true }
1515

1616
[dev-dependencies]
1717
mockall = { workspace = true }
18-
mu_uefi_boot_services = { workspace = true, features = ["mockall"] }
18+
patina = { workspace = true, features = ["mockall"] }
1919

2020
[lints.rust]
2121
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(tarpaulin_include)'] }

MsWheaPkg/Crates/MuTelemetryHelperLib/src/lib.rs

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
//!
1515
//! //Initialize Boot Services
1616
//! unsafe {
17-
//! init_telemetry((*system_table).boot_services.as_ref().unwrap());
17+
//! init_telemetry((*system_table).boot_services);
1818
//! }
1919
//!
2020
//! //if (some_failure) {
@@ -34,16 +34,14 @@
3434
//!
3535
#![cfg_attr(target_os = "uefi", no_std)]
3636

37-
mod status_code_runtime;
38-
39-
use boot_services::{BootServices, StandardBootServices};
4037
use mu_pi::{
4138
protocols::status_code::{EfiStatusCodeType, EfiStatusCodeValue},
4239
status_code::{EFI_ERROR_CODE, EFI_ERROR_MAJOR, EFI_ERROR_MINOR},
4340
};
4441
use mu_rust_helpers::{guid, guid::guid};
42+
use patina::boot_services::{BootServices, StandardBootServices};
43+
use patina::uefi_protocol::status_code::StatusCodeRuntimeProtocol;
4544
use r_efi::efi;
46-
use status_code_runtime::{ReportStatusCode, StatusCodeRuntimeProtocol};
4745

4846
static BOOT_SERVICES: StandardBootServices = StandardBootServices::new_uninit();
4947

@@ -139,37 +137,38 @@ fn log_telemetry_internal<B: BootServices>(
139137
additional_info2: extra_data2,
140138
};
141139

142-
StatusCodeRuntimeProtocol::report_status_code(
143-
boot_services,
140+
let protocol = unsafe { boot_services.locate_protocol::<StatusCodeRuntimeProtocol>(None)? };
141+
142+
let caller_id = component_id.unwrap_or(&guid::CALLER_ID);
143+
144+
protocol.report_status_code_with_data(
144145
status_code_type,
145146
class_id,
146147
0,
147-
component_id,
148+
caller_id,
148149
MS_WHEA_RSC_DATA_TYPE_GUID,
149150
error_data,
150151
)
151152
}
152153

153154
#[cfg(not(tarpaulin_include))]
154-
pub fn init_telemetry(efi_boot_services: &efi::BootServices) {
155-
BOOT_SERVICES.initialize(efi_boot_services)
155+
pub fn init_telemetry(efi_boot_services: *mut efi::BootServices) {
156+
BOOT_SERVICES.init(efi_boot_services)
156157
}
157158

158159
#[cfg(test)]
159160
mod test {
160-
use boot_services::MockBootServices;
161161
use mu_pi::protocols::{
162162
status_code,
163163
status_code::{EfiStatusCodeData, EfiStatusCodeType, EfiStatusCodeValue},
164164
};
165165
use mu_rust_helpers::guid::guid;
166+
use patina::boot_services::MockBootServices;
166167
use r_efi::efi;
167168

168-
use crate::{
169-
log_telemetry_internal, status_code_runtime::StatusCodeRuntimeProtocol, MsWheaRscInternalErrorData,
170-
MS_WHEA_ERROR_STATUS_TYPE_FATAL,
171-
};
169+
use crate::{MS_WHEA_ERROR_STATUS_TYPE_FATAL, MsWheaRscInternalErrorData, log_telemetry_internal};
172170
use core::mem::size_of;
171+
use patina::uefi_protocol::status_code::StatusCodeRuntimeProtocol;
173172

174173
const DATA_SIZE: usize = size_of::<EfiStatusCodeData>() + size_of::<MsWheaRscInternalErrorData>();
175174
const MOCK_CALLER_ID: efi::Guid = guid!("d0d1d2d3-d4d5-d6d7-d8d9-dadbdcdddedf");
@@ -185,33 +184,28 @@ mod test {
185184
assert_eq!(value, MOCK_STATUS_CODE_VALUE);
186185
assert_eq!(instance, 0);
187186
assert_eq!(unsafe { *caller_id }, MOCK_CALLER_ID);
188-
if r#type == MS_WHEA_ERROR_STATUS_TYPE_FATAL {
189-
efi::Status::SUCCESS
190-
} else {
191-
efi::Status::INVALID_PARAMETER
192-
}
187+
if r#type == MS_WHEA_ERROR_STATUS_TYPE_FATAL { efi::Status::SUCCESS } else { efi::Status::INVALID_PARAMETER }
193188
}
194189

195-
static MOCK_STATUS_CODE_RUNTIME_INTERFACE: status_code::Protocol =
196-
status_code::Protocol { report_status_code: mock_report_status_code };
190+
static MOCK_STATUS_CODE_RUNTIME_INTERFACE: status_code::Protocol = {
191+
let f: status_code::ReportStatusCode = mock_report_status_code;
192+
status_code::Protocol { report_status_code: f }
193+
};
197194

198195
#[test]
199196
fn try_log_telemetry() {
200197
let mut mock_boot_services: MockBootServices = MockBootServices::new();
201198

202-
mock_boot_services.expect_locate_protocol().returning(|_: &StatusCodeRuntimeProtocol, registration| unsafe {
199+
mock_boot_services.expect_locate_protocol().returning(|registration| unsafe {
203200
assert_eq!(registration, None);
204-
Ok((&MOCK_STATUS_CODE_RUNTIME_INTERFACE as *const status_code::Protocol as *mut status_code::Protocol)
201+
Ok((&MOCK_STATUS_CODE_RUNTIME_INTERFACE as *const status_code::Protocol as *mut StatusCodeRuntimeProtocol)
205202
.as_mut()
206203
.unwrap())
207204
});
208205

209206
// Test sizes of "repr(C)" structs
210207
assert_eq!(size_of::<MsWheaRscInternalErrorData>(), 48);
211208
assert_eq!(size_of::<[u8; 68]>(), DATA_SIZE);
212-
213-
// Test Deref trait
214-
assert_eq!(*StatusCodeRuntimeProtocol, status_code::PROTOCOL_GUID);
215209
assert_eq!(
216210
Ok(()),
217211
log_telemetry_internal(
@@ -244,7 +238,7 @@ mod test {
244238
fn test_protocol_not_found() {
245239
let mut mock_boot_services: MockBootServices = MockBootServices::new();
246240

247-
mock_boot_services.expect_locate_protocol().returning(|_: &StatusCodeRuntimeProtocol, registration| {
241+
mock_boot_services.expect_locate_protocol::<StatusCodeRuntimeProtocol>().returning(|registration| {
248242
assert_eq!(registration, None);
249243
//Simulate "marker protocol" without an Interface
250244
Err(efi::Status::NOT_FOUND)

MsWheaPkg/Crates/MuTelemetryHelperLib/src/status_code_runtime.rs

Lines changed: 0 additions & 81 deletions
This file was deleted.

0 commit comments

Comments
 (0)