summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohnny Lin <johnny_lin@wiwynn.com>2020-06-03 11:44:22 +0800
committerPatrick Georgi <pgeorgi@google.com>2020-06-28 21:48:38 +0000
commitc746a748c4c5ec6421d7f9f5760717348231d091 (patch)
treedcf81c7606f3d7ba5eff556c965476311a2829f3
parent360684b41aec795d254dcaac1cefb4acf9e129d3 (diff)
downloadcoreboot-c746a748c4c5ec6421d7f9f5760717348231d091.tar.xz
smbios: Add option VPD_SMBIOS_VERSION that reads BIOS version from a VPD variable
If VPD_SMBIOS_VERSION is selected, it would read VPD_RO variable that can override SMBIOS type 0 version. One special scenario of using this feature is to assign a BIOS version to a coreboot image without the need to rebuild from source. VPD_SMBIOS_VERSION default is n. Tested=On OCP Delta Lake, dmidecode -t 0 can see the version being updated from VPD. Change-Id: Iee62ed900095001ffac225fc629b3f2f52045e30 Signed-off-by: Johnny Lin <johnny_lin@wiwynn.com> Reviewed-on: https://review.coreboot.org/c/coreboot/+/42029 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: insomniac <insomniac@slackware.it> Reviewed-by: Julius Werner <jwerner@chromium.org>
-rw-r--r--src/Kconfig10
-rw-r--r--src/arch/x86/smbios.c81
2 files changed, 71 insertions, 20 deletions
diff --git a/src/Kconfig b/src/Kconfig
index 1b49e2bd7e..f9c3e6afc8 100644
--- a/src/Kconfig
+++ b/src/Kconfig
@@ -730,6 +730,16 @@ config MAINBOARD_SMBIOS_PRODUCT_NAME
help
Override the default Product name stored in SMBIOS structures.
+config VPD_SMBIOS_VERSION
+ bool "Populates SMBIOS type 0 version from the VPD_RO variable 'firmware_version'"
+ default n
+ depends on VPD && GENERATE_SMBIOS_TABLES
+ help
+ Selecting this option will read firmware_version from
+ VPD_RO and override SMBIOS type 0 version. One special
+ scenario of using this feature is to assign a BIOS version
+ to a coreboot image without the need to rebuild from source.
+
endmenu
source "payloads/Kconfig"
diff --git a/src/arch/x86/smbios.c b/src/arch/x86/smbios.c
index a8723aa2cc..d102d10758 100644
--- a/src/arch/x86/smbios.c
+++ b/src/arch/x86/smbios.c
@@ -19,6 +19,8 @@
#if CONFIG(CHROMEOS)
#include <vendorcode/google/chromeos/gnvs.h>
#endif
+#include <drivers/vpd/vpd.h>
+#include <stdlib.h>
#define update_max(len, max_len, stmt) \
do { \
@@ -368,12 +370,64 @@ static int create_smbios_type17_for_dimm(struct dimm_info *dimm,
return t->length + smbios_string_table_len(t->eos);
}
-const char *__weak smbios_mainboard_bios_version(void)
+#define VERSION_VPD "firmware_version"
+static const char *vpd_get_bios_version(void)
+{
+ int size;
+ const char *s;
+ char *version;
+
+ s = vpd_find(VERSION_VPD, &size, VPD_RO);
+ if (!s) {
+ printk(BIOS_ERR, "Find version from VPD %s failed\n", VERSION_VPD);
+ return NULL;
+ }
+
+ version = malloc(size + 1);
+ if (!version) {
+ printk(BIOS_ERR, "Failed to malloc %d bytes for VPD version\n", size + 1);
+ return NULL;
+ }
+ memcpy(version, s, size);
+ version[size] = '\0';
+ printk(BIOS_DEBUG, "Firmware version %s from VPD %s\n", version, VERSION_VPD);
+ return version;
+}
+
+static const char *get_bios_version(void)
{
- if (strlen(CONFIG_LOCALVERSION))
+ const char *s;
+
+#define SPACES \
+ " "
+
+ if (CONFIG(CHROMEOS))
+ return SPACES;
+
+ if (CONFIG(VPD_SMBIOS_VERSION)) {
+ s = vpd_get_bios_version();
+ if (s != NULL)
+ return s;
+ }
+
+ s = smbios_mainboard_bios_version();
+ if (s != NULL)
+ return s;
+
+ if (strlen(CONFIG_LOCALVERSION) != 0) {
+ printk(BIOS_DEBUG, "BIOS version set to CONFIG_LOCALVERSION: '%s'\n",
+ CONFIG_LOCALVERSION);
return CONFIG_LOCALVERSION;
- else
- return coreboot_version;
+ }
+
+ printk(BIOS_DEBUG, "SMBIOS firmware version is set to coreboot_version: '%s'\n",
+ coreboot_version);
+ return coreboot_version;
+}
+
+const char *__weak smbios_mainboard_bios_version(void)
+{
+ return NULL;
}
static int smbios_write_type0(unsigned long *current, int handle)
@@ -387,27 +441,14 @@ static int smbios_write_type0(unsigned long *current, int handle)
t->length = len - 2;
t->vendor = smbios_add_string(t->eos, "coreboot");
-#if !CONFIG(CHROMEOS)
t->bios_release_date = smbios_add_string(t->eos, coreboot_dmi_date);
- t->bios_version = smbios_add_string(t->eos,
- smbios_mainboard_bios_version());
-#else
-#define SPACES \
- " "
- t->bios_release_date = smbios_add_string(t->eos, coreboot_dmi_date);
-#if CONFIG(HAVE_ACPI_TABLES)
+#if CONFIG(CHROMEOS) && CONFIG(HAVE_ACPI_TABLES)
u32 version_offset = (u32)smbios_string_table_len(t->eos);
-#endif
- t->bios_version = smbios_add_string(t->eos, SPACES);
-
-#if CONFIG(HAVE_ACPI_TABLES)
/* SMBIOS offsets start at 1 rather than 0 */
- chromeos_get_chromeos_acpi()->vbt10 =
- (u32)t->eos + (version_offset - 1);
+ chromeos_get_chromeos_acpi()->vbt10 = (u32)t->eos + (version_offset - 1);
#endif
-#endif /* CONFIG_CHROMEOS */
-
+ t->bios_version = smbios_add_string(t->eos, get_bios_version());
uint32_t rom_size = CONFIG_ROM_SIZE;
rom_size = MIN(CONFIG_ROM_SIZE, 16 * MiB);
t->bios_rom_size = (rom_size / 65535) - 1;