Skip to contentSkip to conversation

Google VPD sysfs driver

PATCH New Thierry Escande 1 participant 3 messages Apr 12, 2017

lore
Share & tools
lore
#0 lore raw

v2 cover Google VPD sysfs driver

Hi,

This patchset adds support for accessing Google Vital Product Data (VPD) through the sysfs interface under /sys/firmware/vpd.

This patchset contains the VPD decoding routines read from coreboot table entries and the driver responsible for creating the sysfs interface.

This patchset depends on [1] for coreboot support in the Google memory console.

This v2 fixes style issues reported by 'checkpatch --strict', adds the vpd_ prefix to a few function names, and removes the EXPORT_SYMBOL for vpd_decode_string().

Regards,
Thierry

[1] https://lkml.org/lkml/2017/3/28/902

Wei-Ning Huang (2):
firmware: Google Vital Product Data: import lib_vpd source files
firmware: Google VPD sysfs driver

 drivers/firmware/google/Kconfig      |   7 +
 drivers/firmware/google/Makefile     |   3 +
 drivers/firmware/google/vpd.c        | 333 +++++++++++++++++++++++++++++++++++
 drivers/firmware/google/vpd_decode.c | 102 +++++++++++
 drivers/firmware/google/vpd_decode.h |  59 +++++++
 5 files changed, 504 insertions(+)
 create mode 100644 drivers/firmware/google/vpd.c
 create mode 100644 drivers/firmware/google/vpd_decode.c
 create mode 100644 drivers/firmware/google/vpd_decode.h
Signature · 1 line
2.7.4
#2 lore raw

PATCH v2 2/2 firmware: Google VPD sysfs driver

From: Wei-Ning Huang <[email protected]>

This patch introduces the Google Vital Product Data driver.

This driver reads Vital Product Data from coreboot tables and then creates the corresponding sysfs entries under /sys/firmware/vpd to provide easy access for userspace programs (does not require flashrom).

The sysfs is structured as follow:

/sys/firmware/vpd

 |-- ro
 |   |-- key1
 |   `-- key2
 |-- ro_raw
 |-- rw
 |   `-- key1

