[Skiboot] [PATCH 2/7] vpd: add vpd_valid() to check keyword VPD blobs

Oliver O'Halloran oohall at gmail.com
Fri Jan 13 17:56:17 AEDT 2017


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 at gmail.com>
---
 core/vpd.c    | 26 ++++++++++++++++++++++++++
 include/vpd.h |  2 ++
 2 files changed, 28 insertions(+)

diff --git a/core/vpd.c b/core/vpd.c
index 505b3d639ef4..540c5578b47b 100644
--- a/core/vpd.c
+++ b/core/vpd.c
@@ -46,6 +46,32 @@ 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;
+
+	/* 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
diff --git a/include/vpd.h b/include/vpd.h
index bc60d81f782e..02bbde25e7a7 100644
--- a/include/vpd.h
+++ b/include/vpd.h
@@ -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);
 
-- 
2.7.4



More information about the Skiboot mailing list