checkpoint the baremetal routine as we integrate into the boot chain

This commit is contained in:
bunnie 2025-09-29 16:21:53 +08:00
parent ba817cc1a9
commit aabe88e0d5
4 changed files with 76 additions and 5 deletions

View file

@ -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 = [

View file

@ -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

View file

@ -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
}

View file

@ -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);