summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJack Rosenthal <jrosenth@chromium.org>2022-11-21 17:38:38 -0700
committerJack Rosenthal <jrosenth@chromium.org>2023-03-05 00:28:33 +0000
commit1624a09e15a445ce3438df12d259a9cf0c1d751a (patch)
treece21be723774feecb2ef3e88f0b9eb2fbe60821f
parent0cebc9e8f01e72413d5e3577072749b8b41a078a (diff)
downloadvboot-release-R108-15183.B.tar.gz
Reland "crossystem: Add board_id property"release-R108-15183.B
This reverts commit 87663c3bef0f6b198945cf3eb83632f461a5d6f8. The parent CL to this commit should be sufficient to resolve the failure that prevented "crossystem board_id" on ARM from working. Original change's description: > crossystem: Add board_id property > > futility is one of a few places in ChromeOS that uses "mosys platform > version". The goal is to remove this command from mosys. > > This commit adds a new property to crossystem, "board_id", which > reads the board revision from SMBIOS/FDT, and replaces the call in > futility with the appropriate VbGetSystemPropertyInt. > > BUG=b:187790074 > BRANCH=none > TEST="crossystem board_id" on hana and brya > > Change-Id: Id69c8e309c0e509a165aa6da2778573ac7de3455 > Signed-off-by: Jack Rosenthal <jrosenth@chromium.org> > Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/4029537 > Reviewed-by: Julius Werner <jwerner@chromium.org> BUG=b:187790074,b:270917040 BRANCH=none TEST="crossystem board_id" on hana and brya Change-Id: I37b4c622e3c1d294b5be8e0d98ef14175902acc3 Signed-off-by: Jack Rosenthal <jrosenth@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/4045047 Reviewed-by: Julius Werner <jwerner@chromium.org> (cherry picked from commit 5bbd123cac5650dba0db6cc3c40c7cf33bfd7efc) Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/4300250 Reviewed-by: Yu-Ping Wu <yupingso@chromium.org>
-rw-r--r--futility/updater_utils.c24
-rw-r--r--host/arch/arm/lib/crossystem_arch.c2
-rw-r--r--host/arch/x86/lib/crossystem_arch.c26
-rw-r--r--utility/crossystem.c1
4 files changed, 30 insertions, 23 deletions
diff --git a/futility/updater_utils.c b/futility/updater_utils.c
index c5f0ed65..3ac43e0c 100644
--- a/futility/updater_utils.c
+++ b/futility/updater_utils.c
@@ -23,9 +23,6 @@
#define COMMAND_BUFFER_SIZE 256
-/* System environment values. */
-static const char * const STR_REV = "rev";
-
/*
* Strips a string (usually from shell execution output) by removing all the
* trailing characters in pattern. If pattern is NULL, match by space type
@@ -428,28 +425,9 @@ static int host_get_fw_vboot2(void)
return VbGetSystemPropertyInt("fw_vboot2");
}
-/* A help function to get $(mosys platform version). */
static int host_get_platform_version(void)
{
- char *result = host_shell("mosys platform version");
- long rev = -1;
-
- /* Result should be 'revN' */
- if (strncmp(result, STR_REV, strlen(STR_REV)) == 0)
- rev = strtol(result + strlen(STR_REV), NULL, 0);
-
- /* we should never have negative or extremely large versions,
- * but clamp just to be sure
- */
- if (rev < 0)
- rev = 0;
- if (rev > INT_MAX)
- rev = INT_MAX;
-
- VB2_DEBUG("Raw data = [%s], parsed version is %ld\n", result, rev);
-
- free(result);
- return rev;
+ return VbGetSystemPropertyInt("board_id");
}
/*
diff --git a/host/arch/arm/lib/crossystem_arch.c b/host/arch/arm/lib/crossystem_arch.c
index 897036d2..fac6013e 100644
--- a/host/arch/arm/lib/crossystem_arch.c
+++ b/host/arch/arm/lib/crossystem_arch.c
@@ -525,6 +525,8 @@ int VbGetArchPropertyInt(const char* name)
} else if (!strcasecmp(name, "recoverysw_ec_boot")) {
/* TODO: read correct value using ectool */
return 0;
+ } else if (!strcasecmp(name, "board_id")) {
+ return ReadFdtInt("firmware/coreboot/board-id");
} else {
return -1;
}
diff --git a/host/arch/x86/lib/crossystem_arch.c b/host/arch/x86/lib/crossystem_arch.c
index e6bd7e31..f3e631ad 100644
--- a/host/arch/x86/lib/crossystem_arch.c
+++ b/host/arch/x86/lib/crossystem_arch.c
@@ -83,6 +83,10 @@
#define GPIO_BASE_PATH "/sys/class/gpio"
#define GPIO_EXPORT_PATH GPIO_BASE_PATH "/export"
+/* Base for SMBIOS information files */
+#define SMBIOS_BASE_PATH "/sys/class/dmi/id"
+#define SMBIOS_PRODUCT_VERSION_PATH SMBIOS_BASE_PATH "/product_version"
+
/* Filename for NVRAM file */
#define NVRAM_PATH "/dev/nvram"
@@ -834,6 +838,25 @@ static int ReadGpio(unsigned signal_type)
return (value == active_high ? 1 : 0);
}
+static int GetBoardId(void)
+{
+ /*
+ * Can't use vb2_read_file here, as it expects to be able to
+ * seek to the end of the file to tell the size, and the sysfs
+ * SMBIOS implementation will seek to offset 4096.
+ */
+ int board_id = -1;
+ FILE *f = fopen(SMBIOS_PRODUCT_VERSION_PATH, "r");
+
+ if (!f)
+ return -1;
+
+ if (fscanf(f, "rev%d\n", &board_id) != 1)
+ board_id = -1;
+
+ fclose(f);
+ return board_id;
+}
int VbGetArchPropertyInt(const char* name)
{
@@ -897,6 +920,9 @@ int VbGetArchPropertyInt(const char* name)
value = (int)fwupdate_value;
}
+ if (!strcasecmp(name, "board_id"))
+ return GetBoardId();
+
return value;
}
diff --git a/utility/crossystem.c b/utility/crossystem.c
index 1551209f..f5a0a133 100644
--- a/utility/crossystem.c
+++ b/utility/crossystem.c
@@ -32,6 +32,7 @@ const Param sys_param_list[] = {
{"battery_cutoff_request", CAN_WRITE,
"Cut off battery and shutdown on next boot"},
{"block_devmode", CAN_WRITE, "Block all use of developer mode"},
+ {"board_id", 0, "Board hardware revision number"},
{"clear_tpm_owner_done", CAN_WRITE, "Clear TPM owner done"},
{"clear_tpm_owner_request", CAN_WRITE, "Clear TPM owner on next boot"},
{"cros_debug", 0, "OS should allow debug features"},