diff options
Diffstat (limited to 'embassy-boot/boot/src/lib.rs')
| -rw-r--r-- | embassy-boot/boot/src/lib.rs | 21 |
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 | ||
| 409 | fn 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. |
| 413 | pub struct SingleFlashConfig<'a, F> | 417 | pub struct SingleFlashConfig<'a, F> |
| 414 | where | 418 | where |
| @@ -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 |
