Skip to content

Commit

Permalink
Refactor memory_layout and persistent_data
Browse files Browse the repository at this point in the history
* Reserve a portion of DCCM for future changes to PersistentData.
* Remove most hard coded addresses in memory layout.
* Reserved 19KiB in `PersistentData`.
* Left 8K in the Data section. Currently less than 4KiB is being used.

This resolves chipsalliance#1662.
  • Loading branch information
clundin25 committed Nov 15, 2024
1 parent 86a37b0 commit 0792abb
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 157 deletions.
2 changes: 1 addition & 1 deletion common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@ pub const FMC_SIZE: u32 = 20 * 1024;
pub const RUNTIME_ORG: u32 = FMC_ORG + FMC_SIZE;
pub const RUNTIME_SIZE: u32 = 97 * 1024;

pub use memory_layout::{DATA_ORG, FHT_ORG, FHT_SIZE, MAN1_ORG};
pub use memory_layout::{DATA_ORG, PERSISTENT_DATA_ORG};
pub use wdt::{restart_wdt, start_wdt, stop_wdt, WdtTimeout};
5 changes: 2 additions & 3 deletions drivers/src/hand_off.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
use crate::bounded_address::RomAddr;
use crate::soc_ifc;
use crate::{
memory_layout, ColdResetEntry4, ColdResetEntry48, Ecc384PubKey, Ecc384Signature, KeyId,
ResetReason, WarmResetEntry4, WarmResetEntry48,
ColdResetEntry4, ColdResetEntry48, Ecc384PubKey, Ecc384Signature, KeyId, ResetReason,
WarmResetEntry4, WarmResetEntry48,
};
use bitfield::{bitfield_bitrange, bitfield_fields};
use caliptra_error::CaliptraError;
Expand Down Expand Up @@ -177,7 +177,6 @@ impl From<DataStore> for HandOffDataHandle {
/// location in DCCM. It is initially populated by ROM and modified by FMC as a way
/// to pass parameters and configuration information from one firmware layer to the next.
const _: () = assert!(size_of::<FirmwareHandoffTable>() == 2048);
const _: () = assert!(size_of::<FirmwareHandoffTable>() <= memory_layout::FHT_SIZE as usize);
#[repr(C)]
#[derive(Clone, Debug, AsBytes, FromBytes, Zeroize)]
pub struct FirmwareHandoffTable {
Expand Down
112 changes: 11 additions & 101 deletions drivers/src/memory_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ Abstract:
--*/

#[cfg(test)]
use crate::FirmwareHandoffTable;

#[cfg(test)]
use caliptra_image_types::ImageManifest;

//
// Memory Addresses
//
Expand All @@ -28,20 +22,12 @@ pub const DCCM_ORG: u32 = 0x50000000;
pub const ROM_DATA_ORG: u32 = 0x50000000;
pub const CFI_STATE_ORG: u32 = 0x500003E4; // size = 6 words
pub const BOOT_STATUS_ORG: u32 = 0x500003FC;
pub const MAN1_ORG: u32 = 0x50000400;
pub const MAN2_ORG: u32 = 0x50001C00;
pub const FHT_ORG: u32 = 0x50003400;
pub const LDEVID_TBS_ORG: u32 = 0x50003C00;
pub const FMCALIAS_TBS_ORG: u32 = 0x50004000;
pub const RTALIAS_TBS_ORG: u32 = 0x50004400;
pub const PCR_LOG_ORG: u32 = 0x50004800;
pub const MEASUREMENT_LOG_ORG: u32 = 0x50004C00;
pub const FUSE_LOG_ORG: u32 = 0x50005000;
pub const DPE_ORG: u32 = 0x50005400;
pub const PCR_RESET_COUNTER_ORG: u32 = 0x50006800;
pub const AUTH_MAN_IMAGE_METADATA_LIST_ORG: u32 = 0x50006C00;
pub const IDEVID_CSR_ORG: u32 = 0x50008800;
pub const DATA_ORG: u32 = 0x50008C00;
pub const PERSISTENT_DATA_ORG: u32 = 0x50000400;

pub const DATA_ORG: u32 = 0x5000D800;

pub const STACK_ORG: u32 = 0x5000f800;
pub const ROM_STACK_ORG: u32 = 0x5001C000;
Expand All @@ -55,26 +41,18 @@ pub const ROM_NSTACK_ORG: u32 = 0x5001FC00;
//
// Memory Sizes In Bytes
//
pub const PERSISTENT_DATA_SIZE: u32 = 53 * 1024;
pub const LDEVID_TBS_SIZE: u32 = 1024;
pub const FMCALIAS_TBS_SIZE: u32 = 1024;
pub const RTALIAS_TBS_SIZE: u32 = 1024;

pub const ROM_RELAXATION_PADDING: u32 = 4 * 1024;
pub const ROM_SIZE: u32 = 48 * 1024;
pub const MBOX_SIZE: u32 = 128 * 1024;
pub const ICCM_SIZE: u32 = 128 * 1024;
pub const DCCM_SIZE: u32 = 128 * 1024;
pub const ROM_DATA_SIZE: u32 = 996;
pub const MAN1_SIZE: u32 = 6 * 1024;
pub const MAN2_SIZE: u32 = 6 * 1024;
pub const FHT_SIZE: u32 = 2 * 1024;
pub const LDEVID_TBS_SIZE: u32 = 1024;
pub const FMCALIAS_TBS_SIZE: u32 = 1024;
pub const RTALIAS_TBS_SIZE: u32 = 1024;
pub const PCR_LOG_SIZE: u32 = 1024;
pub const MEASUREMENT_LOG_SIZE: u32 = 1024;
pub const FUSE_LOG_SIZE: u32 = 1024;
pub const DPE_SIZE: u32 = 5 * 1024;
pub const PCR_RESET_COUNTER_SIZE: u32 = 1024;
pub const AUTH_MAN_IMAGE_METADATA_MAX_SIZE: u32 = 7 * 1024;
pub const IDEVID_CSR_SIZE: u32 = 1024;
pub const DATA_SIZE: u32 = 27 * 1024;
pub const DATA_SIZE: u32 = 8 * 1024;
pub const STACK_SIZE: u32 = 64 * 1024;
pub const ROM_STACK_SIZE: u32 = 14 * 1024;
pub const ESTACK_SIZE: u32 = 1024;
Expand All @@ -89,76 +67,8 @@ pub const ICCM_RANGE: core::ops::Range<u32> = core::ops::Range {

#[test]
#[allow(clippy::assertions_on_constants)]
fn mem_layout_test_manifest() {
assert!(MAN1_SIZE as usize >= core::mem::size_of::<ImageManifest>());
assert!(MAN2_SIZE as usize >= core::mem::size_of::<ImageManifest>());
assert_eq!(MAN1_SIZE, MAN2_SIZE);
assert_eq!((MAN2_ORG - MAN1_ORG), MAN1_SIZE);
assert_eq!((FHT_ORG - MAN2_ORG), MAN2_SIZE);
}

#[test]
#[allow(clippy::assertions_on_constants)]
fn mem_layout_test_fht() {
assert!(FHT_SIZE as usize >= core::mem::size_of::<FirmwareHandoffTable>());
assert_eq!((LDEVID_TBS_ORG - FHT_ORG), FHT_SIZE);
}

#[test]
#[allow(clippy::assertions_on_constants)]
fn mem_layout_test_ldevid() {
assert_eq!((FMCALIAS_TBS_ORG - LDEVID_TBS_ORG), LDEVID_TBS_SIZE);
}

#[test]
#[allow(clippy::assertions_on_constants)]
fn mem_layout_test_fmcalias() {
assert_eq!((RTALIAS_TBS_ORG - FMCALIAS_TBS_ORG), FMCALIAS_TBS_SIZE);
}

#[test]
#[allow(clippy::assertions_on_constants)]
fn mem_layout_test_rtalias() {
assert_eq!((PCR_LOG_ORG - RTALIAS_TBS_ORG), RTALIAS_TBS_SIZE);
}

#[test]
#[allow(clippy::assertions_on_constants)]
fn mem_layout_test_pcr_log() {
assert_eq!((MEASUREMENT_LOG_ORG - PCR_LOG_ORG), PCR_LOG_SIZE);
}

#[test]
#[allow(clippy::assertions_on_constants)]
fn mem_layout_test_measurement_log() {
assert_eq!((FUSE_LOG_ORG - MEASUREMENT_LOG_ORG), MEASUREMENT_LOG_SIZE);
}

#[test]
#[allow(clippy::assertions_on_constants)]
fn mem_layout_test_fuselog() {
assert_eq!((DPE_ORG - FUSE_LOG_ORG), FUSE_LOG_SIZE);
}

#[test]
#[allow(clippy::assertions_on_constants)]
fn mem_layout_test_dpe() {
assert_eq!((PCR_RESET_COUNTER_ORG - DPE_ORG), DPE_SIZE);
}

#[test]
#[allow(clippy::assertions_on_constants)]
fn mem_layout_test_pcr_reset_counter() {
assert_eq!(
(AUTH_MAN_IMAGE_METADATA_LIST_ORG - PCR_RESET_COUNTER_ORG),
PCR_RESET_COUNTER_SIZE
);
}

#[test]
#[allow(clippy::assertions_on_constants)]
fn mem_layout_test_idevid_csr() {
assert_eq!((DATA_ORG - IDEVID_CSR_ORG), IDEVID_CSR_SIZE);
fn mem_layout_test_persistent_data() {
assert_eq!((DATA_ORG - PERSISTENT_DATA_ORG), PERSISTENT_DATA_SIZE);
}

#[test]
Expand Down
Loading

0 comments on commit 0792abb

Please sign in to comment.