From d1f5aa19a8aa887ff511455965007bca62e8201b Mon Sep 17 00:00:00 2001 From: bunnie Date: Sun, 5 Oct 2025 17:00:39 +0800 Subject: [PATCH] map clock sources to API files, cleanup irqs on boot - clock freq/voltage now in API definitions - IRQ is disabled (or re-disabled) on all exit paths --- bao1x-boot/boot1/src/main.rs | 4 +++- bao1x-boot/boot1/src/platform/bao1x/bao1x.rs | 19 +++++++++++++------ .../boot1/src/platform/bao1x/usb/glue.rs | 1 + 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/bao1x-boot/boot1/src/main.rs b/bao1x-boot/boot1/src/main.rs index 264af3efa..d8c2918e4 100644 --- a/bao1x-boot/boot1/src/main.rs +++ b/bao1x-boot/boot1/src/main.rs @@ -24,9 +24,9 @@ use platform::*; use utralib::*; use ux_api::minigfx::{DrawStyle, FrameBuffer, Point, Rectangle}; -use crate::delay; use crate::platform::usb::glue; use crate::secboot::boot_or_die; +use crate::{delay, platform::irq::disable_all_irqs}; static UART_RX: Mutex>> = Mutex::new(RefCell::new(VecDeque::new())); #[allow(dead_code)] @@ -98,6 +98,7 @@ pub unsafe extern "C" fn rust_entry() -> ! { let boot_wait = one_way.get_decoded::().expect("internal error"); if boot_wait == BootWaitCoding::Disable && current_key.is_none() { + disable_all_irqs(); // this should diverge, rest of code is not run boot_or_die(); } @@ -284,6 +285,7 @@ pub unsafe extern "C" fn rust_entry() -> ! { } }); + disable_all_irqs(); // when we get to this point, there's only two options... crate::secboot::boot_or_die(); } diff --git a/bao1x-boot/boot1/src/platform/bao1x/bao1x.rs b/bao1x-boot/boot1/src/platform/bao1x/bao1x.rs index 46cb3d426..f2907275d 100644 --- a/bao1x-boot/boot1/src/platform/bao1x/bao1x.rs +++ b/bao1x-boot/boot1/src/platform/bao1x/bao1x.rs @@ -79,8 +79,10 @@ pub fn early_init(mut board_type: bao1x_api::BoardTypeCoding) -> (bao1x_api::Boa // setup the dabao 'boot' read pin for reading. This also connects the USB port temporarily. setup_dabao_boot_pin(&iox); - // we're running at 0.8V, setup the RAMs for that - let trim_table = bao1x_hal::sram_trim::get_sram_trim_for_voltage(800); + // setup the RAMs for our trim voltage + let trim_table = bao1x_hal::sram_trim::get_sram_trim_for_voltage( + bao1x_api::offsets::dabao::CPU_VDD_LDO_BOOT_MV, + ); let mut rbist = CSR::new(utra::rbist_wrp::HW_RBIST_WRP_BASE as *mut u32); for item in trim_table { rbist.wo(utra::rbist_wrp::SFRCR_TRM, item.raw_value()); @@ -142,7 +144,9 @@ pub fn early_init(mut board_type: bao1x_api::BoardTypeCoding) -> (bao1x_api::Boa setup_dabao_boot_pin(&iox); // we're running at 0.8V, setup the RAMs for that - let trim_table = bao1x_hal::sram_trim::get_sram_trim_for_voltage(800); + let trim_table = bao1x_hal::sram_trim::get_sram_trim_for_voltage( + bao1x_api::offsets::dabao::CPU_VDD_LDO_BOOT_MV, + ); let mut rbist = CSR::new(utra::rbist_wrp::HW_RBIST_WRP_BASE as *mut u32); for item in trim_table { rbist.wo(utra::rbist_wrp::SFRCR_TRM, item.raw_value()); @@ -165,7 +169,9 @@ pub fn early_init(mut board_type: bao1x_api::BoardTypeCoding) -> (bao1x_api::Boa sramtrm.wo(utra::coresub_sramtrm::SFR_VEXRAM, 0x1); // we should be in 0.9v mode, setup SRAM trimmings for that - let trim_table = bao1x_hal::sram_trim::get_sram_trim_for_voltage(900); + let trim_table = bao1x_hal::sram_trim::get_sram_trim_for_voltage( + bao1x_api::offsets::baosec::CPU_VDD_LDO_BOOT_MV, + ); let mut rbist = CSR::new(utra::rbist_wrp::HW_RBIST_WRP_BASE as *mut u32); for item in trim_table { rbist.wo(utra::rbist_wrp::SFRCR_TRM, item.raw_value()); @@ -221,8 +227,9 @@ pub fn early_init(mut board_type: bao1x_api::BoardTypeCoding) -> (bao1x_api::Boa // set the clock let fclk_freq = match board_type { - BoardTypeCoding::Baosec => bao1x_hal::board::DEFAULT_FCLK_FREQUENCY, - BoardTypeCoding::Dabao | BoardTypeCoding::Oem => SAFE_FCLK_FREQUENCY, + BoardTypeCoding::Baosec => bao1x_api::offsets::baosec::DEFAULT_FCLK_FREQUENCY, + BoardTypeCoding::Oem => SAFE_FCLK_FREQUENCY, + BoardTypeCoding::Dabao => bao1x_api::offsets::dabao::DEFAULT_FCLK_FREQUENCY, }; let perclk = unsafe { init_clock_asic(fclk_freq) }; diff --git a/bao1x-boot/boot1/src/platform/bao1x/usb/glue.rs b/bao1x-boot/boot1/src/platform/bao1x/usb/glue.rs index 3ab9c18d8..6ae8e08e9 100644 --- a/bao1x-boot/boot1/src/platform/bao1x/usb/glue.rs +++ b/bao1x-boot/boot1/src/platform/bao1x/usb/glue.rs @@ -145,6 +145,7 @@ pub fn shutdown() { if let Some(ref mut usb_ref) = crate::platform::bao1x::usb::USB { let usb = &mut *core::ptr::addr_of_mut!(*usb_ref); crate::irq::disable_all_irqs(); + crate::println!("Stopping USB..."); usb.stop(); } }