Skip to content

Commit 1312ce7

Browse files
committed
fpt: define and print EntryFlags
Adapted from ME Analyzer and extended. Signed-off-by: Daniel Maslowski <info@orangecms.org>
1 parent 5a42e68 commit 1312ce7

File tree

1 file changed

+70
-2
lines changed

1 file changed

+70
-2
lines changed

src/part/fpt.rs

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use core::{
1818
num::Wrapping,
1919
};
2020

21+
use bitfield_struct::bitfield;
2122
use serde::{Deserialize, Serialize};
2223
use zerocopy::{AlignmentError, ConvertError, FromBytes, IntoBytes, Ref, SizeError};
2324
use 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)]
154220
pub 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

165231
impl 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

Comments
 (0)