summaryrefslogtreecommitdiff
path: root/embassy-boot
diff options
context:
space:
mode:
authorUlf Lilleengen <ulf.lilleengen@gmail.com>2022-09-20 14:03:04 +0200
committerUlf Lilleengen <ulf.lilleengen@gmail.com>2022-09-20 14:04:57 +0200
commitb418c0e4d620db0332d02c16fbbd455e7b8805a9 (patch)
treeb80d1b64cce947054100e559bb34a170828e3c40 /embassy-boot
parent11da25800bce338e39082e9d35b1af8db3e5875d (diff)
downloadembassy-b418c0e4d620db0332d02c16fbbd455e7b8805a9.zip
Take into account size of revert index
Fixes a bug in the partition assertions that ensures that the state page(s) have enough space for 2x active partition range. Add unit test to verify that panic is observed.
Diffstat (limited to 'embassy-boot')
-rw-r--r--embassy-boot/boot/src/lib.rs21
1 files changed, 17 insertions, 4 deletions
diff --git a/embassy-boot/boot/src/lib.rs b/embassy-boot/boot/src/lib.rs
index 015dd58d..3d359533 100644
--- a/embassy-boot/boot/src/lib.rs
+++ b/embassy-boot/boot/src/lib.rs
@@ -222,10 +222,7 @@ impl BootLoader {
page: &mut [u8],
) -> Result<State, BootError> {
// Ensure we have enough progress pages to store copy progress
- assert_eq!(self.active.len() % page.len(), 0);
- assert_eq!(self.dfu.len() % page.len(), 0);
- assert!(self.dfu.len() - self.active.len() >= page.len());
- assert!(self.active.len() / page.len() <= (self.state.len() - P::STATE::WRITE_SIZE) / P::STATE::WRITE_SIZE);
+ assert_partitions(self.active, self.dfu, self.state, page.len(), P::STATE::WRITE_SIZE);
assert_eq!(magic.len(), P::STATE::WRITE_SIZE);
// Copy contents from partition N to active
@@ -409,6 +406,13 @@ impl BootLoader {
}
}
+fn assert_partitions(active: Partition, dfu: Partition, state: Partition, page_size: usize, write_size: usize) {
+ assert_eq!(active.len() % page_size, 0);
+ assert_eq!(dfu.len() % page_size, 0);
+ assert!(dfu.len() - active.len() >= page_size);
+ assert!(2 * (active.len() / page_size) <= (state.len() - write_size) / write_size);
+}
+
/// Convenience provider that uses a single flash for all partitions.
pub struct SingleFlashConfig<'a, F>
where
@@ -919,6 +923,15 @@ mod tests {
}
}
+ #[test]
+ #[should_panic]
+ fn test_range_asserts() {
+ const ACTIVE: Partition = Partition::new(4096, 4194304);
+ const DFU: Partition = Partition::new(4194304, 2 * 4194304);
+ const STATE: Partition = Partition::new(0, 4096);
+ assert_partitions(ACTIVE, DFU, STATE, 4096, 4);
+ }
+
struct MemFlash<const SIZE: usize, const ERASE_SIZE: usize, const WRITE_SIZE: usize>([u8; SIZE]);
impl<const SIZE: usize, const ERASE_SIZE: usize, const WRITE_SIZE: usize> NorFlash