summaryrefslogtreecommitdiff
path: root/src/vendorcode/google/chromeos
diff options
context:
space:
mode:
Diffstat (limited to 'src/vendorcode/google/chromeos')
-rw-r--r--src/vendorcode/google/chromeos/cros_vpd.c26
-rw-r--r--src/vendorcode/google/chromeos/cros_vpd.h16
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 df2b5bf667..c0e483019b 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 674dbf65d9..19658c2940 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__ */