All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: U-Boot Mailing List <u-boot@lists.denx.de>
Cc: Dennis Gilmore <dennis@ausil.us>,
	Lukas Auer <lukas.auer@aisec.fraunhofer.de>,
	Daniel Schwierzeck <daniel.schwierzeck@gmail.com>,
	Tom Rini <trini@konsulko.com>,
	Michal Simek <michal.simek@xilinx.com>,
	Ilias Apalodimas <ilias.apalodimas@linaro.org>,
	Steffen Jaeckel <jaeckel-floss@eyet-services.de>,
	Simon Glass <sjg@chromium.org>, Marek Vasut <marex@denx.de>
Subject: [PATCH v5 30/34] bootstd: usb: Add a bootdev driver
Date: Sun, 24 Apr 2022 23:31:23 -0600	[thread overview]
Message-ID: <20220424233055.v5.30.Ibb454281fc9a82c3ad084f0f2f876e46809eee02@changeid> (raw)
In-Reply-To: <20220425053127.19950-1-sjg@chromium.org>

Add a bootdev driver for USB host. It can use the distro boot mechanism to
locate a file, or any other available bootmeth.

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

(no changes since v1)

 common/usb_storage.c           | 11 ++++++
 drivers/usb/host/Makefile      |  4 +++
 drivers/usb/host/usb_bootdev.c | 61 ++++++++++++++++++++++++++++++++++
 3 files changed, 76 insertions(+)
 create mode 100644 drivers/usb/host/usb_bootdev.c

diff --git a/common/usb_storage.c b/common/usb_storage.c
index 291728f37e0..eaa31374ef7 100644
--- a/common/usb_storage.c
+++ b/common/usb_storage.c
@@ -34,6 +34,7 @@
 
 #include <common.h>
 #include <blk.h>
+#include <bootdev.h>
 #include <command.h>
 #include <dm.h>
 #include <errno.h>
@@ -243,6 +244,16 @@ static int usb_stor_probe_device(struct usb_device *udev)
 		ret = blk_probe_or_unbind(dev);
 		if (ret)
 			return ret;
+
+		ret = bootdev_setup_sibling_blk(dev, "usb_bootdev");
+		if (ret) {
+			int ret2;
+
+			ret2 = device_unbind(dev);
+			if (ret2)
+				return log_msg_ret("bootdev", ret2);
+			return log_msg_ret("bootdev", ret);
+		}
 	}
 #else
 	/* We don't have space to even probe if we hit the maximum */
diff --git a/drivers/usb/host/Makefile b/drivers/usb/host/Makefile
index a4472da9f18..7785b3744ef 100644
--- a/drivers/usb/host/Makefile
+++ b/drivers/usb/host/Makefile
@@ -8,6 +8,10 @@ obj-y += usb-uclass.o
 obj-$(CONFIG_SANDBOX) += usb-sandbox.o
 endif
 
+ifdef CONFIG_$(SPL_TPL_)USB_STORAGE
+obj-$(CONFIG_$(SPL_TPL_)BOOTSTD) += usb_bootdev.o
+endif
+
 # ohci
 obj-$(CONFIG_USB_OHCI_NEW) += ohci-hcd.o
 obj-$(CONFIG_USB_ATMEL) += ohci-at91.o
