summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorOliver O'Halloran <oohall@gmail.com>2017-01-13 17:56:17 +1100
committerStewart Smith <stewart@linux.vnet.ibm.com>2017-01-16 09:55:43 +1100
commitc134dbfeaa1f24c892919b483c3fc00a05822efb (patch)
treef519bd0d6dcf9c639fe4c7e9e95378bc99e62511 /core
parent45b1170171775ad3df994da69933f2f8c659c398 (diff)
downloadblackbird-skiboot-c134dbfeaa1f24c892919b483c3fc00a05822efb.tar.gz
blackbird-skiboot-c134dbfeaa1f24c892919b483c3fc00a05822efb.zip
vpd: add vpd_valid() to check keyword VPD blobs
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>
Diffstat (limited to 'core')
-rw-r--r--core/vpd.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/core/vpd.c b/core/vpd.c
index 505b3d63..d6591981 100644
--- a/core/vpd.c
+++ b/core/vpd.c
@@ -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
OpenPOWER on IntegriCloud