diff options
| -rw-r--r-- | embassy-boot/boot/src/lib.rs | 3 | ||||
| -rw-r--r-- | embassy-boot/boot/src/partition.rs | 46 |
2 files changed, 48 insertions, 1 deletions
diff --git a/embassy-boot/boot/src/lib.rs b/embassy-boot/boot/src/lib.rs index a2259411f..4c28d7aa4 100644 --- a/embassy-boot/boot/src/lib.rs +++ b/embassy-boot/boot/src/lib.rs | |||
| @@ -313,7 +313,8 @@ mod tests { | |||
| 313 | )) | 313 | )) |
| 314 | .is_ok()); | 314 | .is_ok()); |
| 315 | } | 315 | } |
| 316 | struct MemFlash<const SIZE: usize, const ERASE_SIZE: usize, const WRITE_SIZE: usize>([u8; SIZE]); | 316 | |
| 317 | pub struct MemFlash<const SIZE: usize, const ERASE_SIZE: usize, const WRITE_SIZE: usize>(pub [u8; SIZE]); | ||
| 317 | 318 | ||
| 318 | impl<const SIZE: usize, const ERASE_SIZE: usize, const WRITE_SIZE: usize> NorFlash | 319 | impl<const SIZE: usize, const ERASE_SIZE: usize, const WRITE_SIZE: usize> NorFlash |
| 319 | for MemFlash<SIZE, ERASE_SIZE, WRITE_SIZE> | 320 | for MemFlash<SIZE, ERASE_SIZE, WRITE_SIZE> |
diff --git a/embassy-boot/boot/src/partition.rs b/embassy-boot/boot/src/partition.rs index 9918fb836..3ccd4dd76 100644 --- a/embassy-boot/boot/src/partition.rs +++ b/embassy-boot/boot/src/partition.rs | |||
| @@ -102,3 +102,49 @@ impl Partition { | |||
| 102 | Ok(()) | 102 | Ok(()) |
| 103 | } | 103 | } |
| 104 | } | 104 | } |
| 105 | |||
| 106 | #[cfg(test)] | ||
| 107 | mod tests { | ||
| 108 | use crate::tests::MemFlash; | ||
| 109 | use crate::Partition; | ||
| 110 | |||
| 111 | #[test] | ||
| 112 | fn can_erase() { | ||
| 113 | let mut flash = MemFlash::<1024, 64, 4>([0x00; 1024]); | ||
| 114 | let partition = Partition::new(256, 512); | ||
| 115 | |||
| 116 | partition.erase_blocking(&mut flash, 64, 192).unwrap(); | ||
| 117 | |||
| 118 | for (index, byte) in flash.0.iter().copied().enumerate().take(256 + 64) { | ||
| 119 | assert_eq!(0x00, byte, "Index {}", index); | ||
| 120 | } | ||
| 121 | |||
| 122 | for (index, byte) in flash.0.iter().copied().enumerate().skip(256 + 64).take(128) { | ||
| 123 | assert_eq!(0xFF, byte, "Index {}", index); | ||
| 124 | } | ||
| 125 | |||
| 126 | for (index, byte) in flash.0.iter().copied().enumerate().skip(256 + 64 + 128) { | ||
| 127 | assert_eq!(0x00, byte, "Index {}", index); | ||
| 128 | } | ||
| 129 | } | ||
| 130 | |||
| 131 | #[test] | ||
| 132 | fn can_wipe() { | ||
| 133 | let mut flash = MemFlash::<1024, 64, 4>([0x00; 1024]); | ||
| 134 | let partition = Partition::new(256, 512); | ||
| 135 | |||
| 136 | partition.wipe_blocking(&mut flash).unwrap(); | ||
| 137 | |||
| 138 | for (index, byte) in flash.0.iter().copied().enumerate().take(256) { | ||
| 139 | assert_eq!(0x00, byte, "Index {}", index); | ||
| 140 | } | ||
| 141 | |||
| 142 | for (index, byte) in flash.0.iter().copied().enumerate().skip(256).take(256) { | ||
| 143 | assert_eq!(0xFF, byte, "Index {}", index); | ||
| 144 | } | ||
| 145 | |||
| 146 | for (index, byte) in flash.0.iter().copied().enumerate().skip(512) { | ||
| 147 | assert_eq!(0x00, byte, "Index {}", index); | ||
| 148 | } | ||
| 149 | } | ||
| 150 | } | ||
