Merge pull request #597 from betrusted-io/cram-dev

more cleanup for cram dev target
This commit is contained in:
bunnie 2024-12-02 02:54:18 +08:00 committed by GitHub
commit 4cf9c96f7a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
25 changed files with 14260 additions and 19383 deletions

16
Cargo.lock generated
View file

@ -948,7 +948,6 @@ dependencies = [
"xous-api-names",
"xous-api-ticktimer",
"xous-ipc 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)",
"xous-pio",
"xous-pl230",
"xous-swapper",
]
@ -972,7 +971,6 @@ dependencies = [
"xous-api-names",
"xous-api-ticktimer",
"xous-ipc 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)",
"xous-pio",
"xous-pl230",
]
@ -3018,7 +3016,6 @@ dependencies = [
"sha2-loader",
"simple-fatfs",
"utralib 0.1.25",
"xous-pio",
"xous-pl230",
"xous-riscv",
]
@ -6795,18 +6792,6 @@ dependencies = [
"xous-ipc 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "xous-pio"
version = "0.1.0"
dependencies = [
"defmt",
"log",
"pio",
"pio-proc",
"utralib 0.1.25",
"xous 0.9.64 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "xous-pl230"
version = "0.1.0"
@ -6818,7 +6803,6 @@ dependencies = [
"pio-proc",
"utralib 0.1.25",
"xous 0.9.64 (registry+https://github.com/rust-lang/crates.io-index)",
"xous-pio",
]
[[package]]

View file

@ -100,7 +100,7 @@ members = [
"libs/perflib",
"libs/tls",
"libs/userprefs",
"libs/xous-pio",
# "libs/xous-pio",
"libs/xous-bio",
"libs/xous-bio-bdma",
"libs/xous-pl230",

View file

@ -45,6 +45,7 @@ unexpected_cfgs = { level = "warn", check-cfg = ['cfg(ci)', 'cfg(baremetal)'] }
[features]
cramium-soc = ["utralib/cramium-soc", "cramium-hal", "rand_chacha", "raw-trng"]
verilator-only = ["cramium-hal/verilator-only"]
cramium-fpga = ["utralib/cramium-fpga"]
board-baosec = ["cramium-hal/board-baosec"]
board-baosor = ["cramium-hal/board-baosor"]

View file

@ -290,6 +290,7 @@ impl MemoryManager {
self.ram_size
);
};
#[cfg(feature = "swap")]
for o in 0..self.ram_size / PAGE_SIZE {
unsafe {
println!(

View file

@ -28,9 +28,17 @@ either = { version = "1.9.0", default-features = false }
xous = { version = "0.9.64", features = ["v2p"] }
[features]
board-baosec = [] # USB form factor token
board-baosor = [] # Precursor form factor
board-dabao = [] # Dev board form factor
camera-ov2640 = []
display-sh1107 = []
axp2101 = []
board-baosec = [
"camera-ov2640",
"display-sh1107",
"axp2101",
] # USB form factor token
board-baosor = ["camera-ov2640", "axp2101"] # Precursor form factor
board-dabao = [] # Dev board form factor
verilator-only = []
udma-stress-test = [
] # For RTL simulation testing - aggravates a key corner case
@ -39,4 +47,4 @@ compress-entropy = []
magic-manual = []
std = ["log", "xous-api-names", "usb-device", "xous-api-ticktimer"]
derive-rkyv = ["rkyv"]
default = ["board-baosec"]
default = []

View file

@ -0,0 +1,69 @@
// Constants that define pin locations, RAM offsets, etc. for the DaBao basic breakout board
use crate::iox::IoSetup;
use crate::iox::*;
// console uart buffer
pub const UART_DMA_TX_BUF_PHYS: usize = utralib::HW_IFRAM0_MEM + utralib::HW_IFRAM0_MEM_LEN - 4096;
// RAM needs two buffers of 1k + 16 bytes = 2048 + 16 = 2064 bytes; round up to one page
pub const SPIM_RAM_IFRAM_ADDR: usize = utralib::HW_IFRAM0_MEM + utralib::HW_IFRAM0_MEM_LEN - 2 * 4096;
// app uart buffer
pub const APP_UART_IFRAM_ADDR: usize = utralib::HW_IFRAM0_MEM + utralib::HW_IFRAM0_MEM_LEN - 3 * 4096;
// one page for the I2C driver
pub const I2C_IFRAM_ADDR: usize = utralib::HW_IFRAM0_MEM + utralib::HW_IFRAM0_MEM_LEN - 4 * 4096;
// USB pages - USB subsystem is a hog, needs a lot of pages, note this is mutually exclusive with camera,
// can't use both at once
pub const CRG_IFRAM_PAGES: usize = 23; // +1 for extended application buffer by 4k
pub const CRG_UDC_MEMBASE: usize =
utralib::HW_IFRAM1_MEM + utralib::HW_IFRAM1_MEM_LEN - CRG_IFRAM_PAGES * 0x1000;
// MANUALLY SYNCED TO ALLOCATIONS ABOVE
// inclusive numbering - we allocate pages from the top-down, so the last number should generally be 31
pub const IFRAM0_RESERVED_PAGE_RANGE: [usize; 2] = [31 - 4, 31];
pub const IFRAM1_RESERVED_PAGE_RANGE: [usize; 2] = [31 - 0, 31];
/// returns the USB SE0 port and pin number
const SE0_PIN: u8 = 14;
pub fn setup_usb_pins<T: IoSetup + IoGpio>(iox: &T) -> (IoxPort, u8) {
iox.setup_pin(
IoxPort::PB,
SE0_PIN,
Some(IoxDir::Output),
Some(IoxFunction::Gpio),
None,
None,
Some(IoxEnable::Enable),
Some(IoxDriveStrength::Drive2mA),
);
iox.set_gpio_pin_value(IoxPort::PB, SE0_PIN, IoxValue::Low);
(IoxPort::PB, SE0_PIN)
}
pub fn setup_i2c_pins(iox: &dyn IoSetup) -> crate::udma::I2cChannel {
// I2C_SCL_B[0]
iox.setup_pin(
IoxPort::PB,
11,
Some(IoxDir::Output),
Some(IoxFunction::AF1),
None,
None,
Some(IoxEnable::Enable),
Some(IoxDriveStrength::Drive2mA),
);
// I2C_SDA_B[0]
iox.setup_pin(
IoxPort::PB,
12,
Some(IoxDir::Output),
Some(IoxFunction::AF1),
Some(IoxEnable::Enable),
None,
Some(IoxEnable::Enable),
Some(IoxDriveStrength::Drive2mA),
);
crate::udma::I2cChannel::Channel0
}

View file

@ -6,3 +6,7 @@ pub use baosec::*;
pub mod baosor;
#[cfg(feature = "board-baosor")]
pub use baosor::*;
#[cfg(feature = "board-dabao")]
pub mod dabao;
#[cfg(feature = "board-dabao")]
pub use dabao::*;

View file

@ -2,12 +2,15 @@
#[macro_use]
pub mod debug;
#[cfg(feature = "axp2101")]
pub mod axp2101;
pub mod board;
pub mod ifram;
pub mod iox;
#[cfg(feature = "camera-ov2640")]
pub mod ov2640;
pub mod sce;
#[cfg(feature = "display-sh1107")]
pub mod sh1107;
pub mod shared_csr;
pub mod udma;

View file

@ -84,6 +84,7 @@ const RAW_ENTRIES: usize = 16;
/// for at least this many cycles before the next sample is taken, thus
/// making it more difficult for any adversary to reason about the current
/// state of the TRNG given the QC samples.
#[allow(dead_code)]
const RAW_GUARDBAND: usize = 32;
pub struct Trng {
@ -92,6 +93,9 @@ pub struct Trng {
mode: Mode,
/// Buffer some raw entropy inside the kernel, so we can "burst out" entropy
/// for reseed operations without having to wait for the TRNG to regenerate data.
///
/// This generates an unused warning when `verilator-only` is selected. We leave this
/// warning in place to remind ourselves that the TRNG is not real.
raw: [Option<u32>; RAW_ENTRIES],
#[cfg(feature = "compress-entropy")]
rng_var: u8,
@ -110,6 +114,7 @@ impl Trng {
}
}
#[cfg(not(feature = "verilator-only"))]
pub fn setup_raw_generation(&mut self, count: u16) {
self._count = count;
self.mode = Mode::Raw;
@ -137,6 +142,10 @@ impl Trng {
self.csr.wo(utra::trng::SFR_OPT, 0);
}
#[cfg(feature = "verilator-only")]
pub fn setup_raw_generation(&mut self, _count: u16) { self.mode = Mode::Raw; }
#[cfg(not(feature = "verilator-only"))]
pub fn get_raw(&mut self) -> u32 {
// Pull from the buffered entropy pool, until it's empty.
for d in self.raw.iter_mut() {
@ -217,6 +226,13 @@ impl Trng {
self.raw[0].take().unwrap()
}
#[cfg(feature = "verilator-only")]
pub fn get_raw(&mut self) -> u32 {
// guaranteed random by fair dice roll
// (in all seriousness, this is intentional in verilator because there is no TRNG in the RTL model)
4
}
pub fn get_u32(&mut self) -> Option<u32> {
match self.mode {
Mode::Uninit => None,

View file

@ -9,7 +9,7 @@ edition = "2021"
log = "0.4.14"
utralib = { version = "0.1.25", optional = true, default-features = false }
bitfield = "0.13.2"
xous-pio = { path = "../xous-pio", optional = true, default-features = false }
# xous-pio = { path = "../xous-pio", optional = true, default-features = false }
pio-proc = "0.2.2"
pio = "0.2.1"
cramium-hal = { path = "../cramium-hal", optional = true, default-features = false }
@ -23,10 +23,10 @@ cramium-fpga = ["utralib/cramium-fpga"]
precursor = []
hosted = []
renode = []
pio = ["xous-pio"]
pio = []
dma-mainram = []
baremetal = []
debug-print = []
tests = ["pio", "cramium-hal"]
default = ["tests", "pio"]
tests = ["cramium-hal"]
default = ["tests"]

View file

@ -25,11 +25,11 @@ xous-pl230 = { path = "../libs/xous-pl230", optional = true, features = [
"baremetal",
# "dma-mainram", # PL-230 option - this fails on MPW
] }
xous-pio = { path = "../libs/xous-pio", optional = true, features = [
"tests",
"cramium-soc",
"baremetal",
] }
# xous-pio = { path = "../libs/xous-pio", optional = true, features = [
# "tests",
# "cramium-soc",
# "baremetal",
# ] }
aes-gcm-siv = { version = "0.11.1", default-features = false, features = [
"aes",
], optional = true }
@ -79,29 +79,25 @@ renode = [
cramium-soc = [
"utralib/cramium-soc",
"debug-print",
"simulation-only",
"cramium-hal",
"xous-pio",
"xous-pl230",
"rand_chacha",
"sram-margin",
# "boot-delay",
]
board-baosec = [
"cramium-hal/board-baosec",
"updates",
"usb",
"libm",
"simple-fatfs",
"linked_list_allocator",
"ed25519-dalek",
"sha2",
"digest",
# "boot-delay",
]
board-baosec = ["cramium-hal/board-baosec"]
board-baosor = ["cramium-hal/board-baosor"]
board-dabao = ["cramium-hal/board-dabao"]
cramium-fpga = [
"utralib/cramium-fpga",
"debug-print",
"simulation-only",
"cramium-hal",
]
cramium-fpga = ["utralib/cramium-fpga", "debug-print", "cramium-hal"]
atsama5d27 = ["utralib/atsama5d27", "armv7", "dep:atsama5d27"]
# precursor flags
@ -118,6 +114,7 @@ board-bringup = []
sram-margin = []
boot-delay = []
simulation-only = []
verilator-only = []
quantum-timer-test = ["pio", "pio-proc"]
spim-test = []
irq-test = []
@ -129,10 +126,11 @@ clock-tests = []
reset-debug = []
usb = []
qr = ["nalgebra"]
updates = []
# general flags
debug-print = []
earlyprintk = []
resume = [] # suspend/resume pathway code
default = ["board-bringup", "dump-trng", "usb"]
default = []

View file

@ -16,7 +16,7 @@ pub extern "C" fn _start(_kernel_args: usize, loader_sig: usize) {
// Stub for clearing IFRAM & RAM on Cramium target. This is required
// to clear the parity check bits, which are randomly set on boot. System will
// eventually hang if these bits aren't cleared.
#[cfg(any(feature = "cramium-soc", feature = "cramium-fpga"))]
#[cfg(all(any(feature = "cramium-soc", feature = "cramium-fpga"), not(feature = "simulation-only")))]
unsafe {
#[rustfmt::skip]
asm! (

View file

@ -130,10 +130,15 @@ impl BootConfig {
(self.sram_size - self.init_size - self.extra_pages * PAGE_SIZE) / mem::size_of::<usize>(),
)
};
assert!((val as usize) >= (self.sram_start as usize));
assert!(
(val as usize) >= (self.sram_start as usize),
"val {:x} ! >= sram_start {:x}",
val as usize,
self.sram_start as usize
);
assert!(
(val as usize) < (self.sram_start as usize) + self.sram_size,
"top address {:08x} > (start + size) {:08x} + {:08x} = {:08x}",
"top address {:08x} ! < (start + size) {:08x} + {:08x} = {:08x}",
val as usize,
self.sram_start as usize,
self.sram_size,

View file

@ -83,19 +83,12 @@ pub enum IniType {
/// This function is safe to call exactly once.
#[export_name = "rust_entry"]
pub unsafe extern "C" fn rust_entry(signed_buffer: *const usize, signature: u32) -> ! {
//
// YOU WILL FORGET THIS -- but I haven't figured out a good way to describe this scenario
// when cross-building a SoC image (for s32 sim) to run on the FPGA variant,
// you need to comment this out. or else, the simulation will hang. But really, the SoC
// should be the SoC, the FPGA should be the FPGA...the cross-sim is not really guaranteed to work
// but it is just a handy tool to use when it *does* work.
//
#[cfg(feature = "cramium-soc")]
#[cfg(all(feature = "cramium-soc", not(feature = "verilator-only")))]
let perclk_freq = crate::platform::early_init(); // sets up PLLs so we're not running at 16MHz...
#[cfg(not(feature = "cramium-soc"))]
#[cfg(not(all(feature = "cramium-soc", not(feature = "verilator-only"))))]
let perclk_freq = 0;
#[cfg(feature = "cramium-soc")]
#[cfg(all(feature = "cramium-soc", feature = "updates"))]
crate::platform::process_update(perclk_freq);
// initially validate the whole image on disk (including kernel args)
@ -148,7 +141,7 @@ fn boot_sequence(args: KernelArguments, _signature: u32, fs_prehash: [u8; 64], _
println!("No suspend marker found, doing a cold boot!");
#[cfg(feature = "simulation-only")]
println!("Configured for simulation. Skipping RAM clear!");
#[cfg(not(feature = "simulation-only"))]
#[cfg(not(feature = "cramium-soc"))] // cramium-soc target clears RAM with assembly routine on boot
clear_ram(&mut cfg);
phase_1(&mut cfg);
phase_2(&mut cfg, &fs_prehash);
@ -506,7 +499,7 @@ fn check_resume(cfg: &mut BootConfig) -> (bool, bool, u32) {
/// Clears all of RAM. This is a must for systems that have suspend-to-RAM for security.
/// It is configured to be skipped in simulation only, to accelerate the simulation times
/// since we can initialize the RAM to zero in simulation.
#[cfg(not(feature = "simulation-only"))]
#[cfg(all(not(feature = "simulation-only"), not(feature = "cramium-soc")))]
fn clear_ram(cfg: &mut BootConfig) {
// clear RAM on a cold boot.
// RAM is persistent and battery-backed. This means secret material could potentially

View file

@ -593,6 +593,7 @@ pub fn pt_walk(root: usize, va: usize) -> Option<usize> {
}
#[cfg(all(any(feature = "debug-print", feature = "swap"), not(feature = "atsama5d27")))]
#[allow(dead_code)]
pub fn pt_walk_swap(root: usize, va: usize, swap_root: usize) -> Option<usize> {
let l1_pt = unsafe { &mut (*((root << 12) as *mut PageTable)) };
let l1_entry_va = (l1_pt.entries[(va & 0xFFC0_0000) >> 22] >> 10) << 12;

View file

@ -4,13 +4,19 @@ pub use cramium::*;
pub mod swap;
#[cfg(feature = "swap")]
pub use swap::*;
#[cfg(any(feature = "board-baosec", feature = "board-baosor"))]
mod bootlogo;
#[cfg(any(feature = "board-baosec", feature = "board-baosor"))]
mod poweron_bt;
#[cfg(feature = "updates")]
mod update;
#[cfg(feature = "updates")]
pub use update::*;
#[cfg(feature = "updates")]
mod verifier;
#[cfg(any(feature = "board-baosec", feature = "board-baosor"))]
mod gfx;
#[cfg(feature = "qr")]
mod homography;
@ -19,4 +25,5 @@ mod qr;
#[cfg(feature = "usb")]
mod usb;
#[cfg(feature = "updates")]
mod sha512_digest;

View file

@ -1,7 +1,11 @@
#[cfg(any(feature = "board-baosec", feature = "board-baosor"))]
use cramium_hal::axp2101::Axp2101;
#[cfg(not(feature = "verilator-only"))]
use cramium_hal::iox::{Iox, IoxDir, IoxEnable, IoxFunction, IoxPort};
use cramium_hal::udma;
#[cfg(any(feature = "board-baosec", feature = "board-baosor"))]
use cramium_hal::udma::PeriphId;
#[cfg(any(feature = "board-baosec", feature = "board-baosor"))]
use cramium_hal::udma::UdmaGlobalConfig;
use utralib::generated::*;
@ -75,6 +79,7 @@ pub const FLASH_BASE: usize = utralib::generated::HW_RERAM_MEM;
// exclusive of the signature block offset
pub const KERNEL_OFFSET: usize = 0x6_0000;
#[allow(dead_code)]
pub(crate) fn delay(quantum: usize) {
use utralib::{CSR, utra};
// abuse the d11ctime timer to create some time-out like thing
@ -91,7 +96,7 @@ pub(crate) fn delay(quantum: usize) {
}
}
#[cfg(feature = "cramium-soc")]
#[cfg(all(feature = "cramium-soc", not(feature = "verilator-only")))]
pub fn early_init() -> u32 {
// Set up the initial clocks. This is done as a "poke array" into a table of addresses.
// Why? because this is actually how it's done for the chip verification code. We can
@ -207,8 +212,10 @@ pub fn early_init() -> u32 {
// Now setup the clocks for real
// Safety: this can only be called in the early_init boot context
#[cfg(not(feature = "simulation-only"))]
let perclk = unsafe { init_clock_asic(800_000_000) };
// let perclk = unsafe { init_clock_asic_c(800_000_000, 0) };
#[cfg(feature = "simulation-only")]
let perclk = 100_000_000;
crate::println!("Perclk is {} Hz", perclk);
// Configure the UDMA UART. This UART's settings will be used as the initial console UART.
@ -220,6 +227,7 @@ pub fn early_init() -> u32 {
// UART_TX_A[0] = PA4 app
// UART_RX_A[1] = PD13 console
// UART_RX_A[1] = PD14 console
#[allow(unused_mut)] // some configs require mut
let mut iox = Iox::new(utra::iox::HW_IOX_BASE as *mut u32);
iox.set_alternate_function(IoxPort::PD, 13, IoxFunction::AF1);
iox.set_alternate_function(IoxPort::PD, 14, IoxFunction::AF1);
@ -230,6 +238,7 @@ pub fn early_init() -> u32 {
iox.set_gpio_dir(IoxPort::PD, 14, IoxDir::Output);
// Set up the UDMA_UART block to the correct baud rate and enable status
#[allow(unused_mut)] // some configs require mut
let mut udma_global = udma::GlobalConfig::new(utra::udma_ctrl::HW_UDMA_CTRL_BASE as *mut u32);
udma_global.clock_on(udma::PeriphId::Uart1);
udma_global.map_event(
@ -277,8 +286,11 @@ pub fn early_init() -> u32 {
glbl_csr.wo(utra::sce_glbsfr::SFR_FFCLR, 0xff05);
// configure LDO voltages that aren't correct by default.
#[cfg(any(feature = "board-baosec", feature = "board-baosor"))]
let i2c_channel = cramium_hal::board::setup_i2c_pins(&iox);
#[cfg(any(feature = "board-baosec", feature = "board-baosor"))]
udma_global.clock(PeriphId::from(i2c_channel), true);
#[cfg(any(feature = "board-baosec", feature = "board-baosor"))]
let i2c_ifram = unsafe {
cramium_hal::ifram::IframRange::from_raw_parts(
cramium_hal::board::I2C_IFRAM_ADDR,
@ -286,75 +298,83 @@ pub fn early_init() -> u32 {
4096,
)
};
#[cfg(any(feature = "board-baosec", feature = "board-baosor"))]
let mut i2c = unsafe { cramium_hal::udma::I2c::new_with_ifram(i2c_channel, 400_000, perclk, i2c_ifram) };
// setup PMIC
let mut pmic: Option<Axp2101> = None;
#[cfg(any(feature = "board-baosec", feature = "board-baosor"))]
{
let mut pmic: Option<Axp2101> = None;
for _ in 0..3 {
match cramium_hal::axp2101::Axp2101::new(&mut i2c) {
Ok(p) => {
pmic = Some(p);
break;
}
Err(e) => {
crate::println!("Error initializing pmic: {:?}, retrying", e);
for _ in 0..3 {
match cramium_hal::axp2101::Axp2101::new(&mut i2c) {
Ok(p) => {
pmic = Some(p);
break;
}
Err(e) => {
crate::println!("Error initializing pmic: {:?}, retrying", e);
// we have to reboot it appears if the I2C is unstable - a "soft recovery"
// just leads to CPU lock-up on exit from the init routine? what is going on??
// maybe some IFRAM instability? Maybe the I2C unit is locking up?
let mut rcurst = CSR::new(utra::sysctrl::HW_SYSCTRL_BASE as *mut u32);
rcurst.wo(utra::sysctrl::SFR_RCURST0, 0x55AA);
rcurst.wo(utra::sysctrl::SFR_RCURST1, 0x55AA);
// we have to reboot it appears if the I2C is unstable - a "soft recovery"
// just leads to CPU lock-up on exit from the init routine? what is going on??
// maybe some IFRAM instability? Maybe the I2C unit is locking up?
let mut rcurst = CSR::new(utra::sysctrl::HW_SYSCTRL_BASE as *mut u32);
rcurst.wo(utra::sysctrl::SFR_RCURST0, 0x55AA);
rcurst.wo(utra::sysctrl::SFR_RCURST1, 0x55AA);
/*
unsafe {
let ifram0 = HW_IFRAM0_MEM as *mut u32;
for i in 0..HW_IFRAM0_MEM_LEN / size_of::<u32>() {
ifram0.add(i).write_volatile(0);
}
let ifram1 = HW_IFRAM1_MEM as *mut u32;
for i in 0..HW_IFRAM1_MEM_LEN / size_of::<u32>() {
ifram1.add(i).write_volatile(0);
}
}*/
/*
unsafe {
let ifram0 = HW_IFRAM0_MEM as *mut u32;
for i in 0..HW_IFRAM0_MEM_LEN / size_of::<u32>() {
ifram0.add(i).write_volatile(0);
}
let ifram1 = HW_IFRAM1_MEM as *mut u32;
for i in 0..HW_IFRAM1_MEM_LEN / size_of::<u32>() {
ifram1.add(i).write_volatile(0);
}
}*/
delay(500);
}
};
}
if let Some(mut pmic) = pmic {
pmic.set_ldo(&mut i2c, Some(2.5), cramium_hal::axp2101::WhichLdo::Aldo2).unwrap();
pmic.set_dcdc(&mut i2c, Some((1.2, false)), cramium_hal::axp2101::WhichDcDc::Dcdc4).unwrap();
crate::println!("AXP2101 configure: {:?}", pmic);
// Make this true to have the system shut down by disconnecting its own battery while on battery power
// Note this does nothing if you have USB power plugged in.
if false {
crate::println!("shutting down...");
pmic.set_ldo(&mut i2c, Some(0.9), cramium_hal::axp2101::WhichLdo::Aldo3).ok();
crate::println!("system should be off");
delay(500);
}
};
}
if let Some(mut pmic) = pmic {
pmic.set_ldo(&mut i2c, Some(2.5), cramium_hal::axp2101::WhichLdo::Aldo2).unwrap();
pmic.set_dcdc(&mut i2c, Some((1.2, false)), cramium_hal::axp2101::WhichDcDc::Dcdc4).unwrap();
crate::println!("AXP2101 configure: {:?}", pmic);
// Make this true to have the system shut down by disconnecting its own battery while on battery
// power Note this does nothing if you have USB power plugged in.
if false {
crate::println!("shutting down...");
pmic.set_ldo(&mut i2c, Some(0.9), cramium_hal::axp2101::WhichLdo::Aldo3).ok();
crate::println!("system should be off");
}
} else {
crate::println!("Couldn't init AXP2101, rebooting");
let mut rcurst = CSR::new(utra::sysctrl::HW_SYSCTRL_BASE as *mut u32);
rcurst.wo(utra::sysctrl::SFR_RCURST0, 0x55AA);
rcurst.wo(utra::sysctrl::SFR_RCURST1, 0x55AA);
panic!("System should have reset");
}
} else {
crate::println!("Couldn't init AXP2101, rebooting");
let mut rcurst = CSR::new(utra::sysctrl::HW_SYSCTRL_BASE as *mut u32);
rcurst.wo(utra::sysctrl::SFR_RCURST0, 0x55AA);
rcurst.wo(utra::sysctrl::SFR_RCURST1, 0x55AA);
panic!("System should have reset");
}
// Turn off SE0 on USB
let _se0 = cramium_hal::board::baosec::setup_usb_pins(&iox);
let _se0 = cramium_hal::board::setup_usb_pins(&iox);
#[cfg(feature = "board-bringup")]
let iox_loop = iox.clone();
// show the boot logo
use cramium_hal::minigfx::FrameBuffer;
#[cfg(any(feature = "board-baosec", feature = "board-baosor"))]
{
// show the boot logo
use cramium_hal::minigfx::FrameBuffer;
let mut sh1107 = cramium_hal::sh1107::Oled128x128::new(perclk, &mut iox, &mut udma_global);
sh1107.init();
crate::platform::cramium::bootlogo::show_logo(&mut sh1107);
sh1107.buffer_swap();
sh1107.draw();
let mut sh1107 = cramium_hal::sh1107::Oled128x128::new(perclk, &mut iox, &mut udma_global);
sh1107.init();
crate::platform::cramium::bootlogo::show_logo(&mut sh1107);
sh1107.buffer_swap();
sh1107.draw();
}
// Board bring-up: send characters to confirm the UART is configured & ready to go for the logging crate!
// The "boot gutter" also has a role to pause the system in "real mode" before VM is mapped in Xous
@ -1337,6 +1357,7 @@ fn test_duart() {
pub fn platform_tests() { test_duart(); }
// returns the actual per_clk
#[cfg(not(feature = "simulation-only"))]
unsafe fn init_clock_asic(freq_hz: u32) -> u32 {
use utra::sysctrl;
let daric_cgu = sysctrl::HW_SYSCTRL_BASE as *mut u32;

View file

@ -16,7 +16,7 @@ log = "0.4.14"
num-derive = { version = "0.3.3", default-features = false }
num-traits = { version = "0.2.14", default-features = false }
xous-pio = { path = "../../libs/xous-pio", optional = true }
# xous-pio = { path = "../../libs/xous-pio", optional = true }
xous-pl230 = { path = "../../libs/xous-pl230", optional = true }
# this is temporary, until we get GAM/modals pulled in
graphics-server = { path = "../graphics-server" }
@ -38,7 +38,7 @@ xous-swapper = { path = "../xous-swapper" }
"clifford-poll" = []
"tts" = []
"early-ball" = []
"pio-test" = ["xous-pio"]
# "pio-test" = ["xous-pio"]
"pl230-test" = ["xous-pl230"]
"hwtest" = []
"pddb" = []

View file

@ -20,9 +20,9 @@ cramium-hal = { path = "../../libs/cramium-hal", features = [
"std",
] }
xous-pl230 = { path = "../../libs/xous-pl230", features = ["cramium-soc"] }
xous-pio = { path = "../../libs/xous-pio", default-features = false, features = [
"cramium-soc",
] }
# xous-pio = { path = "../../libs/xous-pio", default-features = false, features = [
# "cramium-soc",
# ] }
pio-proc = "0.2.2"
pio = "0.2.1"
rand_core = "0.6.4"
@ -43,5 +43,5 @@ rawserial = []
pinger = []
swap = []
# add this feature to enable pre-emption
quantum-timer = ["utralib"]
default = ["quantum-timer", "app-uart"]
quantum-timer = ["utralib", "pio"]
default = ["app-uart"]

View file

@ -13,8 +13,10 @@ use utralib::*;
#[cfg(feature = "swap")]
use xous::SWAPPER_PID;
use xous::sender::Sender;
#[cfg(feature = "pio")]
use xous_pio::*;
#[cfg(feature = "quantum-timer")]
struct PreemptionHw {
pub timer_sm: PioSm,
pub irq_csr: CSR<u32>,
@ -169,51 +171,54 @@ fn main() {
// -------------------- begin timer workaround code
// This code should go away with NTO as we have a proper, private ticktimer unit.
let mut pio_ss = xous_pio::PioSharedState::new();
// map and enable the interrupt for the PIO system timer
let irq18_page = xous::syscall::map_memory(
xous::MemoryAddress::new(utralib::generated::HW_IRQARRAY18_BASE),
None,
4096,
xous::MemoryFlags::R | xous::MemoryFlags::W,
)
.expect("couldn't claim irq18 csr");
let mut ptimer = PreemptionHw {
timer_sm: pio_ss.alloc_sm().unwrap(),
irq_csr: CSR::new(irq18_page.as_mut_ptr() as *mut u32),
};
// claim the IRQ for the quanta timer
xous::claim_interrupt(
utralib::LITEX_IRQARRAY18_INTERRUPT,
timer_tick,
&mut ptimer as *mut PreemptionHw as *mut usize,
)
.expect("couldn't claim IRQ");
pio_ss.clear_instruction_memory();
pio_ss.pio.rmwf(utra::rp_pio::SFR_CTRL_EN, 0);
#[rustfmt::skip]
let timer_code = pio_proc::pio_asm!(
"restart:",
"set x, 6", // 4 cycles overhead gets us to 10 iterations per pulse
"waitloop:",
"jmp x-- waitloop",
"irq set 0",
"jmp restart",
);
let a_prog = LoadedProg::load(timer_code.program, &mut pio_ss).unwrap();
ptimer.timer_sm.sm_set_enabled(false);
a_prog.setup_default_config(&mut ptimer.timer_sm);
ptimer.timer_sm.config_set_clkdiv(50_000.0f32); // set to 1ms per cycle
ptimer.timer_sm.sm_init(a_prog.entry());
ptimer.timer_sm.sm_irq0_source_enabled(PioIntSource::Sm, true);
ptimer.timer_sm.sm_set_enabled(true);
#[cfg(feature = "quantum-timer")]
#[cfg(feature = "pio")]
{
ptimer.irq_csr.wfo(utra::irqarray18::EV_ENABLE_PIOIRQ0_DUPE, 1);
log::info!("Quantum timer setup!");
let mut pio_ss = xous_pio::PioSharedState::new();
// map and enable the interrupt for the PIO system timer
let irq18_page = xous::syscall::map_memory(
xous::MemoryAddress::new(utralib::generated::HW_IRQARRAY18_BASE),
None,
4096,
xous::MemoryFlags::R | xous::MemoryFlags::W,
)
.expect("couldn't claim irq18 csr");
let mut ptimer = PreemptionHw {
timer_sm: pio_ss.alloc_sm().unwrap(),
irq_csr: CSR::new(irq18_page.as_mut_ptr() as *mut u32),
};
// claim the IRQ for the quanta timer
xous::claim_interrupt(
utralib::LITEX_IRQARRAY18_INTERRUPT,
timer_tick,
&mut ptimer as *mut PreemptionHw as *mut usize,
)
.expect("couldn't claim IRQ");
pio_ss.clear_instruction_memory();
pio_ss.pio.rmwf(utra::rp_pio::SFR_CTRL_EN, 0);
#[rustfmt::skip]
let timer_code = pio_proc::pio_asm!(
"restart:",
"set x, 6", // 4 cycles overhead gets us to 10 iterations per pulse
"waitloop:",
"jmp x-- waitloop",
"irq set 0",
"jmp restart",
);
let a_prog = LoadedProg::load(timer_code.program, &mut pio_ss).unwrap();
ptimer.timer_sm.sm_set_enabled(false);
a_prog.setup_default_config(&mut ptimer.timer_sm);
ptimer.timer_sm.config_set_clkdiv(50_000.0f32); // set to 1ms per cycle
ptimer.timer_sm.sm_init(a_prog.entry());
ptimer.timer_sm.sm_irq0_source_enabled(PioIntSource::Sm, true);
ptimer.timer_sm.sm_set_enabled(true);
#[cfg(feature = "quantum-timer")]
{
ptimer.irq_csr.wfo(utra::irqarray18::EV_ENABLE_PIOIRQ0_DUPE, 1);
log::info!("Quantum timer setup!");
}
}
// -------------------- end timer workaround code

View file

@ -3,7 +3,7 @@
<device schemaVersion="1.1" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:noNamespaceSchemaLocation="CMSIS-SVD.xsd" >
<vendor>litex</vendor>
<name>SOC</name>
<description><![CDATA[Litex SoC 2024-08-02 00:29:49]]></description>
<description><![CDATA[Litex SoC 2024-11-30 01:26:23]]></description>
<addressUnitBits>8</addressUnitBits>
<width>32</width>
@ -265,215 +265,6 @@ register to disable individual events.]]></description>
<value>21</value>
</interrupt>
</peripheral>
<peripheral>
<name>COREUSER</name>
<baseAddress>0xE0002000</baseAddress>
<groupName>COREUSER</groupName>
<registers>
<register>
<name>SET_ASID</name>
<addressOffset>0x0000</addressOffset>
<resetValue>0x00</resetValue>
<size>32</size>
<fields>
<field>
<name>asid</name>
<msb>8</msb>
<bitRange>[8:0]</bitRange>
<lsb>0</lsb>
<description><![CDATA[ASID to set. Writing to this register commits the value in `trusted` to the
specified `asid` value]]></description>
</field>
<field>
<name>trusted</name>
<msb>9</msb>
<bitRange>[9:9]</bitRange>
<lsb>9</lsb>
<description><![CDATA[Set to `1` if the ASID is trusted]]></description>
</field>
</fields>
</register>
<register>
<name>GET_ASID_ADDR</name>
<addressOffset>0x0004</addressOffset>
<resetValue>0x00</resetValue>
<size>32</size>
<fields>
<field>
<name>asid</name>
<msb>8</msb>
<bitRange>[8:0]</bitRange>
<lsb>0</lsb>
<description><![CDATA[ASID to read back.]]></description>
</field>
</fields>
</register>
<register>
<name>GET_ASID_VALUE</name>
<addressOffset>0x0008</addressOffset>
<resetValue>0x00</resetValue>
<size>32</size>
<fields>
<field>
<name>value</name>
<msb>0</msb>
<bitRange>[0:0]</bitRange>
<lsb>0</lsb>
<description><![CDATA[Value corresponding to the ASID specified in `get_asid_addr`. `1` means trusted]]></description>
</field>
</fields>
</register>
<register>
<name>SET_PRIVILEGE</name>
<addressOffset>0x000c</addressOffset>
<resetValue>0x00</resetValue>
<size>32</size>
<fields>
<field>
<name>mpp</name>
<msb>1</msb>
<bitRange>[1:0]</bitRange>
<lsb>0</lsb>
<description><![CDATA[Value of `mpp` bit from `mstatus` that must match for code to be trusted]]></description>
</field>
</fields>
</register>
<register>
<name>CONTROL</name>
<addressOffset>0x0010</addressOffset>
<resetValue>0x00</resetValue>
<size>32</size>
<fields>
<field>
<name>enable</name>
<msb>0</msb>
<bitRange>[0:0]</bitRange>
<lsb>0</lsb>
<description><![CDATA[Enable `CoreUser` computation. When set to `1`, the settings are applied; when
cleared to `0`, the `CoreUser` signal is always valid. Defaults to `0`.]]></description>
</field>
<field>
<name>asid</name>
<msb>1</msb>
<bitRange>[1:1]</bitRange>
<lsb>1</lsb>
<description><![CDATA[When `1`, requires the ASID mapping to be trusted to assert `CoreUser`]]></description>
</field>
<field>
<name>ppn_a</name>
<msb>2</msb>
<bitRange>[2:2]</bitRange>
<lsb>2</lsb>
<description><![CDATA[When set to `1`, requires the `a` `ppn` window to be trusted to assert
`CoreUser`]]></description>
</field>
<field>
<name>ppn_b</name>
<msb>3</msb>
<bitRange>[3:3]</bitRange>
<lsb>3</lsb>
<description><![CDATA[When set to `1`, requires the `b` `ppn` window to be trusted to assert
`CoreUser`]]></description>
</field>
<field>
<name>privilege</name>
<msb>4</msb>
<bitRange>[4:4]</bitRange>
<lsb>4</lsb>
<description><![CDATA[When set to `1`, requires the current privilege state to match that specified in
`set_privilege.mpp`]]></description>
</field>
</fields>
</register>
<register>
<name>PROTECT</name>
<description><![CDATA[Writing `1` to this bit prevents any further updates to CoreUser configuration
status. Can only be reversed with a system reset.]]></description>
<addressOffset>0x0014</addressOffset>
<resetValue>0x00</resetValue>
<size>32</size>
<fields>
<field>
<name>protect</name>
<msb>0</msb>
<bitRange>[0:0]</bitRange>
<lsb>0</lsb>
</field>
</fields>
</register>
<register>
<name>WINDOW_AL</name>
<addressOffset>0x0018</addressOffset>
<resetValue>0x00</resetValue>
<size>32</size>
<fields>
<field>
<name>ppn</name>
<msb>21</msb>
<bitRange>[21:0]</bitRange>
<lsb>0</lsb>
<description><![CDATA[PPN match value, `a` window lower bound. Matches if ppn is greater than or equal
to this value]]></description>
</field>
</fields>
</register>
<register>
<name>WINDOW_AH</name>
<addressOffset>0x001c</addressOffset>
<resetValue>0x00</resetValue>
<size>32</size>
<fields>
<field>
<name>ppn</name>
<msb>21</msb>
<bitRange>[21:0]</bitRange>
<lsb>0</lsb>
<description><![CDATA[PPN match value, `a` window upper bound. Matches if ppn is less than or equal to
this value (so a value of 255 would match everything from 0 to 255; resulting in
256 total locations]]></description>
</field>
</fields>
</register>
<register>
<name>WINDOW_BL</name>
<addressOffset>0x0020</addressOffset>
<resetValue>0x00</resetValue>
<size>32</size>
<fields>
<field>
<name>ppn</name>
<msb>21</msb>
<bitRange>[21:0]</bitRange>
<lsb>0</lsb>
<description><![CDATA[PPN match value, `b` window lower bound. Matches if ppn is greater than or equal
to this value]]></description>
</field>
</fields>
</register>
<register>
<name>WINDOW_BH</name>
<addressOffset>0x0024</addressOffset>
<resetValue>0x00</resetValue>
<size>32</size>
<fields>
<field>
<name>ppn</name>
<msb>21</msb>
<bitRange>[21:0]</bitRange>
<lsb>0</lsb>
<description><![CDATA[PPN match value, `b` window upper bound. Matches if ppn is less than or equal to
this value (so a value of 255 would match everything from 0 to 255; resulting in
256 total locations]]></description>
</field>
</fields>
</register>
</registers>
<addressBlock>
<offset>0</offset>
<size>0x28</size>
<usage>registers</usage>
</addressBlock>
</peripheral>
<peripheral>
<name>CSRTEST</name>
<baseAddress>0xE0003000</baseAddress>

File diff suppressed because it is too large Load diff

View file

@ -3,7 +3,7 @@
<device schemaVersion="1.1" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:noNamespaceSchemaLocation="CMSIS-SVD.xsd" >
<vendor>litex</vendor>
<name>SOC</name>
<description><![CDATA[Litex SoC 2024-08-02 00:29:50]]></description>
<description><![CDATA[Litex SoC 2024-11-30 01:26:25]]></description>
<addressUnitBits>8</addressUnitBits>
<width>32</width>

File diff suppressed because it is too large Load diff

View file

@ -172,6 +172,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
for feature in kern_features {
builder.add_kernel_feature(&feature);
}
let loader_features = get_flag("--loader-feature")?;
for feature in loader_features {
builder.add_loader_feature(&feature);
}
if !language_set {
// the default language is english
@ -513,7 +517,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// ------ Cramium hardware image configs ------
Some("cramium-fpga") | Some("cramium-soc") => {
let board = "board-baosec";
let board = "board-dabao";
// select the board
builder.add_feature(board);
builder.add_loader_feature(board);
@ -522,35 +526,14 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// placement in flash is a tension between dev convenience and RAM usage. Things in flash
// are resident, non-swapable, but end up making the slow kernel burn process take longer.
let cramium_flash_pkgs =
["xous-ticktimer", "xous-log", "xous-names" /* , "usb-device-xous" */].to_vec();
let cramium_swap_pkgs = ["cram-console", "cram-hal-service"].to_vec();
// minimal config for USB debugging
// let cramium_swap_pkgs = ["usb-device-xous"].to_vec(); // , "cram-console"
if !builder.is_swap_set() {
builder.set_swap(0, 8 * 1024 * 1024);
}
builder.add_loader_feature("board-bringup");
// builder.add_loader_feature("spim-test");
// builder.add_loader_feature("spi-alt-channel"); // this flag, when asserted, uses the J_QSPI
// header. By default, we use JPC7_13 (J_QSPI does not work, for some reason; bit 3 is stuck
// high...)
// builder.add_loader_feature("irq-test");
// builder.add_loader_feature("usb-test");
// builder.add_loader_feature("trng-test");
// builder.add_loader_feature("dump-trng");
// builder.add_loader_feature("usb");
// builder.add_loader_feature("qr");
// builder.add_feature("usb"); // needed if usb-device-xous is selected
builder.add_loader_feature("swap");
builder.add_kernel_feature("swap");
builder.add_feature("swap");
["xous-ticktimer", "xous-log", "xous-names" /* "cram-hal-service" */].to_vec();
let cramium_swap_pkgs = [].to_vec();
builder.add_loader_feature("debug-print");
builder.add_kernel_feature("debug-swap");
// builder.add_kernel_feature("debug-print");
// builder.add_kernel_feature("debug-swap-verbose");
builder.add_feature("quantum-timer");
// builder.add_feature("quantum-timer");
// builder.add_feature("auto-trng"); // automatically initialize TRNG tester inside USB stack
builder.add_kernel_feature("v2p");
// builder.add_feature("mass-storage");
@ -564,9 +547,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
};
broken_aes_cleanup = true;
// It is important that this is the first service added, because the swapper *must* be in PID 2
builder.add_service("xous-swapper", LoaderRegion::Flash);
for service in cramium_flash_pkgs {
builder.add_service(service, LoaderRegion::Flash);
}
@ -611,10 +591,11 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
builder.add_kernel_feature("debug-swap");
// builder.add_kernel_feature("debug-print");
// builder.add_kernel_feature("debug-swap-verbose");
builder.add_feature("quantum-timer");
// builder.add_feature("quantum-timer"); // this isn't in NTO..
builder.add_kernel_feature("v2p");
builder.add_loader_feature("sram-margin");
builder.add_loader_feature("usb");
builder.add_loader_feature("updates");
match task.as_deref() {
Some("baosec") => builder.target_cramium_soc(),
_ => panic!("should be unreachable"),