@@ -8,7 +8,7 @@ use amd_efs::flash::Location;
8
8
use amd_efs:: {
9
9
AddressMode , ComboDirectoryEntryFilter , EfhBulldozerSpiMode ,
10
10
EfhEspiConfiguration , EfhNaplesSpiMode , EfhRomeSpiMode ,
11
- ProcessorGeneration ,
11
+ ProcessorGeneration , PspSoftFuseChain ,
12
12
} ;
13
13
use amd_efs:: {
14
14
BhdDirectoryEntry , BhdDirectoryEntryRegionType , BhdDirectoryEntryType ,
@@ -30,6 +30,8 @@ pub enum Error {
30
30
Io ( std:: io:: Error ) ,
31
31
#[ error( "image too big" ) ]
32
32
ImageTooBig ,
33
+ #[ error( "psp entry source {0} unknown" ) ]
34
+ PspEntrySourceUnknown ( PspDirectoryEntryType ) ,
33
35
}
34
36
35
37
impl From < amd_efs:: Error > for Error {
@@ -106,11 +108,46 @@ impl TryFromSerdeDirectoryEntryWithContext<SerdePspDirectoryEntry>
106
108
}
107
109
}
108
110
111
+ // See <https://github.com/serde-rs/serde/issues/1799>
112
+ #[ derive( Clone , serde:: Serialize , serde:: Deserialize , schemars:: JsonSchema ) ]
113
+ #[ serde( rename = "SerdePspEntrySourceValue" ) ]
114
+ #[ serde( deny_unknown_fields) ]
115
+ pub enum SerdePspEntrySourceValue {
116
+ PspSoftFuseChain ( PspSoftFuseChain ) ,
117
+ #[ serde( default ) ]
118
+ Raw ( u64 ) ,
119
+ }
120
+
121
+ impl SerdePspEntrySourceValue {
122
+ pub fn from_u64 ( value : u64 , typ : PspDirectoryEntryType ) -> Result < Self > {
123
+ match typ {
124
+ PspDirectoryEntryType :: PspSoftFuseChain => {
125
+ Ok ( Self :: PspSoftFuseChain ( PspSoftFuseChain :: from ( value) ) )
126
+ }
127
+ _ => Err ( Error :: PspEntrySourceUnknown ( typ) ) ,
128
+ }
129
+ }
130
+
131
+ pub fn to_u64 (
132
+ & self ,
133
+ typ_or_err : std:: result:: Result < PspDirectoryEntryType , amd_efs:: Error > ,
134
+ ) -> Result < u64 > {
135
+ let typ = typ_or_err. unwrap ( ) ;
136
+ match typ {
137
+ PspDirectoryEntryType :: PspSoftFuseChain => match self {
138
+ Self :: PspSoftFuseChain ( x) => Ok ( u64:: from ( * x) ) ,
139
+ _ => Err ( Error :: PspEntrySourceUnknown ( typ) ) ,
140
+ } ,
141
+ _ => Err ( Error :: PspEntrySourceUnknown ( typ) ) ,
142
+ }
143
+ }
144
+ }
145
+
109
146
#[ derive( Clone , serde:: Serialize , serde:: Deserialize , schemars:: JsonSchema ) ]
110
147
#[ serde( rename = "PspEntrySource" ) ]
111
148
#[ serde( deny_unknown_fields) ]
112
149
pub enum SerdePspEntrySource {
113
- Value ( u64 ) ,
150
+ Value ( SerdePspEntrySourceValue ) ,
114
151
BlobFile ( PathBuf ) ,
115
152
SecondLevelDirectory ( SerdePspDirectory ) ,
116
153
}
0 commit comments