summaryrefslogtreecommitdiff
path: root/src/vendorcode
diff options
context:
space:
mode:
authorPatrick Rudolph <patrick.rudolph@9elements.com>2018-03-08 15:43:12 +0100
committerPhilipp Deppenwiese <zaolin.daisuki@gmail.com>2018-09-09 17:51:37 +0000
commit28cee59ca294422056d983fc06d5d8d5800a4390 (patch)
tree2dab3f2423f474a9075dc9c9d56ad997d6c4ed77 /src/vendorcode
parentc4b0fd0a86db280ad1a8d8572218dc42fd5bb7e4 (diff)
downloadcoreboot-28cee59ca294422056d983fc06d5d8d5800a4390.tar.xz
drivers/vpd: Add VPD support
VPD reference: https://chromium.googlesource.com/chromiumos/platform/vpd/+/master/README.md Copy ChromeOS VPD driver to add support for VPD without CROMEOS. Possible use case: * Storing calibration data * Storing MAC address * Storing serial * Storing boot options + Now it's possible to define the VPD space by choosing one of the following enums: VPD_ANY, VPD_RW, VPD_RO. + CHROMEOS selects now VPD as part of it. + VPD is implemented as driver. Change-Id: Id9263bd39bf25d024e93daa57053fefcb1adc53a Signed-off-by: Patrick Rudolph <patrick.rudolph@9elements.com> Reviewed-on: https://review.coreboot.org/25046 Reviewed-by: David Hendricks <david.hendricks@gmail.com> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Diffstat (limited to 'src/vendorcode')
-rw-r--r--src/vendorcode/google/chromeos/Kconfig1
-rw-r--r--src/vendorcode/google/chromeos/Makefile.inc3
-rw-r--r--src/vendorcode/google/chromeos/cros_vpd.c226
-rw-r--r--src/vendorcode/google/chromeos/cros_vpd.h40
-rw-r--r--src/vendorcode/google/chromeos/lib_vpd.h226
-rw-r--r--src/vendorcode/google/chromeos/sar.c9
-rw-r--r--src/vendorcode/google/chromeos/vpd_calibration.c4
-rw-r--r--src/vendorcode/google/chromeos/vpd_decode.c89
-rw-r--r--src/vendorcode/google/chromeos/vpd_mac.c6
-rw-r--r--src/vendorcode/google/chromeos/vpd_serialno.c6
-rw-r--r--src/vendorcode/google/chromeos/vpd_tables.h115
-rw-r--r--src/vendorcode/google/chromeos/wrdd.c8
12 files changed, 20 insertions, 713 deletions
diff --git a/src/vendorcode/google/chromeos/Kconfig b/src/vendorcode/google/chromeos/Kconfig
index 4f1fad9a73..1dd726f551 100644
--- a/src/vendorcode/google/chromeos/Kconfig
+++ b/src/vendorcode/google/chromeos/Kconfig
@@ -24,6 +24,7 @@ config CHROMEOS
select ELOG if BOOT_DEVICE_SUPPORTS_WRITES
select COLLECT_TIMESTAMPS
select VBOOT
+ select VPD
help
Enable ChromeOS specific features like the GPIO sub table in
the coreboot table. NOTE: Enabling this option on an unsupported
diff --git a/src/vendorcode/google/chromeos/Makefile.inc b/src/vendorcode/google/chromeos/Makefile.inc
index e833e0dd74..ecd82b7a83 100644
--- a/src/vendorcode/google/chromeos/Makefile.inc
+++ b/src/vendorcode/google/chromeos/Makefile.inc
@@ -17,8 +17,7 @@ ramstage-$(CONFIG_ELOG) += elog.c
ramstage-$(CONFIG_HAVE_ACPI_TABLES) += gnvs.c
ramstage-$(CONFIG_HAVE_ACPI_TABLES) += acpi.c
ramstage-$(CONFIG_CHROMEOS_RAMOOPS) += ramoops.c
-romstage-y += vpd_decode.c
-ramstage-y += vpd_decode.c cros_vpd.c vpd_mac.c vpd_serialno.c vpd_calibration.c
+ramstage-y += vpd_mac.c vpd_serialno.c vpd_calibration.c
ramstage-$(CONFIG_CHROMEOS_DISABLE_PLATFORM_HIERARCHY_ON_RESUME) += tpm2.c
ramstage-$(CONFIG_HAVE_REGULATORY_DOMAIN) += wrdd.c
ramstage-$(CONFIG_USE_SAR) += sar.c
diff --git a/src/vendorcode/google/chromeos/cros_vpd.c b/src/vendorcode/google/chromeos/cros_vpd.c
deleted file mode 100644
index d0e2cc1ef9..0000000000
--- a/src/vendorcode/google/chromeos/cros_vpd.c
+++ /dev/null
@@ -1,226 +0,0 @@
-/*
- * Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include <console/console.h>
-
-#include <cbmem.h>
-#include <fmap.h>
-#include <stdlib.h>
-#include <string.h>
-#include <timestamp.h>
-
-#include "cros_vpd.h"
-#include "lib_vpd.h"
-#include "vpd_tables.h"
-
-/* Currently we only support Google VPD 2.0, which has a fixed offset. */
-enum {
- GOOGLE_VPD_2_0_OFFSET = 0x600,
- CROSVPD_CBMEM_MAGIC = 0x43524f53,
- CROSVPD_CBMEM_VERSION = 0x0001,
-};
-
-struct vpd_gets_arg {
- const uint8_t *key;
- const uint8_t *value;
- int32_t key_len, value_len;
- int matched;
-};
-
-struct vpd_cbmem {
- uint32_t magic;
- uint32_t version;
- uint32_t ro_size;
- uint32_t rw_size;
- uint8_t blob[0];
- /* The blob contains both RO and RW data. It starts with RO (0 ..
- * ro_size) and then RW (ro_size .. ro_size+rw_size).
- */
-};
-
-/* returns the size of data in a VPD 2.0 formatted fmap region, or 0 */
-static int32_t get_vpd_size(const char *fmap_name, int32_t *base)
-{
- struct google_vpd_info info;
- struct region_device vpd;
- int32_t size;
-
- if (fmap_locate_area_as_rdev(fmap_name, &vpd)) {
- printk(BIOS_ERR, "%s: No %s FMAP section.\n", __func__,
- fmap_name);
- return 0;
- }
-
- size = region_device_sz(&vpd);
-
- if ((size < GOOGLE_VPD_2_0_OFFSET + sizeof(info)) ||
- rdev_chain(&vpd, &vpd, GOOGLE_VPD_2_0_OFFSET,
- size - GOOGLE_VPD_2_0_OFFSET)) {
- printk(BIOS_ERR, "%s: Too small (%d) for Google VPD 2.0.\n",
- __func__, size);
- return 0;
- }
-
- /* Try if we can find a google_vpd_info, otherwise read whole VPD. */
- if (rdev_readat(&vpd, &info, *base, sizeof(info)) != sizeof(info)) {
- printk(BIOS_ERR, "ERROR: Failed to read %s header.\n",
- fmap_name);
- return 0;
- }
-
- if (memcmp(info.header.magic, VPD_INFO_MAGIC, sizeof(info.header.magic))
- == 0 && size >= info.size + sizeof(info)) {
- *base += sizeof(info);
- size = info.size;
- } else if (info.header.tlv.type == VPD_TYPE_TERMINATOR ||
- info.header.tlv.type == VPD_TYPE_IMPLICIT_TERMINATOR) {
- printk(BIOS_WARNING, "WARNING: %s is uninitialized or empty.\n",
- fmap_name);
- size = 0;
- } else {
- size -= GOOGLE_VPD_2_0_OFFSET;
- }
-
- return size;
-}
-
-static void cbmem_add_cros_vpd(int is_recovery)
-{
- struct region_device vpd;
- struct vpd_cbmem *cbmem;
- int32_t ro_vpd_base = 0, rw_vpd_base = 0;
- int32_t ro_vpd_size, rw_vpd_size;
-
- timestamp_add_now(TS_START_COPYVPD);
-
- ro_vpd_size = get_vpd_size("RO_VPD", &ro_vpd_base);
- rw_vpd_size = get_vpd_size("RW_VPD", &rw_vpd_base);
-
- /* no VPD at all? nothing to do then */
- if ((ro_vpd_size == 0) && (rw_vpd_size == 0))
- return;
-
- cbmem = cbmem_add(CBMEM_ID_VPD, sizeof(*cbmem) + ro_vpd_size +
- rw_vpd_size);
- if (!cbmem) {
- printk(BIOS_ERR, "%s: Failed to allocate CBMEM (%u+%u).\n",
- __func__, ro_vpd_size, rw_vpd_size);
- return;
- }
-
- cbmem->magic = CROSVPD_CBMEM_MAGIC;
- cbmem->version = CROSVPD_CBMEM_VERSION;
- cbmem->ro_size = 0;
- cbmem->rw_size = 0;
-
- if (ro_vpd_size) {
- if (fmap_locate_area_as_rdev("RO_VPD", &vpd)) {
- /* shouldn't happen, but let's be extra defensive */
- printk(BIOS_ERR, "%s: No RO_VPD FMAP section.\n",
- __func__);
- return;
- }
- rdev_chain(&vpd, &vpd, GOOGLE_VPD_2_0_OFFSET,
- region_device_sz(&vpd) - GOOGLE_VPD_2_0_OFFSET);
-
-
- if (rdev_readat(&vpd, cbmem->blob, ro_vpd_base, ro_vpd_size) ==
- ro_vpd_size) {
- cbmem->ro_size = ro_vpd_size;
- } else {
- printk(BIOS_ERR,
- "%s: Reading RO_VPD FMAP section failed.\n",
- __func__);
- ro_vpd_size = 0;
- }
- timestamp_add_now(TS_END_COPYVPD_RO);
- }
-
- if (rw_vpd_size) {
- if (fmap_locate_area_as_rdev("RW_VPD", &vpd)) {
- /* shouldn't happen, but let's be extra defensive */
- printk(BIOS_ERR, "%s: No RW_VPD FMAP section.\n",
- __func__);
- return;
- }
- rdev_chain(&vpd, &vpd, GOOGLE_VPD_2_0_OFFSET,
- region_device_sz(&vpd) - GOOGLE_VPD_2_0_OFFSET);
-
- if (rdev_readat(&vpd, cbmem->blob + ro_vpd_size, rw_vpd_base,
- rw_vpd_size) == rw_vpd_size) {
- cbmem->rw_size = rw_vpd_size;
- } else {
- printk(BIOS_ERR,
- "%s: Reading RW_VPD FMAP section failed.\n",
- __func__);
- }
- timestamp_add_now(TS_END_COPYVPD_RW);
- }
-}
-
-static int vpd_gets_callback(const uint8_t *key, int32_t key_len,
- const uint8_t *value, int32_t value_len,
- void *arg)
-{
- struct vpd_gets_arg *result = (struct vpd_gets_arg *)arg;
- if (key_len != result->key_len ||
- memcmp(key, result->key, key_len) != 0)
- /* Returns VPD_OK to continue parsing. */
- return VPD_OK;
-
- result->matched = 1;
- result->value = value;
- result->value_len = value_len;
- /* Returns VPD_FAIL to stop parsing. */
- return VPD_FAIL;
-}
-
-const void *cros_vpd_find(const char *key, int *size)
-{
- struct vpd_gets_arg arg = {0};
- int consumed = 0;
- const struct vpd_cbmem *vpd;
-
- vpd = cbmem_find(CBMEM_ID_VPD);
- if (!vpd || !vpd->ro_size)
- return NULL;
-
- arg.key = (const uint8_t *)key;
- arg.key_len = strlen(key);
-
- while (VPD_OK == decodeVpdString(vpd->ro_size, vpd->blob, &consumed,
- vpd_gets_callback, &arg)) {
- /* Iterate until found or no more entries. */
- }
-
- if (!arg.matched)
- return NULL;
-
- *size = arg.value_len;
- return arg.value;
-}
-
-char *cros_vpd_gets(const char *key, char *buffer, int size)
-{
- const void *string_address;
- int string_size;
-
- string_address = cros_vpd_find(key, &string_size);
-
- if (!string_address)
- return NULL;
-
- if (size > (string_size + 1)) {
- memcpy(buffer, string_address, string_size);
- buffer[string_size] = '\0';
- } else {
- memcpy(buffer, string_address, size - 1);
- buffer[size - 1] = '\0';
- }
- return buffer;
-}
-
-RAMSTAGE_CBMEM_INIT_HOOK(cbmem_add_cros_vpd)
diff --git a/src/vendorcode/google/chromeos/cros_vpd.h b/src/vendorcode/google/chromeos/cros_vpd.h
deleted file mode 100644
index 1fa56a4725..0000000000
--- a/src/vendorcode/google/chromeos/cros_vpd.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef __CROS_VPD_H__
-#define __CROS_VPD_H__
-
-#define CROS_VPD_REGION_NAME "region"
-#define CROS_VPD_WIFI_SAR_NAME "wifi_sar"
-
-/*
- * Reads VPD string value by key.
- *
- * Reads in at most one less than size characters from VPD and stores them
- * into buffer. A terminating null byte ('\0') is stored after the last
- * character in the buffer.
- *
- * Returns NULL if key is not found, otherwise buffer.
- */
-char *cros_vpd_gets(const char *key, char *buffer, int size);
-
-/*
- * Find VPD value by key.
- *
- * Searches for a VPD entry in the VPD cache. If found, places the size of the
- * entry into '*size' and returns the pointer to the entry data.
- *
- * This function presumes that VPD is cached in DRAM (which is the case in the
- * current implementation) and as such returns the pointer into the cache. The
- * user is not supposed to modify the data, and does not have to free the
- * memory.
- *
- * Returns NULL if key is not found.
- */
-
-const void *cros_vpd_find(const char *key, int *size);
-
-#endif /* __CROS_VPD_H__ */
diff --git a/src/vendorcode/google/chromeos/lib_vpd.h b/src/vendorcode/google/chromeos/lib_vpd.h
deleted file mode 100644
index e08cb3a654..0000000000
--- a/src/vendorcode/google/chromeos/lib_vpd.h
+++ /dev/null
@@ -1,226 +0,0 @@
-/*
- * Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- *
- */
-
-#ifndef __LIB_VPD__
-#define __LIB_VPD__
-
-#include <inttypes.h>
-
-enum {
- VPD_OK = 0,
- VPD_FAIL,
-};
-
-enum {
- VPD_TYPE_TERMINATOR = 0,
- VPD_TYPE_STRING,
- VPD_TYPE_INFO = 0xfe,
- VPD_TYPE_IMPLICIT_TERMINATOR = 0xff,
-};
-
-enum {
- VPD_AS_LONG_AS = -1,
-};
-
-enum { /* export_type */
- VPD_EXPORT_KEY_VALUE = 1,
- VPD_EXPORT_VALUE,
- VPD_EXPORT_AS_PARAMETER,
-};
-
-/* Callback for decodeVpdString to invoke. */
-typedef int VpdDecodeCallback(const uint8_t *key, int32_t key_len,
- const uint8_t *value, int32_t value_len,
- void *arg);
-
-/* Container data types */
-struct StringPair {
- uint8_t *key;
- uint8_t *value;
- int pad_len;
- int filter_out; /* TRUE means not exported. */
- struct StringPair *next;
-};
-
-struct PairContainer {
- struct StringPair *first;
-};
-
-
-/***********************************************************************
- * Encode and decode VPD entries
- ***********************************************************************/
-
-/* Encodes the len into multiple bytes with the following format.
- *
- * 7 6 ............ 0
- * +----+------------------+
- * |More| Length | ...
- * +----+------------------+
- *
- * The encode_buf points to the actual position we are going to store.
- * encoded_len will return the exact bytes we encoded in this function.
- * Returns fail if the buffer is not long enough.
- */
-int encodeLen(
- const int32_t len,
- uint8_t *encode_buf,
- const int32_t max_len,
- int32_t *encoded_len);
-
-/* Given an encoded string, this functions decodes the length field which varies
- * from 1 byte to many bytes.
- *
- * The in points the actual byte going to be decoded. The *length returns
- * the decoded length field. The number of consumed bytes will be stroed in
- * decoded_len.
- *
- * Returns VPD_FAIL if more bit is 1, but actually reaches the end of string.
- */
-int decodeLen(
- const int32_t max_len,
- const uint8_t *in,
- int32_t *length,
- int32_t *decoded_len);
-
-
-/* Encodes the terminator.
- * When calling, the output_buf should point to the start of buffer while
- * *generated_len should contain how many bytes exist in buffer now.
- * After return, *generated_len would be plused the number of bytes generated
- * in this function.
- */
-int encodeVpdTerminator(
- const int max_buffer_len,
- uint8_t *output_buf,
- int *generated_len);
-
-/* Encodes the given type/key/value pair into buffer.
- *
- * The pad_value_len is used to control the output value length.
- * When pad_value_len > 0, the value is outputted into fixed length (pad \0
- * if the value is shorter). Truncated if too long.
- * pad_value_len == VPD_NO_LIMIT, output the value as long as possible.
- * This is useful when we want to fix the structure layout at beginning.
- *
- * The encoded string will be stored in output_buf. If it is longer than
- * max_buffer_len, this function returns fail. If the buffer is long enough,
- * the generated_len will be updated.
- *
- * When calling, the output_buf should point to the start of buffer while
- * *generated_len should contain how many bytes exist in buffer now.
- * After return, *generated_len would be plused the number of bytes generated
- * in this function.
- *
- * The initial value of *generated_len can be non-zero, so that this value
- * can be used between multiple calls to encodeVpd2Pair().
- */
-int encodeVpdString(
- const uint8_t *key,
- const uint8_t *value,
- const int pad_value_len,
- const int max_buffer_len,
- uint8_t *output_buf,
- int *generated_len);
-
-
-/* Given the encoded string, this function invokes callback with extracted
- * (key, value). The *consumed will be plused the number of bytes consumed in
- * this function.
- *
- * The input_buf points to the first byte of the input buffer.
- *
- * The *consumed starts from 0, which is actually the next byte to be decoded.
- * It can be non-zero to be used in multiple calls.
- *
- * If one entry is successfully decoded, sends it to callback and returns the
- * result.
- */
-int decodeVpdString(
- const int32_t max_len,
- const uint8_t *input_buf,
- int32_t *consumed,
- VpdDecodeCallback callback,
- void *callback_arg);
-
-/***********************************************************************
- * Container helpers
- ***********************************************************************/
-void initContainer(struct PairContainer *container);
-
-struct StringPair *findString(struct PairContainer *container,
- const uint8_t *key,
- struct StringPair ***prev_next);
-
-/* If key is already existed in container, its value will be replaced.
- * If not existed, creates new entry in container.
- */
-void setString(struct PairContainer *container,
- const uint8_t *key,
- const uint8_t *value,
- const int pad_len);
-
-/* merge all entries in src into dst. If key is duplicate, overwrite it.
- */
-void mergeContainer(struct PairContainer *dst,
- const struct PairContainer *src);
-
-/* subtract src from dst.
-*/
-int subtractContainer(struct PairContainer *dst,
- const struct PairContainer *src);
-
-/* Given a container, encode its all entries into the buffer.
- */
-int encodeContainer(const struct PairContainer *container,
- const int max_buf_len,
- uint8_t *buf,
- int *generated);
-
-/* Given a VPD blob, decode its entries and push into container.
- */
-int decodeToContainer(struct PairContainer *container,
- const int32_t max_len,
- const uint8_t *input_buf,
- int32_t *consumed);
-
-/* Set filter for exporting functions.
- * If filter is NULL, resets the filter so that everything can be exported.
- */
-int setContainerFilter(struct PairContainer *container,
- const uint8_t *filter);
-
-/*
- * Remove a key.
- * Returns VPD_OK if deleted successfully. Otherwise, VPD_FAIL.
- */
-int deleteKey(struct PairContainer *container,
- const uint8_t *key);
-
-/*
- * Returns number of pairs in container.
- */
-int lenOfContainer(const struct PairContainer *container);
-
-/*
- * Export the container content with human-readable text.
- *
- * The buf points to the first byte of buffer and *generated contains the number
- * of bytes already existed in buffer.
- *
- * Afterward, the *generated will be plused on exact bytes this function has
- * generated.
- */
-int exportContainer(const int export_type,
- const struct PairContainer *container,
- const int max_buf_len,
- uint8_t *buf,
- int *generated);
-
-void destroyContainer(struct PairContainer *container);
-
-#endif /* __LIB_VPD__ */
diff --git a/src/vendorcode/google/chromeos/sar.c b/src/vendorcode/google/chromeos/sar.c
index fc72dc1348..6799f12a24 100644
--- a/src/vendorcode/google/chromeos/sar.c
+++ b/src/vendorcode/google/chromeos/sar.c
@@ -19,9 +19,10 @@
#include <types.h>
#include <string.h>
#include <sar.h>
-#include "cros_vpd.h"
+#include <drivers/vpd/vpd.h>
#define WIFI_SAR_CBFS_FILENAME "wifi_sar_defaults.hex"
+#define CROS_VPD_WIFI_SAR_NAME "wifi_sar"
static int load_sar_file_from_cbfs(void *buf, size_t buffer_size)
{
@@ -55,7 +56,7 @@ For [WGDS_VERSION] 0x00,
int get_wifi_sar_limits(struct wifi_sar_limits *sar_limits)
{
const char *wifi_sar_limit_key = CROS_VPD_WIFI_SAR_NAME;
- /* cros_vpd_gets() reads in one less than size characters from the VPD
+ /* vpd_gets() reads in one less than size characters from the VPD
* with a terminating null byte ('\0') stored as the last character into
* the buffer, thus the increasing by 1 for buffer_size. */
const size_t buffer_size = (sizeof(struct wifi_sar_limits) /
@@ -79,8 +80,8 @@ int get_wifi_sar_limits(struct wifi_sar_limits *sar_limits)
}
/* Try to read the SAR limit entry from VPD */
- if (!cros_vpd_gets(wifi_sar_limit_key, wifi_sar_limit_str,
- buffer_size)) {
+ if (!vpd_gets(wifi_sar_limit_key, wifi_sar_limit_str,
+ buffer_size, VPD_ANY)) {
printk(BIOS_ERR, "Error: Could not locate '%s' in VPD.\n",
wifi_sar_limit_key);
diff --git a/src/vendorcode/google/chromeos/vpd_calibration.c b/src/vendorcode/google/chromeos/vpd_calibration.c
index 697ff953dd..7f9910b3f9 100644
--- a/src/vendorcode/google/chromeos/vpd_calibration.c
+++ b/src/vendorcode/google/chromeos/vpd_calibration.c
@@ -19,7 +19,7 @@
#include <string.h>
#include <vendorcode/google/chromeos/chromeos.h>
-#include <vendorcode/google/chromeos/cros_vpd.h>
+#include <drivers/vpd/vpd.h>
/*
* This file provides functions looking in the VPD for WiFi calibration data,
@@ -112,7 +112,7 @@ static size_t fill_up_entries_cache(struct vpd_blob_cache_t *cache,
strcpy(cache->key_name, templates[i]);
cache->key_name[index_location] = j + '0';
- payload = cros_vpd_find(cache->key_name, &payload_size);
+ payload = vpd_find(cache->key_name, &payload_size, VPD_ANY);
if (!payload)
continue;
diff --git a/src/vendorcode/google/chromeos/vpd_decode.c b/src/vendorcode/google/chromeos/vpd_decode.c
deleted file mode 100644
index 545fd8106f..0000000000
--- a/src/vendorcode/google/chromeos/vpd_decode.c
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- *
- */
-#include <assert.h>
-#include "lib_vpd.h"
-
-int decodeLen(
- const int32_t max_len,
- const uint8_t *in,
- int32_t *length,
- int32_t *decoded_len) {
- uint8_t more;
- int i = 0;
-
- assert(length);
- assert(decoded_len);
-
- *length = 0;
- do {
- if (i >= max_len) return VPD_FAIL;
- more = in[i] & 0x80;
- *length <<= 7;
- *length |= in[i] & 0x7f;
- ++i;
- } while (more);
-
- *decoded_len = i;
-
- return VPD_OK;
-}
-
-/* Sequentially decodes type, key, and value.
- */
-int decodeVpdString(
- const int32_t max_len,
- const uint8_t *input_buf,
- int32_t *consumed,
- VpdDecodeCallback callback,
- void *callback_arg) {
- int type;
- int32_t key_len, value_len;
- int32_t decoded_len;
- const uint8_t *key, *value;
-
- /* type */
- if (*consumed >= max_len)
- return VPD_FAIL;
-
- type = input_buf[*consumed];
- switch (type) {
- case VPD_TYPE_INFO:
- case VPD_TYPE_STRING:
- (*consumed)++;
-
- /* key */
- if (VPD_OK != decodeLen(max_len - *consumed, &input_buf[*consumed],
- &key_len, &decoded_len) ||
- *consumed + decoded_len >= max_len) {
- return VPD_FAIL;
- }
-
- *consumed += decoded_len;
- key = &input_buf[*consumed];
- *consumed += key_len;
-
- /* value */
- if (VPD_OK != decodeLen(max_len - *consumed, &input_buf[*consumed],
- &value_len, &decoded_len) ||
- *consumed + decoded_len > max_len) {
- return VPD_FAIL;
- }
- *consumed += decoded_len;
- value = &input_buf[*consumed];
- *consumed += value_len;
-
- if (type == VPD_TYPE_STRING)
- return callback(key, key_len, value, value_len, callback_arg);
-
- return VPD_OK;
-
- default:
- return VPD_FAIL;
- break;
- }
- return VPD_OK;
-}
diff --git a/src/vendorcode/google/chromeos/vpd_mac.c b/src/vendorcode/google/chromeos/vpd_mac.c
index 061997453a..e3ef04b669 100644
--- a/src/vendorcode/google/chromeos/vpd_mac.c
+++ b/src/vendorcode/google/chromeos/vpd_mac.c
@@ -17,7 +17,7 @@
#include <console/console.h>
#include <string.h>
-#include <vendorcode/google/chromeos/cros_vpd.h>
+#include <drivers/vpd/vpd.h>
/*
* Decode string representation of the MAC address (a string of 12 hex
@@ -84,8 +84,8 @@ void lb_table_add_macs_from_vpd(struct lb_header *header)
* If there are no more MAC addresses of this template
* in the VPD - move on.
*/
- if (!cros_vpd_gets(mac_addr_key, mac_addr_str,
- sizeof(mac_addr_str)))
+ if (!vpd_gets(mac_addr_key, mac_addr_str,
+ sizeof(mac_addr_str), VPD_ANY))
break;
if (!macs) {
diff --git a/src/vendorcode/google/chromeos/vpd_serialno.c b/src/vendorcode/google/chromeos/vpd_serialno.c
index e9a771ebaa..8cae5d6d20 100644
--- a/src/vendorcode/google/chromeos/vpd_serialno.c
+++ b/src/vendorcode/google/chromeos/vpd_serialno.c
@@ -18,7 +18,7 @@
#include <assert.h>
#include <string.h>
-#include <vendorcode/google/chromeos/cros_vpd.h>
+#include <drivers/vpd/vpd.h>
void lb_table_add_serialno_from_vpd(struct lb_header *header)
{
@@ -27,8 +27,8 @@ void lb_table_add_serialno_from_vpd(struct lb_header *header)
char serialno[32];
size_t len;
- if (!cros_vpd_gets(serialno_key, serialno,
- sizeof(serialno))) {
+ if (!vpd_gets(serialno_key, serialno,
+ sizeof(serialno), VPD_ANY)) {
printk(BIOS_ERR, "no serial number in vpd\n");
return;
}
diff --git a/src/vendorcode/google/chromeos/vpd_tables.h b/src/vendorcode/google/chromeos/vpd_tables.h
deleted file mode 100644
index 822ed08b0f..0000000000
--- a/src/vendorcode/google/chromeos/vpd_tables.h
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- *
- * Ported from mosys project (http://code.google.com/p/mosys/).
- */
-
-#ifndef __LIB_VPD_TABLES_H__
-#define __LIB_VPD_TABLES_H__
-
-#include <compiler.h>
-#include <inttypes.h>
-
-#define VPD_ENTRY_MAGIC "_SM_"
-#define VPD_INFO_MAGIC \
- "\xfe" /* type: VPD header */ \
- "\x09" /* key length, 9 = 1 + 8 */ \
- "\x01" /* info version, 1 */ \
- "gVpdInfo" /* signature, 8 bytes */ \
- "\x04" /* value length */
-
-/* Google specific VPD info */
-struct google_vpd_info {
- union {
- struct {
- uint8_t type;
- uint8_t key_len;
- uint8_t info_ver;
- uint8_t signature[8];
- uint8_t value_len;
- } tlv;
- uint8_t magic[12];
- } header;
- uint32_t size;
-} __packed;
-
-/* Entry */
-struct vpd_entry {
- uint8_t anchor_string[4];
- uint8_t entry_cksum;
- uint8_t entry_length;
- uint8_t major_ver;
- uint8_t minor_ver;
- uint16_t max_size;
- uint8_t entry_rev;
- uint8_t format_area[5];
- uint8_t inter_anchor_string[5];
- uint8_t inter_anchor_cksum;
- uint16_t table_length;
- uint32_t table_address;
- uint16_t table_entry_count;
- uint8_t bcd_revision;
-} __packed;
-
-/* Header */
-struct vpd_header {
- uint8_t type;
- uint8_t length;
- uint16_t handle;
-} __packed;
-
-/* Type 0 - firmware information */
-struct vpd_table_firmware {
- uint8_t vendor;
- uint8_t version;
- uint16_t start_address;
- uint8_t release_date;
- uint8_t rom_size_64k_blocks;
- uint32_t characteristics;
- uint8_t extension[2]; /* v2.4+ */
- uint8_t major_ver; /* v2.4+ */
- uint8_t minor_ver; /* v2.4+ */
- uint8_t ec_major_ver; /* v2.4+ */
- uint8_t ec_minor_ver; /* v2.4+ */
-} __packed;
-
-/* Type 1 - system information */
-struct vpd_table_system {
- uint8_t manufacturer;
- uint8_t name;
- uint8_t version;
- uint8_t serial_number;
- uint8_t uuid[16];
- uint8_t wakeup_type;
- uint8_t sku_number; /* v2.4+ */
- uint8_t family; /* v2.4+ */
-} __packed;
-
-/* Type 127 - end of table */
-struct vpd_table_eot {
- struct vpd_header header;
-} __packed;
-
-/* Type 241 - binary blob pointer */
-struct vpd_table_binary_blob_pointer {
- uint8_t struct_major_version;
- uint8_t struct_minor_version;
- uint8_t vendor;
- uint8_t description;
- uint8_t major_version;
- uint8_t minor_version;
- uint8_t variant;
- uint8_t reserved[5];
- uint8_t uuid[16];
- uint32_t offset;
- uint32_t size;
-} __packed;
-
-/* The length and number of strings defined here is not a limitation of VPD.
- * These numbers were deemed good enough during development. */
-#define VPD_MAX_STRINGS 10
-#define VPD_MAX_STRING_LENGTH 64
-
-#endif /* __LIB_VPD_TABLES_H__ */
diff --git a/src/vendorcode/google/chromeos/wrdd.c b/src/vendorcode/google/chromeos/wrdd.c
index ad8099247b..093e6cdb74 100644
--- a/src/vendorcode/google/chromeos/wrdd.c
+++ b/src/vendorcode/google/chromeos/wrdd.c
@@ -18,7 +18,9 @@
#include <types.h>
#include <string.h>
#include <wrdd.h>
-#include "cros_vpd.h"
+#include <drivers/vpd/vpd.h>
+
+#define CROS_VPD_REGION_NAME "region"
/*
* wrdd_domain_value is ISO 3166-2
@@ -59,8 +61,8 @@ uint16_t wifi_regulatory_domain(void)
char *separator;
/* If not found for any reason fall backto the default value */
- if (!cros_vpd_gets(wrdd_domain_key, wrdd_domain_code,
- ARRAY_SIZE(wrdd_domain_code))) {
+ if (!vpd_gets(wrdd_domain_key, wrdd_domain_code,
+ ARRAY_SIZE(wrdd_domain_code), VPD_ANY)) {
printk(BIOS_DEBUG,
"Error: Could not locate '%s' in VPD\n", wrdd_domain_key);
return WRDD_DEFAULT_REGULATORY_DOMAIN;