aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2022-03-31 13:24:25 +0000
committerGitHub <[email protected]>2022-03-31 13:24:25 +0000
commita9e63167e1ec230ca3d28da771378f5f4936a840 (patch)
treebd20dd1db14380f7800e9aeda12d77ae3669d079
parentf028b0064b1ccb8846bfbbb670d1b647b8c7c1cc (diff)
parentb0a53610ba935379320c4ace5f6a4557de04e810 (diff)
Merge #689
689: Avoid writing bootloader flash if not needed r=lulf a=lulf bors r+ Co-authored-by: Ulf Lilleengen <[email protected]>
-rw-r--r--embassy-boot/boot/src/lib.rs60
1 files changed, 36 insertions, 24 deletions
diff --git a/embassy-boot/boot/src/lib.rs b/embassy-boot/boot/src/lib.rs
index f58432410..6f31e280d 100644
--- a/embassy-boot/boot/src/lib.rs
+++ b/embassy-boot/boot/src/lib.rs
@@ -318,21 +318,27 @@ impl FirmwareUpdater {
318 #[repr(align(4))] 318 #[repr(align(4))]
319 struct Aligned([u8; 4]); 319 struct Aligned([u8; 4]);
320 320
321 flash 321 let mut magic = Aligned([0; 4]);
322 .write(self.state.from as u32, &Aligned([0; 4]).0) 322 flash.read(self.state.from as u32, &mut magic.0).await?;
323 .await?; 323 let magic = u32::from_le_bytes(magic.0);
324 flash 324
325 .erase(self.state.from as u32, self.state.to as u32) 325 if magic != SWAP_MAGIC {
326 .await?; 326 flash
327 trace!( 327 .write(self.state.from as u32, &Aligned([0; 4]).0)
328 "Setting swap magic at {} to 0x{:x}, LE: 0x{:x}", 328 .await?;
329 self.state.from, 329 flash
330 &SWAP_MAGIC, 330 .erase(self.state.from as u32, self.state.to as u32)
331 &SWAP_MAGIC.to_le_bytes() 331 .await?;
332 ); 332 trace!(
333 flash 333 "Setting swap magic at {} to 0x{:x}, LE: 0x{:x}",
334 .write(self.state.from as u32, &SWAP_MAGIC.to_le_bytes()) 334 self.state.from,
335 .await?; 335 &SWAP_MAGIC,
336 &SWAP_MAGIC.to_le_bytes()
337 );
338 flash
339 .write(self.state.from as u32, &SWAP_MAGIC.to_le_bytes())
340 .await?;
341 }
336 Ok(()) 342 Ok(())
337 } 343 }
338 344
@@ -341,15 +347,21 @@ impl FirmwareUpdater {
341 #[repr(align(4))] 347 #[repr(align(4))]
342 struct Aligned([u8; 4]); 348 struct Aligned([u8; 4]);
343 349
344 flash 350 let mut magic = Aligned([0; 4]);
345 .write(self.state.from as u32, &Aligned([0; 4]).0) 351 flash.read(self.state.from as u32, &mut magic.0).await?;
346 .await?; 352 let magic = u32::from_le_bytes(magic.0);
347 flash 353
348 .erase(self.state.from as u32, self.state.to as u32) 354 if magic != BOOT_MAGIC {
349 .await?; 355 flash
350 flash 356 .write(self.state.from as u32, &Aligned([0; 4]).0)
351 .write(self.state.from as u32, &BOOT_MAGIC.to_le_bytes()) 357 .await?;
352 .await?; 358 flash
359 .erase(self.state.from as u32, self.state.to as u32)
360 .await?;
361 flash
362 .write(self.state.from as u32, &BOOT_MAGIC.to_le_bytes())
363 .await?;
364 }
353 Ok(()) 365 Ok(())
354 } 366 }
355 367