14
14
use log:: { debug, error, info, trace} ;
15
15
use std:: prelude:: v1:: * ;
16
16
17
- #[ cfg( not( feature = "uefi" ) ) ]
18
- use crate :: guid:: Guid ;
19
17
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 } ;
24
19
25
20
#[ cfg( target_os = "linux" ) ]
26
21
use std:: fs;
@@ -38,73 +33,123 @@ use std::os::fd::AsRawFd;
38
33
#[ cfg( target_os = "freebsd" ) ]
39
34
use std:: os:: unix:: fs:: OpenOptionsExt ;
40
35
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
+ ) ;
95
134
96
135
// In EDK2
97
136
// Handled by MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.c
98
137
// Defined by MdePkg/Include/IndustryStandard/WindowsUxCapsule.h
99
138
/// 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
+ ) ;
101
145
102
146
#[ derive( Debug ) ]
103
147
pub enum FrameworkGuidKind {
104
148
TglBios ,
105
149
AdlBios ,
106
150
RplBios ,
107
151
MtlBios ,
152
+ Fw12RplBios ,
108
153
TglRetimer01 ,
109
154
TglRetimer23 ,
110
155
AdlRetimer01 ,
@@ -122,7 +167,7 @@ pub enum FrameworkGuidKind {
122
167
}
123
168
124
169
pub fn match_guid_kind ( guid : & Guid ) -> FrameworkGuidKind {
125
- match * guid {
170
+ match GUID :: from ( * guid) {
126
171
TGL_BIOS_GUID => FrameworkGuidKind :: TglBios ,
127
172
ADL_BIOS_GUID => FrameworkGuidKind :: AdlBios ,
128
173
RPL_BIOS_GUID => FrameworkGuidKind :: RplBios ,
@@ -288,8 +333,9 @@ fn esrt_from_sysfs(dir: &Path) -> io::Result<Esrt> {
288
333
let last_attempt_version = fs:: read_to_string ( path. join ( "last_attempt_version" ) ) ?;
289
334
let last_attempt_status = fs:: read_to_string ( path. join ( "last_attempt_status" ) ) ?;
290
335
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
+ ) ,
293
339
fw_type : fw_type
294
340
. trim ( )
295
341
. parse :: < u32 > ( )
@@ -358,8 +404,8 @@ pub fn get_esrt() -> Option<Esrt> {
358
404
let guid_str = caps. get ( 1 ) . unwrap ( ) . as_str ( ) . to_string ( ) ;
359
405
let ver_str = caps. get ( 2 ) . unwrap ( ) . as_str ( ) . to_string ( ) ;
360
406
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) ) ;
363
409
let ver = u32:: from_str_radix ( & ver_str, 16 ) . unwrap ( ) ;
364
410
debug ! ( "ESRT Entry {}" , i) ;
365
411
debug ! ( " Name: {:?}" , guid_kind) ;
@@ -379,7 +425,7 @@ pub fn get_esrt() -> Option<Esrt> {
379
425
// TODO: The missing fields are present in Device Manager
380
426
// So there must be a way to get at them
381
427
let esrt = EsrtResourceEntry {
382
- fw_class : guid,
428
+ fw_class : Guid :: from ( guid) ,
383
429
fw_type,
384
430
fw_version : ver,
385
431
// TODO: Not exposed by windows
@@ -428,7 +474,7 @@ pub fn get_esrt() -> Option<Esrt> {
428
474
let mut buf: Vec < u8 > = Vec :: new ( ) ;
429
475
let mut table = EfiGetTableIoc {
430
476
buf : std:: ptr:: null_mut ( ) ,
431
- uuid : SYSTEM_RESOURCE_TABLE_GUID . to_bytes ( ) ,
477
+ uuid : SYSTEM_RESOURCE_TABLE_GUID_BYTES ,
432
478
buf_len : 0 ,
433
479
table_len : 0 ,
434
480
} ;
@@ -448,7 +494,15 @@ pub fn get_esrt() -> Option<Esrt> {
448
494
}
449
495
450
496
/// 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
+ ] ;
452
506
453
507
#[ cfg( feature = "uefi" ) ]
454
508
pub fn get_esrt ( ) -> Option < Esrt > {
@@ -459,6 +513,7 @@ pub fn get_esrt() -> Option<Esrt> {
459
513
// TODO: Why aren't they the same type?
460
514
//debug!("Table: {:?}", table);
461
515
let table_guid: Guid = unsafe { std:: mem:: transmute ( table. guid ) } ;
516
+ let table_guid = GUID :: from ( table_guid) ;
462
517
match table_guid {
463
518
SYSTEM_RESOURCE_TABLE_GUID => unsafe {
464
519
return esrt_from_buf ( table. address as * const u8 ) ;
0 commit comments