]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
tools: fit_image: validate existence of default configuration node
authorAristo Chen <jj251510319013@gmail.com>
Tue, 15 Jul 2025 13:03:06 +0000 (13:03 +0000)
committerTom Rini <trini@konsulko.com>
Wed, 23 Jul 2025 19:12:16 +0000 (13:12 -0600)
When a FIT image declares a default configuration via the
'configurations/default' property, it must reference a valid subnode
under the /configurations node. If the named default does not exist,
U-Boot will fail to boot the image when no explicit configuration is
provided.

This patch adds a validation step in mkimage to check that the
referenced default configuration node is present. If not, mkimage will
print an error and abort.

This helps catch malformed or outdated ITS files early at build time
instead of deferring failure to runtime.

Signed-off-by: Aristo Chen <aristo.chen@canonical.com>
tools/fit_image.c

index 8717dc9a3b1c7b4f8b46b09ecbc3991eebfa78e9..8a1f6c185dde84a3a44aaf3da90a06c022f98ee5 100644 (file)
@@ -756,6 +756,8 @@ static int fit_import_data(struct image_tool_params *params, const char *fname)
        }
 
        confs = fdt_path_offset(fdt, FIT_CONFS_PATH);
+       const char *default_conf =
+               (char *)fdt_getprop(fdt, confs, FIT_DEFAULT_PROP, NULL);
        static const char * const props[] = { FIT_KERNEL_PROP,
                                              FIT_RAMDISK_PROP,
                                              FIT_FDT_PROP,
@@ -764,6 +766,14 @@ static int fit_import_data(struct image_tool_params *params, const char *fname)
                                              FIT_FIRMWARE_PROP,
                                              FIT_SCRIPT_PROP};
 
+       if (default_conf && fdt_subnode_offset(fdt, confs, default_conf) < 0) {
+               fprintf(stderr,
+                       "Error: Default configuration '%s' not found under /configurations\n",
+                       default_conf);
+               ret = FDT_ERR_NOTFOUND;
+               goto err_munmap;
+       }
+
        fdt_for_each_subnode(node, fdt, confs) {
                const char *conf_name = fdt_get_name(fdt, node, NULL);