Skip to content

Commit

Permalink
rt: add FMC compatiblity checks
Browse files Browse the repository at this point in the history
Add compatiblity check funcion to test FMC compatiblity in runtime.

Signed-off-by: leongross <leon.gross@9elements.com>
  • Loading branch information
leongross committed Feb 27, 2025
1 parent 10ac42a commit fbe7ae3
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
2 changes: 2 additions & 0 deletions error/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,8 @@ impl CaliptraError {
pub const RUNTIME_GET_FMC_CSR_UNSUPPORTED_FMC: CaliptraError =
CaliptraError::new_const(0x000E0055);

pub const RUNTIME_FMC_NOT_COMPATIBLE: CaliptraError = CaliptraError::new_const(0x000E0058);

/// FMC Errors
pub const FMC_GLOBAL_NMI: CaliptraError = CaliptraError::new_const(0x000F0001);
pub const FMC_GLOBAL_EXCEPTION: CaliptraError = CaliptraError::new_const(0x000F0002);
Expand Down
39 changes: 39 additions & 0 deletions runtime/src/compatibility.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*++
Licensed under the Apache-2.0 license.
File Name:
compatibility.rs
Abstract:
File contains compatibility functions to to check if the runtime is
compatible with FMC.
--*/

use caliptra_builder::version::RUNTIME_VERSION_MAJOR;
use caliptra_common::FirmwareHandoffTable;

pub fn is_fmc_compatible(fht: &FirmwareHandoffTable) -> bool {
fht.fht_major_ver == RUNTIME_VERSION_MAJOR
}

#[test]
fn test_is_fmc_compatible() {
let mut fht = FirmwareHandoffTable::default();
fht.fht_major_ver = 1;
fht.fht_minor_ver = 0;
assert_eq!(is_fmc_compatible(&fht), true);

// change minor version should not affect compatibility
fht.fht_minor_ver = 1;
assert_eq!(is_fmc_compatible(&fht), true);

fht.fht_minor_ver = 0xff;
assert_eq!(is_fmc_compatible(&fht), true);

fht.fht_major_ver = 2;
assert_eq!(is_fmc_compatible(&fht), false);
}
1 change: 1 addition & 0 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Abstract:
mod authorize_and_stash;
mod capabilities;
mod certify_key_extended;
pub mod compatibility;
pub mod dice;
mod disable;
mod dpe_crypto;
Expand Down
12 changes: 10 additions & 2 deletions runtime/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use caliptra_common::{cprintln, handle_fatal_error};
use caliptra_cpu::{log_trap_record, TrapRecord};
use caliptra_error::CaliptraError;
use caliptra_registers::soc_ifc::SocIfcReg;
use caliptra_runtime::Drivers;
use caliptra_runtime::{compatibility, Drivers};
use core::hint::black_box;

#[cfg(feature = "std")]
Expand Down Expand Up @@ -83,10 +83,18 @@ pub extern "C" fn entry_point() -> ! {
handle_fatal_error(e.into());
});

if !drivers.persistent_data.get().fht.is_valid() {
let fht = &drivers.persistent_data.get().fht;
if !fht.is_valid() {
cprintln!("[rt] Runtime can't load FHT");
handle_fatal_error(caliptra_drivers::CaliptraError::RUNTIME_HANDOFF_FHT_NOT_LOADED.into());
}

// Test if RT version is compatible with the FMC version
if !compatibility::is_fmc_compatible(&fht) {
cprintln!("[rt] Runtime is not compatible with FMC");
handle_fatal_error(caliptra_drivers::CaliptraError::RUNTIME_FMC_NOT_COMPATIBLE.into());
}

cprintln!("[rt] Runtime listening for mailbox commands...");
if let Err(e) = caliptra_runtime::handle_mailbox_commands(&mut drivers) {
handle_fatal_error(e.into());
Expand Down

0 comments on commit fbe7ae3

Please sign in to comment.