security/vboot: Make mrc_cache hash functions generic

We need to extend the functionality of the mrc_cache hash functions to
work for both recovery and normal mrc_cache data.  Updating the API of
these functions to pass in an index to identify the hash indices for
recovery and normal mode.

BUG=b:150502246
BRANCH=None
TEST=make sure memory training still works on nami

Change-Id: I9c0bb25eafc731ca9c7a95113ab940f55997fc0f
Signed-off-by: Shelley Chen <shchen@google.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/46432
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Furquan Shaikh <furquan@google.com>
This commit is contained in:
Shelley Chen
2020-10-16 13:15:59 -07:00
committed by Julius Werner
parent 1fed53f08a
commit a79803cf29
7 changed files with 78 additions and 61 deletions

View File

@@ -10,6 +10,7 @@
#include <fmap.h>
#include <ip_checksum.h>
#include <region_file.h>
#include <security/vboot/antirollback.h>
#include <security/vboot/mrc_cache_hash_tpm.h>
#include <security/vboot/vboot_common.h>
#include <spi_flash.h>
@@ -179,6 +180,7 @@ static int mrc_data_valid(const struct mrc_metadata *md,
void *data, size_t data_size)
{
uint16_t checksum;
uint32_t hash_idx = MRC_REC_HASH_NV_INDEX;
if (md->data_size != data_size)
return -1;
@@ -191,7 +193,7 @@ static int mrc_data_valid(const struct mrc_metadata *md,
return -1;
}
if (CONFIG(MRC_SAVE_HASH_IN_TPM) && !mrc_cache_verify_hash(data, data_size))
if (CONFIG(MRC_SAVE_HASH_IN_TPM) && !mrc_cache_verify_hash(hash_idx, data, data_size))
return -1;
return 0;
@@ -393,6 +395,7 @@ static void update_mrc_cache_by_type(int type,
const struct region_device *backing_rdev;
struct region_device latest_rdev;
const bool fail_bad_data = false;
uint32_t hash_idx = MRC_REC_HASH_NV_INDEX;
cr = lookup_region(&region, type);
@@ -453,7 +456,7 @@ static void update_mrc_cache_by_type(int type,
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))
mrc_cache_update_hash(new_data, new_data_size);
mrc_cache_update_hash(hash_idx, new_data, new_data_size);
}
}