diff options
author | Ulf Lilleengen <lulf@redhat.com> | 2022-03-22 12:52:47 +0100 |
---|---|---|
committer | Ulf Lilleengen <lulf@redhat.com> | 2022-03-22 14:43:17 +0100 |
commit | 73012ed40e20ebcd82aa0243d8914098384911a6 (patch) | |
tree | 25dff09658f26e165c0526e05f15d9899b2410b7 /embassy-boot | |
parent | 48f7d37e75213643afa69b551165e35915ee5e2d (diff) | |
download | embassy-73012ed40e20ebcd82aa0243d8914098384911a6.zip |
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 909397b7..f5843241 100644 --- a/embassy-boot/boot/src/lib.rs +++ b/embassy-boot/boot/src/lib.rs @@ -315,11 +315,16 @@ impl FirmwareUpdater { /// Instruct bootloader that DFU should commence at next boot. pub async fn mark_update<F: AsyncNorFlash>(&mut self, flash: &mut F) -> Result<(), F::Error> { - flash.write(self.state.from as u32, &[0, 0, 0, 0]).await?; + #[repr(align(4))] + struct Aligned([u8; 4]); + + flash + .write(self.state.from as u32, &Aligned([0; 4]).0) + .await?; flash .erase(self.state.from as u32, self.state.to as u32) .await?; - info!( + trace!( "Setting swap magic at {} to 0x{:x}, LE: 0x{:x}", self.state.from, &SWAP_MAGIC, @@ -333,7 +338,12 @@ impl FirmwareUpdater { /// Mark firmware boot successfully pub async fn mark_booted<F: AsyncNorFlash>(&mut self, flash: &mut F) -> Result<(), F::Error> { - flash.write(self.state.from as u32, &[0, 0, 0, 0]).await?; + #[repr(align(4))] + struct Aligned([u8; 4]); + + flash + .write(self.state.from as u32, &Aligned([0; 4]).0) + .await?; flash .erase(self.state.from as u32, self.state.to as u32) .await?; @@ -350,7 +360,7 @@ impl FirmwareUpdater { data: &[u8], flash: &mut F, ) -> Result<(), F::Error> { - info!( + trace!( "Writing firmware at offset 0x{:x} len {}", self.dfu.from + offset, data.len() |