Skip to content

Commit 7b010b6

Browse files
committed
Remove vendored guid_macros crate
Replace with guid-create from crates.io Signed-off-by: Daniel Schaefer <[email protected]>
1 parent cf24bdd commit 7b010b6

File tree

10 files changed

+138
-389
lines changed

10 files changed

+138
-389
lines changed

Cargo.lock

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

Cargo.toml

-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ members = [
1111
"framework_uefi",
1212
# Catchall library that we'll probably want to split up further
1313
"framework_lib",
14-
# Fork of https://github.com/rust-osdev/uefi-rs/blob/main/uefi-macros
15-
# To avoid pulling in UEFI dependencies when building for an OS
16-
"guid_macros",
1714
]
1815

1916
# Don't build UEFI by default. Needs special cargo invocation

framework_lib/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ num-traits = { version = "0.2", default-features = false }
3131
log = { version = "0.4", default-features = true }
3232
spin = { version = "0.9.8" }
3333
no-std-compat = { version = "0.4.1", features = [ "alloc" ] }
34-
guid_macros = { path = "../guid_macros" }
3534
hidapi = { version = "2.6.3", features = [ "windows-native" ], optional = true }
3635
rusb = { version = "0.9.4", optional = true }
36+
guid-create = { git = "https://github.com/FrameworkComputer/guid-create", branch = "no-rand", default-features = false }
3737

3838
[target.'cfg(target_os = "uefi")'.dependencies]
3939
uefi = { version = "0.20", features = ["alloc"] }

framework_lib/src/capsule.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,12 @@
1111
use std::prelude::v1::*;
1212

1313
use core::prelude::rust_2021::derive;
14+
use guid_create::Guid;
1415
#[cfg(not(feature = "uefi"))]
1516
use std::fs::File;
1617
#[cfg(not(feature = "uefi"))]
1718
use std::io::prelude::*;
1819

