Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] Separate real and fake rom flows in individual files #1658

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions rom/dev/src/flow/cold_reset/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Abstract:

--*/

#![cfg_attr(feature = "fake-rom", allow(dead_code))]

mod crypto;
mod dice;
mod fmc_alias;
Expand Down
12 changes: 8 additions & 4 deletions rom/dev/src/flow/fake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,14 @@ mod fw_processor;
use crate::fht;
use crate::flow::update_reset;
use crate::flow::warm_reset;
use crate::handle_fatal_error;
use crate::print::HexBytes;
use crate::rom_env::RomEnv;
use caliptra_common::RomBootStatus::*;
use caliptra_common::{
memory_layout::{FMCALIAS_TBS_ORG, FMCALIAS_TBS_SIZE, LDEVID_TBS_ORG, LDEVID_TBS_SIZE},
FirmwareHandoffTable,
};
use caliptra_drivers::cprintln;
use caliptra_drivers::Lifecycle;
use caliptra_drivers::LmsResult;
use caliptra_drivers::VendorPubKeyRevocation;
use caliptra_drivers::*;
use caliptra_error::CaliptraError;
use caliptra_image_types::*;
Expand Down Expand Up @@ -137,6 +134,13 @@ impl FakeRomFlow {
/// * `env` - ROM Environment
#[inline(never)]
pub fn run(env: &mut RomEnv) -> CaliptraResult<()> {
if (env.soc_ifc.lifecycle() == caliptra_drivers::Lifecycle::Production)
&& !(env.soc_ifc.prod_en_in_fake_mode())
{
cprintln!("Fake ROM in Production lifecycle not enabled");
handle_fatal_error(CaliptraError::ROM_GLOBAL_FAKE_ROM_IN_PRODUCTION.into());
}

let reset_reason = env.soc_ifc.reset_reason();
match reset_reason {
// Cold Reset Flow
Expand Down
65 changes: 14 additions & 51 deletions rom/dev/src/flow/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,66 +13,29 @@ Abstract:
--*/

mod cold_reset;
#[cfg(feature = "fake-rom")]
mod fake;
mod update_reset;
mod warm_reset;

use crate::cprintln;
use crate::{handle_fatal_error, rom_env::RomEnv};
#[cfg(feature = "fake-rom")]
mod fake;
#[cfg(feature = "fake-rom")]
type ActiveFlow = crate::flow::fake::FakeRomFlow;

#[cfg(not(feature = "fake-rom"))]
mod real;
#[cfg(not(feature = "fake-rom"))]
type ActiveFlow = crate::flow::real::RealRomFlow;

use crate::rom_env::RomEnv;
use caliptra_cfi_derive::cfi_mod_fn;
use caliptra_cfi_lib::cfi_assert_eq;
use caliptra_drivers::{CaliptraResult, ResetReason};
use caliptra_error::CaliptraError;
use caliptra_drivers::CaliptraResult;

/// Execute ROM Flows based on reset reason
/// Execute ROM Flows based on real or fake ROM
///
/// # Arguments
///
/// * `env` - ROM Environment
#[cfg_attr(not(feature = "no-cfi"), cfi_mod_fn)]
pub fn run(env: &mut RomEnv) -> CaliptraResult<()> {
let reset_reason = env.soc_ifc.reset_reason();

if cfg!(not(feature = "fake-rom")) {
match reset_reason {
// Cold Reset Flow
ResetReason::ColdReset => {
cfi_assert_eq(env.soc_ifc.reset_reason(), ResetReason::ColdReset);
cold_reset::ColdResetFlow::run(env)
}

// Warm Reset Flow
ResetReason::WarmReset => {
cfi_assert_eq(env.soc_ifc.reset_reason(), ResetReason::WarmReset);
warm_reset::WarmResetFlow::run(env)
}

// Update Reset Flow
ResetReason::UpdateReset => {
cfi_assert_eq(env.soc_ifc.reset_reason(), ResetReason::UpdateReset);
update_reset::UpdateResetFlow::run(env)
}

// Unknown/Spurious Reset Flow
ResetReason::Unknown => {
cfi_assert_eq(env.soc_ifc.reset_reason(), ResetReason::Unknown);
Err(CaliptraError::ROM_UNKNOWN_RESET_FLOW)
}
}
} else {
let _result: CaliptraResult<()> = Err(CaliptraError::ROM_GLOBAL_PANIC);

if (env.soc_ifc.lifecycle() == caliptra_drivers::Lifecycle::Production)
&& !(env.soc_ifc.prod_en_in_fake_mode())
{
cprintln!("Fake ROM in Production lifecycle not enabled");
handle_fatal_error(CaliptraError::ROM_GLOBAL_FAKE_ROM_IN_PRODUCTION.into());
}

#[cfg(feature = "fake-rom")]
let _result = fake::FakeRomFlow::run(env);

_result
}
ActiveFlow::run(env)
}
41 changes: 41 additions & 0 deletions rom/dev/src/flow/real.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use crate::flow::cold_reset;
use crate::flow::update_reset;
use crate::flow::warm_reset;
use crate::RomEnv;
use caliptra_cfi_lib::cfi_assert_eq;
use caliptra_drivers::{CaliptraResult, ResetReason};
use caliptra_error::CaliptraError;

pub struct RealRomFlow {}

impl RealRomFlow {
pub fn run(env: &mut RomEnv) -> CaliptraResult<()> {
let reset_reason = env.soc_ifc.reset_reason();

match reset_reason {
// Cold Reset Flow
ResetReason::ColdReset => {
cfi_assert_eq(env.soc_ifc.reset_reason(), ResetReason::ColdReset);
cold_reset::ColdResetFlow::run(env)
}

// Warm Reset Flow
ResetReason::WarmReset => {
cfi_assert_eq(env.soc_ifc.reset_reason(), ResetReason::WarmReset);
warm_reset::WarmResetFlow::run(env)
}

// Update Reset Flow
ResetReason::UpdateReset => {
cfi_assert_eq(env.soc_ifc.reset_reason(), ResetReason::UpdateReset);
update_reset::UpdateResetFlow::run(env)
}

// Unknown/Spurious Reset Flow
ResetReason::Unknown => {
cfi_assert_eq(env.soc_ifc.reset_reason(), ResetReason::Unknown);
Err(CaliptraError::ROM_UNKNOWN_RESET_FLOW)
}
}
}
}
Loading