From dc073ca75c105b6c471954aff0c913797467ff26 Mon Sep 17 00:00:00 2001 From: Subrata Banik Date: Thu, 29 Feb 2024 23:13:19 +0530 Subject: drivers/vpd: Add vpd_get_feature_level() API This patch introduces the vpd_get_feature_level() API to specifically extract the "feature_level" field from the "feature_device_info" VPD key. This is used to distinguish between Chromebook-Plus and regular Chromebook devices. The previous vpd_get_feature_device_info() API is removed as vpd_get_feature_level() is enough to find VPD and extract the data. Note: The new API decodes the base64-encoded "feature_device_info" VPD data. BUG=b:324107408 TEST=Able to build and boot google/rex0. Change-Id: I76fc220ed792abdfefb0b1a37873b5b828bfdda8 Signed-off-by: Subrata Banik Reviewed-on: https://review.coreboot.org/c/coreboot/+/80805 Reviewed-by: Gwendal Grignou Tested-by: build bot (Jenkins) Reviewed-by: Kapil Porwal Reviewed-by: Dinesh Gehlot Reviewed-by: Eric Lai --- src/drivers/vpd/vpd.h | 5 +++-- src/drivers/vpd/vpd_device_feature.c | 37 +++++++++++++++++++++++++++++------- 2 files changed, 33 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/drivers/vpd/vpd.h b/src/drivers/vpd/vpd.h index a23005fca1..a6631aab55 100644 --- a/src/drivers/vpd/vpd.h +++ b/src/drivers/vpd/vpd.h @@ -60,8 +60,9 @@ bool vpd_get_bool(const char *key, enum vpd_region region, bool vpd_get_int(const char *key, enum vpd_region region, int *val); /* - * Return the value after reading the VPD key named "feature_device_info". + * Extracts the "feature_level" from the "feature_device_info" VPD key. + * This key holds a base64-encoded protobuf where "feature_level" is the first entry. */ -const char *vpd_get_feature_device_info(void); +uint8_t vpd_get_feature_level(void); #endif /* __VPD_H__ */ diff --git a/src/drivers/vpd/vpd_device_feature.c b/src/drivers/vpd/vpd_device_feature.c index 1c8682ab7e..7b92756e54 100644 --- a/src/drivers/vpd/vpd_device_feature.c +++ b/src/drivers/vpd/vpd_device_feature.c @@ -1,15 +1,38 @@ /* SPDX-License-Identifier: GPL-2.0-only */ +#include +#include #include +#include #define VPD_KEY_FEATURE_DEVICE_INFO "feature_device_info" -#define VPD_FEATURE_DEVICE_INFO_LEN 64 -const char *vpd_get_feature_device_info(void) +/* + * Extracts the "feature_level" from the "feature_device_info" VPD key. + * This key holds a base64-encoded protobuf where "feature_level" is the first entry. + */ +uint8_t vpd_get_feature_level(void) { - static char device_info[VPD_FEATURE_DEVICE_INFO_LEN]; - if (vpd_gets(VPD_KEY_FEATURE_DEVICE_INFO, device_info, VPD_FEATURE_DEVICE_INFO_LEN, - VPD_RW)) - return device_info; - return ""; + const uint8_t *device_info; + int device_info_size, feature_level = 0; + uint8_t *decoded_device_info; + size_t decoded_size; + + device_info = vpd_find(VPD_KEY_FEATURE_DEVICE_INFO, &device_info_size, VPD_RW); + if (!device_info) + return feature_level; + + decoded_size = B64_DECODED_SIZE(device_info_size); + decoded_device_info = malloc(decoded_size); + if (!decoded_device_info) { + printk(BIOS_ERR, "%s: failed allocating %zd bytes\n", __func__, decoded_size); + return feature_level; + } + + /* The index 1 of the decoded data is the "feature level" value */ + if (b64_decode(device_info, device_info_size, decoded_device_info)) + feature_level = decoded_device_info[1]; + + free(decoded_device_info); + return feature_level; } -- cgit v1.2.3