From 7dd974aa0dd88ad319971b81083f63a190d278bf Mon Sep 17 00:00:00 2001 From: Badr Bouslikhin Date: Mon, 12 Feb 2024 23:28:04 +0100 Subject: [PATCH] refactor(boot): use sector instead of page for consistency --- embassy-boot/src/firmware_updater/asynch.rs | 16 ++++++++-------- embassy-boot/src/firmware_updater/blocking.rs | 16 ++++++++-------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/embassy-boot/src/firmware_updater/asynch.rs b/embassy-boot/src/firmware_updater/asynch.rs index b76668136..3d211be65 100644 --- a/embassy-boot/src/firmware_updater/asynch.rs +++ b/embassy-boot/src/firmware_updater/asynch.rs @@ -13,7 +13,7 @@ use crate::{FirmwareUpdaterError, State, BOOT_MAGIC, DFU_DETACH_MAGIC, STATE_ERA pub struct FirmwareUpdater<'d, DFU: NorFlash, STATE: NorFlash> { dfu: DFU, state: FirmwareState<'d, STATE>, - last_erased_dfu_page_index: Option, + last_erased_dfu_sector_index: Option, } #[cfg(target_os = "none")] @@ -57,7 +57,7 @@ impl<'d, DFU: NorFlash, STATE: NorFlash> FirmwareUpdater<'d, DFU, STATE> { Self { dfu: config.dfu, state: FirmwareState::new(config.state, aligned), - last_erased_dfu_page_index: None, + last_erased_dfu_sector_index: None, } } @@ -180,7 +180,7 @@ impl<'d, DFU: NorFlash, STATE: NorFlash> FirmwareUpdater<'d, DFU, STATE> { /// It handles sector erasures and data writes while verifying the device is in a proper state /// for firmware updates. The function ensures that only unerased sectors are erased before /// writing and efficiently handles the writing process across sector boundaries and in - /// various configurations (data size, page size, etc.). + /// various configurations (data size, sector size, etc.). /// /// # Arguments /// @@ -215,13 +215,13 @@ impl<'d, DFU: NorFlash, STATE: NorFlash> FirmwareUpdater<'d, DFU, STATE> { let sector_end = sector_start + DFU::ERASE_SIZE; // Determine if the current sector needs to be erased before writing. let need_erase = self - .last_erased_dfu_page_index + .last_erased_dfu_sector_index .map_or(true, |last_erased_sector| current_sector != last_erased_sector); // If the sector needs to be erased, erase it and update the last erased sector index. if need_erase { self.dfu.erase(sector_start as u32, sector_end as u32).await?; - self.last_erased_dfu_page_index = Some(current_sector); + self.last_erased_dfu_sector_index = Some(current_sector); } // Calculate the size of the data chunk that can be written in the current iteration. @@ -380,7 +380,7 @@ mod tests { } #[test] - fn can_verify_sha1_page_bigger_than_chunk() { + fn can_verify_sha1_sector_bigger_than_chunk() { let flash = Mutex::::new(MemFlash::<131072, 4096, 8>::default()); let state = Partition::new(&flash, 0, 4096); let dfu = Partition::new(&flash, 65536, 65536); @@ -404,7 +404,7 @@ mod tests { } #[test] - fn can_verify_sha1_page_smaller_than_chunk() { + fn can_verify_sha1_sector_smaller_than_chunk() { let flash = Mutex::::new(MemFlash::<131072, 1024, 8>::default()); let state = Partition::new(&flash, 0, 4096); let dfu = Partition::new(&flash, 65536, 65536); @@ -428,7 +428,7 @@ mod tests { } #[test] - fn can_verify_sha1_cross_page_boundary() { + fn can_verify_sha1_cross_sector_boundary() { let flash = Mutex::::new(MemFlash::<131072, 1024, 8>::default()); let state = Partition::new(&flash, 0, 4096); let dfu = Partition::new(&flash, 65536, 65536); 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 pub struct BlockingFirmwareUpdater<'d, DFU: NorFlash, STATE: NorFlash> { dfu: DFU, state: BlockingFirmwareState<'d, STATE>, - last_erased_dfu_page_index: Option, + last_erased_dfu_sector_index: Option, } #[cfg(target_os = "none")] @@ -92,7 +92,7 @@ impl<'d, DFU: NorFlash, STATE: NorFlash> BlockingFirmwareUpdater<'d, DFU, STATE> Self { dfu: config.dfu, state: BlockingFirmwareState::new(config.state, aligned), - last_erased_dfu_page_index: None, + last_erased_dfu_sector_index: None, } } @@ -215,7 +215,7 @@ impl<'d, DFU: NorFlash, STATE: NorFlash> BlockingFirmwareUpdater<'d, DFU, STATE> /// It handles sector erasures and data writes while verifying the device is in a proper state /// for firmware updates. The function ensures that only unerased sectors are erased before /// writing and efficiently handles the writing process across sector boundaries and in - /// various configurations (data size, page size, etc.). + /// various configurations (data size, sector size, etc.). /// /// # Arguments /// @@ -250,13 +250,13 @@ impl<'d, DFU: NorFlash, STATE: NorFlash> BlockingFirmwareUpdater<'d, DFU, STATE> let sector_end = sector_start + DFU::ERASE_SIZE; // Determine if the current sector needs to be erased before writing. let need_erase = self - .last_erased_dfu_page_index + .last_erased_dfu_sector_index .map_or(true, |last_erased_sector| current_sector != last_erased_sector); // If the sector needs to be erased, erase it and update the last erased sector index. if need_erase { self.dfu.erase(sector_start as u32, sector_end as u32)?; - self.last_erased_dfu_page_index = Some(current_sector); + self.last_erased_dfu_sector_index = Some(current_sector); } // Calculate the size of the data chunk that can be written in the current iteration. @@ -420,7 +420,7 @@ mod tests { } #[test] - fn can_verify_sha1_page_bigger_than_chunk() { + fn can_verify_sha1_sector_bigger_than_chunk() { let flash = Mutex::::new(RefCell::new(MemFlash::<131072, 4096, 8>::default())); let state = BlockingPartition::new(&flash, 0, 4096); let dfu = BlockingPartition::new(&flash, 65536, 65536); @@ -446,7 +446,7 @@ mod tests { } #[test] - fn can_verify_sha1_page_smaller_than_chunk() { + fn can_verify_sha1_sector_smaller_than_chunk() { let flash = Mutex::::new(RefCell::new(MemFlash::<131072, 1024, 8>::default())); let state = BlockingPartition::new(&flash, 0, 4096); let dfu = BlockingPartition::new(&flash, 65536, 65536); @@ -472,7 +472,7 @@ mod tests { } #[test] - fn can_verify_sha1_cross_page_boundary() { + fn can_verify_sha1_cross_sector_boundary() { let flash = Mutex::::new(RefCell::new(MemFlash::<131072, 1024, 8>::default())); let state = BlockingPartition::new(&flash, 0, 4096); let dfu = BlockingPartition::new(&flash, 65536, 65536);