diff --git a/drivers/usb/host/usb_bootdev.c b/drivers/usb/host/usb_bootdev.c
new file mode 100644
index 00000000000..b85f699933d
--- /dev/null
+++ b/drivers/usb/host/usb_bootdev.c
@@ -0,0 +1,61 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Bootdevice for USB
+ *
+ * Copyright 2021 Google LLC
+ * Written by Simon Glass <sjg@chromium.org>
+ */
+
+#include <common.h>
+#include <bootdev.h>
+#include <dm.h>
+#include <usb.h>
+
+static int usb_get_bootflow(struct udevice *dev, struct bootflow_iter *iter,
+			    struct bootflow *bflow)
+{
+	struct udevice *blk;
+	int ret;
+
+	ret = bootdev_get_sibling_blk(dev, &blk);
+	/*
+	 * If there is no media, indicate that no more partitions should be
+	 * checked
+	 */
+	if (ret == -EOPNOTSUPP)
+		ret = -ESHUTDOWN;
+	if (ret)
+		return log_msg_ret("blk", ret);
+	assert(blk);
+	ret = bootdev_find_in_blk(dev, blk, iter, bflow);
+	if (ret)
+		return log_msg_ret("find", ret);
+
+	return 0;
+}
+
+static int usb_bootdev_bind(struct udevice *dev)
+{
+	struct bootdev_uc_plat *ucp = dev_get_uclass_plat(dev);
+
+	ucp->prio = BOOTDEVP_3_SCAN_SLOW;
+
+	return 0;
+}
+
+struct bootdev_ops usb_bootdev_ops = {
+	.get_bootflow	= usb_get_bootflow,
+};
+
+static const struct udevice_id usb_bootdev_ids[] = {
+	{ .compatible = "u-boot,bootdev-usb" },
+	{ }
+};
+
+U_BOOT_DRIVER(usb_bootdev) = {
+	.name		= "usb_bootdev",
+	.id		= UCLASS_BOOTDEV,
+	.ops		= &usb_bootdev_ops,
+	.bind		= usb_bootdev_bind,
+	.of_match	= usb_bootdev_ids,
+};
-- 
2.36.0.rc2.479.g8af0fa9b8e-goog


  parent reply	other threads:[~2022-04-25  5:35 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-25  5:30 [PATCH v5 00/34] Initial implementation of standard boot Simon Glass
2022-04-25  5:30 ` [PATCH v5 01/34] lib: Move string tests to the string module Simon Glass
2022-04-25  5:30 ` [PATCH v5 02/34] test: Add tests for trailing_strtol() Simon Glass
2022-04-25  5:30 ` [PATCH v5 03/34] lib: Correct comment formatting to avoid sphinx problems Simon Glass
2022-04-25  5:30 ` [PATCH v5 04/34] lib: Fix a few bugs in trailing_strtoln() Simon Glass
2022-04-25  5:30 ` [PATCH v5 05/34] lib: Add a way to find the postiion of a trailing number Simon Glass
2022-04-25  5:30 ` [PATCH v5 06/34] dm: core: Rename and fix uclass_get_by_name_len() Simon Glass
2022-04-25  5:31 ` [PATCH v5 07/34] dm: core: Allow finding a uclass device by partial name Simon Glass
2022-04-25  5:31 ` [PATCH v5 08/34] test: fastboot: Avoid using mmc1 Simon Glass
2022-04-25  5:31 ` [PATCH v5 09/34] test: dm: Restart USB before assuming it is stopped Simon Glass
2022-04-25  5:31 ` [PATCH v5 10/34] dm: blk: Add a function to return the device type Simon Glass
2022-04-25  5:31 ` [PATCH v5 11/34] fs: Add a function to set the filesystem type Simon Glass
2022-04-25  5:31 ` [PATCH v5 12/34] bootstd: Add the concept of a bootflow Simon Glass
2022-04-25  5:31 ` [PATCH v5 13/34] bootstd: Add the bootstd uclass and core implementation Simon Glass
2022-04-25  5:31 ` [PATCH v5 14/34] bootstd: Add the bootdev uclass Simon Glass
2022-04-25  5:31 ` [PATCH v5 15/34] bootstd: Add the bootmeth uclass and helpers Simon Glass
2022-04-25  5:31 ` [PATCH v5 16/34] bootstd: Add support for bootflows Simon Glass
2022-04-25  5:31 ` [PATCH v5 17/34] bootstd: Add a bootdev command Simon Glass
2022-04-25  5:31 ` [PATCH v5 18/34] bootstd: Add a bootflow command Simon Glass
2022-04-25  5:31 ` [PATCH v5 19/34] bootstd: Add a bootmeth command Simon Glass
2022-04-25  5:31 ` [PATCH v5 21/34] bootstd: mmc: Add a bootdev driver Simon Glass
2022-04-25  5:31 ` [PATCH v5 22/34] bootstd: ethernet: " Simon Glass
2022-04-25  5:31 ` [PATCH v5 23/34] bootstd: Add an implementation of distro PXE boot Simon Glass
2022-04-25  5:31 ` [PATCH v5 24/34] bootstd: Add an implementation of EFI boot Simon Glass
2022-04-25  5:31 ` [PATCH v5 26/34] bootstd: Add an implementation of EFI bootmgr Simon Glass
2022-04-25  5:31 ` [PATCH v5 27/34] bootstd: Add a sandbox bootmeth driver Simon Glass
2022-04-25  5:31 ` [PATCH v5 29/34] bootstd: Add an implementation of script boot Simon Glass
2022-04-25  5:31 ` Simon Glass [this message]
2022-04-25  5:31 ` [PATCH v5 31/34] bootstd: Add tests for bootstd including all uclasses Simon Glass
2022-04-25  5:31 ` [PATCH v5 32/34] bootstd: Add setup for the bootflow tests Simon Glass
2022-05-09 18:06   ` Heinrich Schuchardt
2022-04-25  5:31 ` [PATCH v5 33/34] bootstd: doc: Add documentation Simon Glass
2022-04-25  5:31 ` [PATCH v5 34/34] bootstd: Provide a default command Simon Glass
2022-04-25 22:50 ` [PATCH v5 00/34] Initial implementation of standard boot Tom Rini
2022-04-26  4:55   ` Peter Robinson
2022-04-26 12:17     ` Tom Rini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220424233055.v5.30.Ibb454281fc9a82c3ad084f0f2f876e46809eee02@changeid \
    --to=sjg@chromium.org \
    --cc=daniel.schwierzeck@gmail.com \
    --cc=dennis@ausil.us \
    --cc=ilias.apalodimas@linaro.org \
    --cc=jaeckel-floss@eyet-services.de \
    --cc=lukas.auer@aisec.fraunhofer.de \
    --cc=marex@denx.de \
    --cc=michal.simek@xilinx.com \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.