Ensure RawCard size matches flash alignment requirements, add debug logs

This commit is contained in:
2026-08-29 15:01:48 +00:00
committed by rhetenor
parent ed86e88980
commit 704682b0ae
6 changed files with 18 additions and 10 deletions
+1
View File
@@ -17,6 +17,7 @@ pub fn split_nfc_hex(payload: &[u8]) -> Option<RawCard> {
packed_card_text: payload[0x2DB..0x311].try_into().ok()?,
secret: payload[0x311..0x329].try_into().ok()?,
_opaque_trailer: payload[0x329..0x35A].try_into().ok()?,
_padding: Default::default(),
})
}
+3
View File
@@ -19,8 +19,11 @@ pub struct RawCard {
pub packed_card_text: [u8; 54],
pub secret: [u8; 24],
pub _opaque_trailer: [u8; 49],
pub _padding: [u8; 2],
}
static_assertions::const_assert!(RawCard::SERIALIZED_SIZE.is_multiple_of(4));
#[derive(Debug, Clone, Eq, PartialEq, FromPrimitive)]
#[repr(u8)]
pub enum CardType {
+11 -10
View File
@@ -17,6 +17,17 @@ const COUNT_REGION: MemoryRegion = MemoryRegion {
size: size_of::<u32>(),
};
const ALLOCATION_TABLE_REGION: MemoryRegion = MemoryRegion {
offset: COUNT_REGION.end() as u32,
size: MAX_CARDS * AllocationTableEntry::SERIALIZED_SIZE,
};
const CARDS_REGION: MemoryRegion = MemoryRegion {
offset: ALLOCATION_TABLE_REGION.end() as u32,
size: CARDSTORE_REGION.size - ALLOCATION_TABLE_REGION.end(),
};
#[derive(Debug, BinarySerde, PartialEq, Eq, Clone)]
#[repr(C)]
pub struct AllocationTableEntry {
@@ -52,16 +63,6 @@ impl AllocationTableEntry {
}
}
const ALLOCATION_TABLE_REGION: MemoryRegion = MemoryRegion {
offset: COUNT_REGION.end() as u32,
size: MAX_CARDS * AllocationTableEntry::SERIALIZED_SIZE,
};
const CARDS_REGION: MemoryRegion = MemoryRegion {
offset: ALLOCATION_TABLE_REGION.end() as u32,
size: CARDSTORE_REGION.size - ALLOCATION_TABLE_REGION.end(),
};
#[derive(Debug)]
pub enum CardStoreError {
Store(StoreError),
+1
View File
@@ -39,6 +39,7 @@ impl Store {
}
pub fn write(&mut self, offset: u32, bytes: &mut [u8]) -> Result<(), StoreError> {
log::debug!("Writing {} bytes at offset 0x{offset:08x}", bytes.len());
self.storage.write(FLASH_ADDR + offset, bytes)
}
}