From 6a3eb84b18333eb4beb7e660fa9ae8ccff07b0c4 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Fri, 15 Nov 2024 16:19:11 -0700 Subject: bootstd: Drop the bootdev-specific list of bootflows 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 --- boot/bootflow.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'boot/bootflow.c') 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); -- cgit v1.2.3 From 49867e804543f64ca216653c3905d8022c31fc84 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Fri, 15 Nov 2024 16:19:12 -0700 Subject: bootstd: Move the bootflow list into an alist 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 --- boot/bootflow.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) (limited to 'boot/bootflow.c') diff --git a/boot/bootflow.c b/boot/bootflow.c index 804809dc100..7ce04fd92cd 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) -- cgit v1.2.3 From 8a6bf2fb31b6a02227818e679d567ae012494467 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Fri, 15 Nov 2024 16:19:13 -0700 Subject: bootstd: Maintain a list of images We want to keep track of images which are loaded, or those which could perhaps be loaded. This will make it easier to manage memory allocation, as well as permit removal of the EFI set_efi_bootdev() feature. Add a list of these, attached to the bootflow. For now the list is empty. Signed-off-by: Simon Glass --- boot/bootflow.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'boot/bootflow.c') diff --git a/boot/bootflow.c b/boot/bootflow.c index 7ce04fd92cd..94f34dcad0f 100644 --- a/boot/bootflow.c +++ b/boot/bootflow.c @@ -23,6 +23,13 @@ enum { BF_NO_MORE_DEVICES = -ENODEV, }; +static const char *const bootflow_img[BFI_COUNT - BFI_FIRST] = { + "extlinux_cfg", + "logo", + "efi", + "cmdline", +}; + /** * bootflow_state - name for each state * @@ -455,10 +462,13 @@ void bootflow_init(struct bootflow *bflow, struct udevice *bootdev, bflow->dev = bootdev; bflow->method = meth; bflow->state = BOOTFLOWST_BASE; + alist_init_struct(&bflow->images, struct bootflow_img); } void bootflow_free(struct bootflow *bflow) { + struct bootflow_img *img; + free(bflow->name); free(bflow->subdir); free(bflow->fname); @@ -467,6 +477,10 @@ void bootflow_free(struct bootflow *bflow) free(bflow->os_name); free(bflow->fdt_fname); free(bflow->bootmeth_priv); + + alist_for_each(img, &bflow->images) + free(img->fname); + alist_empty(&bflow->images); } void bootflow_remove(struct bootflow *bflow) @@ -950,3 +964,15 @@ int bootflow_cmdline_auto(struct bootflow *bflow, const char *arg) return 0; } + +const char *bootflow_img_type_name(enum bootflow_img_t type) +{ + const char *name; + + if (type >= BFI_FIRST && type < BFI_COUNT) + name = bootflow_img[type - BFI_FIRST]; + else + name = genimg_get_type_short_name(type); + + return name; +} -- cgit v1.2.3 From adc621bf15cf7478e2ac46985216703219ebe778 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Fri, 15 Nov 2024 16:19:14 -0700 Subject: bootstd: Update bootmeth_alloc_file() to record images As a first step to recording images and where they came from, update this function to do so, since it is used by two bootmeths Create a helper function in the bootflow system, since recorded images are always associated with bootflows. Signed-off-by: Simon Glass --- boot/bootflow.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'boot/bootflow.c') diff --git a/boot/bootflow.c b/boot/bootflow.c index 94f34dcad0f..a10d3012b48 100644 --- a/boot/bootflow.c +++ b/boot/bootflow.c @@ -976,3 +976,24 @@ const char *bootflow_img_type_name(enum bootflow_img_t type) return name; } + +struct bootflow_img *bootflow_img_add(struct bootflow *bflow, const char *fname, + enum bootflow_img_t type, ulong addr, + ulong size) +{ + struct bootflow_img img, *ptr; + + memset(&img, '\0', sizeof(struct bootflow_img)); + img.fname = strdup(fname); + if (!img.fname) + return NULL; + + img.type = type; + img.addr = addr; + img.size = size; + ptr = alist_add(&bflow->images, img); + if (!ptr) + return NULL; + + return ptr; +} -- cgit v1.2.3 From d9055f5e4f3c62e693991e15222804ed6c1a93ef Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Fri, 15 Nov 2024 16:19:23 -0700 Subject: bootstd: Add a simple command to list images Add a new 'bootstd images' command, which lists the images which have been loaded. Update some existing tests to use it. Provide some documentation about images in general and this command in particular. Use a more realistic kernel command-line to make the test easier to follow. Signed-off-by: Simon Glass --- boot/bootflow.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'boot/bootflow.c') diff --git a/boot/bootflow.c b/boot/bootflow.c index a10d3012b48..58a1afa7a75 100644 --- a/boot/bootflow.c +++ b/boot/bootflow.c @@ -997,3 +997,15 @@ struct bootflow_img *bootflow_img_add(struct bootflow *bflow, const char *fname, return ptr; } + +int bootflow_get_seq(const struct bootflow *bflow) +{ + struct bootstd_priv *std; + int ret; + + ret = bootstd_get_priv(&std); + if (ret) + return ret; + + return alist_calc_index(&std->bootflows, bflow); +} -- cgit v1.2.3