A FIT image can contain multiple images of the same type, e.g. a device tree followed by overlays or multiple initrds.
To allow checking for that case, let's implement fit_count_images(). Signed-off-by: Ahmad Fatoum <[email protected]> --- common/image-fit.c | 12 ++++-------- include/image-fit.h | 27 +++++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/common/image-fit.c b/common/image-fit.c index 26bd8e265b25..85096aff31e6 100644 --- a/common/image-fit.c +++ b/common/image-fit.c @@ -495,19 +495,15 @@ static int fit_image_verify_signature(struct fit_handle *handle, return ret; } -bool fit_has_image(struct fit_handle *handle, void *configuration, - const char *name) +int fit_count_images(struct fit_handle *handle, void *configuration, + const char *name) { - const char *unit; struct device_node *conf_node = configuration; if (!conf_node) - return false; + return -EINVAL; - if (of_property_read_string(conf_node, name, &unit)) - return false; - - return true; + return of_property_count_strings(conf_node, name); } static int fit_get_address(struct device_node *image, const char *property, diff --git a/include/image-fit.h b/include/image-fit.h index c332f77bd374..31b8b54e272d 100644 --- a/include/image-fit.h +++ b/include/image-fit.h @@ -34,8 +34,31 @@ struct fit_handle *fit_open_buf(const void *buf, size_t len, bool verbose, void *fit_open_configuration(struct fit_handle *handle, const char *name, bool (*match_valid)(struct fit_handle *handle, struct device_node *config)); -bool fit_has_image(struct fit_handle *handle, void *configuration, - const char *name); +/** + * fit_count_images() - count images of a given type in a FIT configuration + * @handle: FIT handle as returned by fit_open() or fit_open_buf() + * @configuration: configuration node as returned by fit_open_configuration() + * @name: image type property name (e.g., "kernel", "fdt", "ramdisk") + * + * Return: number of images on success, negative error code on failure + */ +int fit_count_images(struct fit_handle *handle, void *configuration, + const char *name); + +/** + * fit_has_image() - check if a FIT configuration contains an image type + * @handle: FIT handle as returned by fit_open() or fit_open_buf() + * @configuration: configuration node as returned by fit_open_configuration() + * @name: image type property name (e.g., "kernel", "fdt", "ramdisk") + * + * Return: true if at least one image of the given type exists, false otherwise + */ +static inline bool fit_has_image(struct fit_handle *handle, void *configuration, + const char *name) +{ + return fit_count_images(handle, configuration, name) > 0; +} + int fit_open_image(struct fit_handle *handle, void *configuration, const char *name, const void **outdata, unsigned long *outsize); -- 2.47.3
