Avoid writing bootloader flash if not needed
This commit is contained in:
parent
f028b0064b
commit
b0a53610ba
1 changed files with 36 additions and 24 deletions
|
@ -318,6 +318,11 @@ impl FirmwareUpdater {
|
||||||
#[repr(align(4))]
|
#[repr(align(4))]
|
||||||
struct Aligned([u8; 4]);
|
struct Aligned([u8; 4]);
|
||||||
|
|
||||||
|
let mut magic = Aligned([0; 4]);
|
||||||
|
flash.read(self.state.from as u32, &mut magic.0).await?;
|
||||||
|
let magic = u32::from_le_bytes(magic.0);
|
||||||
|
|
||||||
|
if magic != SWAP_MAGIC {
|
||||||
flash
|
flash
|
||||||
.write(self.state.from as u32, &Aligned([0; 4]).0)
|
.write(self.state.from as u32, &Aligned([0; 4]).0)
|
||||||
.await?;
|
.await?;
|
||||||
|
@ -333,6 +338,7 @@ impl FirmwareUpdater {
|
||||||
flash
|
flash
|
||||||
.write(self.state.from as u32, &SWAP_MAGIC.to_le_bytes())
|
.write(self.state.from as u32, &SWAP_MAGIC.to_le_bytes())
|
||||||
.await?;
|
.await?;
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -341,6 +347,11 @@ impl FirmwareUpdater {
|
||||||
#[repr(align(4))]
|
#[repr(align(4))]
|
||||||
struct Aligned([u8; 4]);
|
struct Aligned([u8; 4]);
|
||||||
|
|
||||||
|
let mut magic = Aligned([0; 4]);
|
||||||
|
flash.read(self.state.from as u32, &mut magic.0).await?;
|
||||||
|
let magic = u32::from_le_bytes(magic.0);
|
||||||
|
|
||||||
|
if magic != BOOT_MAGIC {
|
||||||
flash
|
flash
|
||||||
.write(self.state.from as u32, &Aligned([0; 4]).0)
|
.write(self.state.from as u32, &Aligned([0; 4]).0)
|
||||||
.await?;
|
.await?;
|
||||||
|
@ -350,6 +361,7 @@ impl FirmwareUpdater {
|
||||||
flash
|
flash
|
||||||
.write(self.state.from as u32, &BOOT_MAGIC.to_le_bytes())
|
.write(self.state.from as u32, &BOOT_MAGIC.to_le_bytes())
|
||||||
.await?;
|
.await?;
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue