cleanup the cramium hw implementation feature flags

this re-oragnizes the feature matrix of the loader to
reflect the chip/board division of feature flags better.
This commit is contained in:
bunnie 2024-11-30 02:26:56 +08:00
parent 43988bde05
commit 1710fb7ee2
2 changed files with 85 additions and 57 deletions

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,8 +298,12 @@ 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
#[cfg(any(feature = "board-baosec", feature = "board-baosor"))]
{
let mut pmic: Option<Axp2101> = None;
for _ in 0..3 {
@ -327,8 +343,8 @@ pub fn early_init() -> u32 {
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.
// 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();
@ -341,12 +357,15 @@ pub fn early_init() -> u32 {
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();
#[cfg(any(feature = "board-baosec", feature = "board-baosor"))]
{
// show the boot logo
use cramium_hal::minigfx::FrameBuffer;
@ -355,6 +374,7 @@ pub fn early_init() -> u32 {
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;