[PATCH v2 16/71] bootstd: Add a default method to get bootflows

Simon Glass sjg at chromium.org
Sun Jan 8 03:49:52 CET 2023


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 at 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



More information about the U-Boot mailing list