`-- rw_raw

Where ro_raw and rw_raw contain the raw VPD partition. The files under ro and rw correspond to the key name in the VPD and the the file content is the value for the key.

---

In this v2:
- Fix coding style issues reported by 'checkpatch --strict'
- Add missing vpd_ prefix to some functions

---
 drivers/firmware/google/Kconfig  |   7 +
 drivers/firmware/google/Makefile |   3 +
 drivers/firmware/google/vpd.c    | 332 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 342 insertions(+)
 create mode 100644 drivers/firmware/google/vpd.c
drivers/firmware/google/Kconfig +7 -0
index 00000e0..f16b381 100644
@@ -64,4 +64,11 @@ config GOOGLE_MEMCONSOLE_COREBOOT
 	  the coreboot table.  If found, this log is exported to userland
 	  in the file /sys/firmware/log.
 
+config GOOGLE_VPD
+	tristate "Vital Product Data"
+	depends on GOOGLE_COREBOOT_TABLE
+	help
+	  This option enables the kernel to expose the content of Google VPD
+	  under /sys/firmware/vpd.
+
 endif # GOOGLE_FIRMWARE
drivers/firmware/google/Makefile +3 -0
index bb952c6..bc4de02 100644
@@ -6,3 +6,6 @@ obj-$(CONFIG_GOOGLE_COREBOOT_TABLE_OF)     += coreboot_table-of.o
 obj-$(CONFIG_GOOGLE_MEMCONSOLE)            += memconsole.o
 obj-$(CONFIG_GOOGLE_MEMCONSOLE_COREBOOT)   += memconsole-coreboot.o
 obj-$(CONFIG_GOOGLE_MEMCONSOLE_X86_LEGACY) += memconsole-x86-legacy.o
+
+vpd-sysfs-y := vpd.o vpd_decode.o
+obj-$(CONFIG_GOOGLE_VPD)		+= vpd-sysfs.o
drivers/firmware/google/vpd.c new file +332 -0

332 lines not on this page · raw message

Signature · 1 line
2.7.4
#1 lore raw

PATCH v2 1/2 firmware: Google VPD: import lib_vpd source files

In reply to Thierry Escande

From: Wei-Ning Huang <[email protected]>

This patch imports lib_vpd.h and vpd_decode.c from the Chromium Vital Product Data project.

This library is used to parse VPD sections obtained from coreboot table entries describing Chromebook devices product data. Only the sections of type VPD_TYPE_STRING are decoded.

The VPD string sections in the coreboot tables contain the type (1 byte set to 0x01 for strings), the key length, the key ascii array, the value length, and the value ascii array. The key and value arrays are not null terminated.

---

In this v2:
- Fix coding style issues reported by 'checkpatch --strict'
- Add missing vpd_ prefix to some functions
- Remove uneeded EXPORT_SYMBOL for vpd_decode_string()

---
 drivers/firmware/google/vpd_decode.c | 99 ++++++++++++++++++++++++++++++++++++
 drivers/firmware/google/vpd_decode.h | 58 +++++++++++++++++++++
 2 files changed, 157 insertions(+)
 create mode 100644 drivers/firmware/google/vpd_decode.c
 create mode 100644 drivers/firmware/google/vpd_decode.h
drivers/firmware/google/vpd_decode.c new file +99 -0
new file mode 100644
index 0000000..943acaa
@@ -0,0 +1,99 @@
+/*
+ * vpd_decode.c
+ *
+ * Google VPD decoding routines.
+ *
+ * Copyright 2017 Google Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License v2.0 as published by
+ * the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/export.h>
+
+#include "vpd_decode.h"
+
+static int vpd_decode_len(const s32 max_len, const u8 *in,
+			  s32 *length, s32 *decoded_len)
+{
+	u8 more;
+	int i = 0;
+
+	if (!length || !decoded_len)
+		return VPD_FAIL;
+
+	*length = 0;
+	do {
+		if (i >= max_len)
+			return VPD_FAIL;
+
+		more = in[i] & 0x80;
+		*length <<= 7;
+		*length |= in[i] & 0x7f;
+		++i;
+	} while (more);
+
+	*decoded_len = i;
+
+	return VPD_OK;
+}
+
+int vpd_decode_string(const s32 max_len, const u8 *input_buf, s32 *consumed,
+		      vpd_decode_callback callback, void *callback_arg)
+{
+	int type;
+	int res;
+	s32 key_len;
+	s32 value_len;
+	s32 decoded_len;
+	const u8 *key;
+	const u8 *value;
+
+	/* type */
+	if (*consumed >= max_len)
+		return VPD_FAIL;
+
+	type = input_buf[*consumed];
+
+	switch (type) {
+	case VPD_TYPE_INFO:
+	case VPD_TYPE_STRING:
+		(*consumed)++;
+
+		/* key */
+		res = vpd_decode_len(max_len - *consumed, &input_buf[*consumed],
+				     &key_len, &decoded_len);
+		if (res != VPD_OK || *consumed + decoded_len >= max_len)
+			return VPD_FAIL;
+
+		*consumed += decoded_len;
+		key = &input_buf[*consumed];
+		*consumed += key_len;
+
+		/* value */
+		res = vpd_decode_len(max_len - *consumed, &input_buf[*consumed],
+				     &value_len, &decoded_len);
+		if (res != VPD_OK || *consumed + decoded_len > max_len)
+			return VPD_FAIL;
+
+		*consumed += decoded_len;
+		value = &input_buf[*consumed];
+		*consumed += value_len;
+
+		if (type == VPD_TYPE_STRING)
+			return callback(key, key_len, value, value_len,
+					callback_arg);
+		break;
+
+	default:
+		return VPD_FAIL;
+	}
+
+	return VPD_OK;
+}
drivers/firmware/google/vpd_decode.h new file +58 -0

58 lines not on this page · raw message

Signature · 1 line
2.7.4