mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
add configurations for security testing
This commit is contained in:
parent
4f2d1215bc
commit
5bf4a6416a
4 changed files with 55 additions and 30 deletions
|
|
@ -515,7 +515,7 @@ impl Repl {
|
||||||
}
|
}
|
||||||
use bao1x_hal::board::{BOOKEND_END, BOOKEND_START};
|
use bao1x_hal::board::{BOOKEND_END, BOOKEND_START};
|
||||||
crate::println!(
|
crate::println!(
|
||||||
"{}PUB_MUT,{},{}",
|
"{}SEC.PUBMUT-{},{}",
|
||||||
BOOKEND_START,
|
BOOKEND_START,
|
||||||
if pass { "PASS" } else { "FAIL" },
|
if pass { "PASS" } else { "FAIL" },
|
||||||
BOOKEND_END
|
BOOKEND_END
|
||||||
|
|
|
||||||
|
|
@ -77,8 +77,8 @@ dabao-selftest = [
|
||||||
"xous-bio-bdma/baremetal",
|
"xous-bio-bdma/baremetal",
|
||||||
"xous-bio-bdma/bao1x",
|
"xous-bio-bdma/bao1x",
|
||||||
]
|
]
|
||||||
test-boot0-writeprotect = []
|
ci-security = []
|
||||||
spim-tests = []
|
spim-tests = []
|
||||||
|
|
||||||
verilator-only = []
|
verilator-only = []
|
||||||
default = ["bao1x-usb"]
|
default = ["bao1x-usb", "ci-security"]
|
||||||
|
|
|
||||||
|
|
@ -66,33 +66,6 @@ pub unsafe extern "C" fn rust_entry() -> ! {
|
||||||
crate::platform::early_init();
|
crate::platform::early_init();
|
||||||
crate::println!("\n~~Baremetal up!~~\n");
|
crate::println!("\n~~Baremetal up!~~\n");
|
||||||
|
|
||||||
// Test code for figuring out if boot0 write-protect is working or not.
|
|
||||||
// Keep this around because it's a quick test to make sure that the fuses were set correctly
|
|
||||||
// on a device.
|
|
||||||
//
|
|
||||||
// The test only passes when the IFR protection bits are set.
|
|
||||||
// Also, this only works once we're in baremetal - boot0 can always write boot0, and
|
|
||||||
// the coreuser setup doesn't take us out of boot0 until this stage (note that boot1,
|
|
||||||
// despite being named this, actually operates in the boot0 privilege level).
|
|
||||||
#[cfg(feature = "test-boot0-writeprotect")]
|
|
||||||
{
|
|
||||||
crate::println!("Write protection test");
|
|
||||||
let mut rram = bao1x_hal::rram::Reram::new();
|
|
||||||
// boot0 should end at 0x2_0000; boot1 ends at 0x6_0000
|
|
||||||
// expected result: the first four should have the update fail
|
|
||||||
// the fifth value (in boot1) should update
|
|
||||||
let regions = [0xF000, 0x1_1000, 0x1_F000, 0x2_1000, 0x5_0000];
|
|
||||||
for (i, ®ion) in regions.iter().enumerate() {
|
|
||||||
let test_data =
|
|
||||||
unsafe { core::slice::from_raw_parts((region + utralib::HW_RERAM_MEM) as *const u8, 32) };
|
|
||||||
let base = test_data[0]; // increment whatever is in the original area
|
|
||||||
let test = [base + 1 + i as u8; 32];
|
|
||||||
crate::println!("orig ({:x}): {:x?}", region, test_data);
|
|
||||||
rram.write_slice(region, &test).unwrap();
|
|
||||||
crate::println!("update ({:x}): {:x?} vs {:x?}", region, test_data, test);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "artyvexii")]
|
#[cfg(feature = "artyvexii")]
|
||||||
crate::platform::test_virtual_memory();
|
crate::platform::test_virtual_memory();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@ use alloc::vec::Vec;
|
||||||
#[cfg(feature = "bao1x")]
|
#[cfg(feature = "bao1x")]
|
||||||
use bao1x_api::*;
|
use bao1x_api::*;
|
||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
|
use bao1x_hal::board::{BOOKEND_END, BOOKEND_START};
|
||||||
|
#[allow(unused_imports)]
|
||||||
use utralib::*;
|
use utralib::*;
|
||||||
#[cfg(any(feature = "artybio", feature = "bao1x-bio"))]
|
#[cfg(any(feature = "artybio", feature = "bao1x-bio"))]
|
||||||
use xous_bio_bdma::*;
|
use xous_bio_bdma::*;
|
||||||
|
|
@ -904,6 +906,56 @@ impl Repl {
|
||||||
crate::platform::clockset_wrapper(800_000_000);
|
crate::platform::clockset_wrapper(800_000_000);
|
||||||
crate::println!("exiting wfi");
|
crate::println!("exiting wfi");
|
||||||
}
|
}
|
||||||
|
#[cfg(feature = "ci-security")]
|
||||||
|
// write protection only works after we leave the boot environment, thus it has to be tested in
|
||||||
|
// baremetal
|
||||||
|
"boot0-wp" => {
|
||||||
|
crate::println!("Write protection test");
|
||||||
|
let mut rram = bao1x_hal::rram::Reram::new();
|
||||||
|
// boot0 should end at 0x2_0000; boot1 ends at 0x6_0000
|
||||||
|
// expected result: the first four should have the update fail
|
||||||
|
// the fifth value (in boot1) should update
|
||||||
|
let regions =
|
||||||
|
[(false, 0x0), (false, 0xF000), (false, 0x1_1000), (false, 0x1_F000), (true, 0x5_F000)];
|
||||||
|
let mut passing = true;
|
||||||
|
for (i, &(writable, region)) in regions.iter().enumerate() {
|
||||||
|
let ref_data = unsafe {
|
||||||
|
core::slice::from_raw_parts((region + utralib::HW_RERAM_MEM) as *const u8, 32)
|
||||||
|
};
|
||||||
|
let base = ref_data[0]; // increment whatever is in the original area
|
||||||
|
let try_write = [base + 1 + i as u8; 32];
|
||||||
|
// crate::println!("orig ({:x}): {:x?}", region, test_data);
|
||||||
|
rram.write_slice(region, &try_write).unwrap();
|
||||||
|
if writable {
|
||||||
|
if ref_data != try_write {
|
||||||
|
crate::println!(
|
||||||
|
"Failure on writeable {:?} ({:x}): {:x?} vs {:x?}",
|
||||||
|
writable,
|
||||||
|
region,
|
||||||
|
ref_data,
|
||||||
|
try_write
|
||||||
|
);
|
||||||
|
passing = false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ref_data == try_write {
|
||||||
|
crate::println!(
|
||||||
|
"Failure on writeable {:?} ({:x}): {:x?} vs {:x?}",
|
||||||
|
writable,
|
||||||
|
region,
|
||||||
|
ref_data,
|
||||||
|
try_write
|
||||||
|
);
|
||||||
|
passing = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if passing {
|
||||||
|
crate::println!("{}SEC.BOOT0WP-PASS,{}", BOOKEND_START, BOOKEND_END);
|
||||||
|
} else {
|
||||||
|
crate::println!("{}SEC.BOOT0WP-FAIL,{}", BOOKEND_START, BOOKEND_END);
|
||||||
|
}
|
||||||
|
}
|
||||||
#[cfg(feature = "bao1x-trng")]
|
#[cfg(feature = "bao1x-trng")]
|
||||||
"trngro" => {
|
"trngro" => {
|
||||||
use base64::{Engine as _, engine::general_purpose};
|
use base64::{Engine as _, engine::general_purpose};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue