From c2a59e09030c200a120cecd9bcfbf8c3d73826f6 Mon Sep 17 00:00:00 2001 From: Kor Nielsen Date: Thu, 7 Sep 2023 17:16:23 -0700 Subject: [PATCH] Log fatal errors in CPTRA_FW_ERROR_NON_FATAL too (#665) --- fmc/src/main.rs | 20 +++++++------------- rom/dev/src/main.rs | 5 +++++ runtime/src/main.rs | 21 +++++++++------------ 3 files changed, 21 insertions(+), 25 deletions(-) diff --git a/fmc/src/main.rs b/fmc/src/main.rs index b7a876245d..9fe3919002 100644 --- a/fmc/src/main.rs +++ b/fmc/src/main.rs @@ -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; @@ -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")] @@ -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. diff --git a/rom/dev/src/main.rs b/rom/dev/src/main.rs index b2cf51c01b..cea7af1267 100644 --- a/rom/dev/src/main.rs +++ b/rom/dev/src/main.rs @@ -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. diff --git a/runtime/src/main.rs b/runtime/src/main.rs index 20e9d869de..79703ca840 100644 --- a/runtime/src/main.rs +++ b/runtime/src/main.rs @@ -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; @@ -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.