From bb29c53bad78039fbc7ea93fddf7124bcf3e6d46 Mon Sep 17 00:00:00 2001 From: bunnie Date: Thu, 18 Dec 2025 03:56:18 +0800 Subject: [PATCH] move the backup region check below IRQ handler setup this seems to be necessary for stability on dabao --- bao1x-boot/boot1/src/platform/bao1x/bao1x.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/bao1x-boot/boot1/src/platform/bao1x/bao1x.rs b/bao1x-boot/boot1/src/platform/bao1x/bao1x.rs index a7922fbd9..81fa21c6d 100644 --- a/bao1x-boot/boot1/src/platform/bao1x/bao1x.rs +++ b/bao1x-boot/boot1/src/platform/bao1x/bao1x.rs @@ -140,10 +140,9 @@ pub fn setup_backup_region() -> u32 { /// This can change the board type coding to a safer, simpler board type if the declared board type has /// problems booting. pub fn early_init(mut board_type: bao1x_api::BoardTypeCoding) -> (bao1x_api::BoardTypeCoding, u32) { - #[cfg(not(feature = "alt-boot1"))] - if setup_backup_region() == 0 { - crate::println!("backup region is clean!"); - } + // This can be used to debug stuff early on dabao, assuming boot0 setup the console UART. It normally + // does, but we leave this commented out for non-debug situations because it's a weak guarantee. + // crate::debug::USE_CONSOLE.store(true, core::sync::atomic::Ordering::SeqCst); irq_setup(); // all sensors & IRQs setup already by boot0, but it doesn't hurt to re-write these registers @@ -157,6 +156,13 @@ pub fn early_init(mut board_type: bao1x_api::BoardTypeCoding) -> (bao1x_api::Boa let iox = Iox::new(utra::iox::HW_IOX_BASE as *mut u32); + // this has to happen after the IRQs are enabled because if a false security alarm is triggered the + // system won't reboot properly at the end of the set_backup_region() routine + #[cfg(not(feature = "alt-boot1"))] + if setup_backup_region() == 0 { + crate::println!("backup region is clean!"); + } + // setup board-specific I/Os - early boot set. These are items that have to be // done in a time-sensitive fashion. match board_type {