[PATCH v5 27/34] bootstd: Add a sandbox bootmeth driver

Simon Glass sjg at chromium.org
Mon Apr 25 07:31:20 CEST 2022


Add a bootmeth driver for sandbox, used for testing.

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

(no changes since v3)

Changes in v3:
- Add a log category

 boot/Kconfig            |  7 +++++
 boot/Makefile           |  1 +
 boot/bootmeth_sandbox.c | 69 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 77 insertions(+)
 create mode 100644 boot/bootmeth_sandbox.c

diff --git a/boot/Kconfig b/boot/Kconfig
index 0bfea2791da..373871c49a6 100644
--- a/boot/Kconfig
+++ b/boot/Kconfig
@@ -370,6 +370,13 @@ config BOOTMETH_EFILOADER
 
 	  This provides a way to try out standard boot on an existing boot flow.
 
+config BOOTMETH_SANDBOX
+	def_bool y
+	depends on SANDBOX
+	help
+	  This is a sandbox bootmeth driver used for testing. It always returns
+	  -ENOTSUPP when attempting to boot.
+
 endif
 
 config LEGACY_IMAGE_FORMAT
diff --git a/boot/Makefile b/boot/Makefile
index fe221d7f441..444e6975f10 100644
--- a/boot/Makefile
+++ b/boot/Makefile
@@ -27,6 +27,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_)BOOTMETH_SANDBOX) += bootmeth_sandbox.o
 ifdef CONFIG_$(SPL_TPL_)BOOTSTD_FULL
 obj-$(CONFIG_$(SPL_TPL_)CMD_BOOTEFI_BOOTMGR) += bootmeth_efi_mgr.o
 endif
diff --git a/boot/bootmeth_sandbox.c b/boot/bootmeth_sandbox.c
new file mode 100644
index 00000000000..13ec5e95e64
--- /dev/null
+++ b/boot/bootmeth_sandbox.c
@@ -0,0 +1,69 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Bootmethod for sandbox testing
+ *
+ * Copyright 2021 Google LLC
+ * Written by Simon Glass <sjg at chromium.org>
+ */
+
+#define LOG_CATEGORY UCLASS_BOOTSTD
+
+#include <common.h>
+#include <bootdev.h>
+#include <bootflow.h>
+#include <bootmeth.h>
+#include <dm.h>
+
+static int sandbox_check(struct udevice *dev, struct bootflow_iter *iter)
+{
+	return 0;
+}
+
+static int sandbox_read_bootflow(struct udevice *dev, struct bootflow *bflow)
+{
+	/* pretend we are ready */
+	bflow->state = BOOTFLOWST_READY;
+
+	return 0;
+}
+
+static int sandbox_read_file(struct udevice *dev, struct bootflow *bflow,
+			     const char *file_path, ulong addr, ulong *sizep)
+{
+	return -ENOSYS;
+}
+
+static int sandbox_boot(struct udevice *dev, struct bootflow *bflow)
+{
+	/* always fail: see bootflow_iter_disable() */
+	return -ENOTSUPP;
+}
+
+static int sandbox_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 sandbox_bootmeth_ops = {
+	.check		= sandbox_check,
+	.read_bootflow	= sandbox_read_bootflow,
+	.read_file	= sandbox_read_file,
+	.boot		= sandbox_boot,
+};
+
+static const struct udevice_id sandbox_bootmeth_ids[] = {
+	{ .compatible = "u-boot,sandbox-syslinux" },
+	{ }
+};
+
+U_BOOT_DRIVER(bootmeth_sandbox) = {
+	.name		= "bootmeth_sandbox",
+	.id		= UCLASS_BOOTMETH,
+	.of_match	= sandbox_bootmeth_ids,
+	.ops		= &sandbox_bootmeth_ops,
+	.bind		= sandbox_bootmeth_bind,
+};
-- 
2.36.0.rc2.479.g8af0fa9b8e-goog



More information about the U-Boot mailing list