diff mbox series

[10/13] qemu: Add a bootmeth for qfw

Message ID 20230128220028.53575-11-sjg@chromium.org
State Accepted
Commit 9c6d57dc7e836c67aef95bc49ba6e7fe714b09d4
Delegated to: Tom Rini
Headers show
Series bootstd: Update ARM QEMU for standard boot and environment | expand

Commit Message

Simon Glass Jan. 28, 2023, 10 p.m. UTC
This supports reading a kernel and ramdisk from qfw, then loading it with
either the booti or bootz commands.

For now this uses the existing booti and bootz commands, rather than
trying to call that functionality directly (e.g. do_bootm_states()). It
does not require the HUSH parser though, which helps a little with size.

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

 boot/Makefile       |   1 +
 boot/bootflow.c     |   2 +-
 boot/bootmeth_qfw.c | 102 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 104 insertions(+), 1 deletion(-)
 create mode 100644 boot/bootmeth_qfw.c

Comments

Tom Rini Feb. 7, 2023, 4:52 p.m. UTC | #1
On Sat, Jan 28, 2023 at 03:00:25PM -0700, Simon Glass wrote:

> This supports reading a kernel and ramdisk from qfw, then loading it with
> either the booti or bootz commands.
> 
> For now this uses the existing booti and bootz commands, rather than
> trying to call that functionality directly (e.g. do_bootm_states()). It
> does not require the HUSH parser though, which helps a little with size.
> 
> Signed-off-by: Simon Glass <sjg@chromium.org>

Applied to u-boot/master, thanks!
diff mbox series

Patch

diff --git a/boot/Makefile b/boot/Makefile
index 43baf2b89b3..0db4672b050 100644
--- a/boot/Makefile
+++ b/boot/Makefile
@@ -26,6 +26,7 @@  obj-$(CONFIG_$(SPL_TPL_)BOOTSTD) += bootstd-uclass.o
 obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_DISTRO) += bootmeth_distro.o
 obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_DISTRO_PXE) += bootmeth_pxe.o
 obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_EFILOADER) += bootmeth_efi.o
+obj-$(CONFIG_$(SPL_TPL_)QFW) += bootmeth_qfw.o
 obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_SANDBOX) += bootmeth_sandbox.o
 obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_SCRIPT) += bootmeth_script.o
 ifdef CONFIG_$(SPL_TPL_)BOOTSTD_FULL
diff --git a/boot/bootflow.c b/boot/bootflow.c
index b8fa37ee2a0..60791e681bd 100644
--- a/boot/bootflow.c
+++ b/boot/bootflow.c
@@ -508,7 +508,7 @@  int bootflow_iter_check_blk(const struct bootflow_iter *iter)
 	enum uclass_id id = device_get_uclass_id(media);
 
 	log_debug("uclass %d: %s\n", id, uclass_get_name(id));
-	if (id != UCLASS_ETH && id != UCLASS_BOOTSTD)
+	if (id != UCLASS_ETH && id != UCLASS_BOOTSTD && id != UCLASS_QFW)
 		return 0;
 
 	return -ENOTSUPP;
diff --git a/boot/bootmeth_qfw.c b/boot/bootmeth_qfw.c
new file mode 100644
index 00000000000..a5f95d4d0c5
--- /dev/null
+++ b/boot/bootmeth_qfw.c
@@ -0,0 +1,102 @@ 
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Bootmethod for QEMU qfw
+ *
+ * Copyright 2023 Google LLC
+ * Written by Simon Glass <sjg@chromium.org>
+ */
+
+#define LOG_CATEGORY UCLASS_BOOTSTD
+
+#include <common.h>
+#include <command.h>
+#include <bootdev.h>
+#include <bootflow.h>
+#include <bootmeth.h>
+#include <env.h>
+#include <qfw.h>
+#include <dm.h>
+
+static int qfw_check(struct udevice *dev, struct bootflow_iter *iter)
+{
+	const struct udevice *media = dev_get_parent(iter->dev);
+	enum uclass_id id = device_get_uclass_id(media);
+
+	log_debug("media=%s\n", media->name);
+	if (id == UCLASS_QFW)
+		return 0;
+
+	return -ENOTSUPP;
+}
+
+static int qfw_read_bootflow(struct udevice *dev, struct bootflow *bflow)
+{
+	struct udevice *qfw_dev = dev_get_parent(bflow->dev);
+	ulong load, initrd;
+	int ret;
+
+	load = env_get_hex("kernel_addr_r", 0);
+	initrd = env_get_hex("ramdisk_addr_r", 0);
+	log_debug("setup kernel %s %lx %lx\n", qfw_dev->name, load, initrd);
+	bflow->name = strdup("qfw");
+	if (!bflow->name)
+		return log_msg_ret("name", -ENOMEM);
+
+	ret = qemu_fwcfg_setup_kernel(qfw_dev, load, initrd);
+	log_debug("setup kernel result %d\n", ret);
+	if (ret)
+		return log_msg_ret("cmd", -EIO);
+
+	bflow->state = BOOTFLOWST_READY;
+
+	return 0;
+}
+
+static int qfw_read_file(struct udevice *dev, struct bootflow *bflow,
+			 const char *file_path, ulong addr, ulong *sizep)
+{
+	return -ENOSYS;
+}
+
+static int qfw_boot(struct udevice *dev, struct bootflow *bflow)
+{
+	int ret;
+
+	ret = run_command("booti ${kernel_addr_r} ${ramdisk_addr_r}:${filesize} ${fdtcontroladdr}",
+			  0);
+	if (ret) {
+		ret = run_command("bootz ${kernel_addr_r} ${ramdisk_addr_r}:${filesize} "
+				  "${fdtcontroladdr}", 0);
+	}
+
+	return ret ? -EIO : 0;
+}
+
+static int qfw_bootmeth_bind(struct udevice *dev)
+{
+	struct bootmeth_uc_plat *plat = dev_get_uclass_plat(dev);
+
+	plat->desc = "Sandbox boot for testing";
+
+	return 0;
+}
+
+static struct bootmeth_ops qfw_bootmeth_ops = {
+	.check		= qfw_check,
+	.read_bootflow	= qfw_read_bootflow,
+	.read_file	= qfw_read_file,
+	.boot		= qfw_boot,
+};
+
+static const struct udevice_id qfw_bootmeth_ids[] = {
+	{ .compatible = "u-boot,qfw-syslinux" },
+	{ }
+};
+
+U_BOOT_DRIVER(bootmeth_qfw) = {
+	.name		= "bootmeth_qfw",
+	.id		= UCLASS_BOOTMETH,
+	.of_match	= qfw_bootmeth_ids,
+	.ops		= &qfw_bootmeth_ops,
+	.bind		= qfw_bootmeth_bind,
+};