From e68a61dd9abb164761faf1bd727304d545ce2a05 Mon Sep 17 00:00:00 2001 From: bunnie Date: Mon, 16 Feb 2026 17:23:02 +0800 Subject: [PATCH 1/5] unrelated but update the restore.py script to refer to the new release tag --- tools/restore.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/restore.py b/tools/restore.py index 7e5dd489c..a6c291304 100644 --- a/tools/restore.py +++ b/tools/restore.py @@ -657,6 +657,7 @@ def main(): # now try to download all the artifacts and check their versions # this list should visit kernels in order from newest to oldest. URL_LIST = [ + 'https://ci.betrusted.io/releases/v0.10.0/', 'https://ci.betrusted.io/releases/v0.9.16/', 'https://ci.betrusted.io/releases/v0.9.15/', 'https://ci.betrusted.io/releases/v0.9.14/', From 9be2cbf99e087c17468e3793f625cd2ad9497af9 Mon Sep 17 00:00:00 2001 From: bunnie Date: Mon, 16 Feb 2026 18:07:01 +0800 Subject: [PATCH 2/5] remove baobit commit command line argument the baobit commit will be injected at final file packaging time --- xtask/src/main.rs | 3 +-- xtask/src/versioning.rs | 18 ++---------------- 2 files changed, 3 insertions(+), 18 deletions(-) diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 1e4602ece..d51f0cce8 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -60,8 +60,7 @@ fn main() -> Result<(), Box> { let do_version = env::args().filter(|x| x == "--no-timestamp").count() == 0; let git_describe_opt = get_flag("--git-describe")?.first().cloned(); let git_rev_opt = get_flag("--git-rev")?.first().cloned(); - let baobit_commit_opt = get_flag("--baobit-commit")?.first().cloned(); - generate_version(do_version, git_describe_opt.clone(), baobit_commit_opt.clone()); + generate_version(do_version, git_describe_opt.clone()); if let Some(desc) = git_describe_opt { builder.set_git_describe(desc); } diff --git a/xtask/src/versioning.rs b/xtask/src/versioning.rs index d2f4b57fb..63edee3bc 100644 --- a/xtask/src/versioning.rs +++ b/xtask/src/versioning.rs @@ -27,11 +27,7 @@ fn write_if_changed(path: &str, new_data: &[u8]) { vfile.write_all(new_data).expect(&format!("couldn't write to {}", path)); } -pub(crate) fn generate_version( - add_timestamp: bool, - forced_version: Option, - baobit_commit: Option, -) { +pub(crate) fn generate_version(add_timestamp: bool, forced_version: Option) { let gitver = { if let Some(ver) = forced_version { ver.as_bytes().to_vec() @@ -77,17 +73,7 @@ pub(crate) fn generate_version( .expect("couldn't add our semver"); new_data.extend_from_slice(&semver_code); - // Baochip versioning is just SEMVER + BAOBIT_COMMIT. Now that - // the semver_code has been added to new_data, we can extend it with the Baobit commit. - if let Some(ref commit) = baobit_commit { - writeln!(semver_code, "pub const BAOBIT_COMMIT: &'static str = \"{}\";", commit) - .expect("couldn't add baobit commit"); - } else { - // For builds that aren't built in the reproducible environment, the baobit commit is unspecified - writeln!(semver_code, "pub const BAOBIT_COMMIT: &'static str = \"unspecified\";") - .expect("couldn't add baobit commit placeholder"); - } - + // Baochip versioning is just SEMVER write_if_changed(version_file, &new_data); write_if_changed(boot0_version_file, &semver_code); write_if_changed(boot1_version_file, &semver_code); From 692fb5fed9d4a150a1e779dfdbd62aff6173b37d Mon Sep 17 00:00:00 2001 From: bunnie Date: Mon, 16 Feb 2026 18:07:42 +0800 Subject: [PATCH 3/5] update signer to accept and inject baobit-commit hash in order to prevent the recursive introspection issue, the code image is built from a reproducible toolchain from a given commit on xous-core. However, in order for us to record *which* toolchain was used, it's impossible to do this without modifying the commit hash of the toolchain - thus making it impossible to know what toolchain was actually used to build the reproducible code. The fix to this is to out-of-band, at the final signature time, patch over a field in the signature header expressly laid out to accommodate the hash. --- signing/fido-signer/src/main.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/signing/fido-signer/src/main.rs b/signing/fido-signer/src/main.rs index c1b9d628a..dfcb40e44 100644 --- a/signing/fido-signer/src/main.rs +++ b/signing/fido-signer/src/main.rs @@ -43,6 +43,10 @@ struct Args { /// Function code e.g. partition - if provided, creates a uf2 file #[arg(short = 'p', long = "function-code", value_name = "CODE")] function_code: Option, + + /// Hash to embed in the signature (hex string) + #[arg(short = 'b', long = "baobit-hash", value_name = "HASH")] + baobit_hash: Option, } #[derive(Debug, Deserialize, Serialize)] @@ -58,6 +62,11 @@ fn main() -> Result<(), Box> { // Parse command line arguments let args = Args::parse(); + let baobit_hash: Option<[u8; 20]> = args.baobit_hash.as_deref().map(|hex_str| { + let vec = hex::decode(hex_str).expect("invalid hex string"); + vec.try_into().expect("Baobit hash must be exactly 20 bytes") + }); + // Load and parse the credential file let credential_data = fs::read_to_string(&args.credential_file) .map_err(|e| format!("Failed to read credential file: {}", e))?; @@ -100,6 +109,13 @@ fn main() -> Result<(), Box> { sig.as_mut().copy_from_slice(&file[offset..offset + size_of::()]); if sig.sealed_data.magic == bao1x_api::signatures::MAGIC_NUMBER { is_bao1x = true; + // inject the baobit hash here, if it is specified + if let Some(toolchain) = baobit_hash { + patch_hash_in_file(&file_path, &toolchain, offset)?; + } + // Re-read the file so we hash the patched contents + let file = fs::read(&file_path) + .map_err(|e| format!("Failed to re-read file '{}': {}", file_path.display(), e))?; let mut h: Sha512 = Sha512::new(); // hash the sealed region h.update(&file[offset + SignatureInFlash::sealed_data_offset()..]); @@ -212,6 +228,22 @@ fn patch_signature_in_file( Ok(()) } +fn patch_hash_in_file( + file_path: &PathBuf, + hash: &[u8], + offset: usize, +) -> Result<(), Box> { + // Open file with read and write permissions + let mut file = OpenOptions::new().read(true).write(true).open(file_path)?; + + let mut signature_struct = read_header_from_file(&mut file, offset)?; + signature_struct.sealed_data.toolchain.copy_from_slice(&hash); + + write_header_to_file(&mut file, &signature_struct, offset)?; + + Ok(()) +} + fn read_header_from_file( file: &mut std::fs::File, offset: usize, From da895b2c1f8a17cba33a78daabd0b98263f1ecc7 Mon Sep 17 00:00:00 2001 From: bunnie Date: Mon, 16 Feb 2026 18:10:08 +0800 Subject: [PATCH 4/5] extend sealed data to contain a toolchain hash field the sealed data records are laid out with some extra space at the end for future expansion. The first such expansion added is a toolchain hash, which allows us to note which toolchain is required to reproduce the current image. The change is backward compatible so the version field of the record is *not* incremented. --- libs/bao1x-api/src/signatures.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/libs/bao1x-api/src/signatures.rs b/libs/bao1x-api/src/signatures.rs index cbde26ff4..8e723378f 100644 --- a/libs/bao1x-api/src/signatures.rs +++ b/libs/bao1x-api/src/signatures.rs @@ -162,6 +162,16 @@ pub struct SealedFields { /// /// If no valid keys are found, the device is effectively bricked and goes into a "die" state. pub pubkeys: [Pubkey; 4], + /// Placeholder for baobit commit: this is the hash of the toolchain used to generate the image. + /// In many images, this is just 0's; but for signed release images, this is injected into the file + /// prior to applying the final signature. This injection has to happen after everything is done + /// because the rules of the reproducible build system disallow it from knowing its final commit + /// state: you have to commit its final state, which changes its reported commit state, and so + /// forth, so at build time you can't know what toolchain was used to build you - only after + /// the build is complete is the information revealed to the user. + /// + /// This field is long enough to hold a SHA-1 git hash. + pub toolchain: [u8; 20], } impl AsRef<[u8]> for SealedFields { @@ -178,6 +188,7 @@ impl Default for SealedFields { min_semver: [0u8; 16], semver: [0u8; 16], pubkeys: [Pubkey::default(); 4], + toolchain: [0u8; 20], } } } From eb2e370632f4e9c80a36ba374032d268a66bed4f Mon Sep 17 00:00:00 2001 From: bunnie Date: Mon, 16 Feb 2026 18:11:34 +0800 Subject: [PATCH 5/5] update audit print to facilitate build checking - include the toolchain hash for reproduction iff it is specified - for the code hash, report *only* the code region, none of the signature headers. This should match exactly what is reported by the *_presign.img artifacts. --- bao1x-boot/boot1/src/audit.rs | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/bao1x-boot/boot1/src/audit.rs b/bao1x-boot/boot1/src/audit.rs index 19b4c9f86..b69861a8b 100644 --- a/bao1x-boot/boot1/src/audit.rs +++ b/bao1x-boot/boot1/src/audit.rs @@ -1,7 +1,7 @@ use core::convert::TryInto; use bao1x_api::pubkeys::{BOOT0_SELF_CHECK, BOOT0_TO_BOOT1, BOOT1_TO_LOADER_OR_BAREMETAL}; -use bao1x_api::signatures::{SignatureInFlash, UNSIGNED_LEN}; +use bao1x_api::signatures::{SIGBLOCK_LEN, SignatureInFlash, UNSIGNED_LEN}; use bao1x_api::*; use bao1x_hal::acram::OneWayCounter; use bao1x_hal::sigcheck::ERASE_VALUE; @@ -29,6 +29,18 @@ fn hash_region(region: &[u8], description: &str) { crate::println!("{}: {}", description, hex_str); } +fn report_toolchain(sig: &SignatureInFlash, description: &str) { + let hash = sig.sealed_data.toolchain; + if hash == [0u8; 20] { + crate::println!("{}: unspecified", description); + } else { + let mut buffer = [0u8; 40]; + hex::encode_to_slice(&hash, &mut buffer).unwrap(); + let hex_str = core::str::from_utf8(&buffer).unwrap(); + crate::println!("{}: {}", description, hex_str); + } +} + /// Stepping detection: attempt to modify the RRCR configuration. If bit 12 (code area protection) /// can be flipped, then we are A0 stepping. fn detect_stepping() -> &'static str { @@ -57,7 +69,6 @@ pub fn audit() { crate::println!("Board type reads as: {:?}", boardtype); crate::println!("Boot partition is: {:?}", owc.get_decoded::()); crate::println!("Semver is: {}", crate::version::SEMVER); - crate::println!("Baobit commit is: {}", crate::version::BAOBIT_COMMIT); crate::println!("Description is: {}", crate::RELEASE_DESCRIPTION); crate::println!("Stepping is: {}", detect_stepping()); let slot_mgr = bao1x_hal::acram::SlotManager::new(); @@ -169,12 +180,13 @@ pub fn audit() { let b0_pk: &SignatureInFlash = unsafe { b0_pk_ptr.as_ref().unwrap() }; let boot0_used = unsafe { core::slice::from_raw_parts( - (bao1x_api::BOOT0_START + UNSIGNED_LEN) as *const u8, - b0_pk.sealed_data.signed_len as usize, + (bao1x_api::BOOT0_START + SIGBLOCK_LEN) as *const u8, + b0_pk.sealed_data.signed_len as usize - (SIGBLOCK_LEN - UNSIGNED_LEN), ) }; - // only the portion that's protected by signature + // only the portion that's strictly reproducible hash_region(boot0_used, "boot0 code only"); + report_toolchain(b0_pk, "boot0 baobit toolchain"); let boot1_region = unsafe { core::slice::from_raw_parts( @@ -185,6 +197,18 @@ pub fn audit() { // includes free space hash_region(boot1_region, "boot1 partition"); + let b1_pk_ptr = bao1x_api::BOOT1_START as *const SignatureInFlash; + let b1_pk: &SignatureInFlash = unsafe { b1_pk_ptr.as_ref().unwrap() }; + let boot1_used = unsafe { + core::slice::from_raw_parts( + (bao1x_api::BOOT1_START + SIGBLOCK_LEN) as *const u8, + b1_pk.sealed_data.signed_len as usize - (SIGBLOCK_LEN - UNSIGNED_LEN), + ) + }; + // only the portion that's strictly reproducible + hash_region(boot1_used, "boot1 code only"); + report_toolchain(b1_pk, "boot1 baobit toolchain"); + // detailed state checks let mut secure = true; // check that boot1 pubkeys match the indelible entries