U-Boot Archive on 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: "Tom Rini" <trini@konsulko.com>, "Simon Glass" <sjg@chromium.org>,
	"Caleb Connolly" <caleb.connolly@linaro.org>,
	"Dragan Simic" <dsimic@manjaro.org>,
	"Guillaume La Roque" <glaroque@baylibre.com>,
	"Heinrich Schuchardt" <xypron.glpk@gmx.de>,
	"Igor Opaniuk" <igor.opaniuk@gmail.com>,
	"Ilias Apalodimas" <ilias.apalodimas@linaro.org>,
	"Julien Masson" <jmasson@baylibre.com>,
	"Mattijs Korpershoek" <mkorpershoek@baylibre.com>,
	"Maximilian Brune" <maximilian.brune@9elements.com>,
	"Nam Cao" <namcao@linutronix.de>,
	"Peter Robinson" <pbrobinson@gmail.com>,
	"Quentin Schulz" <quentin.schulz@cherry.de>,
	"Shantur Rathore" <i@shantur.com>,
	"Thomas Weißschuh" <thomas.weissschuh@linutronix.de>,
	"Tony Dinh" <mibodhi@gmail.com>
Subject: [PATCH v3 04/19] bootstd: Drop the bootdev-specific list of bootflows
Date: Mon,  4 Nov 2024 10:50:55 -0700	[thread overview]
Message-ID: <20241104175110.1048449-5-sjg@chromium.org> (raw)
In-Reply-To: <20241104175110.1048449-1-sjg@chromium.org>

This list is only used by two functions, which can be updated to iterate
through the global list. Take this approach, which allows the bootdev
list to be dropped.

Overall this makes the code slightly more complicated, but will allow
moving the bootflow list into an alist

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

(no changes since v1)

 boot/bootdev-uclass.c | 61 +++++++++++++++++++++++++++----------------
 boot/bootflow.c       |  2 --
 boot/bootstd-uclass.c | 17 +++++-------
 include/bootdev.h     |  2 --
 include/bootflow.h    |  5 +---
 include/bootstd.h     |  2 +-
 6 files changed, 48 insertions(+), 41 deletions(-)

diff --git a/boot/bootdev-uclass.c b/boot/bootdev-uclass.c
index 26b003427ec..81adfb4cfb7 100644
--- a/boot/bootdev-uclass.c
+++ b/boot/bootdev-uclass.c
@@ -32,30 +32,57 @@ enum {
 	BOOT_TARGETS_MAX_LEN	= 100,
 };
 
+struct bootflow *bootdev_next_bootflow_(struct bootstd_priv *std,
+					struct udevice *dev,
+					struct bootflow *prev)
+{
+	struct bootflow *bflow = prev;
+
+	if (bflow) {
+		if (list_is_last(&bflow->glob_node, &std->glob_head))
+			return NULL;
+		bflow = list_entry(bflow->glob_node.next, struct bootflow,
+				   glob_node);
+	} else {
+		if (list_empty(&std->glob_head))
+			return NULL;
+
+		bflow = list_first_entry(&std->glob_head, struct bootflow,
+					 glob_node);
+	}
+
+	while (bflow->dev != dev) {
+		if (list_is_last(&bflow->glob_node, &std->glob_head))
+			return NULL;
+		bflow = list_entry(bflow->glob_node.next, struct bootflow,
+				   glob_node);
+	}
+
+	return bflow;
+}
+
 int bootdev_first_bootflow(struct udevice *dev, struct bootflow **bflowp)
 {
-	struct bootdev_uc_plat *ucp = dev_get_uclass_plat(dev);
+	struct bootstd_priv *std = bootstd_try_priv();
+	struct bootflow *bflow;
 
-	if (list_empty(&ucp->bootflow_head))
+	bflow = bootdev_next_bootflow_(std, dev, NULL);
+	if (!bflow)
 		return -ENOENT;
-
-	*bflowp = list_first_entry(&ucp->bootflow_head, struct bootflow,
-				   bm_node);
+	*bflowp = bflow;
 
 	return 0;
 }
 
 int bootdev_next_bootflow(struct bootflow **bflowp)
 {
-	struct bootflow *bflow = *bflowp;
-	struct bootdev_uc_plat *ucp = dev_get_uclass_plat(bflow->dev);
-
-	*bflowp = NULL;
+	struct bootstd_priv *std = bootstd_try_priv();
+	struct bootflow *bflow;
 
-	if (list_is_last(&bflow->bm_node, &ucp->bootflow_head))
+	bflow = bootdev_next_bootflow_(std, (*bflowp)->dev, *bflowp);
+	if (!bflow)
 		return -ENOENT;
-
-	*bflowp = list_entry(bflow->bm_node.next, struct bootflow, bm_node);
+	*bflowp = bflow;
 
 	return 0;
 }
