firmware_techo/
proto_store.rs

1//! Protocol snapshot / identity / counter journals: shared machinery
2//! from `umsh-journal-store`, plus this firmware's flash placement.
3//!
4//! The record codec and its power-cut tests live in the crate; only the
5//! journal page chain — a `memory.x` fact — is decided here.
6
7pub use umsh_journal_store::proto::*;
8pub use umsh_journal_store::record::PAGE_SIZE;
9
10use super::ble_store;
11
12/// Flash pages owned by the snapshot journal: the two 4 KB pages
13/// immediately after the BLE store's, inside the NV storage region
14/// (0x000E_4000..0x000F_4000; see `memory.x`).
15pub const PAGE0: u32 = ble_store::PAGE1 + PAGE_SIZE;
16pub const PAGE1: u32 = PAGE0 + PAGE_SIZE;
17
18/// Flash pages owned by the device-identity journal: the next two
19/// pages. The identity is persisted the moment it is installed or
20/// generated, independently of snapshots (spec §PROP_DEV_PRIVATE_KEY),
21/// so it gets a journal of its own: snapshot saves can never rotate
22/// the identity record away, and each journal clears atomically with
23/// one committed tombstone.
24pub const IDENTITY_PAGE0: u32 = PAGE1 + PAGE_SIZE;
25/// T-1000E user-facing Sleep/Silence preference journal. The shared T-Echo
26/// image does not use it, but reserving it here keeps the flash map explicit.
27pub const UX_PAGE0: u32 = IDENTITY_PAGE0 + 2 * PAGE_SIZE;
28/// Device-node frame-counter journal (device-node plan increment 4):
29/// the persisted TX reservation boundary for the device identity and
30/// RX replay boundaries for its peers, batch-written as one
31/// `counter_map` payload per flush. Separate journal because its write
32/// cadence (every `COUNTER_PERSIST_BLOCK_SIZE` secured frames) must
33/// never rotate a snapshot or the identity record away.
34pub const COUNTER_PAGE0: u32 = UX_PAGE0 + 2 * PAGE_SIZE;
35
36#[cfg(test)]
37mod tests {
38    use super::*;
39
40    /// The journal chain stays inside the reserved NV region
41    /// (0x000E_4000..0x000F_4000; see `memory.x`).
42    #[test]
43    fn journal_pages_stay_in_the_nv_region() {
44        assert_eq!(ble_store::PAGE0, 0x000E_4000);
45        assert_eq!(PAGE0, 0x000E_6000);
46        assert_eq!(IDENTITY_PAGE0, 0x000E_8000);
47        assert_eq!(UX_PAGE0, 0x000E_A000);
48        assert_eq!(COUNTER_PAGE0, 0x000E_C000);
49        assert!(COUNTER_PAGE0 + 2 * PAGE_SIZE <= 0x000F_4000);
50    }
51}