diff --git a/loader/src/main.rs b/loader/src/main.rs index 06b42b449..8230b7db8 100644 --- a/loader/src/main.rs +++ b/loader/src/main.rs @@ -91,7 +91,9 @@ pub unsafe extern "C" fn rust_entry(signed_buffer: *const usize, signature: u32) // but it is just a handy tool to use when it *does* work. // #[cfg(feature = "cramium-soc")] - crate::platform::early_init(); // sets up PLLs so we're not running at 16MHz... + let perclk_freq = crate::platform::early_init(); // sets up PLLs so we're not running at 16MHz... + #[cfg(not(feature = "cramium-soc"))] + let perclk_freq = 0; #[cfg(feature = "cramium-soc")] crate::platform::process_update(); @@ -116,10 +118,10 @@ pub unsafe extern "C" fn rust_entry(signed_buffer: *const usize, signature: u32) // But for now, the basic "validate everything as a blob" is perhaps good enough to // armor code-at-rest against front-line patching attacks. let kab = KernelArguments::new(arg_buffer); - boot_sequence(kab, signature, fs_prehash); + boot_sequence(kab, signature, fs_prehash, perclk_freq); } -fn boot_sequence(args: KernelArguments, _signature: u32, fs_prehash: [u8; 64]) -> ! { +fn boot_sequence(args: KernelArguments, _signature: u32, fs_prehash: [u8; 64], _perclk_freq: u32) -> ! { // Store the initial boot config on the stack. We don't know // where in heap this memory will go. #[allow(clippy::cast_ptr_alignment)] // This test only works on 32-bit systems @@ -133,7 +135,7 @@ fn boot_sequence(args: KernelArguments, _signature: u32, fs_prehash: [u8; 64]) - #[cfg(feature = "swap")] { - cfg.swap_hal = SwapHal::new(&cfg); + cfg.swap_hal = SwapHal::new(&cfg, _perclk_freq); read_swap_config(&mut cfg); } diff --git a/loader/src/platform/cramium/bootlogo.rs b/loader/src/platform/cramium/bootlogo.rs index e5cbaa2f3..9936148d8 100644 --- a/loader/src/platform/cramium/bootlogo.rs +++ b/loader/src/platform/cramium/bootlogo.rs @@ -1,13 +1,13 @@ use cramium_hal::iox::{IoGpio, IoSetup}; use cramium_hal::udma::UdmaGlobalConfig; -pub fn show_logo(pclk_freq: u32, udma_global: &dyn UdmaGlobalConfig, iox: &T) +pub fn show_logo(perclk_freq: u32, udma_global: &dyn UdmaGlobalConfig, iox: &T) where T: IoSetup + IoGpio, { // test the display SPI interface // safety: this is called exactly once on boot - let mut sh1107 = cramium_hal::sh1107::Oled128x128::new(iox, udma_global); + let mut sh1107 = cramium_hal::sh1107::Oled128x128::new(perclk_freq, iox, udma_global); sh1107.init(); { /* // pattern test for debugging pixel orientations - done with this now, I think? diff --git a/loader/src/platform/cramium/cramium.rs b/loader/src/platform/cramium/cramium.rs index e1110063c..4e96036bc 100644 --- a/loader/src/platform/cramium/cramium.rs +++ b/loader/src/platform/cramium/cramium.rs @@ -69,7 +69,7 @@ pub const FLASH_BASE: usize = utralib::generated::HW_RERAM_MEM; pub const KERNEL_OFFSET: usize = 0x4_0000; #[cfg(feature = "cramium-soc")] -pub fn early_init() { +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 // make this nicer and more abstract with register meanings down the road, if necessary, @@ -740,6 +740,8 @@ pub fn early_init() { udma_uart.write("Press any key to continue...".as_bytes()); getc(); udma_uart.write(b"\n\rBooting!\n\r"); + + perclk } #[cfg(feature = "clock-tests")] diff --git a/loader/src/platform/cramium/link-soc.x b/loader/src/platform/cramium/link-soc.x index 91f1a1b42..2514ff015 100644 --- a/loader/src/platform/cramium/link-soc.x +++ b/loader/src/platform/cramium/link-soc.x @@ -86,12 +86,12 @@ SECTIONS . = ALIGN(4); _edata = .; } > REGION_DATA AT > REGION_RODATA - +/* .fonts : ALIGN(65536) { KEEP(*(.fontdata)); } > FONTS - +*/ .bss (NOLOAD) : { _sbss = .; diff --git a/loader/src/platform/cramium/swap.rs b/loader/src/platform/cramium/swap.rs index 095f4ed34..35c5743d1 100644 --- a/loader/src/platform/cramium/swap.rs +++ b/loader/src/platform/cramium/swap.rs @@ -36,7 +36,7 @@ pub struct SwapHal { } impl SwapHal { - pub fn new(cfg: &BootConfig) -> Option { + pub fn new(cfg: &BootConfig, perclk_freq: u32) -> Option { if let Some(swap) = cfg.swap { let udma_global = GlobalConfig::new(utralib::generated::HW_UDMA_CTRL_BASE as *mut u32); @@ -49,8 +49,10 @@ impl SwapHal { let mut flash_spim = unsafe { Spim::new_with_ifram( channel, - 25_000_000, - 50_000_000, + // has to be half the clock frequency reaching the block, but run it as fast + // as we can run perclk + perclk_freq / 4, + perclk_freq / 2, SpimClkPol::LeadingEdgeRise, SpimClkPha::CaptureOnLeading, SpimCs::Cs0, @@ -68,8 +70,8 @@ impl SwapHal { let mut ram_spim = unsafe { Spim::new_with_ifram( channel, - 25_000_000, - 50_000_000, + perclk_freq / 4, + perclk_freq / 2, SpimClkPol::LeadingEdgeRise, SpimClkPha::CaptureOnLeading, SpimCs::Cs1,