diff options
| author | Badr Bouslikhin <[email protected]> | 2024-02-07 16:40:24 +0100 |
|---|---|---|
| committer | Badr Bouslikhin <[email protected]> | 2024-02-07 16:40:24 +0100 |
| commit | 2e8b7d259057a0cf345396b250cacfc04a0e64a0 (patch) | |
| tree | d16b316b620047c5c792ac0932c851ee93869819 /embassy-boot/src | |
| parent | 2c5426aa5c41563f3b225d99d39793a765ec9204 (diff) | |
feat(boot): introduce non-erase flash write method
Diffstat (limited to 'embassy-boot/src')
| -rw-r--r-- | embassy-boot/src/firmware_updater/blocking.rs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/embassy-boot/src/firmware_updater/blocking.rs b/embassy-boot/src/firmware_updater/blocking.rs index f1368540d..514070639 100644 --- a/embassy-boot/src/firmware_updater/blocking.rs +++ b/embassy-boot/src/firmware_updater/blocking.rs | |||
| @@ -194,6 +194,41 @@ impl<'d, DFU: NorFlash, STATE: NorFlash> BlockingFirmwareUpdater<'d, DFU, STATE> | |||
| 194 | Ok(()) | 194 | Ok(()) |
| 195 | } | 195 | } |
| 196 | 196 | ||
| 197 | /// Write data directly to a flash page without erasing it first. | ||
| 198 | /// | ||
| 199 | /// This function writes the provided data to the specified offset in the flash memory, | ||
| 200 | /// without performing an erase operation beforehand. It is crucial that the area being | ||
| 201 | /// written to is either already erased. | ||
| 202 | /// This method is intended to be used in conjunction with the `prepare_update` method. | ||
| 203 | /// | ||
| 204 | /// The buffer must follow the alignment requirements of the target flash and be a multiple of | ||
| 205 | /// the page size. This is essential to ensure data integrity and prevent corruption. | ||
| 206 | /// | ||
| 207 | /// # Safety | ||
| 208 | /// | ||
| 209 | /// This function requires careful management of the memory being written to. Writing to a | ||
| 210 | /// non-erased page or not adhering to alignment and size requirements may result in a panic. | ||
| 211 | /// | ||
| 212 | /// Ensure that the data being written is compatible with the current contents of the flash | ||
| 213 | /// memory, as no erase operation will be performed to reset the page content to a default state. | ||
| 214 | /// | ||
| 215 | /// # Parameters | ||
| 216 | /// | ||
| 217 | /// - `offset`: The offset within the DFU partition where the data will be written. Must be | ||
| 218 | /// aligned according to the flash's requirements and within the writable memory range. | ||
| 219 | /// - `data`: A reference to the slice of bytes to be written. The length of the data must not | ||
| 220 | /// exceed the partition size and must follow the flash's alignment requirements. | ||
| 221 | /// | ||
| 222 | /// # Returns | ||
| 223 | /// | ||
| 224 | /// A result indicating the success or failure of the write operation. On success, returns `Ok(())`. | ||
| 225 | /// On failure, returns an `Err` with a `FirmwareUpdaterError` detailing the cause of the failure. | ||
| 226 | pub fn write_firmware_without_erase(&mut self, offset: usize, data: &[u8]) -> Result<(), FirmwareUpdaterError> { | ||
| 227 | self.dfu.write(offset as u32, data)?; | ||
| 228 | |||
| 229 | Ok(()) | ||
| 230 | } | ||
| 231 | |||
| 197 | /// Prepare for an incoming DFU update by erasing the entire DFU area and | 232 | /// Prepare for an incoming DFU update by erasing the entire DFU area and |
| 198 | /// returning its `Partition`. | 233 | /// returning its `Partition`. |
| 199 | /// | 234 | /// |
