diff --git a/sw/host/rom_ext_image_tools/signer/Cargo.toml b/sw/host/rom_ext_image_tools/signer/Cargo.toml index 908210a28b41c..16aec0e47e50e 100644 --- a/sw/host/rom_ext_image_tools/signer/Cargo.toml +++ b/sw/host/rom_ext_image_tools/signer/Cargo.toml @@ -27,6 +27,7 @@ debug = true anyhow = "1.0.40" object = "0.25.3" rom_ext_image = { path = "image" } +thiserror = "1.0.24" zerocopy = "0.5.0" [dependencies.mundane] diff --git a/sw/host/rom_ext_image_tools/signer/src/main.rs b/sw/host/rom_ext_image_tools/signer/src/main.rs index 55db46c2a159b..af44b0433161a 100644 --- a/sw/host/rom_ext_image_tools/signer/src/main.rs +++ b/sw/host/rom_ext_image_tools/signer/src/main.rs @@ -105,12 +105,17 @@ fn update_image_manifest( addr.checked_sub(manifest_addr).context("Overflow")? }, code_end: { - let text = elf - .section_by_name(".text") - .context("Could not find the `.text` section.")?; + // TODO: Consider requiring all binaries signed by this tool to have a .shutdown section. + let section = elf + .section_by_name(".shutdown") + .or(elf.section_by_name(".text")) + .context( + "Could not find the `.shutdown` or `.text` section.", + )?; let addr = u32::try_from( - text.address() - .checked_add(text.size()) + section + .address() + .checked_add(section.size()) .context("Overflow")?, )?; addr.checked_sub(manifest_addr).context("Overflow")? @@ -171,7 +176,8 @@ fn update_image_manifest( "`entry_point` is outside the code region." ); ensure!( - (manifest::MANIFEST_LENGTH_FIELD_MIN..=manifest::MANIFEST_LENGTH_FIELD_MAX) + (manifest::MANIFEST_LENGTH_FIELD_MIN + ..=manifest::MANIFEST_LENGTH_FIELD_MAX) .contains(&image.manifest.length), "`length` is outside the allowed range." );