better altboot support

for updating boot1 on dabao
This commit is contained in:
bunnie 2025-10-28 21:37:55 +08:00
parent 28f7a8d6b2
commit 09309eb3ae
No known key found for this signature in database
3 changed files with 26 additions and 5 deletions

View file

@ -44,6 +44,7 @@ verbose-debug = ["bao1x-hal/debug-print-uart", "bao1x-hal/verbose-debug"]
print-ifr = []
test-boot0-keys = []
alt-boot1 = []
verilator-only = []
default = []

View file

@ -1,8 +1,8 @@
use core::convert::TryInto;
use core::sync::atomic::Ordering;
use bao1x_api::KERNEL_START;
use bao1x_api::*;
use bao1x_api::{BAREMETAL_START, KERNEL_START};
use bao1x_hal::iox::Iox;
use bao1x_hal::sh1107::Oled128x128;
use bao1x_hal::udma::*;
@ -208,9 +208,13 @@ pub fn usb_ep1_bulk_out_complete(
const SWAP_END_ADDR: usize =
bao1x_api::offsets::SWAP_START_UF2 + bao1x_api::offsets::SWAP_UF2_LEN;
#[cfg(not(feature = "alt-boot1"))]
const START_RANGE: usize = bao1x_api::BAREMETAL_START;
#[cfg(feature = "alt-boot1")]
const START_RANGE: usize = bao1x_api::BOOT1_START;
// program the flash if a valid u2f block was found
if let Some(record) = uf2_data {
if matches!(record.address() as usize, bao1x_api::BAREMETAL_START..=STORAGE_END_ADDR)
if matches!(record.address() as usize, START_RANGE..=STORAGE_END_ADDR)
&& record.family() == bao1x_api::BAOCHIP_1X_UF2_FAMILY
{
let mut rram = bao1x_hal::rram::Reram::new();
@ -258,7 +262,7 @@ pub fn usb_ep1_bulk_out_complete(
}
// do some bookkeeping for the UI
let (partition, status) = if !IS_BAOSEC.load(Ordering::SeqCst) {
if matches!(record.address() as usize, BAREMETAL_START..=APP_RAM_ADDR) {
if matches!(record.address() as usize, START_RANGE..=APP_RAM_ADDR) {
("core", BAREMETAL_BYTES.fetch_add(record.data().len() as u32, Ordering::SeqCst))
} else if matches!(record.address() as usize, APP_RAM_ADDR..=STORAGE_END_ADDR) {
("app", APP_BYTES.fetch_add(record.data().len() as u32, Ordering::SeqCst))
@ -266,7 +270,7 @@ pub fn usb_ep1_bulk_out_complete(
("none", 0)
}
} else {
if matches!(record.address() as usize, BAREMETAL_START..=KERNEL_START) {
if matches!(record.address() as usize, START_RANGE..=KERNEL_START) {
(
"loader",
BAREMETAL_BYTES.fetch_add(record.data().len() as u32, Ordering::SeqCst),

View file

@ -211,6 +211,22 @@ impl Repl {
crate::platform::slots::check_slots(&new_type);
crate::println!("Key & data slots checked according to the new type");
}
"altboot" => {
let owc = OneWayCounter::new();
if args.len() == 0 {
crate::println!("Boot partition is: {:?}", owc.get_decoded::<AltBootCoding>());
self.abort_cmd();
return Ok(());
} else if args.len() != 1 {
return Err(Error::help("altboot [toggle]"));
}
if args[0] == "toggle" {
owc.inc_coded::<bao1x_api::AltBootCoding>().unwrap();
crate::println!("Boot partition is now: {:?}", owc.get_decoded::<AltBootCoding>());
} else {
return Err(Error::help("altboot [toggle]"));
}
}
"audit" => {
let owc = OneWayCounter::new();
crate::println!("Board type reads as: {:?}", owc.get_decoded::<BoardTypeCoding>());
@ -473,7 +489,7 @@ impl Repl {
_ => {
crate::println!("Command not recognized: {}", cmd);
crate::print!(
"Commands include: reset, echo, boot, bootwait, localecho, uf2, boardtype, audit, lockdown"
"Commands include: reset, echo, altboot, boot, bootwait, localecho, uf2, boardtype, audit, lockdown"
);
#[cfg(feature = "test-boot0-keys")]
crate::print!(", publock");