From 4486438df3b99ff14a852b1f24e0cc2c6c86dcd2 Mon Sep 17 00:00:00 2001 From: bunnie Date: Mon, 27 Oct 2025 19:06:42 +0800 Subject: [PATCH] add loader code that configures the board type for baosec only when the baosec feature is specified for the loader. Note: Will blow up if you try to load a baosec image on a dabao board. --- loader/src/platform/bao1x/bao1x.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/loader/src/platform/bao1x/bao1x.rs b/loader/src/platform/bao1x/bao1x.rs index 5c2eda0e1..d6a5b256e 100644 --- a/loader/src/platform/bao1x/bao1x.rs +++ b/loader/src/platform/bao1x/bao1x.rs @@ -100,6 +100,23 @@ pub fn early_init_hw() -> u32 { #[cfg(feature = "board-baosec")] { + // if board type is the default (dabao), reset to baosec, and reboot so that key + // provisioning can run. This should only happen if the avalanche generator is known to be good. + // TODO: implement avalanche generator test? + let one_way = bao1x_hal::acram::OneWayCounter::new(); + let board_type = + one_way.get_decoded::().expect("Board type coding error"); + if board_type != bao1x_api::BoardTypeCoding::Baosec { + while one_way.get_decoded::().expect("owc coding error") + != bao1x_api::BoardTypeCoding::Baosec + { + one_way.inc_coded::().expect("increment error"); + } + crate::println!("Board type set to baosec, rebooting so boot1 can provision keys!"); + let mut rcurst = CSR::new(utra::sysctrl::HW_SYSCTRL_BASE as *mut u32); + rcurst.wo(utra::sysctrl::SFR_RCURST0, 0x55AA); + } + // setup all the board pins to a known state let iox = Iox::new(utra::iox::HW_IOX_BASE as *mut u32); bao1x_hal::board::setup_display_pins(&iox);