CBFS verification: support Top Swap redundancy

Separating the bootblock into two copies (in BOOTBLOCK and TOPSWAP fmap
regions) breaks the CBFS verification as TSPI CRTM knows nothing about
the new regions and looks for bootblock in a hard-coded COREBOOT fmap
region.

Introduce and use cbfs_unverified_area_type_alloc() which is an
extension of cbfs_unverified_area_alloc(), very similar to how
cbfs_ro_type_map() is an extension of cbfs_ro_map().  This allows to
specify a region of the bootblock file and skip verification because
bootblock serves as a container of hashes and is not verified itself.

The branching is done on the state of RTC BUC to always use the current
bootblock.  Somewhat confusingly, the measurement always uses BOOTBLOCK
region because with active Top Swap that's the way to access a
memory-mapped TOPSWAP region.

Makefile.mk now verifies both COREBOOT and COREBOOT_TS regions.
cbfstool needed a few updates as well:
 - recognize both "BOOTBLOCK" and "TOPSWAP" regions
 - recognize both "COREBOOT" and "COREBOOT_TS" regions
 - reset metadata cache before processing each region as cache may now
   be invalid

SMM doesn't link with vboot functions, so cbfs_file_hash_mismatch() has
to skip verification in SMM due to the use of CMOS options backend.

This is a part of the bootblock redundancy feature proposed
on the mailing list:
https://mail.coreboot.org/archives/list/coreboot@coreboot.org/thread/C6JN2PB7K7D67EG7OIKB6BBERZU5YV35/

Tested by successfully booting into Protectli VP6670 with Top Swap and
CBFS Verification features enabled and Top Swap state being toggled.

Change-Id: Ia75e714ae84d8c0ae09b27495e3056313b109999
Signed-off-by: Filip Gołaś <filip.golas@3mdeb.com>
Signed-off-by: Sergii Dmytruk <sergii.dmytruk@3mdeb.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/89691
Reviewed-by: Michał Kopeć <michal.kopec@3mdeb.com>
Reviewed-by: Filip Lewiński <filip.lewinski@3mdeb.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
Filip Gołaś 2025-12-10 16:44:24 +02:00 committed by Matt DeVillier
commit 7c7feca258
7 changed files with 96 additions and 22 deletions

View file

@ -9,6 +9,10 @@
#include <stdio.h>
#include <string.h>
/* This include is available as <intelblocks/rtc.h> only if CONFIG_SOC_INTEL_COMMON_BLOCK is
set, which is not guaranteed for this file. */
#include <soc/intel/common/block/include/intelblocks/rtc.h>
static int tpm_log_initialized;
static inline int tpm_log_available(void)
{
@ -72,7 +76,28 @@ static tpm_result_t tspi_init_crtm(void)
/* Mapping measures the file. We know we can safely map here because
bootblock-as-a-file is only used on x86, where we don't need cache to map. */
enum cbfs_type type = CBFS_TYPE_BOOTBLOCK;
void *mapping = cbfs_ro_type_map("bootblock", NULL, &type);
void *mapping = NULL;
if (CONFIG(INTEL_TOP_SWAP_SEPARATE_REGIONS)) {
enum ts_config top_swap = get_rtc_buc_top_swap_status();
if (top_swap == TS_ENABLE)
printk(BIOS_INFO,
"CRTM Top Swap: Measuring bootblock in TOPSWAP (will be logged as BOOTBLOCK).\n");
else
printk(BIOS_INFO,
"CRTM Top Swap: Measuring bootblock in BOOTBLOCK.\n");
/*
* Whether Top Swap is active or not, FMAP always refers to the same
* memory ranges but the contents of BOOTBLOCK and TOPSWAP are swapped.
* Hence always using BOOTBLOCK region to access the active bootblock.
*/
mapping = cbfs_unverified_area_type_alloc("BOOTBLOCK", "bootblock",
NULL, NULL, NULL, &type);
} else {
mapping = cbfs_ro_type_map("bootblock", NULL, &type);
}
if (!mapping) {
printk(BIOS_INFO,
"TSPI: Couldn't measure bootblock into CRTM!\n");