vpd: Add vpd_get_int() function

Change-Id: I1c1b5710a5236fe4a3bdda1fc978393e636e9817
Signed-off-by: Nico Huber <nico.h@gmx.de>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/45773
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
Reviewed-by: Julius Werner <jwerner@chromium.org>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
Nico Huber 2020-09-27 16:21:22 +02:00
parent bdb37982d6
commit c00ffef47c
2 changed files with 32 additions and 0 deletions

View File

@ -3,10 +3,12 @@
#include <assert.h> #include <assert.h>
#include <console/console.h> #include <console/console.h>
#include <cbmem.h> #include <cbmem.h>
#include <ctype.h>
#include <fmap.h> #include <fmap.h>
#include <program_loading.h> #include <program_loading.h>
#include <string.h> #include <string.h>
#include <timestamp.h> #include <timestamp.h>
#include <types.h>
#include "vpd.h" #include "vpd.h"
#include "vpd_decode.h" #include "vpd_decode.h"
@ -274,4 +276,25 @@ bool vpd_get_bool(const char *key, enum vpd_region region, uint8_t *val)
return false; return false;
} }
/*
* Find value of integer type by vpd key.
*
* Expects to find a decimal string, trailing chars are ignored.
* Returns true if the key is found and the value is not too long and
* starts with a decimal digit. Leaves `val` untouched if unsuccessful.
*/
bool vpd_get_int(const char *const key, const enum vpd_region region, int *const val)
{
char value[11];
if (!vpd_gets(key, value, sizeof(value), region))
return false;
if (!isdigit(*value))
return false;
*val = (int)atol(value);
return true;
}
ROMSTAGE_CBMEM_INIT_HOOK(cbmem_add_cros_vpd) ROMSTAGE_CBMEM_INIT_HOOK(cbmem_add_cros_vpd)

View File

@ -50,4 +50,13 @@ const void *vpd_find(const char *key, int *size, enum vpd_region region);
bool vpd_get_bool(const char *key, enum vpd_region region, bool vpd_get_bool(const char *key, enum vpd_region region,
uint8_t *val); uint8_t *val);
/*
* Find value of integer type by vpd key.
*
* Expects to find a decimal string, trailing chars are ignored.
* Returns true if the key is found and the value is not too long and
* starts with a decimal digit.
*/
bool vpd_get_int(const char *key, enum vpd_region region, int *val);
#endif /* __VPD_H__ */ #endif /* __VPD_H__ */