From 3893bc78a7e4e32a5c51635933d4709d03ec3e7f Mon Sep 17 00:00:00 2001 From: bunnie Date: Wed, 19 Nov 2025 14:00:08 +0800 Subject: [PATCH] add more annotations & set bootwait on setting board type bootwait allows automation to load the swap image after the board type is set correctly breaks the paradox that you can't init swap on a blank chip because it doesn't know it has swap --- loader/src/main.rs | 21 +++++++++++---------- loader/src/platform/bao1x/bao1x.rs | 9 +++++++++ loader/src/platform/bao1x/swap.rs | 15 ++++++++------- 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/loader/src/main.rs b/loader/src/main.rs index ce2b01c21..da5f14dad 100644 --- a/loader/src/main.rs +++ b/loader/src/main.rs @@ -93,6 +93,8 @@ pub mod swap; use core::{mem, ptr, slice}; use asm::*; +#[cfg(feature = "bao1x")] +use bao1x_hal::board::{BOOKEND_END, BOOKEND_START}; use bootconfig::BootConfig; use consts::*; pub use loader::*; @@ -285,18 +287,16 @@ pub unsafe extern "C" fn rust_entry(signed_buffer: *const usize, signature: u32) // out at this point. Thus, ensure that the system is already in developer mode. let owc = bao1x_hal::acram::OneWayCounter::new(); if owc.get(bao1x_api::DEVELOPER_MODE).unwrap() == 0 { - crate::println!( - "Kernel is devkey signed, but system is not in developer mode. Dying!" - ); + println!("{}LOADER.KERNDIE,{}", BOOKEND_START, BOOKEND_END); + println!("Kernel is devkey signed, but system is not in developer mode. Dying!"); bao1x_hal::sigcheck::die_no_std(); } else { - crate::println!("Developer key detected on kernel. Proceeding in developer mode!"); + println!("{}LOADER.KERNDEV,{}", BOOKEND_START, BOOKEND_END); + println!("Developer key detected on kernel. Proceeding in developer mode!"); } } } Err(e) => { - use bao1x_hal::board::{BOOKEND_END, BOOKEND_START}; - println!("Kernel failed signature check. Dying: {:?}", e); println!("{}LOADER.KERNFAIL,{}", BOOKEND_START, BOOKEND_END); bao1x_hal::sigcheck::die_no_std(); @@ -331,19 +331,20 @@ pub unsafe extern "C" fn rust_entry(signed_buffer: *const usize, signature: u32) // out at this point. Thus, ensure that the system is already in developer mode. let owc = bao1x_hal::acram::OneWayCounter::new(); if owc.get(bao1x_api::DEVELOPER_MODE).unwrap() == 0 { - crate::println!( + println!("{}LOADER.APPDIE,{}", BOOKEND_START, BOOKEND_END); + println!( "Detached app is devkey signed, but system is not in developer mode. Dying!" ); bao1x_hal::sigcheck::die_no_std(); } else { - crate::println!( - "Developer key detected on detached app. Proceeding in developer mode!" - ); + println!("{}LOADER.APPDEV,{}", BOOKEND_START, BOOKEND_END); + println!("Developer key detected on detached app. Proceeding in developer mode!"); } } true } Err(_e) => { + println!("{}LOADER.APPFAIL,{}", BOOKEND_START, BOOKEND_END); println!("No valid detached app found"); false } diff --git a/loader/src/platform/bao1x/bao1x.rs b/loader/src/platform/bao1x/bao1x.rs index 478a0abdf..1c3ed87e6 100644 --- a/loader/src/platform/bao1x/bao1x.rs +++ b/loader/src/platform/bao1x/bao1x.rs @@ -108,12 +108,21 @@ pub fn early_init_hw() -> u32 { let board_type = one_way.get_decoded::().expect("Board type coding error"); if board_type != bao1x_api::BoardTypeCoding::Baosec { + use bao1x_hal::board::{BOOKEND_END, BOOKEND_START}; + crate::println!("Board type is not Baosec; resetting it and rebooting!"); while one_way.get_decoded::().expect("owc coding error") != bao1x_api::BoardTypeCoding::Baosec { one_way.inc_coded::().expect("increment error"); } + // set bootwait, because we need to provision swap + while one_way.get_decoded::().expect("owc coding error") + != bao1x_api::BootWaitCoding::Enable + { + one_way.inc_coded::().expect("increment error"); + } + crate::println!("{}LOADER.SETBOARD,{}", BOOKEND_START, BOOKEND_END); 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); diff --git a/loader/src/platform/bao1x/swap.rs b/loader/src/platform/bao1x/swap.rs index 4b0785b00..9fbc50aa7 100644 --- a/loader/src/platform/bao1x/swap.rs +++ b/loader/src/platform/bao1x/swap.rs @@ -261,22 +261,22 @@ impl SwapHal { // ensure that the system is already in developer mode. let owc = bao1x_hal::acram::OneWayCounter::new(); if owc.get(bao1x_api::DEVELOPER_MODE).unwrap() == 0 { - crate::println!( + println!("{}LOADER.SWAPDIE,{}", BOOKEND_START, BOOKEND_END); + println!( "Swap is devkey signed, but system is not in developer mode. Dying!" ); bao1x_hal::sigcheck::die_no_std(); } else { - crate::println!( + println!("{}LOADER.SWAPDEV,{}", BOOKEND_START, BOOKEND_END); + println!( "Developer key detected on swap. Proceeding in developer mode!" ); } } } Err(e) => { - crate::println!( - "Fresh swap image did not pass public key validation: {:?}", - e - ); + println!("{}LOADER.SWAPSIGFAIL,{}", BOOKEND_START, BOOKEND_END); + println!("Fresh swap image did not pass public key validation: {:?}", e); bao1x_hal::sigcheck::die_no_std(); } } @@ -288,7 +288,8 @@ impl SwapHal { // replace the cipher with the new key hal.src_cipher = Aes256GcmSiv::new((*swap_key).into()); if hal.decrypt_src_page_at(0).is_err() { - crate::println!("Swap image failed cryptographic integrity checks!"); + println!("{}LOADER.SWAPDECFAIL,{}", BOOKEND_START, BOOKEND_END); + println!("Swap image failed cryptographic integrity checks!"); bao1x_hal::sigcheck::die_no_std(); } }