Merge pull request #646 from betrusted-io/pddb-baosec-bringup

Fix hosted mode build targets
This commit is contained in:
bunnie 2025-05-18 09:32:49 +08:00 committed by GitHub
commit a26da3c3b2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 49 additions and 37 deletions

View file

@ -55,6 +55,7 @@ cramium-fpga = ["utralib/cramium-fpga", "rand_chacha"]
board-baosec = ["cramium-hal/kernel-baosec", "memmap-flash", "swap"]
board-baosor = ["cramium-hal/kernel-baosor"]
board-dabao = ["cramium-hal/kernel-dabao"]
hosted-baosec = []
atsama5d27 = ["utralib/atsama5d27"]
precursor = ["utralib/precursor"]

View file

@ -6,10 +6,9 @@ use core::fmt;
use xous_kernel::{MemoryFlags, MemoryRange, PID, arch::*};
pub use crate::arch::mem::MemoryMapping;
use crate::arch::{
mem::{MMUFlags, flush_mmu, pagetable_entry},
process::Process,
};
#[cfg(baremetal)]
use crate::arch::mem::{MMUFlags, flush_mmu, pagetable_entry};
use crate::arch::process::Process;
#[cfg(feature = "swap")]
use crate::swap::SwapAlloc;
@ -621,6 +620,7 @@ impl MemoryManager {
// just allocate the region as "swapped". No further checks is done on the validity of the requested
// range - if the range is out of bounds, it will be caught as a runtime error in the resolver
// that attempts to find the physical page that corresponds to a virtual mapping.
#[cfg(baremetal)]
if phys == 0
&& (flags & MemoryFlags::VIRT == MemoryFlags::VIRT)
&& ((virt_ptr as usize & MMAP_VIRT_BASE) == MMAP_VIRT_BASE)

View file

@ -31,6 +31,8 @@ pub const EC_REGION_LEN: u32 = 0x0008_0000;
pub const PDDB_LOC: u32 = 0x01D8_0000; // PDDB start
pub const PDDB_LEN: u32 = EC_REGION_LOC - PDDB_LOC; // must be 64k-aligned (bulk erase block size) for proper function.
pub const SPINOR_ERASE_SIZE: u32 = 0x1000;
// quantum alloted to each process before a context switch is forced
// This is also platform-specific because it can be tuned based on CPU speed.
pub const BASE_QUANTA_MS: u32 = 10;

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")]
{

View file

@ -17,7 +17,7 @@ xous-ipc = "0.10.6"
num-derive = { version = "0.4.2", default-features = false }
num-traits = { version = "0.2.14", default-features = false }
log = "0.4.14"
loader = { path = "../../loader", features = ["swap"] }
loader = { path = "../../loader", features = ["swap"], optional = true }
aes-gcm-siv = { version = "0.11.1", default-features = false, features = [
"aes",
] }

View file

@ -1,3 +1,8 @@
#[cfg(feature = "cramium-soc")]
use cramium_hal::board::SPINOR_ERASE_SIZE;
#[cfg(any(feature = "precursor", feature = "renode"))]
use precursor_hal::board::SPINOR_ERASE_SIZE;
pub const PAGE_SIZE: usize = xous::arch::PAGE_SIZE;
/// userspace swapper -> kernel ABI
@ -116,7 +121,6 @@ impl Swapper {
use core::sync::atomic::{AtomicU32, Ordering};
use std::num::NonZero;
use cramium_hal::board::SPINOR_ERASE_SIZE;
use num_traits::ToPrimitive;
use xous::{MemoryMessage, MemoryRange};
static REFCOUNT: AtomicU32 = AtomicU32::new(0);