Subrata Banik has submitted this change. ( https://review.coreboot.org/c/coreboot/+/85905?usp=email )
Change subject: drivers/option: Add CBFS file based option backend ......................................................................
drivers/option: Add CBFS file based option backend
Add a new option backend that uses values stored in CBFS files, similar to the SeaBIOS runtime config options stored in files with the etc/ prefix. Options should be stored in CBFS with the option/ prefix. Values can be set using `cbfstool coreboot.rom add-int -n option/<option-name> -i <value>`. For simplicity, options should be stored in the COREBOOT (RO) FMAP region, which is the default for cbfstool. This backend is not available in SMM due to CBFS dependencies on vboot functions which are not added to SMM, and thus the fallback will be returned by calls to get_uint_option() in SMM.
Tested with QEMU Q35 by setting various options for "sata_mode" and observing the console output for the SATA controller mode during i82801ix_sata initialization.
Change-Id: Ifc0439ee42f13f49ae54d4855d1d9333c39b01f5 Signed-off-by: Nicholas Chin nic.c3.14@gmail.com Reviewed-on: https://review.coreboot.org/c/coreboot/+/85905 Tested-by: build bot (Jenkins) no-reply@coreboot.org Reviewed-by: Subrata Banik subratabanik@google.com Reviewed-by: Julius Werner jwerner@chromium.org Reviewed-by: Jérémy Compostella jeremy.compostella@intel.com --- M src/Kconfig M src/drivers/option/Makefile.mk A src/drivers/option/cbfs_file_option.c M src/include/option.h 4 files changed, 39 insertions(+), 1 deletion(-)
Approvals: Subrata Banik: Looks good to me, approved Julius Werner: Looks good to me, approved Jérémy Compostella: Looks good to me, but someone else must approve build bot (Jenkins): Verified
diff --git a/src/Kconfig b/src/Kconfig index 55fad95..320d6db 100644 --- a/src/Kconfig +++ b/src/Kconfig @@ -149,6 +149,7 @@
choice prompt "Option backend to use" + default USE_CBFS_FILE_OPTION_BACKEND if CHROMEOS && PLATFORM_USES_FSP2_0 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 && \ @@ -164,6 +165,12 @@ Enable this option if coreboot shall read options from the "CMOS" NVRAM instead of using hard-coded values.
+config USE_CBFS_FILE_OPTION_BACKEND + bool "Use CBFS files for configuration values" + help + Enable this option if coreboot shall read options from files in CBFS. + Options can be set using `cbfstool add-int -n option/<option-name> -i value`. + config USE_UEFI_VARIABLE_STORE bool "Use UEFI variable-store in SPI flash as option backend" depends on DRIVERS_EFI_VARIABLE_STORE diff --git a/src/drivers/option/Makefile.mk b/src/drivers/option/Makefile.mk index 7ca439d..63ac1ba 100644 --- a/src/drivers/option/Makefile.mk +++ b/src/drivers/option/Makefile.mk @@ -1,3 +1,5 @@ # SPDX-License-Identifier: GPL-2.0-only
ramstage-$(CONFIG_DRIVERS_OPTION_CFR) += cfr.c + +all-$(CONFIG_USE_CBFS_FILE_OPTION_BACKEND) += cbfs_file_option.c diff --git a/src/drivers/option/cbfs_file_option.c b/src/drivers/option/cbfs_file_option.c new file mode 100644 index 0000000..b87bba8 --- /dev/null +++ b/src/drivers/option/cbfs_file_option.c @@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include <cbfs.h> +#include <endian.h> +#include <option.h> + +unsigned int get_uint_option(const char *name, const unsigned int fallback) +{ + size_t size; + uint64_t value; + char full_name[CBFS_METADATA_MAX_SIZE]; + snprintf(full_name, sizeof(full_name), "option/%s", name); + + void *p = cbfs_ro_map(full_name, &size); + if (!p || size < sizeof(value)) { + value = fallback; + } else { + value = le64dec(p); + cbfs_unmap(p); + } + return (unsigned int)value; +} + +enum cb_err set_uint_option(const char *name, unsigned int value) +{ + return CB_ERR_NOT_IMPLEMENTED; +} diff --git a/src/include/option.h b/src/include/option.h index 3a00570..bee761a 100644 --- a/src/include/option.h +++ b/src/include/option.h @@ -7,7 +7,9 @@
void sanitize_cmos(void);
-#if CONFIG(OPTION_BACKEND_NONE) +/* The CBFS file option backend cannot be used in SMM due to vboot + * dependencies, which are not added to SMM */ +#if CONFIG(OPTION_BACKEND_NONE) || (CONFIG(USE_CBFS_FILE_OPTION_BACKEND) && ENV_SMM)
static inline unsigned int get_uint_option(const char *name, const unsigned int fallback) {