diff --git a/bao1x-boot/boot1/src/main.rs b/bao1x-boot/boot1/src/main.rs index f37fb14a7..119a49c46 100644 --- a/bao1x-boot/boot1/src/main.rs +++ b/bao1x-boot/boot1/src/main.rs @@ -25,9 +25,9 @@ use platform::*; use utralib::*; use ux_api::minigfx::{DrawStyle, FrameBuffer, Point, Rectangle}; +use crate::delay; use crate::platform::usb::glue; -use crate::secboot::boot_or_die; -use crate::{delay, platform::irq::disable_all_irqs}; +use crate::secboot::try_boot; // Notes: // - "Towards" - not a release yet, but working towards the stated milestone @@ -104,9 +104,9 @@ pub unsafe extern "C" fn rust_entry() -> ! { let boot_wait = one_way.get_decoded::().expect("internal error"); if boot_wait == BootWaitCoding::Disable && current_key.is_none() { - disable_all_irqs(); - // this should diverge, rest of code is not run - boot_or_die(); + // diverges if there is code to run + try_boot(false); + // or_die == false means the rest of this gets run if there is no valid image } if boot_wait == BootWaitCoding::Enable { @@ -291,9 +291,9 @@ pub unsafe extern "C" fn rust_entry() -> ! { } }); - disable_all_irqs(); // when we get to this point, there's only two options... - crate::secboot::boot_or_die(); + try_boot(true); + unreachable!("`or_die = true` means this should be unreachable"); } pub fn marquee(sh1107: &mut Oled128x128, msg: &str) { diff --git a/bao1x-boot/boot1/src/repl.rs b/bao1x-boot/boot1/src/repl.rs index e329987b0..0a47f5f62 100644 --- a/bao1x-boot/boot1/src/repl.rs +++ b/bao1x-boot/boot1/src/repl.rs @@ -106,7 +106,7 @@ impl Repl { rcurst.wo(utra::sysctrl::SFR_RCURST0, 0x55AA); } "boot" => { - crate::secboot::boot_or_die(); + crate::secboot::try_boot(true); } "uf2" => { use base64::{Engine as _, engine::general_purpose}; diff --git a/bao1x-boot/boot1/src/secboot.rs b/bao1x-boot/boot1/src/secboot.rs index a05ebc764..39fcc1efc 100644 --- a/bao1x-boot/boot1/src/secboot.rs +++ b/bao1x-boot/boot1/src/secboot.rs @@ -22,7 +22,7 @@ fn seal_boot1_keys() { cu.protect(); } -pub fn boot_or_die() -> ! { +pub fn try_boot(or_die: bool) { // loader is at the same offset as baremetal. Accept either as valid boot. // This diverges if the signature check is successful match bao1x_hal::sigcheck::validate_image( @@ -39,6 +39,10 @@ pub fn boot_or_die() -> ! { k, core::str::from_utf8(&tag).unwrap_or("invalid tag") ); + + // disable IRQs in preparation for next phase + crate::platform::irq::disable_all_irqs(); + // the tag is from signed, trusted data // k is just a nominal slot number. If either match, assume we are dealing with a // developer image. @@ -56,6 +60,8 @@ pub fn boot_or_die() -> ! { } Err(e) => crate::println!("Image did not validate: {:?}", e), } - crate::println!("No valid loader or baremetal image found. Halting!"); - bao1x_hal::sigcheck::die_no_std(); + if or_die { + crate::println!("No valid loader or baremetal image found. Halting!"); + bao1x_hal::sigcheck::die_no_std(); + } } diff --git a/libs/bao1x-api/src/offsets/common.rs b/libs/bao1x-api/src/offsets/common.rs index 3b4f15dde..7aba484db 100644 --- a/libs/bao1x-api/src/offsets/common.rs +++ b/libs/bao1x-api/src/offsets/common.rs @@ -76,8 +76,8 @@ encode_oneway! { encode_oneway! { #[offset = 81] pub enum BoardTypeCoding { - Baosec, Dabao, + Baosec, Oem, } } @@ -151,6 +151,14 @@ pub const IFR_HASH: SlotIndex = SlotIndex::Data(2, PartitionAccess::All, RwPerms /// during CP. pub const CP_ID: SlotIndex = SlotIndex::Data(3, PartitionAccess::All, RwPerms::ReadOnly); +/// Indelible versions of the public keys. The problem with the pubkeys in boot0 region is that +/// boot0 itself has the ability to modify its own memory. A copy here can have a bit set in +/// the IFR that blocks any attempt to modify these keys. +pub const BAO1_PUBKEY: SlotIndex = SlotIndex::Data(4, PartitionAccess::All, RwPerms::ReadOnly); +pub const BAO2_PUBKEY: SlotIndex = SlotIndex::Data(5, PartitionAccess::All, RwPerms::ReadOnly); +pub const BETA_PUBKEY: SlotIndex = SlotIndex::Data(6, PartitionAccess::All, RwPerms::ReadOnly); +pub const DEV_PUBKEY: SlotIndex = SlotIndex::Data(7, PartitionAccess::All, RwPerms::ReadOnly); + // Notes on defining the boot0 IFR region. // RISC-V boot0 region start is defined by IFR slot 6, bits [55:48] // RISC-V boot1 region start (which is boot0 end) is defined by IFR slot 6, bits[47:40]