diff options
| author | Badr Bouslikhin <[email protected]> | 2024-02-12 23:28:04 +0100 |
|---|---|---|
| committer | Badr Bouslikhin <[email protected]> | 2024-02-12 23:28:04 +0100 |
| commit | 7dd974aa0dd88ad319971b81083f63a190d278bf (patch) | |
| tree | dee620d6c74c20a6bd82d7086ccbbe2c3cf5fc12 /embassy-boot/src/firmware_updater/blocking.rs | |
| parent | 56e6b6bee6bd6087b35857e8aa1a011f6e83f703 (diff) | |
refactor(boot): use sector instead of page for consistency
Diffstat (limited to 'embassy-boot/src/firmware_updater/blocking.rs')
| -rw-r--r-- | embassy-boot/src/firmware_updater/blocking.rs | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/embassy-boot/src/firmware_updater/blocking.rs b/embassy-boot/src/firmware_updater/blocking.rs index eb96a9523..35772a856 100644 --- a/embassy-boot/src/firmware_updater/blocking.rs +++ b/embassy-boot/src/firmware_updater/blocking.rs | |||
| @@ -13,7 +13,7 @@ use crate::{FirmwareUpdaterError, State, BOOT_MAGIC, DFU_DETACH_MAGIC, STATE_ERA | |||
| 13 | pub struct BlockingFirmwareUpdater<'d, DFU: NorFlash, STATE: NorFlash> { | 13 | pub struct BlockingFirmwareUpdater<'d, DFU: NorFlash, STATE: NorFlash> { |
| 14 | dfu: DFU, | 14 | dfu: DFU, |
| 15 | state: BlockingFirmwareState<'d, STATE>, | 15 | state: BlockingFirmwareState<'d, STATE>, |
| 16 | last_erased_dfu_page_index: Option<usize>, | 16 | last_erased_dfu_sector_index: Option<usize>, |
| 17 | } | 17 | } |
| 18 | 18 | ||
| 19 | #[cfg(target_os = "none")] | 19 | #[cfg(target_os = "none")] |
| @@ -92,7 +92,7 @@ impl<'d, DFU: NorFlash, STATE: NorFlash> BlockingFirmwareUpdater<'d, DFU, STATE> | |||
| 92 | Self { | 92 | Self { |
| 93 | dfu: config.dfu, | 93 | dfu: config.dfu, |
| 94 | state: BlockingFirmwareState::new(config.state, aligned), | 94 | state: BlockingFirmwareState::new(config.state, aligned), |
| 95 | last_erased_dfu_page_index: None, | 95 | last_erased_dfu_sector_index: None, |
| 96 | } | 96 | } |
| 97 | } | 97 | } |
| 98 | 98 | ||
| @@ -215,7 +215,7 @@ impl<'d, DFU: NorFlash, STATE: NorFlash> BlockingFirmwareUpdater<'d, DFU, STATE> | |||
| 215 | /// It handles sector erasures and data writes while verifying the device is in a proper state | 215 | /// It handles sector erasures and data writes while verifying the device is in a proper state |
| 216 | /// for firmware updates. The function ensures that only unerased sectors are erased before | 216 | /// for firmware updates. The function ensures that only unerased sectors are erased before |
| 217 | /// writing and efficiently handles the writing process across sector boundaries and in | 217 | /// writing and efficiently handles the writing process across sector boundaries and in |
| 218 | /// various configurations (data size, page size, etc.). | 218 | /// various configurations (data size, sector size, etc.). |
| 219 | /// | 219 | /// |
| 220 | /// # Arguments | 220 | /// # Arguments |
| 221 | /// | 221 | /// |
| @@ -250,13 +250,13 @@ impl<'d, DFU: NorFlash, STATE: NorFlash> BlockingFirmwareUpdater<'d, DFU, STATE> | |||
| 250 | let sector_end = sector_start + DFU::ERASE_SIZE; | 250 | let sector_end = sector_start + DFU::ERASE_SIZE; |
| 251 | // Determine if the current sector needs to be erased before writing. | 251 | // Determine if the current sector needs to be erased before writing. |
| 252 | let need_erase = self | 252 | let need_erase = self |
| 253 | .last_erased_dfu_page_index | 253 | .last_erased_dfu_sector_index |
| 254 | .map_or(true, |last_erased_sector| current_sector != last_erased_sector); | 254 | .map_or(true, |last_erased_sector| current_sector != last_erased_sector); |
| 255 | 255 | ||
| 256 | // If the sector needs to be erased, erase it and update the last erased sector index. | 256 | // If the sector needs to be erased, erase it and update the last erased sector index. |
| 257 | if need_erase { | 257 | if need_erase { |
| 258 | self.dfu.erase(sector_start as u32, sector_end as u32)?; | 258 | self.dfu.erase(sector_start as u32, sector_end as u32)?; |
| 259 | self.last_erased_dfu_page_index = Some(current_sector); | 259 | self.last_erased_dfu_sector_index = Some(current_sector); |
| 260 | } | 260 | } |
| 261 | 261 | ||
| 262 | // Calculate the size of the data chunk that can be written in the current iteration. | 262 | // Calculate the size of the data chunk that can be written in the current iteration. |
| @@ -420,7 +420,7 @@ mod tests { | |||
| 420 | } | 420 | } |
| 421 | 421 | ||
| 422 | #[test] | 422 | #[test] |
| 423 | fn can_verify_sha1_page_bigger_than_chunk() { | 423 | fn can_verify_sha1_sector_bigger_than_chunk() { |
| 424 | let flash = Mutex::<NoopRawMutex, _>::new(RefCell::new(MemFlash::<131072, 4096, 8>::default())); | 424 | let flash = Mutex::<NoopRawMutex, _>::new(RefCell::new(MemFlash::<131072, 4096, 8>::default())); |
| 425 | let state = BlockingPartition::new(&flash, 0, 4096); | 425 | let state = BlockingPartition::new(&flash, 0, 4096); |
| 426 | let dfu = BlockingPartition::new(&flash, 65536, 65536); | 426 | let dfu = BlockingPartition::new(&flash, 65536, 65536); |
| @@ -446,7 +446,7 @@ mod tests { | |||
| 446 | } | 446 | } |
| 447 | 447 | ||
| 448 | #[test] | 448 | #[test] |
| 449 | fn can_verify_sha1_page_smaller_than_chunk() { | 449 | fn can_verify_sha1_sector_smaller_than_chunk() { |
| 450 | let flash = Mutex::<NoopRawMutex, _>::new(RefCell::new(MemFlash::<131072, 1024, 8>::default())); | 450 | let flash = Mutex::<NoopRawMutex, _>::new(RefCell::new(MemFlash::<131072, 1024, 8>::default())); |
| 451 | let state = BlockingPartition::new(&flash, 0, 4096); | 451 | let state = BlockingPartition::new(&flash, 0, 4096); |
| 452 | let dfu = BlockingPartition::new(&flash, 65536, 65536); | 452 | let dfu = BlockingPartition::new(&flash, 65536, 65536); |
| @@ -472,7 +472,7 @@ mod tests { | |||
| 472 | } | 472 | } |
| 473 | 473 | ||
| 474 | #[test] | 474 | #[test] |
| 475 | fn can_verify_sha1_cross_page_boundary() { | 475 | fn can_verify_sha1_cross_sector_boundary() { |
| 476 | let flash = Mutex::<NoopRawMutex, _>::new(RefCell::new(MemFlash::<131072, 1024, 8>::default())); | 476 | let flash = Mutex::<NoopRawMutex, _>::new(RefCell::new(MemFlash::<131072, 1024, 8>::default())); |
| 477 | let state = BlockingPartition::new(&flash, 0, 4096); | 477 | let state = BlockingPartition::new(&flash, 0, 4096); |
| 478 | let dfu = BlockingPartition::new(&flash, 65536, 65536); | 478 | let dfu = BlockingPartition::new(&flash, 65536, 65536); |
