diff --git a/boards/bootloaders/stm32h723/Cargo.toml b/boards/bootloaders/stm32h723/Cargo.toml index 13fc2d16..89deadb8 100644 --- a/boards/bootloaders/stm32h723/Cargo.toml +++ b/boards/bootloaders/stm32h723/Cargo.toml @@ -15,8 +15,8 @@ test = false [dependencies] cortex-m = { version = "0.7", features = ["critical-section-single-core"] } cortex-m-rt = "0.7" -defmt = {version = "0.3.1", optional = true} -defmt-rtt = {version = "0.3.2", optional = true} +defmt = {version = "0.3.8", optional = true} +defmt-rtt = {version = "0.4.1", optional = true} rustBoot-hal = {path = "../../hal", default-features = false, features = ["stm32h723"]} rustBoot-update = {path = "../../update", features = ["stm32h723"]} diff --git a/boards/hal/Cargo.toml b/boards/hal/Cargo.toml index c7d22ec6..b48269d7 100644 --- a/boards/hal/Cargo.toml +++ b/boards/hal/Cargo.toml @@ -26,7 +26,7 @@ test = false [dependencies] # common dependencies cortex-m = { version = "0.7", features = ["critical-section-single-core"] } -defmt = {version = "0.3.1", optional = true} +defmt = {version = "0.3.8", optional = true} # platform specific dependencies for aarch64 # [target.'cfg(target_arch = "aarch64")'.dependencies] aarch64-cpu = {version = "9.3.1", path = "./src/nxp/imx8mn/aarch64-cpu", optional = true} diff --git a/boards/update/Cargo.toml b/boards/update/Cargo.toml index 1cef0403..69a4a25c 100644 --- a/boards/update/Cargo.toml +++ b/boards/update/Cargo.toml @@ -24,7 +24,7 @@ doctest = false test = false [dependencies] -defmt = {version = "0.3.2", optional = true} +defmt = {version = "0.3.8", optional = true} rustBoot = {path = "../../rustBoot", default-features = true, features = ["mcu"]} rustBoot-hal = {path = "../hal"} diff --git a/boards/update/src/update/update_flash.rs b/boards/update/src/update/update_flash.rs index 045cc3da..5ce30496 100644 --- a/boards/update/src/update/update_flash.rs +++ b/boards/update/src/update/update_flash.rs @@ -168,12 +168,11 @@ where { return Err(RustbootError::ECCError); } - if (!updt_part.hdr_ok - || updt.verify_integrity::().is_err() - || updt.verify_authenticity::().is_err()) - { - panic!("firmware authentication failed"); + if (!updt_part.hdr_ok) { + return Err(RustbootError::InvalidImage); } + updt.verify_integrity::()?; + updt.verify_authenticity::()?; } // disallow downgrades match boot { @@ -272,25 +271,23 @@ where Interface: FlashInterface, { fn rustboot_start(self) -> ! { + let trigger_rollback = || -> Result<()> { + self.update_trigger(); + self.rustboot_update(true)?; + Ok(()) + }; let mut boot = PartDescriptor::open_partition(Boot, self).unwrap(); let updt = PartDescriptor::open_partition(Update, self).unwrap(); // Check the BOOT partition for state - if it is still in TESTING, trigger rollback. if let ImageType::BootInTestingState(_v) = boot { - self.update_trigger(); - match self.rustboot_update(true) { - Ok(_v) => {} - Err(_e) => { - panic!("rollback failed.") - } + if trigger_rollback().is_err() { + panic!("rollback failed."); } // Check the UPDATE partition for state - if it is marked as UPDATING, trigger update. } else if let ImageType::UpdateInUpdatingState(_v) = updt { - match self.rustboot_update(false) { - Ok(_v) => {} - Err(_e) => { - panic!("update-swap failed.") - } + if self.rustboot_update(false).is_err() { + /* If update cannot be performed, launch former boot partition by default */ } } else { match boot { diff --git a/rustBoot/Cargo.toml b/rustBoot/Cargo.toml index 2d91f517..311092d0 100644 --- a/rustBoot/Cargo.toml +++ b/rustBoot/Cargo.toml @@ -24,7 +24,7 @@ version = "0.1.0" # common dependencies as-slice = "0.2.1" byteorder = {version = "1.4.3", default-features = false} -defmt = {version = "0.3.1", optional = true} +defmt = {version = "0.3.8", optional = true} log = {version = "0.4", default-features = false, optional = true} # rustBoot parser dependencies nom = {version = "7.1.0", default-features = false} @@ -60,4 +60,4 @@ stm32f469 = ["mcu"] stm32h723 = ["mcu"] stm32f746 = ["mcu"] stm32f334 = ["mcu"] -rp2040 = ["mcu"] \ No newline at end of file +rp2040 = ["mcu"] diff --git a/rustBoot/src/image/image.rs b/rustBoot/src/image/image.rs index 4205a25e..96ba1591 100644 --- a/rustBoot/src/image/image.rs +++ b/rustBoot/src/image/image.rs @@ -569,7 +569,7 @@ impl<'a, Part: ValidPart + Swappable, State: TypeState> RustbootImage<'a, Part, let hasher = compute_img_hash::(self, fw_size)?; let computed_hash = hasher.finalize(); if computed_hash.as_slice() != stored_hash { - panic!("..integrity check failed"); + return Err(RustbootError::IntegrityCheckFailed); } integrity_check = true; Some(stored_hash.as_ptr())