Provide a way to locate an image in a bootflow based on its type. Signed-off-by: Simon Glass <s...@chromium.org> ---
boot/bootflow.c | 13 +++++++++++++ boot/bootmeth-uclass.c | 2 +- include/bootflow.h | 11 +++++++++++ test/boot/bootflow.c | 16 ++++++++++++++++ 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/boot/bootflow.c b/boot/bootflow.c index 76dadb93be1..ec455e86215 100644 --- a/boot/bootflow.c +++ b/boot/bootflow.c @@ -998,6 +998,19 @@ struct bootflow_img *bootflow_img_add(struct bootflow *bflow, const char *fname, return ptr; } +const struct bootflow_img *bootflow_img_find(const struct bootflow *bflow, + enum bootflow_img_t type) +{ + const struct bootflow_img *img; + + alist_for_each(img, &bflow->images) { + if (img->type == type) + return img; + } + + return NULL; +} + int bootflow_get_seq(const struct bootflow *bflow) { struct bootstd_priv *std; diff --git a/boot/bootmeth-uclass.c b/boot/bootmeth-uclass.c index 02bbe77b563..5f2e10c879b 100644 --- a/boot/bootmeth-uclass.c +++ b/boot/bootmeth-uclass.c @@ -388,7 +388,7 @@ int bootmeth_alloc_other(struct bootflow *bflow, const char *fname, if (ret) return log_msg_ret("all", ret); - if (!bootflow_img_add(bflow, bflow->fname, type, map_to_sysmem(buf), + if (!bootflow_img_add(bflow, bflow->fname, type, abuf_addr(buf), size)) return log_msg_ret("boi", -ENOMEM); diff --git a/include/bootflow.h b/include/bootflow.h index c0e19feb9cc..1c3f950bfe3 100644 --- a/include/bootflow.h +++ b/include/bootflow.h @@ -647,6 +647,17 @@ const char *bootflow_img_type_name(enum bootflow_img_t type); struct bootflow_img *bootflow_img_add(struct bootflow *bflow, const char *fname, enum bootflow_img_t type, ulong addr, ulong size); + +/** + * bootflow_img_find() - Find the first image of a given type + * + * @bflow: Bootflow to search + * @type: Image type to search for + * Return: Pointer to image, or NULL if not found + */ +const struct bootflow_img *bootflow_img_find(const struct bootflow *bflow, + enum bootflow_img_t type); + /** * bootflow_get_seq() - Get the sequence number of a bootflow * diff --git a/test/boot/bootflow.c b/test/boot/bootflow.c index 0dd8fa71261..a39757627c7 100644 --- a/test/boot/bootflow.c +++ b/test/boot/bootflow.c @@ -1488,6 +1488,22 @@ static int bootstd_images(struct unit_test_state *uts) ptr = map_sysmem(img->addr, 0); ut_asserteq(0, *(ulong *)ptr); + /* check we can find images */ + bflow = alist_get(&std->bootflows, 1, struct bootflow); + img = bootflow_img_find(bflow, (enum bootflow_img_t)IH_TYPE_SCRIPT); + ut_assertnonnull(img); + ut_asserteq(IH_TYPE_SCRIPT, img->type); + ut_asserteq(map_to_sysmem(bflow->buf), img->addr); + ut_asserteq(bflow->size, img->size); + + img = bootflow_img_find(bflow, BFI_LOGO); + ut_assertnonnull(img); + ut_asserteq(BFI_LOGO, img->type); + ut_asserteq(map_to_sysmem(bflow->logo), img->addr); + ut_asserteq(bflow->logo_size, img->size); + + ut_assertnull(bootflow_img_find(bflow, BFI_CMDLINE)); + ut_assert_console_end(); return 0; -- 2.43.0 base-commit: e3ced530e543c9f24cbc66430abc6109ce8df015 branch: boo