aboutsummaryrefslogtreecommitdiff
path: root/embassy-boot/boot/src/lib.rs
diff options
context:
space:
mode:
authorUlf Lilleengen <[email protected]>2022-09-20 14:03:04 +0200
committerUlf Lilleengen <[email protected]>2022-09-20 14:04:57 +0200
commitb418c0e4d620db0332d02c16fbbd455e7b8805a9 (patch)
treeb80d1b64cce947054100e559bb34a170828e3c40 /embassy-boot/boot/src/lib.rs
parent11da25800bce338e39082e9d35b1af8db3e5875d (diff)
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/boot/src/lib.rs')
-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 015dd58db..3d359533e 100644
--- a/embassy-boot/boot/src/lib.rs
+++ b/embassy-boot/boot/src/lib.rs
@@ -222,10 +222,7 @@ impl BootLoader {
222 page: &mut [u8], 222 page: &mut [u8],
223 ) -> Result<State, BootError> { 223 ) -> Result<State, BootError> {
224 // Ensure we have enough progress pages to store copy progress 224 // Ensure we have enough progress pages to store copy progress
225 assert_eq!(self.active.len() % page.len(), 0); 225 assert_partitions(self.active, self.dfu, self.state, page.len(), P::STATE::WRITE_SIZE);
226 assert_eq!(self.dfu.len() % page.len(), 0);
227 assert!(self.dfu.len() - self.active.len() >= page.len());
228 assert!(self.active.len() / page.len() <= (self.state.len() - P::STATE::WRITE_SIZE) / P::STATE::WRITE_SIZE);
229 assert_eq!(magic.len(), P::STATE::WRITE_SIZE); 226 assert_eq!(magic.len(), P::STATE::WRITE_SIZE);
230 227
231 // Copy contents from partition N to active 228 // Copy contents from partition N to active
@@ -409,6 +406,13 @@ impl BootLoader {
409 } 406 }
410} 407}
411 408
409fn assert_partitions(active: Partition, dfu: Partition, state: Partition, page_size: usize, write_size: usize) {
410 assert_eq!(active.len() % page_size, 0);
411 assert_eq!(dfu.len() % page_size, 0);
412 assert!(dfu.len() - active.len() >= page_size);
413 assert!(2 * (active.len() / page_size) <= (state.len() - write_size) / write_size);
414}
415
412/// Convenience provider that uses a single flash for all partitions. 416/// Convenience provider that uses a single flash for all partitions.
413pub struct SingleFlashConfig<'a, F> 417pub struct SingleFlashConfig<'a, F>
414where 418where
@@ -919,6 +923,15 @@ mod tests {
919 } 923 }
920 } 924 }
921 925
926 #[test]
927 #[should_panic]
928 fn test_range_asserts() {
929 const ACTIVE: Partition = Partition::new(4096, 4194304);
930 const DFU: Partition = Partition::new(4194304, 2 * 4194304);
931 const STATE: Partition = Partition::new(0, 4096);
932 assert_partitions(ACTIVE, DFU, STATE, 4096, 4);
933 }
934
922 struct MemFlash<const SIZE: usize, const ERASE_SIZE: usize, const WRITE_SIZE: usize>([u8; SIZE]); 935 struct MemFlash<const SIZE: usize, const ERASE_SIZE: usize, const WRITE_SIZE: usize>([u8; SIZE]);
923 936
924 impl<const SIZE: usize, const ERASE_SIZE: usize, const WRITE_SIZE: usize> NorFlash 937 impl<const SIZE: usize, const ERASE_SIZE: usize, const WRITE_SIZE: usize> NorFlash