@@ -18,6 +18,7 @@ use core::{
1818 num:: Wrapping ,
1919} ;
2020
21+ use bitfield_struct:: bitfield;
2122use serde:: { Deserialize , Serialize } ;
2223use zerocopy:: { AlignmentError , ConvertError , FromBytes , IntoBytes , Ref , SizeError } ;
2324use zerocopy_derive:: { FromBytes , Immutable , IntoBytes } ;
@@ -149,6 +150,71 @@ pub enum FptError<'a> {
149150 ) ,
150151}
151152
153+ #[ derive( Serialize , Deserialize , Clone , Copy , Debug , Eq , PartialEq ) ]
154+ pub enum PartitionKind {
155+ Code ,
156+ Data ,
157+ NVRAM ,
158+ XXData ,
159+ EFFS ,
160+ Unknown ,
161+ }
162+
163+ impl PartitionKind {
164+ const fn from_bits ( val : u8 ) -> Self {
165+ match val {
166+ 0 => Self :: Code ,
167+ 1 => Self :: Data ,
168+ 2 => Self :: NVRAM ,
169+ 3 => Self :: XXData ,
170+ 4 => Self :: EFFS ,
171+ _ => Self :: Unknown ,
172+ }
173+ }
174+
175+ const fn into_bits ( self ) -> u8 {
176+ self as u8
177+ }
178+ }
179+
180+ #[ derive( Serialize , Deserialize , Clone , Copy , Debug , Eq , PartialEq ) ]
181+ #[ repr( u8 ) ]
182+ pub enum Validity {
183+ Valid ,
184+ Invalid ,
185+ Unknown ,
186+ }
187+
188+ impl Validity {
189+ const fn from_bits ( val : u8 ) -> Self {
190+ match val {
191+ 0x00 => Self :: Valid ,
192+ 0xff => Self :: Invalid ,
193+ _ => Self :: Unknown ,
194+ }
195+ }
196+
197+ const fn into_bits ( self ) -> u8 {
198+ self as u8
199+ }
200+ }
201+
202+ #[ bitfield( u32 ) ]
203+ #[ derive( Immutable , IntoBytes , FromBytes , Serialize , Deserialize ) ]
204+ pub struct EntryFlags {
205+ #[ bits( 7 ) ]
206+ kind : PartitionKind ,
207+ copy_to_dram_cache : bool ,
208+ #[ bits( 7 ) ]
209+ _res : u8 ,
210+ len1 : bool ,
211+ len2 : bool ,
212+ #[ bits( 7 ) ]
213+ _res : u8 ,
214+ #[ bits( 8 ) ]
215+ validity : Validity ,
216+ }
217+
152218#[ derive( Immutable , IntoBytes , FromBytes , Serialize , Deserialize , Clone , Copy , Debug ) ]
153219#[ repr( C , packed) ]
154220pub struct FPTEntry {
@@ -159,7 +225,7 @@ pub struct FPTEntry {
159225 pub start_tokens : u32 ,
160226 pub max_tokens : u32 ,
161227 pub scratch_sectors : u32 ,
162- pub flags : u32 ,
228+ pub flags : EntryFlags ,
163229}
164230
165231impl FPTEntry {
@@ -198,7 +264,9 @@ impl Display for FPTEntry {
198264 let part_info = format ! ( "{part_type:?}: {full_name}" ) ;
199265 let name_offset_end_size = format ! ( "{name:>4} @ 0x{o:08x}:0x{end:08x} (0x{s:08x})" ) ;
200266
201- write ! ( f, "{name_offset_end_size} {part_info}" )
267+ let fl = self . flags ;
268+ let fb = fl. into_bits ( ) ;
269+ write ! ( f, "{name_offset_end_size} {part_info}\n {fb:08x}: {fl:?}" )
202270 }
203271}
204272
0 commit comments