diff options
Diffstat (limited to 'src/lib/metadata_hash.c')
-rw-r--r-- | src/lib/metadata_hash.c | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/src/lib/metadata_hash.c b/src/lib/metadata_hash.c index a823c5f26f..5619efea7f 100644 --- a/src/lib/metadata_hash.c +++ b/src/lib/metadata_hash.c @@ -5,6 +5,7 @@ #include <metadata_hash.h> #include <symbols.h> +#if !CONFIG(COMPRESS_BOOTBLOCK) || ENV_DECOMPRESSOR __attribute__((used, section(".metadata_hash_anchor"))) static struct metadata_hash_anchor metadata_hash_anchor = { /* This is the only place in all of coreboot where we actually need to use this. */ @@ -12,15 +13,39 @@ static struct metadata_hash_anchor metadata_hash_anchor = { .cbfs_hash = { .algo = CONFIG_CBFS_HASH_ALGO } }; +static struct metadata_hash_anchor *get_anchor(void) +{ + return &metadata_hash_anchor; +} + +void *metadata_hash_export_anchor(void) +{ + return get_anchor(); +} +#else +static struct metadata_hash_anchor *anchor_ptr = NULL; + +static struct metadata_hash_anchor *get_anchor(void) +{ + assert(anchor_ptr != NULL); + return anchor_ptr; +} + +void metadata_hash_import_anchor(void *ptr) +{ + anchor_ptr = ptr; +} +#endif + struct vb2_hash *metadata_hash_get(void) { - return &metadata_hash_anchor.cbfs_hash; + return &get_anchor()->cbfs_hash; } vb2_error_t metadata_hash_verify_fmap(const void *fmap_buffer, size_t fmap_size) { - struct vb2_hash hash = { .algo = metadata_hash_anchor.cbfs_hash.algo }; - memcpy(hash.raw, metadata_hash_anchor_fmap_hash(&metadata_hash_anchor), + struct vb2_hash hash = { .algo = get_anchor()->cbfs_hash.algo }; + memcpy(hash.raw, metadata_hash_anchor_fmap_hash(get_anchor()), vb2_digest_size(hash.algo)); return vb2_hash_verify(fmap_buffer, fmap_size, &hash); } |