From 8e7251c6257aa59fc73ae1f64c278341bfde4c95 Mon Sep 17 00:00:00 2001 From: Subrata Banik Date: Tue, 2 Jan 2024 23:28:49 +0530 Subject: vendorcode/google/chromeos: Use unsigned int for "factory_config" This patch ensures `chromeos_get_factory_config()` returns an unsigned integer value because factory config represents bit-fields to determine the Chromebook Plus branding. Additionally, introduced safety measures to catch future "factory_config" bit-field exhaustion. BUG=b:317880956 TEST=Able to verify that google/screebo is branded as Chromebook Plus. Change-Id: I3021b8646de4750b4c8e2a2981f42500894fa2d0 Signed-off-by: Subrata Banik Reviewed-on: https://review.coreboot.org/c/coreboot/+/79769 Reviewed-by: Kapil Porwal Tested-by: build bot (Jenkins) Reviewed-by: Eric Lai Reviewed-by: Julius Werner --- src/vendorcode/google/chromeos/chromeos.h | 6 ++++-- src/vendorcode/google/chromeos/tpm_factory_config.c | 19 +++++++++++-------- 2 files changed, 15 insertions(+), 10 deletions(-) (limited to 'src/vendorcode/google/chromeos') diff --git a/src/vendorcode/google/chromeos/chromeos.h b/src/vendorcode/google/chromeos/chromeos.h index 0c5e4f7daf..a4315c360f 100644 --- a/src/vendorcode/google/chromeos/chromeos.h +++ b/src/vendorcode/google/chromeos/chromeos.h @@ -17,6 +17,8 @@ static inline void mark_watchdog_tombstone(void) { return; } static inline void reboot_from_watchdog(void) { return; } #endif /* CONFIG_CHROMEOS */ +#define UNDEFINED_FACTORY_CONFIG ~((uint64_t)0) + /** * Perform any platform specific actions required prior to resetting the Cr50. * Defined as weak function in cr50_enable_update.c @@ -29,9 +31,9 @@ void chromeos_set_ramoops(void *ram_oops, size_t size); /* * The factory config space is a one-time programmable info page. * For the unprovisioned one, the read will be 0x0. - * Return `-1` in case of error. + * Return "UNDEFINED_FACTORY_CONFIG" in case of error. */ -int64_t chromeos_get_factory_config(void); +uint64_t chromeos_get_factory_config(void); /* * Determines whether a ChromeOS device is branded as a Chromebook Plus * based on specific bit flags: diff --git a/src/vendorcode/google/chromeos/tpm_factory_config.c b/src/vendorcode/google/chromeos/tpm_factory_config.c index 4f8801ab0d..44fb9f0fef 100644 --- a/src/vendorcode/google/chromeos/tpm_factory_config.c +++ b/src/vendorcode/google/chromeos/tpm_factory_config.c @@ -1,5 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0-only */ +#include #include #include #include @@ -9,11 +10,11 @@ #define CHROMEBOOK_PLUS_SOFT_BRANDED BIT(0) #define CHROMEBOOK_PLUS_DEVICE (CHROMEBOOK_PLUS_HARD_BRANDED | CHROMEBOOK_PLUS_SOFT_BRANDED) -int64_t chromeos_get_factory_config(void) +uint64_t chromeos_get_factory_config(void) { - static int64_t factory_config = -1; + static uint64_t factory_config = UNDEFINED_FACTORY_CONFIG; - if (factory_config >= 0) + if (factory_config != UNDEFINED_FACTORY_CONFIG) return factory_config; /* Initialize TPM driver. */ @@ -21,17 +22,19 @@ int64_t chromeos_get_factory_config(void) if (rc != TPM_SUCCESS) { printk(BIOS_ERR, "%s:%d - tlcl_lib_init() failed: %#x\n", __func__, __LINE__, rc); - return -1; + return UNDEFINED_FACTORY_CONFIG; } - rc = tlcl_cr50_get_factory_config((uint64_t *)&factory_config); + rc = tlcl_cr50_get_factory_config(&factory_config); if (rc != TPM_SUCCESS) { printk(BIOS_ERR, "%s:%d - tlcl_cr50_get_factory_config() failed: %#x\n", __func__, __LINE__, rc); - return -1; + return UNDEFINED_FACTORY_CONFIG; } + assert(factory_config != UNDEFINED_FACTORY_CONFIG); + return factory_config; } @@ -48,9 +51,9 @@ int64_t chromeos_get_factory_config(void) */ bool chromeos_device_branded_plus(void) { - int64_t factory_config = chromeos_get_factory_config(); + uint64_t factory_config = chromeos_get_factory_config(); - if (factory_config < 0) + if (factory_config == UNDEFINED_FACTORY_CONFIG) return false; return factory_config & CHROMEBOOK_PLUS_DEVICE; -- cgit v1.2.3