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>,
Julien Masson <jmasson@baylibre.com>,
Mattijs Korpershoek <mkorpershoek@baylibre.com>,
Nam Cao <namcao@linutronix.de>,
Peter Robinson <pbrobinson@gmail.com>,
Quentin Schulz <quentin.schulz@cherry.de>,
Shantur Rathore <i@shantur.com>, Tony Dinh <mibodhi@gmail.com>
Subject: [PATCH 14/34] bootstd: Move the bootflow list into an alist
Date: Thu, 17 Oct 2024 17:23:53 -0600 [thread overview]
Message-ID: <20241017232413.724808-15-sjg@chromium.org> (raw)
In-Reply-To: <20241017232413.724808-1-sjg@chromium.org>
Use an alist for this data structure as it is somewhat simpler to
manage. This means that bootstd holds a simple list of bootflow structs
and can drop it at will, without chasing down lists.
Signed-off-by: Simon Glass <sjg@chromium.org>
---
boot/bootdev-uclass.c | 47 +++++++++++++------------------------------
boot/bootflow.c | 16 ++++-----------
boot/bootstd-uclass.c | 39 +++++++++++++++++------------------
cmd/bootdev.c | 2 +-
include/bootflow.h | 11 +++++-----
include/bootstd.h | 6 ++++--
6 files changed, 47 insertions(+), 74 deletions(-)
diff --git a/boot/bootdev-uclass.c b/boot/bootdev-uclass.c
index 8f4a4bec129..6ed59a206e2 100644
--- a/boot/bootdev-uclass.c
+++ b/boot/bootdev-uclass.c
@@ -32,41 +32,17 @@ 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 bootstd_priv *std = bootstd_try_priv();
+ struct bootstd_priv *std;
struct bootflow *bflow;
+ int ret;
+
+ ret = bootstd_get_priv(&std);
+ if (ret)
+ return log_msg_ret("bff", ret);
- bflow = bootdev_next_bootflow_(std, dev, NULL);
+ bflow = alist_getw(&std->bootflows, 0, struct bootflow);
if (!bflow)
return -ENOENT;
*bflowp = bflow;
@@ -76,10 +52,15 @@ int bootdev_first_bootflow(struct udevice *dev, struct bootflow **bflowp)
int bootdev_next_bootflow(struct bootflow **bflowp)
{
- struct bootstd_priv *std = bootstd_try_priv();
+ struct bootstd_priv *std;
struct bootflow *bflow;
+ int ret;
+
+ ret = bootstd_get_priv(&std);
+ if (ret)
+ return log_msg_ret("bff", ret);
- bflow = bootdev_next_bootflow_(std, (*bflowp)->dev, *bflowp);
+ bflow = alist_nextw(&std->bootflows, *bflowp);
if (!bflow)
return -ENOENT;
*bflowp = bflow;
diff --git a/boot/bootflow.c b/boot/bootflow.c
index ae59d1a4092..72b51ebd49b 100644
--- a/boot/bootflow.c
+++ b/boot/bootflow.c
@@ -55,11 +55,10 @@ int bootflow_first_glob(struct bootflow **bflowp)
if (ret)
return ret;
- if (list_empty(&std->glob_head))
+ if (!std->bootflows.count)
return -ENOENT;
- *bflowp = list_first_entry(&std->glob_head, struct bootflow,
- glob_node);
+ *bflowp = alist_getw(&std->bootflows, 0, struct bootflow);
return 0;
}
@@ -67,20 +66,16 @@ int bootflow_first_glob(struct bootflow **bflowp)
int bootflow_next_glob(struct bootflow **bflowp)
{
struct bootstd_priv *std;
- struct bootflow *bflow = *bflowp;
int ret;
ret = bootstd_get_priv(&std);
if (ret)
return ret;
- *bflowp = NULL;
-
- if (list_is_last(&bflow->glob_node, &std->glob_head))
+ *bflowp = alist_nextw(&std->bootflows, *bflowp);
+ if (!*bflowp)
return -ENOENT;
- *bflowp = list_entry(bflow->glob_node.next, struct bootflow, glob_node);
-
return 0;
}
@@ -476,10 +471,7 @@ void bootflow_free(struct bootflow *bflow)
void bootflow_remove(struct bootflow *bflow)
{
- list_del(&bflow->glob_node);
-
bootflow_free(bflow);
- free(bflow);
}
#if CONFIG_IS_ENABLED(BOOTSTD_FULL)
diff --git a/boot/bootstd-uclass.c b/boot/bootstd-uclass.c
index 91e90bdf43c..5675719ee84 100644
--- a/boot/bootstd-uclass.c
+++ b/boot/bootstd-uclass.c
@@ -6,6 +6,7 @@
* Written by Simon Glass <sjg@chromium.org>
*/
+#include <alist.h>
#include <bootflow.h>
#include <bootstd.h>
#include <dm.h>
@@ -42,13 +43,11 @@ static int bootstd_of_to_plat(struct udevice *dev)
static void bootstd_clear_glob_(struct bootstd_priv *priv)
{
- while (!list_empty(&priv->glob_head)) {
- struct bootflow *bflow;
+ struct bootflow *bflow;
- bflow = list_first_entry(&priv->glob_head, struct bootflow,
- glob_node);
+ alist_for_each(bflow, &priv->bootflows)
bootflow_remove(bflow);
- }
+ alist_empty(&priv->bootflows);
}
void bootstd_clear_glob(void)
@@ -64,19 +63,15 @@ void bootstd_clear_glob(void)
int bootstd_add_bootflow(struct bootflow *bflow)
{
struct bootstd_priv *std;
- struct bootflow *new;
int ret;
ret = bootstd_get_priv(&std);
if (ret)
return ret;
- new = malloc(sizeof(*bflow));
- if (!new)
- return log_msg_ret("bflow", -ENOMEM);
- memcpy(new, bflow, sizeof(*bflow));
-
- list_add_tail(&new->glob_node, &std->glob_head);
+ bflow = alist_add(&std->bootflows, *bflow);
+ if (!bflow)
+ return log_msg_ret("bf2", -ENOMEM);
return 0;
}
@@ -84,16 +79,20 @@ int bootstd_add_bootflow(struct bootflow *bflow)
int bootstd_clear_bootflows_for_bootdev(struct udevice *dev)
{
struct bootstd_priv *std = bootstd_try_priv();
+ struct bootflow *from, *to;
- if (std) {
- struct bootflow *bflow;
- struct list_head *pos;
+ /* if bootstd does not exist we cannot have any bootflows */
+ if (!std)
+ return 0;
- list_for_each(pos, &std->glob_head) {
- bflow = list_entry(pos, struct bootflow, glob_node);
- bootflow_remove(bflow);
- }
+ /* Drop any bootflows that mention this dev */
+ alist_for_each_filter(from, to, &std->bootflows) {
+ if (from->dev == dev)
+ bootflow_remove(from);
+ else
+ *to++ = *from;
}
+ alist_update_end(&std->bootflows, to);
return 0;
}
@@ -165,7 +164,7 @@ static int bootstd_probe(struct udevice *dev)
{
struct bootstd_priv *std = dev_get_priv(dev);
- INIT_LIST_HEAD(&std->glob_head);
+ alist_init_struct(&std->bootflows, struct bootflow);
return 0;
}
diff --git a/cmd/bootdev.c b/cmd/bootdev.c
index fa7285ba25e..4bc229e809a 100644
--- a/cmd/bootdev.c
+++ b/cmd/bootdev.c
@@ -81,7 +81,7 @@ static int do_bootdev_info(struct cmd_tbl *cmdtp, int flag, int argc,
dev = priv->cur_bootdev;
- /* Count the number of bootflows, including how many are valid*/
+ /* Count the number of bootflows, including how many are valid */
num_valid = 0;
for (ret = bootdev_first_bootflow(dev, &bflow), i = 0;
!ret;
diff --git a/include/bootflow.h b/include/bootflow.h
index 64d1d6c3786..9b24fb5c3eb 100644
--- a/include/bootflow.h
+++ b/include/bootflow.h
@@ -56,11 +56,8 @@ enum bootflow_flags_t {
/**
* struct bootflow - information about a bootflow
*
- * This is connected into a linked list:
+ * All bootflows are listed in bootstd's bootflow alist in struct bootstd_priv
*
- * glob_sibling - links all bootflows in all bootdevs
- *
- * @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
* @blk: Block device which contains this bootflow, NULL if this is a network
@@ -90,7 +87,6 @@ enum bootflow_flags_t {
* @bootmeth_priv: Private data for the bootmeth
*/
struct bootflow {
- struct list_head glob_node;
struct udevice *dev;
struct udevice *blk;
int part;
@@ -390,7 +386,10 @@ const char *bootflow_state_get_name(enum bootflow_state_t state);
/**
* bootflow_remove() - Remove a bootflow and free its memory
*
- * This updates the linked lists containing the bootflow then frees it.
+ * This updates the 'global' linked list containing the bootflow, then frees it.
+ * It does not remove it from bootflows alist in struct bootstd_priv
+ *
+ * This does not free bflow itself, since this is assumed to be in an alist
*
* @bflow: Bootflow to remove
*/
diff --git a/include/bootstd.h b/include/bootstd.h
index 8aff536e3cb..c5b902372c3 100644
--- a/include/bootstd.h
+++ b/include/bootstd.h
@@ -9,6 +9,7 @@
#ifndef __bootstd_h
#define __bootstd_h
+#include <alist.h>
#include <dm/ofnode_decl.h>
#include <linux/list.h>
#include <linux/types.h>
@@ -30,7 +31,8 @@ struct udevice;
* terminated)
* @cur_bootdev: Currently selected bootdev (for commands)
* @cur_bootflow: Currently selected bootflow (for commands)
- * @glob_head: Head for the global list of all bootflows across all bootdevs
+ * @bootflows: (struct bootflow) Global list of all bootflows across all
+ * bootdevs
* @bootmeth_count: Number of bootmeth devices in @bootmeth_order
* @bootmeth_order: List of bootmeth devices to use, in order, NULL-terminated
* @vbe_bootmeth: Currently selected VBE bootmeth, NULL if none
@@ -44,7 +46,7 @@ struct bootstd_priv {
const char **env_order;
struct udevice *cur_bootdev;
struct bootflow *cur_bootflow;
- struct list_head glob_head;
+ struct alist bootflows;
int bootmeth_count;
struct udevice **bootmeth_order;
struct udevice *vbe_bootmeth;
--
2.34.1
next prev parent reply other threads:[~2024-10-17 23:26 UTC|newest]
Thread overview: 60+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-17 23:23 [PATCH 00/34] bootstd: Support recording images Simon Glass
2024-10-17 23:23 ` [PATCH 01/34] alist: Mention the error condition in alist_add_placeholder() Simon Glass
2024-10-17 23:23 ` [PATCH 02/34] alist: Add a comment for alist_init_struct() Simon Glass
2024-10-17 23:23 ` [PATCH 03/34] alist: Expand the comment for alist_get() Simon Glass
2024-10-17 23:23 ` [PATCH 04/34] alist: Add a way to get the next element Simon Glass
2024-10-17 23:23 ` [PATCH 05/34] alist: Add for-loop helpers Simon Glass
2024-10-17 23:23 ` [PATCH 06/34] alist: Add a function to empty the list Simon Glass
2024-10-17 23:23 ` [PATCH 07/34] alist: Add a way to efficiently filter an alist Simon Glass
2024-10-17 23:23 ` [PATCH 08/34] dm: core: Add a function to see if a device exists Simon Glass
2024-10-17 23:23 ` [PATCH 09/34] test: boot: Use a consistent name for the script bootmeth Simon Glass
2024-10-17 23:23 ` [PATCH 10/34] bootstd: Move bootflow-adding to bootstd Simon Glass
2024-10-17 23:23 ` [PATCH 11/34] bootstd: Move bootflow-clearing " Simon Glass
2024-10-17 23:23 ` [PATCH 12/34] bootstd: Add a function to get bootstd only if available Simon Glass
2024-10-17 23:23 ` [PATCH 13/34] bootstd: Drop the bootdev-specific list of bootflows Simon Glass
2024-10-17 23:23 ` Simon Glass [this message]
2024-10-17 23:23 ` [PATCH 15/34] image: Add a new type for extlinux Simon Glass
2024-10-18 3:14 ` Tom Rini
2024-10-18 14:57 ` Simon Glass
2024-10-18 15:17 ` Tom Rini
2024-10-18 17:20 ` Simon Glass
2024-10-18 17:54 ` Tom Rini
2024-10-18 18:19 ` Simon Glass
2024-10-18 18:31 ` Tom Rini
2024-10-17 23:23 ` [PATCH 16/34] image: Add a new type for EFI apps Simon Glass
2024-10-18 9:03 ` Mark Kettenis
2024-10-18 14:55 ` Simon Glass
2024-10-17 23:23 ` [PATCH 17/34] image: Add a new type for logo images Simon Glass
2024-10-17 23:23 ` [PATCH 18/34] image: Add a new type for a command-line string Simon Glass
2024-10-17 23:23 ` [PATCH 19/34] test: Expand implementation of ut_list_has_dm_tests() Simon Glass
2024-10-17 23:23 ` [PATCH 20/34] test: Drop the duplicate line in setup_bootmenu_image() Simon Glass
2024-10-17 23:24 ` [PATCH 21/34] test: boot: Update bootflow_iter() for console checking Simon Glass
2024-10-17 23:24 ` [PATCH 22/34] bootstd: cros: Correct the x86-setup address Simon Glass
2024-10-17 23:24 ` [PATCH 23/34] bootstd: Maintain a list of images Simon Glass
2024-10-18 3:14 ` Tom Rini
2024-10-18 4:01 ` Heinrich Schuchardt
2024-10-18 15:01 ` Simon Glass
2024-10-18 16:33 ` Tom Rini
2024-10-18 17:20 ` Simon Glass
2024-10-18 18:04 ` Tom Rini
2024-10-18 18:48 ` Simon Glass
2024-10-18 21:30 ` Tom Rini
2024-10-19 11:49 ` Simon Glass
2024-10-19 16:30 ` Tom Rini
2024-10-22 12:16 ` Simon Glass
2024-10-22 15:01 ` Tom Rini
2024-10-22 17:00 ` Simon Glass
2024-10-23 18:41 ` Tom Rini
2024-10-31 18:04 ` Simon Glass
2024-10-17 23:24 ` [PATCH 24/34] bootstd: Update bootmeth_alloc_file() to record images Simon Glass
2024-10-17 23:24 ` [PATCH 25/34] boot: pxe: Drop the duplicate comment on get_pxe_file() Simon Glass
2024-10-17 23:24 ` [PATCH 26/34] efi: Simplify reading files by using the common function Simon Glass
2024-10-18 3:14 ` Tom Rini
2024-10-17 23:24 ` [PATCH 27/34] bootmeth: Update the read_file() method to include a type Simon Glass
2024-10-17 23:24 ` [PATCH 28/34] efi: Check the filename-allocation in the network path Simon Glass
2024-10-17 23:24 ` [PATCH 29/34] boot: Update extlinux pxe_getfile_func() to include type Simon Glass
2024-10-17 23:24 ` [PATCH 30/34] boot: Update pxe bootmeth to record images Simon Glass
2024-10-17 23:24 ` [PATCH 31/34] Update bootmeth_alloc_other() " Simon Glass
2024-10-17 23:24 ` [PATCH 32/34] bootstd: Avoid showing an invalid buffer address Simon Glass
2024-10-17 23:24 ` [PATCH 33/34] bootstd: Update cros bootmeth to record images Simon Glass
2024-10-17 23:24 ` [PATCH 34/34] bootstd: Add a simple command to list images 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=20241017232413.724808-15-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=jmasson@baylibre.com \
--cc=mibodhi@gmail.com \
--cc=mkorpershoek@baylibre.com \
--cc=namcao@linutronix.de \
--cc=pbrobinson@gmail.com \
--cc=quentin.schulz@cherry.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 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.