[PATCH v2 02/22] vbe: Start a common header file

Simon Glass sjg at chromium.org
Thu Jan 16 02:27:03 CET 2025


Move a few things into a new, common header file so that vbe-simple can
share code with the upcoming abrec.

Put struct simple_nvdata in it and rename it.

Signed-off-by: Simon Glass <sjg at chromium.org>
---

Changes in v2:
- Split patch into several pieces

 boot/vbe_common.h | 51 +++++++++++++++++++++++++++++++++++++++++++++++
 boot/vbe_simple.c | 13 ++----------
 boot/vbe_simple.h | 16 ++-------------
 3 files changed, 55 insertions(+), 25 deletions(-)
 create mode 100644 boot/vbe_common.h

diff --git a/boot/vbe_common.h b/boot/vbe_common.h
new file mode 100644
index 00000000000..1fc70ee74c8
--- /dev/null
+++ b/boot/vbe_common.h
@@ -0,0 +1,51 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Verified Boot for Embedded (VBE) common functions
+ *
+ * Copyright 2024 Google LLC
+ * Written by Simon Glass <sjg at chromium.org>
+ */
+
+#ifndef __VBE_COMMON_H
+#define __VBE_COMMON_H
+
+#include <linux/types.h>
+
+struct udevice;
+
+enum {
+	MAX_VERSION_LEN		= 256,
+
+	NVD_HDR_VER_SHIFT	= 0,
+	NVD_HDR_VER_MASK	= 0xf,
+	NVD_HDR_SIZE_SHIFT	= 4,
+	NVD_HDR_SIZE_MASK	= 0xf << NVD_HDR_SIZE_SHIFT,
+
+	/* Firmware key-version is in the top 16 bits of fw_ver */
+	FWVER_KEY_SHIFT		= 16,
+	FWVER_FW_MASK		= 0xffff,
+
+	NVD_HDR_VER_CUR		= 1,	/* current version */
+};
+
+/**
+ * struct vbe_nvdata - basic storage format for non-volatile data
+ *
+ * This is used for all VBE methods
+ *
+ * @crc8: crc8 for the entire record except @crc8 field itself
+ * @hdr: header size and version (NVD_HDR_...)
+ * @spare1: unused, must be 0
+ * @fw_vernum: version and key version (FWVER_...)
+ * @flags: Flags controlling operation (enum vbe_flags)
+ */
+struct vbe_nvdata {
+	u8 crc8;
+	u8 hdr;
+	u16 spare1;
+	u32 fw_vernum;
+	u32 flags;
+	u8 spare2[0x34];
+};
+
+#endif /* __VBE_ABREC_H */
diff --git a/boot/vbe_simple.c b/boot/vbe_simple.c
index f260e9b731d..b175c5d3a59 100644
--- a/boot/vbe_simple.c
+++ b/boot/vbe_simple.c
@@ -21,15 +21,6 @@
 #include <u-boot/crc.h>
 #include "vbe_simple.h"
 
-/** struct simple_nvdata - storage format for non-volatile data */
-struct simple_nvdata {
-	u8 crc8;
-	u8 hdr;
-	u16 spare1;
-	u32 fw_vernum;
-	u8 spare2[0x38];
-};
-
 static int simple_read_version(struct udevice *dev, struct blk_desc *desc,
 			       u8 *buf, struct simple_state *state)
 {
@@ -57,7 +48,7 @@ static int simple_read_nvdata(struct udevice *dev, struct blk_desc *desc,
 {
 	struct simple_priv *priv = dev_get_priv(dev);
 	uint hdr_ver, hdr_size, size, crc;
-	const struct simple_nvdata *nvd;
+	const struct vbe_nvdata *nvd;
 	int start;
 
 	if (priv->state_size > MMC_MAX_BLOCK_LEN)
@@ -70,7 +61,7 @@ static int simple_read_nvdata(struct udevice *dev, struct blk_desc *desc,
 
 	if (blk_read(desc->bdev, start, 1, buf) != 1)
 		return log_msg_ret("read", -EIO);
-	nvd = (struct simple_nvdata *)buf;
+	nvd = (struct vbe_nvdata *)buf;
 	hdr_ver = (nvd->hdr & NVD_HDR_VER_MASK) >> NVD_HDR_VER_SHIFT;
 	hdr_size = (nvd->hdr & NVD_HDR_SIZE_MASK) >> NVD_HDR_SIZE_SHIFT;
 	if (hdr_ver != NVD_HDR_VER_CUR)
diff --git a/boot/vbe_simple.h b/boot/vbe_simple.h
index 56d319206f2..dc3f70052b0 100644
--- a/boot/vbe_simple.h
+++ b/boot/vbe_simple.h
@@ -9,20 +9,8 @@
 #ifndef __VBE_SIMPLE_H
 #define __VBE_SIMPLE_H
 
-enum {
-	MAX_VERSION_LEN		= 256,
-
-	NVD_HDR_VER_SHIFT	= 0,
-	NVD_HDR_VER_MASK	= 0xf,
-	NVD_HDR_SIZE_SHIFT	= 4,
-	NVD_HDR_SIZE_MASK	= 0xf << NVD_HDR_SIZE_SHIFT,
-
-	/* Firmware key-version is in the top 16 bits of fw_ver */
-	FWVER_KEY_SHIFT		= 16,
-	FWVER_FW_MASK		= 0xffff,
-
-	NVD_HDR_VER_CUR		= 1,	/* current version */
-};
+#include <linux/types.h>
+#include "vbe_common.h"
 
 /** struct simple_priv - information read from the device tree */
 struct simple_priv {
-- 
2.34.1



More information about the U-Boot mailing list