mb/google/brya: Create rull variant
[coreboot2.git] / src / drivers / vpd / vpd_device_feature.c
blob7b92756e54608f03bebe126dab2cc157e4b0602a
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <b64_decode.h>
4 #include <console/console.h>
5 #include <drivers/vpd/vpd.h>
6 #include <stdlib.h>
8 #define VPD_KEY_FEATURE_DEVICE_INFO "feature_device_info"
11 * Extracts the "feature_level" from the "feature_device_info" VPD key.
12 * This key holds a base64-encoded protobuf where "feature_level" is the first entry.
14 uint8_t vpd_get_feature_level(void)
16 const uint8_t *device_info;
17 int device_info_size, feature_level = 0;
18 uint8_t *decoded_device_info;
19 size_t decoded_size;
21 device_info = vpd_find(VPD_KEY_FEATURE_DEVICE_INFO, &device_info_size, VPD_RW);
22 if (!device_info)
23 return feature_level;
25 decoded_size = B64_DECODED_SIZE(device_info_size);
26 decoded_device_info = malloc(decoded_size);
27 if (!decoded_device_info) {
28 printk(BIOS_ERR, "%s: failed allocating %zd bytes\n", __func__, decoded_size);
29 return feature_level;
32 /* The index 1 of the decoded data is the "feature level" value */
33 if (b64_decode(device_info, device_info_size, decoded_device_info))
34 feature_level = decoded_device_info[1];
36 free(decoded_device_info);
37 return feature_level;