[coreboot-gerrit] Patch set updated for coreboot: d37ebc3 chromeos: add another VPD access API

Aaron Durbin (adurbin@chromium.org) gerrit at coreboot.org
Thu Apr 9 19:52:41 CEST 2015


Aaron Durbin (adurbin at chromium.org) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/9434

-gerrit

commit d37ebc315eab74c81a27dfb3c3f140d61178b69d
Author: Vadim Bendebury <vbendeb at chromium.org>
Date:   Wed Oct 22 17:39:24 2014 -0700

    chromeos: add another VPD access API
    
    The new API allows to find VPD objects in the VPD cache.  There is no
    need for the caller to allocate or free the per object memory.
    
    The existing API (cros_vpd_gets) now uses the new function as well.
    
    BRANCH=storm
    BUG=chrome-os-partner:32611
    TEST=verified that MAC addresses still show up in the device tree on
         the booted storm device
    
    Original-Change-Id: I6c0b11bb844d6235930124d642da632319142d88
    Original-Signed-off-by: Vadim Bendebury <vbendeb at chromium.org>
    Original-Reviewed-on: https://chromium-review.googlesource.com/225258
    Original-Reviewed-by: Hung-Te Lin <hungte at chromium.org>
    
    (cherry picked from commit 99a34344448a5521cee8ad3918aefb1fde28417d)
    Signed-off-by: Aaron Durbin <adurbin at chromium.org>
    
    Change-Id: Ia1da362b12389a18a784ac3c8195127e91bb8d00
---
 src/vendorcode/google/chromeos/cros_vpd.c | 26 +++++++++++++++++++++-----
 src/vendorcode/google/chromeos/cros_vpd.h | 16 ++++++++++++++++
 2 files changed, 37 insertions(+), 5 deletions(-)

diff --git a/src/vendorcode/google/chromeos/cros_vpd.c b/src/vendorcode/google/chromeos/cros_vpd.c
index df2b5bf..c0e4830 100644
--- a/src/vendorcode/google/chromeos/cros_vpd.c
+++ b/src/vendorcode/google/chromeos/cros_vpd.c
@@ -99,7 +99,7 @@ static int vpd_gets_callback(const uint8_t *key, int32_t key_len,
 	return VPD_FAIL;
 }
 
-char *cros_vpd_gets(const char *key, char *buffer, int size)
+const void *cros_vpd_find(const char *key, int *size)
 {
 	uint8_t *vpd_address = NULL;
 	int32_t vpd_size = 0;
@@ -121,10 +121,26 @@ char *cros_vpd_gets(const char *key, char *buffer, int size)
 	if (!arg.matched)
 		return NULL;
 
-	if (size < arg.value_len + 1)
-		size = arg.value_len + 1;
-	memcpy(buffer, arg.value, size - 1);
-	buffer[size - 1] = '\0';
+	*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)) {
+		strcpy(buffer, string_address);
+	} else {
+		memcpy(buffer, string_address, size - 1);
+		buffer[size - 1] = '\0';
+	}
 	return buffer;
 }
 
diff --git a/src/vendorcode/google/chromeos/cros_vpd.h b/src/vendorcode/google/chromeos/cros_vpd.h
index 674dbf6..19658c2 100644
--- a/src/vendorcode/google/chromeos/cros_vpd.h
+++ b/src/vendorcode/google/chromeos/cros_vpd.h
@@ -18,4 +18,20 @@
  */
 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__ */



More information about the coreboot-gerrit mailing list