19-
#[cfg(not(feature = "uefi"))]
20-
use crate::guid::Guid;
21-
#[cfg(feature = "uefi")]
22-
use uefi::Guid;
23-
2420
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
2521
#[repr(C)]
2622
pub struct EfiCapsuleHeader {
@@ -209,14 +205,14 @@ mod tests {
209205
let data = fs::read(capsule_path).unwrap();
210206
let cap = parse_capsule_header(&data).unwrap();
211207
let expected_header = EfiCapsuleHeader {
212-
capsule_guid: esrt::WINUX_GUID,
208+
capsule_guid: Guid::from(esrt::WINUX_GUID),
213209
header_size: 28,
214210
flags: 65536,
215211
capsule_image_size: 676898,
216212
};
217213
assert_eq!(cap, expected_header);
218214

219-
assert_eq!(cap.capsule_guid, esrt::WINUX_GUID);
215+
assert_eq!(cap.capsule_guid, Guid::from(esrt::WINUX_GUID));
220216
let ux_header = parse_ux_header(&data);
221217
assert_eq!(
222218
ux_header,

framework_lib/src/commandline/mod.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use alloc::format;
77
use alloc::string::String;
88
use alloc::string::ToString;
99
use alloc::vec::Vec;
10+
use guid_create::{Guid, GUID};
1011
use log::Level;
1112
use num_traits::FromPrimitive;
1213

@@ -494,7 +495,7 @@ fn print_versions(ec: &CrosEc) {
494495
let mut right_retimer: Option<u32> = None;
495496
if let Some(esrt) = esrt::get_esrt() {
496497
for entry in &esrt.entries {
497-
match entry.fw_class {
498+
match GUID::from(entry.fw_class) {
498499
esrt::TGL_RETIMER01_GUID
499500
| esrt::ADL_RETIMER01_GUID
500501
| esrt::RPL_RETIMER01_GUID
@@ -700,7 +701,7 @@ fn compare_version(device: Option<HardwareDeviceType>, version: String, ec: &Cro
700701

701702
if let Some(esrt) = esrt::get_esrt() {
702703
for entry in &esrt.entries {
703-
match entry.fw_class {
704+
match GUID::from(entry.fw_class) {
704705
esrt::TGL_RETIMER01_GUID | esrt::ADL_RETIMER01_GUID | esrt::RPL_RETIMER01_GUID => {
705706
if device == Some(HardwareDeviceType::RTM01) {
706707
println!("Comparing RTM01 version {:?}", entry.fw_version.to_string());
@@ -1032,7 +1033,7 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 {
10321033
println!(" Size: {:>20} B", data.len());
10331034
println!(" Size: {:>20} KB", data.len() / 1024);
10341035
if let Some(header) = analyze_capsule(&data) {
1035-
if header.capsule_guid == esrt::WINUX_GUID {
1036+
if header.capsule_guid == Guid::from(esrt::WINUX_GUID) {
10361037
let ux_header = capsule::parse_ux_header(&data);
10371038
if let Some(dump_path) = &args.dump {
10381039
// TODO: Better error handling, rather than just panicking
@@ -1434,7 +1435,7 @@ pub fn analyze_capsule(data: &[u8]) -> Option<capsule::EfiCapsuleHeader> {
14341435
let header = capsule::parse_capsule_header(data)?;
14351436
capsule::print_capsule_header(&header);
14361437

1437-
match header.capsule_guid {
1438+
match GUID::from(header.capsule_guid) {
14381439
esrt::TGL_BIOS_GUID => {
14391440
println!(" Type: Framework TGL Insyde BIOS");
14401441
}

framework_lib/src/esrt/mod.rs

+124-69
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,8 @@
1414
use log::{debug, error, info, trace};
1515
use std::prelude::v1::*;
1616

17-
#[cfg(not(feature = "uefi"))]
18-
use crate::guid::Guid;
1917
use core::prelude::v1::derive;
20-
#[cfg(not(feature = "uefi"))]
21-
use guid_macros::guid;
22-
#[cfg(feature = "uefi")]
23-
use uefi::{guid, Guid};
18+
use guid_create::{Guid, GUID};
2419

2520
#[cfg(target_os = "linux")]
2621
use std::fs;
@@ -38,73 +33,123 @@ use std::os::fd::AsRawFd;
3833
#[cfg(target_os = "freebsd")]
3934
use std::os::unix::fs::OpenOptionsExt;
4035

41-
/// Decode from GUID string version
42-
///
43-
/// # Examples
44-
/// ```
45-
/// use framework_lib::esrt::*;
46-
/// use framework_lib::guid::*;
47-
///
48-
/// let valid_guid = Guid::from_values(0xA9C91B0C, 0xC0B8, 0x463D, 0xA7DA, 0xA5D6EC646333);
49-
/// // Works with lower-case
50-
/// let guid = guid_from_str("a9c91b0c-c0b8-463d-a7da-a5d6ec646333");
51-
/// assert_eq!(guid, Some(valid_guid));
52-
/// // And upper-case
53-
/// let guid = guid_from_str("A9C91B0C-C0B8-463D-A7DA-A5D6EC646333");
54-
/// assert_eq!(guid, Some(valid_guid));
55-
///
56-
/// let guid = guid_from_str("invalid-guid");
57-
/// assert_eq!(guid, None);
58-
/// ```
59-
pub fn guid_from_str(string: &str) -> Option<Guid> {
60-
let string = string.strip_suffix('\n').unwrap_or(string);
61-
let sections: Vec<&str> = string.split('-').collect();
62-
let time_low = u32::from_str_radix(sections[0], 16).ok()?;
63-
let time_mid = u16::from_str_radix(sections[1], 16).ok()?;
64-
let time_high_and_version = u16::from_str_radix(sections[2], 16).ok()?;
65-
let clock_seq_and_variant = u16::from_str_radix(sections[3], 16).ok()?;
66-
let node = u64::from_str_radix(sections[4], 16).ok()?;
67-
68-
Some(Guid::from_values(
69-
time_low,
70-
time_mid,
71-
time_high_and_version,
72-
clock_seq_and_variant,
73-
node,
74-
))
75-
}
76-
77-
pub const TGL_BIOS_GUID: Guid = guid!("b3bdb2e4-c5cb-5c1b-bdc3-e6fc132462ff");
78-
pub const ADL_BIOS_GUID: Guid = guid!("a30a8cf3-847f-5e59-bd59-f9ec145c1a8c");
79-
pub const RPL_BIOS_GUID: Guid = guid!("13fd4ed2-cba9-50ba-bb91-aece0acb4cc3");
80-
pub const MTL_BIOS_GUID: Guid = guid!("72cecb9b-2b37-5ec2-a9ff-c739aabaadf3");
81-
82-
pub const TGL_RETIMER01_GUID: Guid = guid!("832af090-2ef9-7c47-8f6d-b405c8c7f156");
83-
pub const TGL_RETIMER23_GUID: Guid = guid!("20ef4108-6c64-d049-b6de-11ee35980b8f");
84-
pub const ADL_RETIMER01_GUID: Guid = guid!("a9c91b0c-c0b8-463d-a7da-a5d6ec646333");
85-
pub const ADL_RETIMER23_GUID: Guid = guid!("ba2e4e6e-3b0c-4f25-8a59-4c553fc86ea2");
86-
pub const RPL_RETIMER01_GUID: Guid = guid!("0c42b824-818f-428f-8687-5efcaf059bea");
87-
pub const RPL_RETIMER23_GUID: Guid = guid!("268ccbde-e087-420b-bf82-2212bd3f9bfc");
88-
pub const MTL_RETIMER01_GUID: Guid = guid!("c57fd615-2ac9-4154-bf34-4dc715344408");
89-
pub const MTL_RETIMER23_GUID: Guid = guid!("bdffce36-809c-4fa6-aecc-54536922f0e0");
90-
91-
pub const FL16_BIOS_GUID: Guid = guid!("6ae76af1-c002-5d64-8e18-658d205acf34");
92-
pub const AMD13_BIOS_GUID: Guid = guid!("b5f7dcc1-568c-50f8-a4dd-e39d1f93fda1");
93-
pub const RPL_CSME_GUID: Guid = guid!("865d322c-6ac7-4734-b43e-55db5a557d63");
94-
pub const MTL_CSME_GUID: Guid = guid!("32d8d677-eebc-4947-8f8a-0693a45240e5");
36+
pub const TGL_BIOS_GUID: GUID = GUID::build_from_components(
37+
0xb3bdb2e4,
38+
0xc5cb,
39+
0x5c1b,
40+
&[0xbd, 0xc3, 0xe6, 0xfc, 0x13, 0x24, 0x62, 0xff],
41+
);
42+
pub const ADL_BIOS_GUID: GUID = GUID::build_from_components(
43+
0xa30a8cf3,
44+
0x847f,
45+
0x5e59,
46+
&[0xbd, 0x59, 0xf9, 0xec, 0x14, 0x5c, 0x1a, 0x8c],
47+
);
48+
pub const RPL_BIOS_GUID: GUID = GUID::build_from_components(
49+
0x13fd4ed2,
50+
0xcba9,
51+
0x50ba,
52+
&[0xbb, 0x91, 0xae, 0xce, 0x0a, 0xcb, 0x4c, 0xc3],
53+
);
54+
pub const MTL_BIOS_GUID: GUID = GUID::build_from_components(
55+
0x72cecb9b,
56+
0x2b37,
57+
0x5ec2,
58+
&[0xa9, 0xff, 0xc7, 0x39, 0xaa, 0xba, 0xad, 0xf3],
59+
);
60+
61+
pub const TGL_RETIMER01_GUID: GUID = GUID::build_from_components(
62+
0x832af090,
63+
0x2ef9,
64+
0x7c47,
65+
&[0x8f, 0x6d, 0xb4, 0x05, 0xc8, 0xc7, 0xf1, 0x56],
66+
);
67+
pub const TGL_RETIMER23_GUID: GUID = GUID::build_from_components(
68+
0x20ef4108,
69+
0x6c64,
70+
0xd049,
71+
&[0xb6, 0xde, 0x11, 0xee, 0x35, 0x98, 0x0b, 0x8f],
72+
);
73+
pub const ADL_RETIMER01_GUID: GUID = GUID::build_from_components(
74+
0xa9c91b0c,
75+
0xc0b8,
76+
0x463d,
77+
&[0xa7, 0xda, 0xa5, 0xd6, 0xec, 0x64, 0x63, 0x33],
78+
);
79+
pub const ADL_RETIMER23_GUID: GUID = GUID::build_from_components(
80+
0xba2e4e6e,
81+
0x3b0c,
82+
0x4f25,
83+
&[0x8a, 0x59, 0x4c, 0x55, 0x3f, 0xc8, 0x6e, 0xa2],
84+
);
85+
pub const RPL_RETIMER01_GUID: GUID = GUID::build_from_components(
86+
0x0c42b824,
87+
0x818f,
88+
0x428f,
89+
&[0x86, 0x87, 0x5e, 0xfc, 0xaf, 0x05, 0x9b, 0xea],
90+
);
91+
pub const RPL_RETIMER23_GUID: GUID = GUID::build_from_components(
92+
0x268ccbde,
93+
0xe087,
94+
0x420b,
95+
&[0xbf, 0x82, 0x22, 0x12, 0xbd, 0x3f, 0x9b, 0xfc],
96+
);
97+
pub const MTL_RETIMER01_GUID: GUID = GUID::build_from_components(
98+
0xc57fd615,
99+
0x2ac9,
100+
0x4154,
101+
&[0xbf, 0x34, 0x4d, 0xc7, 0x15, 0x34, 0x44, 0x08],
102+
);
103+
pub const MTL_RETIMER23_GUID: GUID = GUID::build_from_components(
104+
0xbdffce36,
105+
0x809c,
106+
0x4fa6,
107+
&[0xae, 0xcc, 0x54, 0x53, 0x69, 0x22, 0xf0, 0xe0],
108+
);
109+
110+
pub const FL16_BIOS_GUID: GUID = GUID::build_from_components(
111+
0x6ae76af1,
112+
0xc002,
113+
0x5d64,
114+
&[0x8e, 0x18, 0x65, 0x8d, 0x20, 0x5a, 0xcf, 0x34],
115+
);
116+
pub const AMD13_BIOS_GUID: GUID = GUID::build_from_components(
117+
0xb5f7dcc1,
118+
0x568c,
119+
0x50f8,
120+
&[0xa4, 0xdd, 0xe3, 0x9d, 0x1f, 0x93, 0xfd, 0xa1],
121+
);
122+
pub const RPL_CSME_GUID: GUID = GUID::build_from_components(
123+
0x865d322c,
124+
0x6ac7,
125+
0x4734,
126+
&[0xb4, 0x3e, 0x55, 0xdb, 0x5a, 0x55, 0x7d, 0x63],
127+
);
128+
pub const MTL_CSME_GUID: GUID = GUID::build_from_components(
129+
0x32d8d677,
130+
0xeebc,
131+
0x4947,
132+
&[0x8f, 0x8a, 0x06, 0x93, 0xa4, 0x52, 0x40, 0xe5],
133+
);
95134

96135
// In EDK2
97136
// Handled by MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.c
98137
// Defined by MdePkg/Include/IndustryStandard/WindowsUxCapsule.h
99138
/// gWindowsUxCapsuleGuid from MdePkg/MdePkg.dec
100-
pub const WINUX_GUID: Guid = guid!("3b8c8162-188c-46a4-aec9-be43f1d65697");
139+
pub const WINUX_GUID: GUID = GUID::build_from_components(
140+
0x3b8c8162,
141+
0x188c,
142+
0x46a4,
143+
&[0xae, 0xc9, 0xbe, 0x43, 0xf1, 0xd6, 0x56, 0x97],
144+
);
101145

102146
#[derive(Debug)]
103147
pub enum FrameworkGuidKind {
104148
TglBios,
105149
AdlBios,
106150
RplBios,
107151
MtlBios,
152+
Fw12RplBios,
108153
TglRetimer01,
109154
TglRetimer23,
110155
AdlRetimer01,
@@ -122,7 +167,7 @@ pub enum FrameworkGuidKind {
122167
}
123168

124169
pub fn match_guid_kind(guid: &Guid) -> FrameworkGuidKind {
125-
match *guid {
170+
match GUID::from(*guid) {
126171
TGL_BIOS_GUID => FrameworkGuidKind::TglBios,
127172
ADL_BIOS_GUID => FrameworkGuidKind::AdlBios,
128173
RPL_BIOS_GUID => FrameworkGuidKind::RplBios,
@@ -288,8 +333,9 @@ fn esrt_from_sysfs(dir: &Path) -> io::Result<Esrt> {
288333
let last_attempt_version = fs::read_to_string(path.join("last_attempt_version"))?;
289334
let last_attempt_status = fs::read_to_string(path.join("last_attempt_status"))?;
290335
let esrt = EsrtResourceEntry {
291-
// TODO: Parse GUID
292-
fw_class: guid_from_str(&fw_class).expect("Kernel provided wrong value"),
336+
fw_class: Guid::from(
337+
GUID::parse(fw_class.trim()).expect("Kernel provided wrong value"),
338+
),
293339
fw_type: fw_type
294340
.trim()
295341
.parse::<u32>()
@@ -358,8 +404,8 @@ pub fn get_esrt() -> Option<Esrt> {
358404
let guid_str = caps.get(1).unwrap().as_str().to_string();
359405
let ver_str = caps.get(2).unwrap().as_str().to_string();
360406

361-
let guid = guid_from_str(&guid_str).unwrap();
362-
let guid_kind = match_guid_kind(&guid);
407+
let guid = GUID::parse(guid_str.trim()).expect("Kernel provided wrong value");
408+
let guid_kind = match_guid_kind(&Guid::from(guid));
363409
let ver = u32::from_str_radix(&ver_str, 16).unwrap();
364410
debug!("ESRT Entry {}", i);
365411
debug!(" Name: {:?}", guid_kind);
@@ -379,7 +425,7 @@ pub fn get_esrt() -> Option<Esrt> {
379425
// TODO: The missing fields are present in Device Manager
380426
// So there must be a way to get at them
381427
let esrt = EsrtResourceEntry {
382-
fw_class: guid,
428+
fw_class: Guid::from(guid),
383429
fw_type,
384430
fw_version: ver,
385431
// TODO: Not exposed by windows
@@ -428,7 +474,7 @@ pub fn get_esrt() -> Option<Esrt> {
428474
let mut buf: Vec<u8> = Vec::new();
429475
let mut table = EfiGetTableIoc {
430476
buf: std::ptr::null_mut(),
431-
uuid: SYSTEM_RESOURCE_TABLE_GUID.to_bytes(),
477+
uuid: SYSTEM_RESOURCE_TABLE_GUID_BYTES,
432478
buf_len: 0,
433479
table_len: 0,
434480
};
@@ -448,7 +494,15 @@ pub fn get_esrt() -> Option<Esrt> {
448494
}
449495

450496
/// gEfiSystemResourceTableGuid from MdePkg/MdePkg.dec
451-
pub const SYSTEM_RESOURCE_TABLE_GUID: Guid = guid!("b122a263-3661-4f68-9929-78f8b0d62180");
497+
pub const SYSTEM_RESOURCE_TABLE_GUID: GUID = GUID::build_from_components(
498+
0xb122a263,
499+
0x3661,
500+
0x4f68,
501+
&[0x99, 0x29, 0x78, 0xf8, 0xb0, 0xd6, 0x21, 0x80],
502+
);
503+
pub const SYSTEM_RESOURCE_TABLE_GUID_BYTES: [u8; 16] = [
504+
0xb1, 0x22, 0xa2, 0x63, 0x36, 0x61, 0x4f, 0x68, 0x99, 0x29, 0x78, 0xf8, 0xb0, 0xd6, 0x21, 0x80,
505+
];
452506

453507
#[cfg(feature = "uefi")]
454508
pub fn get_esrt() -> Option<Esrt> {
@@ -459,6 +513,7 @@ pub fn get_esrt() -> Option<Esrt> {
459513
// TODO: Why aren't they the same type?
460514
//debug!("Table: {:?}", table);
461515
let table_guid: Guid = unsafe { std::mem::transmute(table.guid) };
516+
let table_guid = GUID::from(table_guid);
462517
match table_guid {
463518
SYSTEM_RESOURCE_TABLE_GUID => unsafe {
464519
return esrt_from_buf(table.address as *const u8);

0 commit comments

Comments
 (0)