From 0e55bb2a208f7038fe15567166e9655abe5480df Mon Sep 17 00:00:00 2001 From: Vincent Stakenburg Date: Thu, 30 Jun 2022 14:45:59 +0200 Subject: [PATCH 1/2] add log feature to embassy-boot-stm32 --- embassy-boot/stm32/Cargo.toml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/embassy-boot/stm32/Cargo.toml b/embassy-boot/stm32/Cargo.toml index 1b6eeef93..13ae54b31 100644 --- a/embassy-boot/stm32/Cargo.toml +++ b/embassy-boot/stm32/Cargo.toml @@ -9,6 +9,7 @@ description = "Bootloader lib for STM32 chips" [dependencies] defmt = { version = "0.3", optional = true } defmt-rtt = { version = "0.3", optional = true } +log = { version = "0.4", optional = true } embassy = { path = "../../embassy", default-features = false } embassy-stm32 = { path = "../../embassy-stm32", default-features = false, features = ["nightly"] } @@ -25,6 +26,11 @@ defmt = [ "embassy-boot/defmt", "embassy-stm32/defmt", ] +log = [ + "dep:log", + "embassy-boot/log", + "embassy-stm32/log", +] debug = ["defmt-rtt"] [profile.dev] From 3dc26bbe399723d62f2fccda665ee9e1c85e9991 Mon Sep 17 00:00:00 2001 From: Vincent Stakenburg Date: Thu, 30 Jun 2022 14:46:17 +0200 Subject: [PATCH 2/2] simplify `set_magic` --- embassy-boot/boot/src/lib.rs | 17 ++++------------- 1 file 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 { ) -> Result<(), F::Error> { flash.read(self.state.from as u32, aligned).await?; - let mut is_set = true; - for b in 0..aligned.len() { - if aligned[b] != magic { - is_set = false; - } - } - if !is_set { - for i in 0..aligned.len() { - aligned[i] = 0; - } + if aligned.iter().find(|&&b| b != magic).is_some() { + aligned.fill(0); + flash.write(self.state.from as u32, aligned).await?; flash.erase(self.state.from as u32, self.state.to as u32).await?; - for i in 0..aligned.len() { - aligned[i] = magic; - } + aligned.fill(magic); flash.write(self.state.from as u32, aligned).await?; } Ok(())