[PATCH v2 52/71] bootstd: Add a new bootmeth method to set the bootflow

Simon Glass sjg at chromium.org
Sun Jan 8 03:50:28 CET 2023


Normally the bootmeth driver reads the bootflow from the bootdev, since
it knows the correct way to do it.

However it is easier for some bootdevs to handle this themselves. For
example, reading from SPI flash is quite different from other devices.

Add a way for the bootdev to pass a bootflow to the bootmeth, so that
this can be supported.

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

(no changes since v1)

 boot/bootmeth-uclass.c | 11 +++++++++++
 include/bootmeth.h     | 33 +++++++++++++++++++++++++++++++++
 2 files changed, 44 insertions(+)

diff --git a/boot/bootmeth-uclass.c b/boot/bootmeth-uclass.c
index 4c3529d1555..2aee1e0f0c5 100644
--- a/boot/bootmeth-uclass.c
+++ b/boot/bootmeth-uclass.c
@@ -50,6 +50,17 @@ int bootmeth_read_bootflow(struct udevice *dev, struct bootflow *bflow)
 	return ops->read_bootflow(dev, bflow);
 }
 
+int bootmeth_set_bootflow(struct udevice *dev, struct bootflow *bflow,
+			  char *buf, int size)
+{
+	const struct bootmeth_ops *ops = bootmeth_get_ops(dev);
+
+	if (!ops->set_bootflow)
+		return -ENOSYS;
+
+	return ops->set_bootflow(dev, bflow, buf, size);
+}
+
 int bootmeth_boot(struct udevice *dev, struct bootflow *bflow)
 {
 	const struct bootmeth_ops *ops = bootmeth_get_ops(dev);
diff --git a/include/bootmeth.h b/include/bootmeth.h
index bdce301e925..b12dfd42c90 100644
--- a/include/bootmeth.h
+++ b/include/bootmeth.h
@@ -87,6 +87,22 @@ struct bootmeth_ops {
 	 */
 	int (*read_bootflow)(struct udevice *dev, struct bootflow *bflow);
 
+	/**
+	 * set_bootflow() - set the bootflow for a device
+	 *
+	 * This provides a bootflow file to the bootmeth, to see if it is valid.
+	 * If it is, the bootflow is set up accordingly.
+	 *
+	 * @dev:	Bootmethod device to use
+	 * @bflow:	On entry, provides bootdev.
+	 *	Returns updated bootflow if found
+	 * @buf:	Buffer containing the possible bootflow file
+	 * @size:	Size of file
+	 * Return: 0 if OK, -ve on error
+	 */
+	int (*set_bootflow)(struct udevice *dev, struct bootflow *bflow,
+			    char *buf, int size);
+
 	/**
 	 * read_file() - read a file needed for a bootflow
 	 *
@@ -173,6 +189,23 @@ int bootmeth_check(struct udevice *dev, struct bootflow_iter *iter);
  */
 int bootmeth_read_bootflow(struct udevice *dev, struct bootflow *bflow);
 
+/**
+ * bootmeth_set_bootflow() - set the bootflow for a device
+ *
+ * This provides a bootflow file to the bootmeth, to see if it is valid.
+ * If it is, the bootflow is set up accordingly.
+ *
+ * @dev:	Bootmethod device to use
+ * @bflow:	On entry, provides bootdev.
+ *	Returns updated bootflow if found
+ * @buf:	Buffer containing the possible bootflow file (must be allocated
+ * by caller to @size + 1 bytes)
+ * @size:	Size of file
+ * Return: 0 if OK, -ve on error
+ */
+int bootmeth_set_bootflow(struct udevice *dev, struct bootflow *bflow,
+			  char *buf, int size);
+
 /**
  * bootmeth_read_file() - read a file needed for a bootflow
  *
-- 
2.39.0.314.g84b9a713c41-goog



More information about the U-Boot-Custodians mailing list