Patrick Rudolph has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/62562 )
Change subject: option: Allow to use the EFI variable driver as option backend ......................................................................
option: Allow to use the EFI variable driver as option backend
Use the introduced EFI variable store driver on top of the SMMSTORE region in SPI flash to read/write options.
Change-Id: I520eca96bcd573f825ed35a29bf8f750e313a02d Signed-off-by: Patrick Rudolph patrick.rudolph@9elements.com --- M src/Kconfig M src/drivers/efi/Makefile.inc A src/drivers/efi/option.c 3 files changed, 58 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/62/62562/1
diff --git a/src/Kconfig b/src/Kconfig index 44e84bf..e19345a 100644 --- a/src/Kconfig +++ b/src/Kconfig @@ -124,6 +124,8 @@ prompt "Option backend to use" default USE_MAINBOARD_SPECIFIC_OPTION_BACKEND if HAVE_MAINBOARD_SPECIFIC_OPTION_BACKEND default USE_OPTION_TABLE if NVRAMCUI_SECONDARY_PAYLOAD + default USE_UEFI_VARIABLE_STORE if DRIVERS_EFI_VARIABLE_STORE && \ + PAYLOAD_TIANOCORE && SMMSTORE_V2
config OPTION_BACKEND_NONE bool "None" @@ -135,6 +137,15 @@ Enable this option if coreboot shall read options from the "CMOS" NVRAM instead of using hard-coded values.
+config USE_UEFI_VARIABLE_STORE + bool "Use UEFI variable-store in SPI flash as option backend" + depends on DRIVERS_EFI_VARIABLE_STORE + depends on SMMSTORE_V2 + help + Enable this option if coreboot shall read/write options from the + SMMSTORE region within the SPI flash. The region must be formatted + by the payload first before it can be used. + config USE_MAINBOARD_SPECIFIC_OPTION_BACKEND bool "Use mainboard-specific option backend" depends on HAVE_MAINBOARD_SPECIFIC_OPTION_BACKEND diff --git a/src/drivers/efi/Makefile.inc b/src/drivers/efi/Makefile.inc index e059c48..bc332df 100644 --- a/src/drivers/efi/Makefile.inc +++ b/src/drivers/efi/Makefile.inc @@ -1,3 +1,7 @@
all-$(CONFIG_DRIVERS_EFI_VARIABLE_STORE) += efivars.c smm-$(CONFIG_DRIVERS_EFI_VARIABLE_STORE) += efivars.c + +all-$(CONFIG_USE_UEFI_VARIABLE_STORE) += option.c +smm-$(CONFIG_USE_UEFI_VARIABLE_STORE) += option.c + diff --git a/src/drivers/efi/option.c b/src/drivers/efi/option.c new file mode 100644 index 0000000..3960cfc --- /dev/null +++ b/src/drivers/efi/option.c @@ -0,0 +1,43 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include <stdlib.h> +#include <string.h> +#include <option.h> +#include <smmstore.h> + +#include <Uefi/UefiBaseType.h> + +#include "efivars.h" + +static const EFI_GUID EficorebootNvDataGuid = { + 0xceae4c1d, 0x335b, 0x4685, { 0xa4, 0xa0, 0xfc, 0x4a, 0x94, 0xee, 0xa0, 0x85 } }; + +unsigned int get_uint_option(const char *name, const unsigned int fallback) +{ + struct region_device rdev; + enum cb_err ret; + uint32_t var; + uint32_t size; + + if (smmstore_lookup_region(&rdev)) + return fallback; + + var = 0; + size = sizeof(var); + ret = efi_fv_get_option(&rdev, &EficorebootNvDataGuid, name, &var, &size); + if (ret != CB_SUCCESS) + return fallback; + + return var; +} + +enum cb_err set_uint_option(const char *name, unsigned int value) +{ + struct region_device rdev; + uint32_t var = value; + + if (smmstore_lookup_region(&rdev)) + return CB_CMOS_OTABLE_DISABLED; + + return efi_fv_set_option(&rdev, &EficorebootNvDataGuid, name, &var, sizeof(var)); +}