Ensure RawCard size matches flash alignment requirements, add debug logs
This commit is contained in:
Generated
+1
@@ -376,6 +376,7 @@ dependencies = [
|
|||||||
"ndef",
|
"ndef",
|
||||||
"num_enum",
|
"num_enum",
|
||||||
"pn532",
|
"pn532",
|
||||||
|
"static_assertions",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ ch1115 = { version = "0.1.2", features = ["graphics"] }
|
|||||||
esp-storage = "0.9.0"
|
esp-storage = "0.9.0"
|
||||||
embedded-storage = "0.3.1"
|
embedded-storage = "0.3.1"
|
||||||
binary_serde = "1.0.25"
|
binary_serde = "1.0.25"
|
||||||
|
static_assertions = { version = "1.1.0", default-features = false }
|
||||||
|
|
||||||
|
|
||||||
[patch.crates-io]
|
[patch.crates-io]
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ pub fn split_nfc_hex(payload: &[u8]) -> Option<RawCard> {
|
|||||||
packed_card_text: payload[0x2DB..0x311].try_into().ok()?,
|
packed_card_text: payload[0x2DB..0x311].try_into().ok()?,
|
||||||
secret: payload[0x311..0x329].try_into().ok()?,
|
secret: payload[0x311..0x329].try_into().ok()?,
|
||||||
_opaque_trailer: payload[0x329..0x35A].try_into().ok()?,
|
_opaque_trailer: payload[0x329..0x35A].try_into().ok()?,
|
||||||
|
_padding: Default::default(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,8 +19,11 @@ pub struct RawCard {
|
|||||||
pub packed_card_text: [u8; 54],
|
pub packed_card_text: [u8; 54],
|
||||||
pub secret: [u8; 24],
|
pub secret: [u8; 24],
|
||||||
pub _opaque_trailer: [u8; 49],
|
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)]
|
#[derive(Debug, Clone, Eq, PartialEq, FromPrimitive)]
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
pub enum CardType {
|
pub enum CardType {
|
||||||
|
|||||||
+11
-10
@@ -17,6 +17,17 @@ const COUNT_REGION: MemoryRegion = MemoryRegion {
|
|||||||
size: size_of::<u32>(),
|
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)]
|
#[derive(Debug, BinarySerde, PartialEq, Eq, Clone)]
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub struct AllocationTableEntry {
|
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)]
|
#[derive(Debug)]
|
||||||
pub enum CardStoreError {
|
pub enum CardStoreError {
|
||||||
Store(StoreError),
|
Store(StoreError),
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ impl Store {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn write(&mut self, offset: u32, bytes: &mut [u8]) -> Result<(), StoreError> {
|
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)
|
self.storage.write(FLASH_ADDR + offset, bytes)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user