make the flash test optional based on the configuration

allow the console to be built for hosted targets
This commit is contained in:
bunnie 2025-05-18 09:25:01 +08:00
parent 7947949589
commit 4251686c1f
2 changed files with 36 additions and 31 deletions

View file

@ -22,7 +22,7 @@ usb-cramium = { path = "../usb-cramium" }
modals = { path = "../modals", default-features = false }
ux-api = { path = "../../libs/ux-api", optional = true }
pddb = { path = "../pddb", optional = true }
xous-swapper = { path = "../xous-swapper" }
xous-swapper = { path = "../xous-swapper", optional = true }
# pddb testing
rand = { version = "0.8.5", features = ["getrandom"], optional = true }
@ -40,6 +40,7 @@ board-baosec = [
"cramium-hal",
"usb-cramium/board-baosec",
"pddb/board-baosec",
"xous-swapper",
]
hosted-baosec = [
"modals/hosted-baosec",
@ -54,4 +55,5 @@ test-rekey = []
autobasis = ["rand_chacha", "rand"]
modal-testing = ["ux-api", "modals/modal-testing"]
test-scrollbars = []
default = []
test-flash = []
default = ["test-flash"]

View file

@ -3,7 +3,6 @@ mod repl;
mod shell;
use cmds::*;
use xous_swapper::FlashPage;
fn main() {
log_server::init_wait().unwrap();
@ -15,36 +14,40 @@ fn main() {
tt.sleep_ms(4000).ok();
log::info!("start spi flash map test");
let swapper = xous_swapper::Swapper::new().unwrap();
log::info!("got handle on swapper object");
let mut spimap = xous::map_memory(
None,
xous::MemoryAddress::new(xous::arch::MMAP_VIRT_BASE),
cramium_hal::board::SPINOR_LEN as usize,
xous::MemoryFlags::R | xous::MemoryFlags::W | xous::MemoryFlags::VIRT,
)
.expect("couldn't map spi range");
log::info!("spimap: {:x?}", spimap);
// we have the mapping, now try to dereference it and read something to test it
let spislice: &mut [u8] = unsafe { spimap.as_slice_mut() };
// this should trigger the page fault and thus the handler
log::info!("spislice read 0..64: {:x?}", &spislice[..64]);
log::info!("spislice read 256..264: {:x?}", &spislice[256..264]);
let test_start = 8192 * 1024 + 4096;
log::info!("spislice read 8M: {:x?}", &spislice[test_start..test_start + 16]);
#[cfg(all(feature = "board-baosec", feature = "test-flash"))]
{
use xous_swapper::FlashPage;
log::info!("start spi flash map test");
let swapper = xous_swapper::Swapper::new().unwrap();
log::info!("got handle on swapper object");
let mut spimap = xous::map_memory(
None,
xous::MemoryAddress::new(xous::arch::MMAP_VIRT_BASE),
cramium_hal::board::SPINOR_LEN as usize,
xous::MemoryFlags::R | xous::MemoryFlags::W | xous::MemoryFlags::VIRT,
)
.expect("couldn't map spi range");
log::info!("spimap: {:x?}", spimap);
// we have the mapping, now try to dereference it and read something to test it
let spislice: &mut [u8] = unsafe { spimap.as_slice_mut() };
// this should trigger the page fault and thus the handler
log::info!("spislice read 0..64: {:x?}", &spislice[..64]);
log::info!("spislice read 256..264: {:x?}", &spislice[256..264]);
let test_start = 8192 * 1024 + 4096;
log::info!("spislice read 8M: {:x?}", &spislice[test_start..test_start + 16]);
let mut fp = FlashPage::new();
fp.data.copy_from_slice(&spislice[test_start..test_start + 4096]);
for (i, d) in fp.data[..32].iter_mut().enumerate() {
*d = 128u8 - i as u8;
let mut fp = FlashPage::new();
fp.data.copy_from_slice(&spislice[test_start..test_start + 4096]);
for (i, d) in fp.data[..32].iter_mut().enumerate() {
*d = 128u8 - i as u8;
}
swapper
.write_page(spislice[test_start..test_start + 32].as_ptr() as usize, fp)
.expect("couldn't write page");
log::info!("spislice read 8M (again): {:x?}", &spislice[test_start..test_start + 16]);
log::info!("end spi flash map test");
}
swapper
.write_page(spislice[test_start..test_start + 32].as_ptr() as usize, fp)
.expect("couldn't write page");
log::info!("spislice read 8M (again): {:x?}", &spislice[test_start..test_start + 16]);
log::info!("end spi flash map test");
#[cfg(feature = "test-scrollbars")]
{