uImage support used to be very intertwined with the bootm code. This changed now, but we still have uImage specific logic in bootm_find_handler().
Instead of push more image format specific logic into bootm_find_handler(), let's allow bootm handlers to specify a "full custom" check by means of a check_image callback. To keep changes elsewhere to a minimum, we keep the uImage logic installed in common code, but inside register_image_handler() for now. Signed-off-by: Ahmad Fatoum <[email protected]> --- common/bootm.c | 30 ++++++++++++++++++++++++------ include/bootm.h | 3 +++ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/common/bootm.c b/common/bootm.c index 17792b2a1d81..298a193e3f62 100644 --- a/common/bootm.c +++ b/common/bootm.c @@ -23,10 +23,32 @@ static struct sconfig_notifier_block sconfig_notifier; static __maybe_unused struct bootm_overrides bootm_overrides; +static bool uimage_check(struct image_handler *handler, + struct image_data *data, + enum filetype detected_filetype) +{ + return detected_filetype == filetype_uimage && + handler->ih_os == data->os->header.ih_os; +} + +static bool filetype_check(struct image_handler *handler, + struct image_data *data, + enum filetype detected_filetype) +{ + return handler->filetype == detected_filetype; +} + int register_image_handler(struct image_handler *handler) { - list_add_tail(&handler->list, &handler_list); + if (!handler->check_image) { + if (IS_ENABLED(CONFIG_BOOTM_UIMAGE) && + handler->filetype == filetype_uimage) + handler->check_image = uimage_check; + else + handler->check_image = filetype_check; + } + list_add_tail(&handler->list, &handler_list); return 0; } @@ -36,11 +58,7 @@ static struct image_handler *bootm_find_handler(enum filetype filetype, struct image_handler *handler; list_for_each_entry(handler, &handler_list, list) { - if (filetype != filetype_uimage && - handler->filetype == filetype) - return handler; - if (filetype == filetype_uimage && - handler->ih_os == data->os->header.ih_os) + if (handler->check_image(handler, data, filetype)) return handler; } diff --git a/include/bootm.h b/include/bootm.h index b35deb25bf8f..bed0263b2eec 100644 --- a/include/bootm.h +++ b/include/bootm.h @@ -117,6 +117,9 @@ struct image_handler { int ih_os; enum filetype filetype; + bool (*check_image)(struct image_handler *handler, + struct image_data *data, + enum filetype detected_filetype); int (*bootm)(struct image_data *data); }; -- 2.47.3
