From aabe88e0d5917dcb273ccb41e1c240e47c25a1df Mon Sep 17 00:00:00 2001 From: bunnie Date: Mon, 29 Sep 2025 16:21:53 +0800 Subject: [PATCH] checkpoint the baremetal routine as we integrate into the boot chain --- baremetal/Cargo.toml | 10 ++-- baremetal/src/platform/bao1x/bao1x.rs | 2 +- baremetal/src/platform/bao1x/link.x | 2 +- baremetal/src/repl.rs | 67 +++++++++++++++++++++++++++ 4 files changed, 76 insertions(+), 5 deletions(-) diff --git a/baremetal/Cargo.toml b/baremetal/Cargo.toml index 5b14e34a7..5bb445ed0 100644 --- a/baremetal/Cargo.toml +++ b/baremetal/Cargo.toml @@ -19,13 +19,15 @@ ux-api = { path = "../libs/ux-api", optional = true, default-features = false } simple-fatfs = { git = "https://github.com/betrusted-io/simple-fatfs.git", branch = "baosec", optional = true, default-features = false } sha2 = { version = "0.10.8", optional = true, default-features = false } digest = { version = "0.10.7", optional = true } -ed25519-dalek = { version = "=2.1.0", optional = true, default-features = false, features = [ - "rand_core", +ed25519-dalek = { package = "ed25519-dalek-bao1x", path = "../bao1x-boot/ed25519-dalek-bao1x", default-features = false, features = [ "digest", -] } + "zeroize", +], optional = true } base64 = { version = "0.22.1", optional = true, default-features = false, features = [ "alloc", ] } +sha2-bao1x = { path = "../bao1x-boot/sha2-bao1x", optional = true, default-features = false } +hex-literal = "1.0.0" [features] artybio = [ @@ -46,6 +48,8 @@ bao1x = [ # "bao1x-hal/debug-print-usb", "bao1x-api", "v0p9", + "digest", + "sha2-bao1x", ] # activates BIO test suite bao1x-bio = [ diff --git a/baremetal/src/platform/bao1x/bao1x.rs b/baremetal/src/platform/bao1x/bao1x.rs index abfc286da..94634599c 100644 --- a/baremetal/src/platform/bao1x/bao1x.rs +++ b/baremetal/src/platform/bao1x/bao1x.rs @@ -165,7 +165,7 @@ pub fn early_init() { // Now that SRAM trims are setup, initialize all the statics by writing to memory. // For baremetal, the statics structure is just at the flash base. - const STATICS_LOC: usize = FLASH_BASE + SIGBLOCK_LEN; + const STATICS_LOC: usize = bao1x_api::BAREMETAL_START + SIGBLOCK_LEN; // safety: this data structure is pre-loaded by the image loader and is guaranteed to // only have representable, valid values that are aligned according to the repr(C) spec diff --git a/baremetal/src/platform/bao1x/link.x b/baremetal/src/platform/bao1x/link.x index 7d926abec..452ba9ccb 100644 --- a/baremetal/src/platform/bao1x/link.x +++ b/baremetal/src/platform/bao1x/link.x @@ -2,7 +2,7 @@ MEMORY { /* Note: ORIGIN is updated by xtask for baremetal targets */ - FLASH : ORIGIN = 0x60000400, LENGTH = 256k - 1024 + FLASH : ORIGIN = 0x60060400, LENGTH = 256k - 1024 RAM : ORIGIN = 0x61000000, LENGTH = 2048k } diff --git a/baremetal/src/repl.rs b/baremetal/src/repl.rs index 769cd033c..fd72987b0 100644 --- a/baremetal/src/repl.rs +++ b/baremetal/src/repl.rs @@ -14,6 +14,17 @@ use xous_bio_bdma::*; #[cfg(feature = "bao1x-trng")] static TRNG_INIT: core::sync::atomic::AtomicBool = core::sync::atomic::AtomicBool::new(false); +// courtesy of claude +#[cfg(feature = "bao1x")] +const K_DATA: &'static [u8; 853] = b"The quick brown fox jumps over the lazy dog while contemplating \ +the meaning of existence in a digital world. Numbers like 123456789 and symbols @#$%^&*() add variety to this test \ +message. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore \ +magna aliqua. Testing patterns: ABCDEFGHIJKLMNOPQRSTUVWXYZ and abcdefghijklmnopqrstuvwxyz provide full alphabet coverage. \ +Special characters !@#$%^&*()_+-=[]{}|;':.,.<>?/ enhance the diversity of this sample text. The year 2024 brings new \ +challenges and opportunities for software development and testing methodologies. Random words like elephant, butterfly, \ +quantum, nebula, crystalline, harmonic, and serendipity fill the remaining space. Pi equals 3.14159265358979323846 \ +approximately. This text serves as a placeholder for various testing scenarios!!!"; + pub struct Error { pub message: Option<&'static str>, } @@ -938,6 +949,62 @@ impl Repl { } } } + #[cfg(feature = "bao1x")] + "sha2" => { + use digest::Digest; + use hex_literal::hex; + use sha2_bao1x::Sha256; + + const K_EXPECTED_DIGEST_256: [u8; 32] = + hex!("de1b3b58e16d6b12c906898025d4bc5a594075f4fd4252fa88128b2e0b7a266a"); + + let mut pass: bool = true; + let mut hasher = Sha256::new(); + + hasher.update(K_DATA); + // hasher.update(data); + let digest = hasher.finalize(); + + for (&expected, result) in K_EXPECTED_DIGEST_256.iter().zip(digest) { + if expected != result { + pass = false; + } + } + if pass { + crate::println!("Sha256 passed."); + } else { + crate::println!("Sha256 failed: {:x?}", digest); + } + } + #[cfg(feature = "bao1x")] + "sha5" => { + use digest::Digest; + use hex_literal::hex; + use sha2_bao1x::Sha512; + + // generated by claude. + const K_EXPECTED_DIGEST_512: [u8; 64] = hex!( + "e827276a7d5f2653fe27abc0b0c86533e75acfd4d75253b1229bf86aee19e4a0722691e9ef60510892dc60f4edff795d7875d0d8293a39a7a327a7e1bf07000a" + ); + + let mut pass: bool = true; + let mut hasher = Sha512::new(); + + hasher.update(K_DATA); + // hasher.update(data); + let digest = hasher.finalize(); + + for (&expected, result) in K_EXPECTED_DIGEST_512.iter().zip(digest) { + if expected != result { + pass = false; + } + } + if pass { + crate::println!("Sha512 passed."); + } else { + crate::println!("Sha512 failed: {:x?}", digest); + } + } "echo" => { for word in args { crate::print!("{} ", word);