Skip to content

Commit

Permalink
add persistent bootrom method just in case
Browse files Browse the repository at this point in the history
  • Loading branch information
conorpp committed Jun 1, 2021
1 parent dfbd988 commit f40f4ce
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
15 changes: 12 additions & 3 deletions components/admin-app/src/management.rs
Expand Up @@ -18,6 +18,7 @@ const UUID: VendorCommand = VendorCommand::H62;
pub trait BootInterface {
fn reboot() -> !;
fn reboot_to_application_update() -> !;
fn reboot_to_application_update_persistent() -> !;
}

pub struct App<T, BI>
Expand Down Expand Up @@ -72,14 +73,18 @@ where T: TrussedClient,
]
}

fn call(&mut self, command: HidCommand, _: &Message, response: &mut Message) -> hid::AppResult {
fn call(&mut self, command: HidCommand, input_data: &Message, response: &mut Message) -> hid::AppResult {
match command {
HidCommand::Vendor(REBOOT) => {
BI::reboot();
}
HidCommand::Vendor(UPDATE) => {
if self.user_present() {
BI::reboot_to_application_update();
if input_data.len() > 0 && input_data[0] == 0x01 {
BI::reboot_to_application_update_persistent();
} else {
BI::reboot_to_application_update();
}
} else {
return Err(hid::Error::InvalidLength);
}
Expand Down Expand Up @@ -139,7 +144,11 @@ where T: TrussedClient,
// Boot to mcuboot (only when contact interface)
if interface == apdu::Interface::Contact && self.user_present()
{
BI::reboot_to_application_update();
if apdu.p1 == 0x01 {
BI::reboot_to_application_update_persistent();
} else {
BI::reboot_to_application_update();
}
}
return Err(Status::ConditionsOfUseNotSatisfied);
}
Expand Down
9 changes: 9 additions & 0 deletions runners/lpc55/src/types.rs
Expand Up @@ -90,6 +90,15 @@ pub struct Lpc55RebootInterface {}
impl admin_app::BootInterface for Lpc55RebootInterface {
fn reboot() -> ! { hal::raw::SCB::sys_reset() }
fn reboot_to_application_update() -> ! { hal::boot_to_bootrom() }
fn reboot_to_application_update_persistent() -> ! {
// Erasing the first flash page & rebooting will keep processer in bootrom persistently.
use hal::traits::flash::WriteErase;
let flash = unsafe { hal::peripherals::flash::Flash::steal() }.enabled(
&mut unsafe {hal::peripherals::syscon::Syscon::steal()}
);
hal::drivers::flash::FlashGordon::new(flash).erase_page(0).ok();
hal::raw::SCB::sys_reset()
}
}

#[cfg(feature = "admin-app")]
Expand Down

0 comments on commit f40f4ce

Please sign in to comment.