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>
This commit is contained in:
Vadim Bendebury 2014-10-22 17:39:24 -07:00 committed by Patrick Georgi
parent cb3b0c5a0d
commit 127c3393b4
2 changed files with 37 additions and 5 deletions

View File

@ -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;
}

View File

@ -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__ */