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: U-Boot Custodians <u-boot-custodians@lists.denx.de>,
	Simon Glass <sjg@chromium.org>
Subject: [PATCH v2 16/71] bootstd: Add a default method to get bootflows
Date: Sat,  7 Jan 2023 19:49:52 -0700	[thread overview]
Message-ID: <20230108025047.522240-17-sjg@chromium.org> (raw)
In-Reply-To: <20230108025047.522240-1-sjg@chromium.org>

The code in these functions turns out to often be the same. Add a default
get_bootflow() function and allow the drivers to select it by setting
the method to NULL.

This saves a little code space.

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

(no changes since v1)

 boot/bootdev-uclass.c          | 27 +++++++++++++++++++++++++--
 drivers/mmc/mmc_bootdev.c      | 25 -------------------------
 drivers/usb/host/usb_bootdev.c | 24 ------------------------
 include/bootdev.h              |  5 ++++-
 4 files changed, 29 insertions(+), 52 deletions(-)

diff --git a/boot/bootdev-uclass.c b/boot/bootdev-uclass.c
index 97f75cba49d..0ef3daf24cb 100644
--- a/boot/bootdev-uclass.c
+++ b/boot/bootdev-uclass.c
@@ -450,14 +450,37 @@ int bootdev_find_by_any(const char *name, struct udevice **devp)
 	return 0;
 }
 
+static int default_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;
+}
+
 int bootdev_get_bootflow(struct udevice *dev, struct bootflow_iter *iter,
 			 struct bootflow *bflow)
 {
 	const struct bootdev_ops *ops = bootdev_get_ops(dev);
 
-	if (!ops->get_bootflow)
-		return -ENOSYS;
 	bootflow_init(bflow, dev, iter->method);
+	if (!ops->get_bootflow)
+		return default_get_bootflow(dev, iter, bflow);
 
 	return ops->get_bootflow(dev, iter, bflow);
 }
diff --git a/drivers/mmc/mmc_bootdev.c b/drivers/mmc/mmc_bootdev.c
index b4f41fb3a67..037b67bc0ff 100644
--- a/drivers/mmc/mmc_bootdev.c
+++ b/drivers/mmc/mmc_bootdev.c
@@ -11,30 +11,6 @@
 #include <dm.h>
 #include <mmc.h>
 
