diff --git a/bao1x-boot/boot1/Cargo.toml b/bao1x-boot/boot1/Cargo.toml index dd32d8bdc..4395d11ee 100644 --- a/bao1x-boot/boot1/Cargo.toml +++ b/bao1x-boot/boot1/Cargo.toml @@ -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 = [] diff --git a/bao1x-boot/boot1/src/platform/bao1x/usb/handlers.rs b/bao1x-boot/boot1/src/platform/bao1x/usb/handlers.rs index f5f00f4e9..6b8da719c 100644 --- a/bao1x-boot/boot1/src/platform/bao1x/usb/handlers.rs +++ b/bao1x-boot/boot1/src/platform/bao1x/usb/handlers.rs @@ -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), diff --git a/bao1x-boot/boot1/src/repl.rs b/bao1x-boot/boot1/src/repl.rs index 10eab4dc2..8017f89c6 100644 --- a/bao1x-boot/boot1/src/repl.rs +++ b/bao1x-boot/boot1/src/repl.rs @@ -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::()); + self.abort_cmd(); + return Ok(()); + } else if args.len() != 1 { + return Err(Error::help("altboot [toggle]")); + } + if args[0] == "toggle" { + owc.inc_coded::().unwrap(); + crate::println!("Boot partition is now: {:?}", owc.get_decoded::()); + } else { + return Err(Error::help("altboot [toggle]")); + } + } "audit" => { let owc = OneWayCounter::new(); crate::println!("Board type reads as: {:?}", owc.get_decoded::()); @@ -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");