diff options
| author | Ulf Lilleengen <[email protected]> | 2022-03-22 12:52:47 +0100 |
|---|---|---|
| committer | Ulf Lilleengen <[email protected]> | 2022-03-22 14:43:17 +0100 |
| commit | 73012ed40e20ebcd82aa0243d8914098384911a6 (patch) | |
| tree | 25dff09658f26e165c0526e05f15d9899b2410b7 /embassy-boot | |
| parent | 48f7d37e75213643afa69b551165e35915ee5e2d (diff) | |
Fix potential unaligned write
Reduce log level
Diffstat (limited to 'embassy-boot')
| -rw-r--r-- | embassy-boot/boot/src/lib.rs | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/embassy-boot/boot/src/lib.rs b/embassy-boot/boot/src/lib.rs index 909397b7b..f58432410 100644 --- a/embassy-boot/boot/src/lib.rs +++ b/embassy-boot/boot/src/lib.rs | |||
| @@ -315,11 +315,16 @@ impl FirmwareUpdater { | |||
| 315 | 315 | ||
| 316 | /// Instruct bootloader that DFU should commence at next boot. | 316 | /// Instruct bootloader that DFU should commence at next boot. |
| 317 | pub async fn mark_update<F: AsyncNorFlash>(&mut self, flash: &mut F) -> Result<(), F::Error> { | 317 | pub async fn mark_update<F: AsyncNorFlash>(&mut self, flash: &mut F) -> Result<(), F::Error> { |
| 318 | flash.write(self.state.from as u32, &[0, 0, 0, 0]).await?; | 318 | #[repr(align(4))] |
| 319 | struct Aligned([u8; 4]); | ||
| 320 | |||
| 321 | flash | ||
| 322 | .write(self.state.from as u32, &Aligned([0; 4]).0) | ||
| 323 | .await?; | ||
| 319 | flash | 324 | flash |
| 320 | .erase(self.state.from as u32, self.state.to as u32) | 325 | .erase(self.state.from as u32, self.state.to as u32) |
| 321 | .await?; | 326 | .await?; |
| 322 | info!( | 327 | trace!( |
| 323 | "Setting swap magic at {} to 0x{:x}, LE: 0x{:x}", | 328 | "Setting swap magic at {} to 0x{:x}, LE: 0x{:x}", |
| 324 | self.state.from, | 329 | self.state.from, |
| 325 | &SWAP_MAGIC, | 330 | &SWAP_MAGIC, |
| @@ -333,7 +338,12 @@ impl FirmwareUpdater { | |||
| 333 | 338 | ||
| 334 | /// Mark firmware boot successfully | 339 | /// Mark firmware boot successfully |
| 335 | pub async fn mark_booted<F: AsyncNorFlash>(&mut self, flash: &mut F) -> Result<(), F::Error> { | 340 | pub async fn mark_booted<F: AsyncNorFlash>(&mut self, flash: &mut F) -> Result<(), F::Error> { |
| 336 | flash.write(self.state.from as u32, &[0, 0, 0, 0]).await?; | 341 | #[repr(align(4))] |
| 342 | struct Aligned([u8; 4]); | ||
| 343 | |||
| 344 | flash | ||
| 345 | .write(self.state.from as u32, &Aligned([0; 4]).0) | ||
| 346 | .await?; | ||
| 337 | flash | 347 | flash |
| 338 | .erase(self.state.from as u32, self.state.to as u32) | 348 | .erase(self.state.from as u32, self.state.to as u32) |
| 339 | .await?; | 349 | .await?; |
| @@ -350,7 +360,7 @@ impl FirmwareUpdater { | |||
| 350 | data: &[u8], | 360 | data: &[u8], |
| 351 | flash: &mut F, | 361 | flash: &mut F, |
| 352 | ) -> Result<(), F::Error> { | 362 | ) -> Result<(), F::Error> { |
| 353 | info!( | 363 | trace!( |
| 354 | "Writing firmware at offset 0x{:x} len {}", | 364 | "Writing firmware at offset 0x{:x} len {}", |
| 355 | self.dfu.from + offset, | 365 | self.dfu.from + offset, |
| 356 | data.len() | 366 | data.len() |
