Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore broken update partition content when in UpdateInUpdatingState (closes #80) #82

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions boards/bootloaders/stm32h723/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]}

Expand Down
2 changes: 1 addition & 1 deletion boards/hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
2 changes: 1 addition & 1 deletion boards/update/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"}

Expand Down
29 changes: 13 additions & 16 deletions boards/update/src/update/update_flash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,11 @@ where
{
return Err(RustbootError::ECCError);
}
if (!updt_part.hdr_ok
|| updt.verify_integrity::<SHA256_DIGEST_SIZE>().is_err()
|| updt.verify_authenticity::<HDR_IMG_TYPE_AUTH>().is_err())
{
panic!("firmware authentication failed");
if (!updt_part.hdr_ok) {
return Err(RustbootError::InvalidImage);
}
updt.verify_integrity::<SHA256_DIGEST_SIZE>()?;
updt.verify_authenticity::<HDR_IMG_TYPE_AUTH>()?;
}
// disallow downgrades
match boot {
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions rustBoot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -60,4 +60,4 @@ stm32f469 = ["mcu"]
stm32h723 = ["mcu"]
stm32f746 = ["mcu"]
stm32f334 = ["mcu"]
rp2040 = ["mcu"]
rp2040 = ["mcu"]
2 changes: 1 addition & 1 deletion rustBoot/src/image/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ impl<'a, Part: ValidPart + Swappable, State: TypeState> RustbootImage<'a, Part,
let hasher = compute_img_hash::<Part, State, Sha256, N>(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())
Expand Down
Loading