Shelley Chen has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/46514 )
Change subject: mrc_cache: Add tpm_hash_index field to cache_region struct ......................................................................
mrc_cache: Add tpm_hash_index field to cache_region struct
Pull selection of tpm hash index logic into cache_region struct.
BUG=b:150502246 BRANCH=None TEST=make sure memory training still works on nami and lazor
Change-Id: I1a744d6f40f062ca3aab6157b3747e6c1f6977f9 Signed-off-by: Shelley Chen shchen@google.com --- M src/drivers/mrc_cache/mrc_cache.c 1 file changed, 18 insertions(+), 9 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/14/46514/1
diff --git a/src/drivers/mrc_cache/mrc_cache.c b/src/drivers/mrc_cache/mrc_cache.c index 69f00e7..8124b24 100644 --- a/src/drivers/mrc_cache/mrc_cache.c +++ b/src/drivers/mrc_cache/mrc_cache.c @@ -46,6 +46,7 @@ uint32_t cbmem_id; int type; int elog_slot; + uint32_t tpm_hash_index; int flags; };
@@ -54,6 +55,11 @@ .cbmem_id = CBMEM_ID_MRCDATA, .type = MRC_TRAINING_DATA, .elog_slot = ELOG_MEM_CACHE_UPDATE_SLOT_RECOVERY, +#if CONFIG(HAS_RECOVERY_MRC_CACHE) && CONFIG(MRC_SAVE_HASH_IN_TPM) + .tpm_hash_index = MRC_REC_HASH_NV_INDEX, +#else + .tpm_hash_index = 0, +#endif #if CONFIG(HAS_RECOVERY_MRC_CACHE) .flags = RECOVERY_FLAG, #else @@ -66,6 +72,7 @@ .cbmem_id = CBMEM_ID_MRCDATA, .type = MRC_TRAINING_DATA, .elog_slot = ELOG_MEM_CACHE_UPDATE_SLOT_NORMAL, + .tpm_hash_index = MRC_RW_HASH_NV_INDEX, .flags = NORMAL_FLAG | RECOVERY_FLAG, };
@@ -74,6 +81,7 @@ .cbmem_id = CBMEM_ID_VAR_MRCDATA, .type = MRC_VARIABLE_DATA, .elog_slot = ELOG_MEM_CACHE_UPDATE_SLOT_VARIABLE, + .tpm_hash_index = 0, .flags = NORMAL_FLAG | RECOVERY_FLAG, };
@@ -176,12 +184,12 @@ return 0; }
-static int mrc_data_valid(const struct mrc_metadata *md, +static int mrc_data_valid(int type, const struct mrc_metadata *md, void *data, size_t data_size) { uint16_t checksum; - uint32_t hash_idx = vboot_recovery_mode_enabled() ? - MRC_REC_HASH_NV_INDEX : MRC_RW_HASH_NV_INDEX; + struct region region; + uint32_t hash_idx = lookup_region(®ion, type)->tpm_hash_index;
if (md->data_size != data_size) return -1; @@ -194,7 +202,8 @@ return -1; }
- if (CONFIG(MRC_SAVE_HASH_IN_TPM) && !mrc_cache_verify_hash(hash_idx, data, data_size)) + if (hash_idx && CONFIG(MRC_SAVE_HASH_IN_TPM) && + !mrc_cache_verify_hash(hash_idx, data, data_size)) return -1;
return 0; @@ -289,7 +298,7 @@ if (rdev_readat(&rdev, buffer, 0, data_size) != data_size) return -1;
- if (mrc_data_valid(&md, buffer, data_size) < 0) + if (mrc_data_valid(type, &md, buffer, data_size) < 0) return -1;
return data_size; @@ -316,7 +325,7 @@ return NULL; }
- if (mrc_data_valid(&md, data, region_device_size) < 0) + if (mrc_data_valid(type, &md, data, region_device_size) < 0) return NULL;
return data; @@ -396,8 +405,7 @@ const struct region_device *backing_rdev; struct region_device latest_rdev; const bool fail_bad_data = false; - uint32_t hash_idx = vboot_recovery_mode_enabled() ? - MRC_REC_HASH_NV_INDEX : MRC_RW_HASH_NV_INDEX; + uint32_t hash_idx;
cr = lookup_region(®ion, type);
@@ -457,7 +465,8 @@ } else { printk(BIOS_DEBUG, "MRC: updated '%s'.\n", cr->name); log_event_cache_update(cr->elog_slot, UPDATE_SUCCESS); - if (CONFIG(MRC_SAVE_HASH_IN_TPM)) + hash_idx = cr->tpm_hash_index; + if (hash_idx && CONFIG(MRC_SAVE_HASH_IN_TPM)) mrc_cache_update_hash(hash_idx, new_data, new_data_size); } }