diff options
| author | Vincent Stakenburg <[email protected]> | 2022-06-30 14:46:17 +0200 |
|---|---|---|
| committer | Vincent Stakenburg <[email protected]> | 2022-06-30 14:56:40 +0200 |
| commit | 3dc26bbe399723d62f2fccda665ee9e1c85e9991 (patch) | |
| tree | 88788985ec36f98694972556cb4a0fda82e344ae /embassy-boot | |
| parent | 0e55bb2a208f7038fe15567166e9655abe5480df (diff) | |
simplify `set_magic`
Diffstat (limited to 'embassy-boot')
| -rw-r--r-- | embassy-boot/boot/src/lib.rs | 17 |
1 files changed, 4 insertions, 13 deletions
diff --git a/embassy-boot/boot/src/lib.rs b/embassy-boot/boot/src/lib.rs index b18c88a6b..51e1056cf 100644 --- a/embassy-boot/boot/src/lib.rs +++ b/embassy-boot/boot/src/lib.rs | |||
| @@ -587,22 +587,13 @@ impl FirmwareUpdater { | |||
| 587 | ) -> Result<(), F::Error> { | 587 | ) -> Result<(), F::Error> { |
| 588 | flash.read(self.state.from as u32, aligned).await?; | 588 | flash.read(self.state.from as u32, aligned).await?; |
| 589 | 589 | ||
| 590 | let mut is_set = true; | 590 | if aligned.iter().find(|&&b| b != magic).is_some() { |
| 591 | for b in 0..aligned.len() { | 591 | aligned.fill(0); |
| 592 | if aligned[b] != magic { | 592 | |
| 593 | is_set = false; | ||
| 594 | } | ||
| 595 | } | ||
| 596 | if !is_set { | ||
| 597 | for i in 0..aligned.len() { | ||
| 598 | aligned[i] = 0; | ||
| 599 | } | ||
| 600 | flash.write(self.state.from as u32, aligned).await?; | 593 | flash.write(self.state.from as u32, aligned).await?; |
| 601 | flash.erase(self.state.from as u32, self.state.to as u32).await?; | 594 | flash.erase(self.state.from as u32, self.state.to as u32).await?; |
| 602 | 595 | ||
| 603 | for i in 0..aligned.len() { | 596 | aligned.fill(magic); |
| 604 | aligned[i] = magic; | ||
| 605 | } | ||
| 606 | flash.write(self.state.from as u32, aligned).await?; | 597 | flash.write(self.state.from as u32, aligned).await?; |
| 607 | } | 598 | } |
| 608 | Ok(()) | 599 | Ok(()) |
