From a45f8959c02cd73d8eebe5e39c0fa9957bc05ae3 Mon Sep 17 00:00:00 2001 From: Shelley Chen Date: Sat, 17 Oct 2020 00:53:41 -0700 Subject: mrc_cache: Remove unnecessary data checksum calculation When MRC_SAVE_HASH_IN_TPM is selected, we can just use the TPM hash to verify the MRC_CACHE data. Thus, we don't need to calculate the checksum anymore in this case. BUG=b:150502246 BRANCH=None TEST=make sure memory training still works on nami Change-Id: I1db4469da49755805b541f50c7ef2f9cdb749425 Signed-off-by: Shelley Chen Reviewed-on: https://review.coreboot.org/c/coreboot/+/46515 Tested-by: build bot (Jenkins) Reviewed-by: Furquan Shaikh --- src/drivers/mrc_cache/mrc_cache.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'src/drivers/mrc_cache') diff --git a/src/drivers/mrc_cache/mrc_cache.c b/src/drivers/mrc_cache/mrc_cache.c index 1bbb426b5d..3b98dbaa63 100644 --- a/src/drivers/mrc_cache/mrc_cache.c +++ b/src/drivers/mrc_cache/mrc_cache.c @@ -193,19 +193,20 @@ static int mrc_data_valid(int type, const struct mrc_metadata *md, if (md->data_size != data_size) return -1; - checksum = compute_ip_checksum(data, data_size); + hash_idx = cr->tpm_hash_index; + if (hash_idx && CONFIG(MRC_SAVE_HASH_IN_TPM)) { + if (!mrc_cache_verify_hash(hash_idx, data, data_size)) + return -1; + } else { + checksum = compute_ip_checksum(data, data_size); - if (md->data_checksum != checksum) { - printk(BIOS_ERR, "MRC: data checksum mismatch: %x vs %x\n", - md->data_checksum, checksum); - return -1; + if (md->data_checksum != checksum) { + printk(BIOS_ERR, "MRC: data checksum mismatch: %x vs %x\n", + md->data_checksum, checksum); + return -1; + } } - hash_idx = cr->tpm_hash_index; - if (hash_idx && CONFIG(MRC_SAVE_HASH_IN_TPM) && - !mrc_cache_verify_hash(hash_idx, data, data_size)) - return -1; - return 0; } -- cgit v1.2.3