Merge #957
957: Take into account size of revert index r=lulf a=lulf 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. Co-authored-by: Ulf Lilleengen <ulf.lilleengen@gmail.com>
This commit is contained in:
commit
44d7a84e47
1 changed files with 17 additions and 4 deletions
|
@ -222,10 +222,7 @@ impl BootLoader {
|
||||||
page: &mut [u8],
|
page: &mut [u8],
|
||||||
) -> Result<State, BootError> {
|
) -> Result<State, BootError> {
|
||||||
// Ensure we have enough progress pages to store copy progress
|
// Ensure we have enough progress pages to store copy progress
|
||||||
assert_eq!(self.active.len() % page.len(), 0);
|
assert_partitions(self.active, self.dfu, self.state, page.len(), P::STATE::WRITE_SIZE);
|
||||||
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_eq!(magic.len(), P::STATE::WRITE_SIZE);
|
assert_eq!(magic.len(), P::STATE::WRITE_SIZE);
|
||||||
|
|
||||||
// Copy contents from partition N to active
|
// 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.
|
/// Convenience provider that uses a single flash for all partitions.
|
||||||
pub struct SingleFlashConfig<'a, F>
|
pub struct SingleFlashConfig<'a, F>
|
||||||
where
|
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]);
|
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
|
impl<const SIZE: usize, const ERASE_SIZE: usize, const WRITE_SIZE: usize> NorFlash
|
||||||
|
|
Loading…
Reference in a new issue