From 00d954977c9572f2af3e2bcfe374e2691717963e Mon Sep 17 00:00:00 2001 From: Benjamin Doron Date: Fri, 11 Jul 2025 15:20:00 -0400 Subject: [PATCH] util/smmstoretool: Support other block sizes smmstoretool is effectively a UEFI variable store writing tool, with a specific emphasis on the SMMSTORE backend implementation. However, it could also support other backends. Since it's typical for the variable store to be `n / 2 - 1` blocks, but not typical how large each block should be, allow this to be overridden on the command line. This is necessary because in EDK2, the module producing the firmware volume block protocol, the backend, will initialise a HOB or set PCDs to indicate the size of the store to the rest of the stack, and an assertion will be hit if the store has been preseeded by smmstoretool using differently-sized blocks. For example, `make CFLAGS=-DSMM_BLOCK_SIZE=8192` builds this for a firmware volume block protocol implementation with 8K blocks. Change-Id: I08b78cfb0b591641f09fcf86f40dd31e6b6c9b30 Signed-off-by: Benjamin Doron Reviewed-on: https://review.coreboot.org/c/coreboot/+/88427 Tested-by: build bot (Jenkins) Reviewed-by: Alicja Michalska --- util/smmstoretool/fv.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/util/smmstoretool/fv.c b/util/smmstoretool/fv.c index 2744292761..b7744a57e0 100644 --- a/util/smmstoretool/fv.c +++ b/util/smmstoretool/fv.c @@ -11,7 +11,9 @@ #include "udk2017.h" // The same as in `smmstore.h` header, which isn't in `commonlib`. +#ifndef SMM_BLOCK_SIZE #define SMM_BLOCK_SIZE (64 * 1024) +#endif static const EFI_GUID EfiVariableGuid = EFI_VARIABLE_GUID; @@ -37,10 +39,12 @@ bool fv_init(struct mem_range_t fv) { if (fv.length % SMM_BLOCK_SIZE != 0) { fprintf(stderr, - "Firmware Volume size is not a multiple of 64KiB\n"); + "Firmware Volume size is not a multiple of the block size (%dKiB)\n", + SMM_BLOCK_SIZE / 1024); return false; } + uint32_t number_of_blocks = fv.length / SMM_BLOCK_SIZE; memset(fv.start, 0xff, fv.length); const EFI_FIRMWARE_VOLUME_HEADER vol_hdr = { @@ -58,7 +62,7 @@ bool fv_init(struct mem_range_t fv) + sizeof(EFI_FV_BLOCK_MAP_ENTRY), .Revision = EFI_FVH_REVISION, .BlockMap[0] = { - .NumBlocks = fv.length / SMM_BLOCK_SIZE, + .NumBlocks = number_of_blocks, .Length = SMM_BLOCK_SIZE, }, }; @@ -74,9 +78,9 @@ bool fv_init(struct mem_range_t fv) const VARIABLE_STORE_HEADER var_store_hdr = { .Signature = EfiAuthenticatedVariableGuid, - // Actual size of the storage is block size, the rest is + // Actual size of the storage is `n / 2 - 1` blocks, the rest is // Fault Tolerant Write (FTW) space and the FTW spare space. - .Size = SMM_BLOCK_SIZE - vol_hdr.HeaderLength, + .Size = ((number_of_blocks / 2 - 1) * SMM_BLOCK_SIZE) - vol_hdr.HeaderLength, .Format = VARIABLE_STORE_FORMATTED, .State = VARIABLE_STORE_HEALTHY, };