Skip to content

Commit

Permalink
vpd: add vpd_valid() to check keyword VPD blobs
Browse files Browse the repository at this point in the history
Adds a function to check whether a blob is a valid IBM ASCII keyword
VPD blob. This allows us to recognise when we do and do not have a VPD
blob and act accordingly.

Signed-off-by: Oliver O'Halloran <oohall@gmail.com>
[stewart@linux.vnet.ibm.com: check if initial 0x84 exists. Spotted by Vasant]
Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
  • Loading branch information
oohal authored and stewartsmith committed Jan 15, 2017
1 parent 45b1170 commit c134dbf
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
29 changes: 29 additions & 0 deletions core/vpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,35 @@ const void *vpd_find_keyword(const void *rec, size_t rec_sz,
return NULL;
}

/* vpd_valid - does some basic sanity checks to ensure a VPD blob is
* actually a VPD blob
*/
bool vpd_valid(const void *vvpd, size_t vpd_size)
{
const uint8_t *vpd = vvpd;
int size, i = 0;

/* find the record start byte */
while (i < vpd_size)
if (vpd[i++] == 0x84)
break;

if (i >= vpd_size)
return false;

/* next two bytes are the record length, little endian */
size = 2;
size += vpd[i];
size += vpd[i + 1] << 8;

i += size; /* skip to the end marker */

if (i >= vpd_size || vpd[i] != 0x78)
return false;

return true;
}

/* Locate a record in a VPD blob
*
* Note: This works with VPD LIDs. It will scan until it finds
Expand Down
2 changes: 2 additions & 0 deletions include/vpd.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ const void *vpd_find(const void *vpd, size_t vpd_size,
const char *record, const char *keyword,
uint8_t *sz);

bool vpd_valid(const void *vvpd, size_t vpd_size);

/* Add model property to dt_root */
void add_dtb_model(void);

Expand Down

0 comments on commit c134dbf

Please sign in to comment.