add oem-baosec-lite to boot1

This commit is contained in:
bunnie 2026-01-24 23:48:35 +08:00
parent b37d58fd59
commit b6e85f551d
4 changed files with 139 additions and 11 deletions

View file

@ -47,5 +47,8 @@ print-ifr = []
test-boot0-keys = []
alt-boot1 = []
oem = []
oem-baosec-lite = ["oem", "bao1x-hal/oem-baosec-lite"]
verilator-only = []
default = []
default = ["oem-baosec-lite"]

View file

@ -79,6 +79,16 @@ pub unsafe extern "C" fn rust_entry() -> ! {
let one_way = bao1x_hal::acram::OneWayCounter::new();
let mut board_type =
one_way.get_decoded::<bao1x_api::BoardTypeCoding>().expect("Board type coding error");
#[cfg(feature = "oem-baosec-lite")]
{
// this this flag was explicitly passed, this firmware image is only useful for OEM boards.
// set the board type as thus.
while board_type != bao1x_api::BoardTypeCoding::Oem {
one_way.inc_coded::<bao1x_api::BoardTypeCoding>().ok();
board_type =
one_way.get_decoded::<bao1x_api::BoardTypeCoding>().expect("Board type coding error");
}
}
// crate::println_d!("TX_IDLE: {:?}", crate::platform::usb::TX_IDLE.load(Ordering::SeqCst));
let perclk: u32;
@ -107,6 +117,10 @@ pub unsafe extern "C" fn rust_entry() -> ! {
if board_type == BoardTypeCoding::Baosec {
IS_BAOSEC.store(true, Ordering::SeqCst);
}
#[cfg(feature = "oem-baosec-lite")]
{
IS_BAOSEC.store(true, Ordering::SeqCst);
}
let iox = Iox::new(utra::iox::HW_IOX_BASE as *mut u32);
@ -164,6 +178,14 @@ pub unsafe extern "C" fn rust_entry() -> ! {
// grab a handle to the OLED if it exists on the board.
let mut udma_global = GlobalConfig::new();
let mut oled_iox = iox.clone();
#[cfg(feature = "oem-baosec-lite")]
let mut oled = Some(bao1x_hal::sh1107::Oled128x128::new(
bao1x_hal::sh1107::MainThreadToken::new(),
perclk,
&mut oled_iox,
&mut udma_global,
));
#[cfg(not(feature = "oem-baosec-lite"))]
let mut oled = if board_type == BoardTypeCoding::Baosec {
Some(bao1x_hal::sh1107::Oled128x128::new(
bao1x_hal::sh1107::MainThreadToken::new(),
@ -221,6 +243,8 @@ pub unsafe extern "C" fn rust_entry() -> ! {
if board_type == BoardTypeCoding::Baosec {
crate::glue::setup_spim(perclk);
}
#[cfg(feature = "oem-baosec-lite")]
crate::glue::setup_spim(perclk);
// it's in this loop that the board type would be set after initial boot
let mut repl = crate::repl::Repl::new();
@ -324,10 +348,16 @@ pub unsafe extern "C" fn rust_entry() -> ! {
iox.set_gpio_dir(se0_dabao.0, se0_dabao.1, bao1x_api::IoxDir::Input);
(se0_baosec.0, se0_baosec.1)
}
#[cfg(not(feature = "oem-baosec-lite"))]
_ => {
iox.set_gpio_dir(se0_baosec.0, se0_baosec.1, bao1x_api::IoxDir::Input);
(se0_dabao.0, se0_dabao.1)
}
#[cfg(feature = "oem-baosec-lite")]
_ => {
iox.set_gpio_dir(se0_dabao.0, se0_dabao.1, bao1x_api::IoxDir::Input);
(se0_baosec.0, se0_baosec.1)
}
};
boot(&iox, oled, se0_port, se0_pin, &mut csprng)
}

View file

@ -32,6 +32,7 @@ pub const FREE_MEM_LEN: usize = (RAM_BASE + RAM_SIZE) - FREE_MEM_START - STACK_L
// NOTE: this forces the mapping to be the same on both baosec and dabao
pub const UART_IFRAM_ADDR: usize = bao1x_hal::board::UART_DMA_TX_BUF_PHYS;
#[allow(dead_code)]
const SAFE_FCLK_FREQUENCY: u32 = 350_000_000;
// Dabao port/pin constants have to be vendored in because this crate is compiled with baosec as the target.
@ -168,17 +169,73 @@ pub fn early_init(mut board_type: bao1x_api::BoardTypeCoding) -> (bao1x_api::Boa
if setup_backup_region() == 0 {
crate::println!("backup region is clean!");
}
/* // debug RTC setting - remove once confident
let rtc = CSR::new(bao1x_hal::rtc::HW_RTC_BASE as *mut u32);
for i in 0..8 {
crate::println_d!("rtc {}: {:x}", i, unsafe { rtc.base().add(i).read_volatile() });
}
*/
// setup board-specific I/Os - early boot set. These are items that have to be
// done in a time-sensitive fashion.
match board_type {
BoardTypeCoding::Dabao | BoardTypeCoding::Oem => {
#[cfg(feature = "oem-baosec-lite")]
BoardTypeCoding::Oem => {
let power_off_port = bao1x_hal::board::get_power_off_pin();
iox.setup_pin(
power_off_port.0,
power_off_port.1,
Some(IoxDir::Output),
Some(IoxFunction::Gpio),
None,
Some(IoxEnable::Disable),
None,
Some(IoxDriveStrength::Drive2mA),
);
// ensures the device stays on
iox.set_gpio_pin(power_off_port.0, power_off_port.1, IoxValue::Low);
let mut sramtrm = CSR::new(utra::coresub_sramtrm::HW_CORESUB_SRAMTRM_BASE as *mut u32);
sramtrm.wo(utra::coresub_sramtrm::SFR_CACHE, 0x3);
sramtrm.wo(utra::coresub_sramtrm::SFR_ITCM, 0x3);
sramtrm.wo(utra::coresub_sramtrm::SFR_DTCM, 0x3);
sramtrm.wo(utra::coresub_sramtrm::SFR_VEXRAM, 0x1);
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());
rbist.wo(utra::rbist_wrp::SFRAR_TRM, 0x5a);
}
let (se0_port, se0_pin) = bao1x_hal::board::setup_usb_pins(&iox);
iox.set_gpio_pin(se0_port, se0_pin, IoxValue::Low); // put the USB port into SE0 while we initialize things
// setup display - turn on its power, reset the framebuffer
bao1x_hal::board::setup_display_pins(&iox);
// power on
let (oled_on_port, oled_on_pin) = bao1x_hal::board::setup_oled_power_pin(&iox);
iox.set_gpio_pin_value(oled_on_port, oled_on_pin, IoxValue::High);
// reset enable - note inversion compared to baosec (at least as of this board rev of baosec)
bao1x_hal::board::setup_periph_reset_pin(&iox);
bao1x_hal::board::assert_periph_reset(&iox, true);
// delay for reset assert
delay(1);
bao1x_hal::board::assert_periph_reset(&iox, false);
}
#[cfg(not(feature = "oem"))]
BoardTypeCoding::Oem => {
// provide a default behavior for unbound OEM board settings
setup_dabao_boot_pin(&iox);
// 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());
rbist.wo(utra::rbist_wrp::SFRAR_TRM, 0x5a);
}
}
BoardTypeCoding::Dabao => {
// setup the dabao 'boot' read pin for reading. This also connects the USB port temporarily.
setup_dabao_boot_pin(&iox);
@ -342,6 +399,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_api::offsets::baosec::DEFAULT_FCLK_FREQUENCY,
#[cfg(feature = "oem-baosec-lite")]
BoardTypeCoding::Oem => bao1x_api::offsets::baosec::DEFAULT_FCLK_FREQUENCY,
#[cfg(not(feature = "oem-baosec-lite"))]
BoardTypeCoding::Oem => SAFE_FCLK_FREQUENCY,
BoardTypeCoding::Dabao => bao1x_api::offsets::dabao::DEFAULT_FCLK_FREQUENCY,
};
@ -456,7 +516,25 @@ pub fn get_key<T: IoSetup + IoGpio>(board_type: &BoardTypeCoding, iox: &T) -> Op
// record which key is pressed
if kps[0] != KeyPress::None { Some(kps[0]) } else { None }
}
_ => {
BoardTypeCoding::Dabao => {
let (port, pin) = crate::platform::setup_dabao_boot_pin(iox);
// sample the pin
if iox.get_gpio_pin_value(port, pin) == IoxValue::Low {
// "borrow" the dabao keypress meaning for this pin
Some(KeyPress::Select)
} else {
None
}
}
#[cfg(feature = "oem-baosec-lite")]
BoardTypeCoding::Oem => {
let (rows, cols) = bao1x_hal::board::setup_kb_pins(iox);
let kps = bao1x_hal::board::scan_keyboard(iox, &rows, &cols);
// record which key is pressed
if kps[0] != KeyPress::None { Some(kps[0]) } else { None }
}
#[cfg(not(feature = "oem-baosec-lite"))]
BoardTypeCoding::Oem => {
let (port, pin) = crate::platform::setup_dabao_boot_pin(iox);
// sample the pin
if iox.get_gpio_pin_value(port, pin) == IoxValue::Low {

View file

@ -597,6 +597,7 @@ impl Repl {
let one_way = bao1x_hal::acram::OneWayCounter::new();
let board_type =
one_way.get_decoded::<bao1x_api::BoardTypeCoding>().expect("Board type coding error");
#[cfg(not(feature = "oem-baosec-lite"))]
if board_type != bao1x_api::BoardTypeCoding::Baosec {
while one_way.get_decoded::<bao1x_api::BoardTypeCoding>().expect("owc coding error")
!= bao1x_api::BoardTypeCoding::Baosec
@ -604,6 +605,14 @@ impl Repl {
one_way.inc_coded::<bao1x_api::BoardTypeCoding>().expect("increment error");
}
}
#[cfg(feature = "oem-baosec-lite")]
if board_type != bao1x_api::BoardTypeCoding::Oem {
while one_way.get_decoded::<bao1x_api::BoardTypeCoding>().expect("owc coding error")
!= bao1x_api::BoardTypeCoding::Oem
{
one_way.inc_coded::<bao1x_api::BoardTypeCoding>().expect("increment error");
}
}
// reset the USB stack so that we'll re-enumerate correctly after this reboot.
// This also has the side-effect of redirecting the console output back to the serial port.
crate::platform::usb::glue::shutdown();
@ -615,8 +624,16 @@ impl Repl {
// CI note: this appears on the "hard UART", not on USB serial. If we want this on USB
// serial, we would want to add some wait time to ensure the USB packets get sent before
// issuing the reboot command.
crate::println!("{}BOOT1.SETBOARD,{}", BOOKEND_START, BOOKEND_END);
crate::println!("Board type set to baosec, rebooting so boot1 can provision keys!");
#[cfg(not(feature = "oem-baosec-lite"))]
{
crate::println!("{}BOOT1.SETBOARD,{}", BOOKEND_START, BOOKEND_END);
crate::println!("Board type set to baosec, rebooting so boot1 can provision keys!");
}
#[cfg(feature = "oem-baosec-lite")]
{
crate::println!("Board type set to baosec-lite, rebooting so boot1 can provision keys!");
crate::println!("{}BOOT1.SETBOARD-LITE,{}", BOOKEND_START, BOOKEND_END);
}
let mut rcurst = CSR::new(utra::sysctrl::HW_SYSCTRL_BASE as *mut u32);
rcurst.wo(utra::sysctrl::SFR_RCURST0, 0x55AA);
}