-static int mmc_get_bootflow(struct udevice *dev, struct bootflow_iter *iter,
-			    struct bootflow *bflow)
-{
-	struct udevice *mmc_dev = dev_get_parent(dev);
-	struct udevice *blk;
-	int ret;
-
-	ret = mmc_get_blk(mmc_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 mmc_bootdev_bind(struct udevice *dev)
 {
 	struct bootdev_uc_plat *ucp = dev_get_uclass_plat(dev);
@@ -45,7 +21,6 @@ static int mmc_bootdev_bind(struct udevice *dev)
 }
 
 struct bootdev_ops mmc_bootdev_ops = {
-	.get_bootflow	= mmc_get_bootflow,
 };
 
 static const struct udevice_id mmc_bootdev_ids[] = {
diff --git a/drivers/usb/host/usb_bootdev.c b/drivers/usb/host/usb_bootdev.c
index b85f699933d..b2d157faf33 100644
--- a/drivers/usb/host/usb_bootdev.c
+++ b/drivers/usb/host/usb_bootdev.c
@@ -11,29 +11,6 @@
 #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);
@@ -44,7 +21,6 @@ static int usb_bootdev_bind(struct udevice *dev)
 }
 
 struct bootdev_ops usb_bootdev_ops = {
-	.get_bootflow	= usb_get_bootflow,
 };
 
 static const struct udevice_id usb_bootdev_ids[] = {
diff --git a/include/bootdev.h b/include/bootdev.h
index d0ca51c6d5e..1e91d4130e7 100644
--- a/include/bootdev.h
+++ b/include/bootdev.h
@@ -50,7 +50,10 @@ struct bootdev_uc_plat {
 /** struct bootdev_ops - Operations for the bootdev uclass */
 struct bootdev_ops {
 	/**
-	 * get_bootflow() - get a bootflow
+	 * get_bootflow() - get a bootflow (optional)
+	 *
+	 * If this is NULL then the default implementaton is used, which is
+	 * default_get_bootflow()
 	 *
 	 * @dev:	Bootflow device to check
 	 * @iter:	Provides current dev, part, method to get. Should update
-- 
2.39.0.314.g84b9a713c41-goog


  parent reply	other threads:[~2023-01-08  2:55 UTC|newest]

Thread overview: 87+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-08  2:49 [PATCH v2 00/71] bootstd: Allow migration from distro_bootcmd scripts Simon Glass
2023-01-08  2:49 ` [PATCH v2 01/71] dm: core: Correct ordering of uclasses IDs Simon Glass
2023-01-08  2:49 ` [PATCH v2 02/71] dm: core: Support sorting devices with dm tree Simon Glass
2023-01-08  2:49 ` [PATCH v2 03/71] dm: test: Correct assertion in dm_test_part() Simon Glass
2023-01-08  2:49 ` [PATCH v2 04/71] lib: Add a function to split a string into substrings Simon Glass
2023-01-08  2:49 ` [PATCH v2 05/71] bootstd: Remove special-case code for boot_targets Simon Glass
2023-01-08  2:49 ` [PATCH v2 06/71] bootstd: Simplify locating existing bootdevs Simon Glass
2023-01-08  2:49 ` [PATCH v2 07/71] test: Fix the help for the ut command Simon Glass
2023-01-08  2:49 ` [PATCH v2 08/71] test: Drop duplicate restore of DM state Simon Glass
2023-01-08  2:49 ` [PATCH v2 09/71] sandbox: mmc: Start off with a zeroed file Simon Glass
2023-01-08  2:49 ` [PATCH v2 10/71] vbe: Avoid a build failure when bloblist is not enabled Simon Glass
2023-01-08  2:49 ` [PATCH v2 11/71] vbe: sandbox: Drop VBE node in chosen Simon Glass
2023-01-08  2:49 ` [PATCH v2 12/71] dm: part: Update test to use mmc2 Simon Glass
2023-01-08  2:49 ` [PATCH v2 13/71] dm: test: Correct ordering of DM setup Simon Glass
2023-01-08  2:49 ` [PATCH v2 14/71] ide: Drop non-DM code for BLK Simon Glass
2023-01-08  2:49 ` [PATCH v2 15/71] dm: mmc: Use bootdev_setup_sibling_blk() Simon Glass
2023-01-08  2:49 ` Simon Glass [this message]
2023-01-08  2:49 ` [PATCH v2 17/71] sandbox: Allow ethernet to be disabled at runtime Simon Glass
2023-01-08  2:49 ` [PATCH v2 18/71] sandbox: Allow ethernet bootdevs to be disabled for tests Simon Glass
2023-01-08  2:49 ` [PATCH v2 19/71] sandbox: Enable the Ethernet bootdev Simon Glass
2023-01-08  2:49 ` [PATCH v2 20/71] lib: Support printing an error string Simon Glass
2023-01-08  2:49 ` [PATCH v2 21/71] event: Correct duplicate log message in event_notify() Simon Glass
2023-01-08  2:49 ` [PATCH v2 22/71] efi: Improve logging in efi_disk Simon Glass
2023-01-13 20:35   ` Heinrich Schuchardt
2023-01-13 20:40     ` Tom Rini
2023-01-13 20:49       ` Heinrich Schuchardt
2023-01-13 22:40       ` Simon Glass
2023-01-13 22:52         ` Heinrich Schuchardt
2023-01-08  2:49 ` [PATCH v2 23/71] bootstd: Add the concept of a bootdev hunter Simon Glass
2023-01-08  2:50 ` [PATCH v2 24/71] bootstd: Support running bootdev hunters Simon Glass
2023-01-08  2:50 ` [PATCH v2 25/71] dm: usb: Drop some dead code Simon Glass
2023-01-08  2:50 ` [PATCH v2 26/71] dm: usb: Mark the device name as alloced when binding Simon Glass
2023-01-08  2:50 ` [PATCH v2 27/71] test: Add a generic function to skip delays Simon Glass
2023-01-08  2:50 ` [PATCH v2 28/71] bootstd: Add a USB hunter Simon Glass
2023-01-08  2:50 ` [PATCH v2 29/71] bootstd: Add an MMC hunter Simon Glass
2023-01-08  2:50 ` [PATCH v2 30/71] net: Add a function to run dhcp Simon Glass
2023-01-10 17:03   ` Ramon Fried
2023-01-08  2:50 ` [PATCH v2 31/71] bootstd: Add a hunter for ethernet Simon Glass
2023-01-08  2:50 ` [PATCH v2 32/71] part: Add a function to find the first bootable partition Simon Glass
2023-01-08  2:50 ` [PATCH v2 33/71] bootstd: Only scan bootable partitions Simon Glass
2023-01-08  2:50 ` [PATCH v2 34/71] scsi: Correct allocation of block-device name Simon Glass
2023-01-08  2:50 ` [PATCH v2 35/71] scsi: Remove all children of SCSI devices before rescanning Simon Glass
2023-01-08  2:50 ` [PATCH v2 36/71] bootstd: Add a SCSI bootdev Simon Glass
2023-01-08  2:50 ` [PATCH v2 37/71] bootstd: Add an IDE bootdev Simon Glass
2023-01-08  2:50 ` [PATCH v2 38/71] bootstd: Add an NVMe bootdev Simon Glass
2023-01-08  2:50 ` [PATCH v2 39/71] virtio: Avoid repeating a long expression Simon Glass
2023-01-08  2:50 ` [PATCH v2 40/71] virtio: Fix returning -ENODEV Simon Glass
2023-01-08  2:50 ` [PATCH v2 41/71] virtio: Avoid strange behaviour on removal Simon Glass
2023-01-08  2:50 ` [PATCH v2 42/71] virtio: Add a block device Simon Glass
2023-01-08  2:50 ` [PATCH v2 43/71] bootstd: Add a virtio bootdev Simon Glass
2023-01-08  2:50 ` [PATCH v2 44/71] ata: Don't try to use non-existent ports Simon Glass
2023-01-08  2:50 ` [PATCH v2 45/71] bootstd: Rename bootdev checkers Simon Glass
2023-01-08  2:50 ` [PATCH v2 46/71] bootstd: Allow reading an EFI file from the network Simon Glass
2023-01-08  2:50 ` [PATCH v2 47/71] bootstd: Include the device tree in the bootflow Simon Glass
2023-01-08  2:50 ` [PATCH v2 48/71] bootstd: Support reading the device tree with EFI Simon Glass
2023-01-08 10:25   ` Mark Kettenis
2023-01-13 18:00     ` Simon Glass
2023-01-08  2:50 ` [PATCH v2 49/71] bootstd: Set the distro_bootpart env var with scripts Simon Glass
2023-01-08  2:50 ` [PATCH v2 50/71] bootstd: Update docs on bootmeth_try_file() for sandbox Simon Glass
2023-01-08  2:50 ` [PATCH v2 51/71] bootstd: Move label parsing into its own function Simon Glass
2023-01-08  2:50 ` [PATCH v2 52/71] bootstd: Add a new bootmeth method to set the bootflow Simon Glass
2023-01-08  2:50 ` [PATCH v2 53/71] sandbox: Allow SPI flash bootdevs to be disabled for tests Simon Glass
2023-01-08  2:50 ` [PATCH v2 54/71] bootstd: Add a SPI flash bootdev Simon Glass
2023-01-08  2:50 ` [PATCH v2 55/71] bootstd: Support reading a script from network or SPI flash Simon Glass
2023-01-08  2:50 ` [PATCH v2 56/71] bootstd: Treat DHCP and PXE as bootdev labels Simon Glass
2023-01-08  2:50 ` [PATCH v2 57/71] bootstd: Use hunters when scanning for bootflows Simon Glass
2023-01-08  2:50 ` [PATCH v2 58/71] bootstd: Allow hunting for bootdevs of a given priority Simon Glass
2023-01-08  2:50 ` [PATCH v2 59/71] bootstd: Add a new pre-scan priority for bootdevs Simon Glass
2023-01-08  2:50 ` [PATCH v2 60/71] bootstd: Allow hunting for a bootdev by label Simon Glass
2023-01-08  2:50 ` [PATCH v2 61/71] bootstd: Allow iterating to the next label in a list Simon Glass
2023-01-08  2:50 ` [PATCH v2 63/71] extension: Refactor to allow non-command usage Simon Glass
2023-01-08  2:50 ` [PATCH v2 64/71] bootstd: Add a hunter for the extension feature Simon Glass
2023-01-08  2:50 ` [PATCH v2 65/71] bootstd: Switch bootdev scanning to use labels Simon Glass
2023-01-08  2:50 ` [PATCH v2 66/71] bootstd: Allow scanning a single bootdev label Simon Glass
2023-01-08  2:50 ` [PATCH v2 67/71] bootstd: Drop the old bootflow_scan_first() Simon Glass
2023-01-08  2:50 ` [PATCH v2 68/71] bootstd: Record the bootdevs used during scanning Simon Glass
2023-01-08  2:50 ` [PATCH v2 69/71] bootstd: Add a little more logging of bootflows Simon Glass
2023-01-08  2:50 ` [PATCH v2 70/71] bootstd: Update documentation for new features Simon Glass
2023-01-08  2:50 ` [PATCH v2 71/71] rockchip: Convert rockpro64-rk3399 to use standard boot Simon Glass
2023-01-16  9:54   ` Kever Yang
2023-01-13 19:54 ` [PATCH v2 00/71] bootstd: Allow migration from distro_bootcmd scripts Heinrich Schuchardt
2023-01-13 20:32   ` Mark Kettenis
2023-01-13 21:05     ` Simon Glass
2023-01-14  1:58       ` Peter Robinson
2023-01-13 20:47   ` Tom Rini
2023-01-17 13:57 ` Tom Rini
2023-01-17 16:07   ` Simon Glass

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=20230108025047.522240-17-sjg@chromium.org \
    --to=sjg@chromium.org \
    --cc=u-boot-custodians@lists.denx.de \
    --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.