@@ -911,15 +938,6 @@ void bootdev_list_hunters(struct bootstd_priv *std)
 	printf("(total hunters: %d)\n", n_ent);
 }
 
-static int bootdev_post_bind(struct udevice *dev)
-{
-	struct bootdev_uc_plat *ucp = dev_get_uclass_plat(dev);
-
-	INIT_LIST_HEAD(&ucp->bootflow_head);
-
-	return 0;
-}
-
 static int bootdev_pre_unbind(struct udevice *dev)
 {
 	int ret;
@@ -936,6 +954,5 @@ UCLASS_DRIVER(bootdev) = {
 	.name		= "bootdev",
 	.flags		= DM_UC_FLAG_SEQ_ALIAS,
 	.per_device_plat_auto	= sizeof(struct bootdev_uc_plat),
-	.post_bind	= bootdev_post_bind,
 	.pre_unbind	= bootdev_pre_unbind,
 };
diff --git a/boot/bootflow.c b/boot/bootflow.c
index d8807eb109d..804809dc100 100644
--- a/boot/bootflow.c
+++ b/boot/bootflow.c
@@ -476,8 +476,6 @@ void bootflow_free(struct bootflow *bflow)
 
 void bootflow_remove(struct bootflow *bflow)
 {
-	if (bflow->dev)
-		list_del(&bflow->bm_node);
 	list_del(&bflow->glob_node);
 
 	bootflow_free(bflow);
diff --git a/boot/bootstd-uclass.c b/boot/bootstd-uclass.c
index b2f80808c85..91e90bdf43c 100644
--- a/boot/bootstd-uclass.c
+++ b/boot/bootstd-uclass.c
@@ -77,25 +77,22 @@ int bootstd_add_bootflow(struct bootflow *bflow)
 	memcpy(new, bflow, sizeof(*bflow));
 
 	list_add_tail(&new->glob_node, &std->glob_head);
-	if (bflow->dev) {
-		struct bootdev_uc_plat *ucp = dev_get_uclass_plat(bflow->dev);
-
-		list_add_tail(&new->bm_node, &ucp->bootflow_head);
-	}
 
 	return 0;
 }
 
 int bootstd_clear_bootflows_for_bootdev(struct udevice *dev)
 {
-	struct bootdev_uc_plat *ucp = dev_get_uclass_plat(dev);
+	struct bootstd_priv *std = bootstd_try_priv();
 
-	while (!list_empty(&ucp->bootflow_head)) {
+	if (std) {
 		struct bootflow *bflow;
+		struct list_head *pos;
 
-		bflow = list_first_entry(&ucp->bootflow_head, struct bootflow,
-					 bm_node);
-		bootflow_remove(bflow);
+		list_for_each(pos, &std->glob_head) {
+			bflow = list_entry(pos, struct bootflow, glob_node);
+			bootflow_remove(bflow);
+		}
 	}
 
 	return 0;
diff --git a/include/bootdev.h b/include/bootdev.h
index f9cae2fd1fd..991b6229c1c 100644
--- a/include/bootdev.h
+++ b/include/bootdev.h
@@ -109,11 +109,9 @@ struct bootdev_hunter {
  * This is attached to each device in the bootdev uclass and accessible via
  * dev_get_uclass_plat(dev)
  *
- * @bootflows: List of available bootflows for this bootdev
  * @piro: Priority of this bootdev
  */
 struct bootdev_uc_plat {
-	struct list_head bootflow_head;
 	enum bootdev_prio_t prio;
 };
 
diff --git a/include/bootflow.h b/include/bootflow.h
index 4d2fc7b69b5..64d1d6c3786 100644
--- a/include/bootflow.h
+++ b/include/bootflow.h
@@ -56,12 +56,10 @@ enum bootflow_flags_t {
 /**
  * struct bootflow - information about a bootflow
  *
- * This is connected into two separate linked lists:
+ * This is connected into a linked list:
  *
- *   bm_sibling - links all bootflows in the same bootdev
  *   glob_sibling - links all bootflows in all bootdevs
  *
- * @bm_node: Points to siblings in the same bootdev
  * @glob_node: Points to siblings in the global list (all bootdev)
  * @dev: Bootdev device which produced this bootflow, NULL for flows created by
  *      BOOTMETHF_GLOBAL bootmeths
@@ -92,7 +90,6 @@ enum bootflow_flags_t {
  * @bootmeth_priv: Private data for the bootmeth
  */
 struct bootflow {
-	struct list_head bm_node;
 	struct list_head glob_node;
 	struct udevice *dev;
 	struct udevice *blk;
diff --git a/include/bootstd.h b/include/bootstd.h
index 4535d91e2ad..8aff536e3cb 100644
--- a/include/bootstd.h
+++ b/include/bootstd.h
@@ -123,7 +123,7 @@ void bootstd_clear_glob(void);
 int bootstd_prog_boot(void);
 
 /**
- * bootstd_add_bootflow() - Add a bootflow to the bootdev's and global list
+ * bootstd_add_bootflow() - Add a bootflow to the global list
  *
  * All fields in @bflow must be set up. Note that @bflow->dev is used to add the
  * bootflow to that device.
-- 
2.34.1


  parent reply	other threads:[~2024-11-04 17:51 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-04 17:50 [PATCH v3 00/19] bootstd: Support recording images Simon Glass
2024-11-04 17:50 ` [PATCH v3 01/19] bootstd: Move bootflow-adding to bootstd Simon Glass
2024-11-04 22:02   ` Heinrich Schuchardt
2024-11-05 15:13     ` Simon Glass
2024-11-05 15:39       ` Tom Rini
2024-11-05 16:07         ` Simon Glass
2024-11-04 17:50 ` [PATCH v3 02/19] bootstd: Move bootflow-clearing " Simon Glass
2024-11-04 22:04   ` Heinrich Schuchardt
2024-11-04 17:50 ` [PATCH v3 03/19] bootstd: Add a function to get bootstd only if available Simon Glass
2024-11-04 17:50 ` Simon Glass [this message]
2024-11-04 17:50 ` [PATCH v3 05/19] bootstd: Move the bootflow list into an alist Simon Glass
2024-11-04 17:50 ` [PATCH v3 06/19] bootstd: Maintain a list of images Simon Glass
2024-11-04 17:50 ` [PATCH v3 07/19] bootstd: Update bootmeth_alloc_file() to record images Simon Glass
2024-11-04 17:50 ` [PATCH v3 08/19] boot: pxe: Drop the duplicate comment on get_pxe_file() Simon Glass
2024-11-04 17:51 ` [PATCH v3 09/19] bootmeth_efi: Simplify reading files by using the common function Simon Glass
2024-11-04 17:51 ` [PATCH v3 10/19] bootmeth: Update the read_file() method to include a type Simon Glass
2024-11-04 17:51 ` [PATCH v3 11/19] bootmeth_efi: Check the filename-allocation in the network path Simon Glass
2024-11-04 21:42   ` Heinrich Schuchardt
2024-11-15 23:19     ` Simon Glass
2024-11-04 17:51 ` [PATCH v3 12/19] boot: Update extlinux pxe_getfile_func() to include type Simon Glass
2024-11-04 17:51 ` [PATCH v3 13/19] boot: Update pxe bootmeth to record images Simon Glass
2024-11-04 17:51 ` [PATCH v3 14/19] Update bootmeth_alloc_other() " Simon Glass
2024-11-04 17:51 ` [PATCH v3 15/19] bootstd: Update cros bootmeth " Simon Glass
2024-11-04 17:51 ` [PATCH v3 16/19] bootstd: Add a simple command to list images Simon Glass
2024-11-04 17:51 ` [PATCH v3 17/19] bootstd: Export bootdev_get_from_blk() Simon Glass
2024-11-04 17:51 ` [PATCH v3 18/19] bootstd: Add the concept of an ad-hoc bootflow Simon Glass
2024-11-04 17:51 ` [PATCH v3 19/19] fs: Record loaded files in " Simon Glass
2025-01-15 13:55 ` [PATCH v3 00/19] bootstd: Support recording images Simon Glass
2025-01-15 21:24   ` Tom Rini
2025-01-15 23:14     ` Simon Glass
2025-01-15 23:31       ` Tom Rini
2025-01-16 15:52         ` Simon Glass
2025-01-16 17:21           ` Tom Rini
2025-01-18  4:32             ` Simon Glass
2025-01-18  5:49               ` Tony Dinh
2025-01-18 14:41                 ` Tom Rini
2025-01-18 19:26                   ` Tony Dinh
2025-01-23 14:38                   ` Simon Glass
2025-01-23 17:17                     ` Tom Rini
2025-01-25 17:13                       ` Simon Glass
2025-01-25 18:27                         ` 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=20241104175110.1048449-5-sjg@chromium.org \
    --to=sjg@chromium.org \
    --cc=caleb.connolly@linaro.org \
    --cc=dsimic@manjaro.org \
    --cc=glaroque@baylibre.com \
    --cc=i@shantur.com \
    --cc=igor.opaniuk@gmail.com \
    --cc=ilias.apalodimas@linaro.org \
    --cc=jmasson@baylibre.com \
    --cc=maximilian.brune@9elements.com \
    --cc=mibodhi@gmail.com \
    --cc=mkorpershoek@baylibre.com \
    --cc=namcao@linutronix.de \
    --cc=pbrobinson@gmail.com \
    --cc=quentin.schulz@cherry.de \
    --cc=thomas.weissschuh@linutronix.de \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    --cc=xypron.glpk@gmx.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox