Skip to content

Commit

Permalink
Log fatal errors in CPTRA_FW_ERROR_NON_FATAL too (#665)
Browse files Browse the repository at this point in the history
  • Loading branch information
korran authored Sep 8, 2023
1 parent 8d25ef3 commit c2a59e0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 25 deletions.
20 changes: 7 additions & 13 deletions fmc/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ use core::hint::black_box;

use caliptra_common::cprintln;
use caliptra_drivers::{
report_fw_error_non_fatal, Ecc384, Hmac384, KeyVault, Mailbox, Sha256, Sha384, Sha384Acc,
SocIfc,
report_fw_error_fatal, report_fw_error_non_fatal, Ecc384, Hmac384, KeyVault, Mailbox, Sha256,
Sha384, Sha384Acc, SocIfc,
};
mod boot_status;
mod flow;
Expand All @@ -27,7 +27,6 @@ mod hand_off;

pub use boot_status::FmcBootStatus;
use caliptra_cpu::TrapRecord;
use caliptra_registers::soc_ifc::SocIfcReg;
use hand_off::HandOff;

#[cfg(feature = "std")]
Expand Down Expand Up @@ -113,20 +112,15 @@ fn report_error(code: u32) -> ! {
}
}

/// Report fatal F/W error
///
/// # Arguments
///
/// * `val` - F/W error code.
fn report_fw_error_fatal(val: u32) {
let mut soc_ifc = unsafe { SocIfcReg::new() };
soc_ifc.regs_mut().cptra_fw_error_fatal().write(|_| val);
}

#[allow(clippy::empty_loop)]
fn handle_fatal_error(code: u32) -> ! {
cprintln!("RT Fatal Error: 0x{:08X}", code);
report_fw_error_fatal(code);
// Populate the non-fatal error code too; if there was a
// non-fatal error stored here before we don't want somebody
// mistakenly thinking that was the reason for their mailbox
// command failure.
report_fw_error_non_fatal(code);

unsafe {
// Zeroize the crypto blocks.
Expand Down
5 changes: 5 additions & 0 deletions rom/dev/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,11 @@ extern "C" fn cfi_panic_handler(code: u32) -> ! {
fn handle_fatal_error(code: u32) -> ! {
cprintln!("ROM Fatal Error: 0x{:08X}", code);
report_fw_error_fatal(code);
// Populate the non-fatal error code too; if there was a
// non-fatal error stored here before we don't want somebody
// mistakenly thinking that was the reason for their mailbox
// command failure.
report_fw_error_non_fatal(code);

unsafe {
// Zeroize the crypto blocks.
Expand Down
21 changes: 9 additions & 12 deletions runtime/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ Abstract:

use caliptra_common::cprintln;
use caliptra_cpu::TrapRecord;
use caliptra_drivers::{Ecc384, Hmac384, KeyVault, Mailbox, Sha256, Sha384, Sha384Acc, SocIfc};
use caliptra_registers::soc_ifc::SocIfcReg;
use caliptra_drivers::{
report_fw_error_fatal, report_fw_error_non_fatal, Ecc384, Hmac384, KeyVault, Mailbox, Sha256,
Sha384, Sha384Acc, SocIfc,
};
use caliptra_runtime::Drivers;
use core::hint::black_box;

Expand Down Expand Up @@ -90,20 +92,15 @@ fn runtime_panic(_: &core::panic::PanicInfo) -> ! {
handle_fatal_error(caliptra_drivers::CaliptraError::RUNTIME_GLOBAL_PANIC.into());
}

/// Report fatal F/W error
///
/// # Arguments
///
/// * `val` - F/W error code.
fn report_fw_error_fatal(val: u32) {
let mut soc_ifc = unsafe { SocIfcReg::new() };
soc_ifc.regs_mut().cptra_fw_error_fatal().write(|_| val);
}

#[allow(clippy::empty_loop)]
fn handle_fatal_error(code: u32) -> ! {
cprintln!("RT Fatal Error: 0x{:08X}", code);
report_fw_error_fatal(code);
// Populate the non-fatal error code too; if there was a
// non-fatal error stored here before we don't want somebody
// mistakenly thinking that was the reason for their mailbox
// command failure.
report_fw_error_non_fatal(code);

unsafe {
// Zeroize the crypto blocks.
Expand Down

0 comments on commit c2a59e0

Please sign in to comment.