diff options
author | Vadim Bendebury <vbendeb@chromium.org> | 2014-10-22 17:39:24 -0700 |
---|---|---|
committer | Patrick Georgi <pgeorgi@google.com> | 2015-04-10 11:57:50 +0200 |
commit | 127c3393b44830987e83ce8c8e7a77f79dd4f5c1 (patch) | |
tree | 64f566544c30c5f0060758fe8a1e9d1ae05dd11c | |
parent | cb3b0c5a0dd5164fb4a8c0c6b8d2656948748343 (diff) |
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
Change-Id: Id06be315981cdaa2285fc1ec61b96b62b1178a4b
Signed-off-by: Patrick Georgi <pgeorgi@chromium.org>
Original-Commit-Id: 99a34344448a5521cee8ad3918aefb1fde28417d
Original-Change-Id: I6c0b11bb844d6235930124d642da632319142d88
Original-Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Original-Reviewed-on: https://chromium-review.googlesource.com/225258
Original-Reviewed-by: Hung-Te Lin <hungte@chromium.org>
Reviewed-on: http://review.coreboot.org/9403
Tested-by: build bot (Jenkins)
Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
-rw-r--r-- | src/vendorcode/google/chromeos/cros_vpd.c | 26 | ||||
-rw-r--r-- | 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 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__ */ |