tools: mkimage: validate image references in FIT configurations
PATCH 1/1 tools: mkimage: validate image references in FIT configurations
When parsing a FIT image source (ITS), mkimage does not currently check whether the image names referenced in the /configurations section (e.g. "kernel", "fdt", "ramdisk", "loadables") actually exist in the /images node.
This patch introduces a validation step during FIT import that iterates over each configuration and verifies that all referenced image names are defined under /images. If a missing image is detected, an appropriate error is reported and mkimage exits with FDT_ERR_NOTFOUND.
This ensures that configuration integrity is validated at build time.
--- tools/fit_image.c | 48 +++++++++++++++++++++++++++++++++++++++++++++-- tools/mkimage.c | 7 ++++++- 2 files changed, 52 insertions(+), 3 deletions(-)
tools/fit_image.c +46 -2
@@ -627,6 +627,7 @@ static int fit_import_data(struct image_tool_params *params, const char *fname)struct stat sbuf;int ret;int images; +int confs;int node; fd =mmap_fdt (params->cmdname, fname,0 , &old_fdt, &sbuf, false, false);
@@ -695,6 +696,49 @@ static int fit_import_data(struct image_tool_params *params, const char *fname) } } + confs =fdt_path_offset (fdt,FIT_CONFS_PATH ); + +for (node =fdt_first_subnode (fdt, confs); + node >=0 ; + node =fdt_next_subnode (fdt, node)) { +static const char *const props[] = {FIT_KERNEL_PROP , +FIT_RAMDISK_PROP , +FIT_FDT_PROP , +FIT_LOADABLE_PROP }; + +for (int i =0 ; i <ARRAY_SIZE (props); i++) { +const char *list; +int len =0 ; +int offset =0 ; + + list =fdt_getprop (fdt, node, props[i], &len); +if (!list) +continue ; + +// Some properties (like loadables) are stringlists +while (offset < len) { +const char *img_name = list + offset; +char img_path[256 ]; + + offset +=strlen (img_name) +1 ; +snprintf (img_path,sizeof (img_path),"%s/%s" ,FIT_IMAGES_PATH , + img_name); + +int img =fdt_path_offset (fdt, img_path); + +if (img <0 ) { +const char *conf_name =fdt_get_name (fdt, node,NULL ); + +fprintf (stderr, +"Error: configuration '%s' references undefined image '%s'\n" , + conf_name, img_name); + ret =FDT_ERR_NOTFOUND ; + goto err_munmap; + } + } + } + } +munmap (old_fdt, sbuf.st_size);/* Close the old fd so we can re-use it. */
@@ -750,7 +794,7 @@ static int fit_handle_file(struct image_tool_params *params)char bakfile[MKIMAGE_MAX_TMPFILE_LEN +4 ] = {0 };char cmd[MKIMAGE_MAX_DTC_CMDLINE_LEN ];size_t size_inc; -int ret; +int ret =EXIT_FAILURE ;/* Flattened Image Tree (FIT) format handling */ debug ("FIT format handling\n" );
@@ -854,7 +898,7 @@ static int fit_handle_file(struct image_tool_params *params) err_system:unlink (tmpfile);unlink (bakfile); -return -1 ; +return ret; }/**
tools/mkimage.c +6 -1
@@ -519,8 +519,13 @@ int main(int argc, char **argv)*/ retval = tparams->fflag_handle (¶ms); -if (retval !=EXIT_SUCCESS ) +if (retval !=EXIT_SUCCESS ) { +if (retval ==FDT_ERR_NOTFOUND ) { +// Already printed error, exit cleanly +exit (EXIT_FAILURE ); + }usage ("Bad parameters for FIT image type" ); + } }if (params.lflag || params.fflag) {
Signature · 1 line
2.43.0
Hi Aristo,
Quoted 10 lines · Aristo Chen
When parsing a FIT image source (ITS), mkimage does not currently check whether the image names referenced in the /configurations section (e.g. "kernel", "fdt", "ramdisk", "loadables") actually exist in the /images node.
This patch introduces a validation step during FIT import that iterates over each configuration and verifies that all referenced image names are defined under /images. If a missing image is detected, an appropriate error is reported and mkimage exits with
FDT_ERR_NOTFOUND.
Wondering if
fdt = &fdt_1, &fdt_2;
for example would have saved us from this issue since this would be enforced by dtc requiring a label to exist. Ship has sailed already though :)
Quoted 21 lines
This ensures that configuration integrity is validated at build time.
Signed-off-by Aristo Chen <[email protected]>--- tools/fit_image.c | 48 +++++++++++++++++++++++++++++++++++++++++++++-- tools/mkimage.c | 7 ++++++- 2 files changed, 52 insertions(+), 3 deletions(-)tools/fit_image.c +1
-0@@ -627,6 +627,7 @@ static int fit_import_data(struct image_tool_params *params, const char *fname)struct stat sbuf;int ret;int images; +int confs;int node; fd =mmap_fdt (params->cmdname, fname,0 , &old_fdt, &sbuf, false, false);
tools/fit_image.c static int fit_import_data(struct image_tool_params *params, const char *fname) · line 703
Quoted 8 lines
tools/fit_image.c +5
-0@@ -695,6 +696,49 @@ static int fit_import_data(struct image_tool_params *params, const char *fname) } } + confs =fdt_path_offset (fdt,FIT_CONFS_PATH ); + +for (node =fdt_first_subnode (fdt, confs); + node >=0 ; + node =fdt_next_subnode (fdt, node)) {
This should be fdt_for_each_subnode instead?
tools/fit_image.c static int fit_import_data(struct image_tool_params *params, const char *fname) · line 708
Quoted 5 lines
tools/fit_image.c +5
-0+static const char *const props[] = {FIT_KERNEL_PROP , +FIT_RAMDISK_PROP , +FIT_FDT_PROP , +FIT_LOADABLE_PROP }; +
Why only those?
https://fitspec.osfw.foundation/#optional-properties specifies "fpga", "script" as unit names. https://fitspec.osfw.foundation/#id6 specifies "firmware" as a unit name. So I'm assuming we should be checking those as well?
Reading the code, it's not entirely clear (to me) whether FIT_SETUP_PROP is about a unit name.
tools/fit_image.c static int fit_import_data(struct image_tool_params *params, const char *fname) · line 718
Quoted 10 lines
tools/fit_image.c +10
-0+for (int i =0 ; i <ARRAY_SIZE (props); i++) { +const char *list; +int len =0 ; +int offset =0 ; + + list =fdt_getprop (fdt, node, props[i], &len); +if (!list) +continue ; + +// Some properties (like loadables) are stringlists
Aren't they all stringlists?
Simply get the stringlist length with fdt_stringlist_count() and then iterate over all fdt_stringlist_get() instead of handcrafting some iterator?
tools/fit_image.c static int fit_import_data(struct image_tool_params *params, const char *fname) · line 727
Quoted 9 lines
tools/fit_image.c +9
-0+while (offset < len) { +const char *img_name = list + offset; +char img_path[256 ]; + + offset +=strlen (img_name) +1 ; +snprintf (img_path,sizeof (img_path),"%s/%s" ,FIT_IMAGES_PATH , + img_name); + +int img =fdt_path_offset (fdt, img_path);
I believe you could save the snprintf by doing the following
- get the offset to the /images node with fdt_path_offset(fdt, FIT_IMAGES_PATH)
- use that offset with fdt_subnode_offset(fdt, images_offset, img_name)
You only need to access the /images node once, outside of all loops.
tools/fit_image.c static int fit_import_data(struct image_tool_params *params, const char *fname) · line 734
Quoted 7 lines
tools/fit_image.c +7
-0+ +if (img <0 ) { +const char *conf_name =fdt_get_name (fdt, node,NULL ); + +fprintf (stderr, +"Error: configuration '%s' references undefined image '%s'\n" , + conf_name, img_name);
Would be nice to tell in which property as well since we already have that info.
Quoted 20 lines
tools/fit_image.c +8
-1+ ret =FDT_ERR_NOTFOUND ; + goto err_munmap; + } + } + } + } +munmap (old_fdt, sbuf.st_size);/* Close the old fd so we can re-use it. */ @@ -750,7 +794,7 @@ static int fit_handle_file(struct image_tool_params *params)char bakfile[MKIMAGE_MAX_TMPFILE_LEN +4 ] = {0 };char cmd[MKIMAGE_MAX_DTC_CMDLINE_LEN ];size_t size_inc; -int ret; +int ret =EXIT_FAILURE ;/* Flattened Image Tree (FIT) format handling */ debug ("FIT format handling\n" );
tools/fit_image.c static int fit_handle_file(struct image_tool_params *params) · line 901
Quoted 5 lines
tools/fit_image.c +1
-1@@ -854,7 +898,7 @@ static int fit_handle_file(struct image_tool_params *params) err_system:unlink (tmpfile);unlink (bakfile); -return -1 ; +return ret;
This propagates more than simply the FDT_ERR_NOTFOUND added in this patch. Not sure this is entirely safe to do? Please check that all possible return codes of all functions whose return code is stored in ret are negative.
Maybe we should have this as a separate commit too, seems like we could benefit from it regardless of the first part of the patch being merged.
Quoted 8 lines
tools/fit_image.c +0
-0}/** tools/mkimage.c +0
-0
tools/mkimage.c int main(int argc, char **argv) · line 525
Quoted 8 lines
tools/mkimage.c +4
-1@@ -519,8 +519,13 @@ int main(int argc, char **argv)*/ retval = tparams->fflag_handle (¶ms); -if (retval !=EXIT_SUCCESS ) +if (retval !=EXIT_SUCCESS ) { +if (retval ==FDT_ERR_NOTFOUND ) { +// Already printed error, exit cleanly +exit (EXIT_FAILURE );
Considering we only have one U_BOOT_IMAGE_TYPE with a fflag_handle, I guess this is "fine", but this seems very enthusiastic :)
Cheers,
Quentin
Hi,
Quoted 14 lines · Quentin Schulz
Hi Aristo,
Quoted 10 lines · Aristo Chen
When parsing a FIT image source (ITS), mkimage does not currently check whether the image names referenced in the /configurations section (e.g. "kernel", "fdt", "ramdisk", "loadables") actually exist in the /images node.
This patch introduces a validation step during FIT import that iterates over each configuration and verifies that all referenced image names are defined under /images. If a missing image is detected, an appropriate error is reported and mkimage exits with
FDT_ERR_NOTFOUND.
One option (for boards which use Binman) would be to put these sorts of checks in there, since it might be easier to code? But having it in mkimage as well seems reasonable to me.
Regards,
Simon
Hi Simon,
Quoted 18 lines · Simon Glass
Hi,
Quoted 14 lines · Quentin Schulz
Hi Aristo,
Quoted 10 lines · Aristo Chen
When parsing a FIT image source (ITS), mkimage does not currently check whether the image names referenced in the /configurations section (e.g. "kernel", "fdt", "ramdisk", "loadables") actually exist in the /images node.
This patch introduces a validation step during FIT import that iterates over each configuration and verifies that all referenced image names are defined under /images. If a missing image is detected, an appropriate error is reported and mkimage exits with
FDT_ERR_NOTFOUND.
Quoted 4 lines
One option (for boards which use Binman) would be to put these sorts of checks in there, since it might be easier to code? But having it in mkimage as well seems reasonable to me.
mkimage can be used to generate images from outside of U-Boot. I believe this is what Yocto does for example to generate kernel FIT (see UBOOT_MKIMAGE and others), so having an additional check in mkimage is probably a good idea.
Cheers,
Quentin
Quoted 2 lines
Regards,
Simon
Hei hei,
Am Thu, May 15, 2025 at 09:35:34AM +0200 schrieb Quentin Schulz:
Quoted 26 lines
Hi Simon,
Quoted 18 lines · Simon Glass
Hi,
Quoted 14 lines · Quentin Schulz
Hi Aristo,
Quoted 10 lines · Aristo Chen
When parsing a FIT image source (ITS), mkimage does not currently check whether the image names referenced in the /configurations section (e.g. "kernel", "fdt", "ramdisk", "loadables") actually exist in the /images node.
This patch introduces a validation step during FIT import that iterates over each configuration and verifies that all referenced image names are defined under /images. If a missing image is detected, an appropriate error is reported and mkimage exits with
FDT_ERR_NOTFOUND.Quoted 4 lines
One option (for boards which use Binman) would be to put these sorts of checks in there, since it might be easier to code? But having it in mkimage as well seems reasonable to me.
Quoted 4 lines
mkimage can be used to generate images from outside of U-Boot. I believe this is what Yocto does for example to generate kernel FIT (see
UBOOT_MKIMAGEand others), so having an additional check in mkimage is probably a good idea.
Not sure about Yocto, but ptxdist [1] does exactly this: using mkimage to build signed FIT images, even if U-Boot is not used as bootloader.
(ptxdist also uses mkimage when optionally packing U-Boot scripts. Those need to be put into an image so U-Boot can execute it.)
Greets
Alex
Hi all,
Alexander Dahl <[email protected]> 於 2025年5月15日 週四 下午12:44寫道:
Quoted 38 lines
Hei hei,
Am Thu, May 15, 2025 at 09:35:34AM +0200 schrieb Quentin Schulz:
Quoted 26 lines
Hi Simon,
Quoted 18 lines · Simon Glass
Hi,
Quoted 14 lines · Quentin Schulz
Hi Aristo,
Quoted 10 lines · Aristo Chen
When parsing a FIT image source (ITS), mkimage does not currently check whether the image names referenced in the /configurations section (e.g. "kernel", "fdt", "ramdisk", "loadables") actually exist in the /images node.
This patch introduces a validation step during FIT import that iterates over each configuration and verifies that all referenced image names are defined under /images. If a missing image is detected, an appropriate error is reported and mkimage exits with
FDT_ERR_NOTFOUND.Quoted 4 lines
One option (for boards which use Binman) would be to put these sorts of checks in there, since it might be easier to code? But having it in mkimage as well seems reasonable to me.
Quoted 4 lines
mkimage can be used to generate images from outside of U-Boot. I believe this is what Yocto does for example to generate kernel FIT (see
UBOOT_MKIMAGEand others), so having an additional check in mkimage is probably a good idea.Not sure about Yocto, but ptxdist [1] does exactly this: using mkimage to build signed FIT images, even if U-Boot is not used as bootloader.
Quoted 7 lines
(ptxdist also uses mkimage when optionally packing U-Boot scripts. Those need to be put into an image so U-Boot can execute it.)
Greets
Alex
Thank you very much for the reviews and all the helpful suggestions!
Previously, I verified my patch using ./test/py/test.py -ra --bd sandbox --build, and AFAICT everything looked fine. However, I just ran make tests and noticed that my patch causes some binman related test failures.
I'll take some time to investigate the root cause before sending out the v2 patch.
Best regards,
Aristo
v2 cover mkimage: validate image references in FIT configurations
In reply to Aristo ChenHi all,
This series introduces a validation step in mkimage to ensure that all image names referenced under the /configurations node of a FIT source (ITS) are actually defined under the /images node.
### Motivation
When using mkimage to build FIT images, it's easy to mistakenly reference nonexistent image nodes in configurations (e.g., referencing a missing fdt or firmware node). Such issues are often not caught until runtime in U-Boot.
This series aims to catch these errors early during FIT image creation by validating the configuration references in mkimage itself.
### Changes in v2
- Use fdt_stringlist_count() and fdt_stringlist_get() to handle stringlist properties cleanly
- Validate additional properties (firmware, fpga, script)
- Improve error messages by including the failing configuration and property name
- Refactor error propagation in fit_handle_file() as a separate commit
- Update all affected binman test DTS files to include the missing atf and uboot image nodes
- Add a new Python test case under test/py/ to ensure mkimage correctly fails when an image is missing
Best regards,
Aristo Chen
PATCH v2 1/4 tools: mkimage: propagate error codes from fit_handle_file()
In reply to Aristo ChenThe fit_handle_file() function previously returned a hardcoded -1 on error. This change updates the logic to return the actual error code stored in ret, allowing for error propagation.
This improves debuggability and enables downstream callers to distinguish different failure causes, such as FDT_ERR_NOTFOUND or other errors.
--- tools/fit_image.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/fit_image.c +2 -2
@@ -750,7 +750,7 @@ static int fit_handle_file(struct image_tool_params *params)char bakfile[MKIMAGE_MAX_TMPFILE_LEN +4 ] = {0 };char cmd[MKIMAGE_MAX_DTC_CMDLINE_LEN ];size_t size_inc; -int ret; +int ret =EXIT_FAILURE ;/* Flattened Image Tree (FIT) format handling */ debug ("FIT format handling\n" );
@@ -854,7 +854,7 @@ static int fit_handle_file(struct image_tool_params *params) err_system:unlink (tmpfile);unlink (bakfile); -return -1 ; +return ret; }/**
Signature · 1 line
2.43.0
PATCH v2 2/4 tools: mkimage: validate image references in FIT configurations
In reply to Aristo ChenWhen parsing a FIT image source (ITS), mkimage does not currently check whether the image names referenced in the /configurations section (e.g. "kernel", "fdt", "ramdisk", "loadables") actually exist in the /images node.
This patch introduces a validation step during FIT import that iterates over each configuration and verifies that all referenced image names are defined under /images. If a missing image is detected, an appropriate error is reported and mkimage exits with FDT_ERR_NOTFOUND.
This ensures that configuration integrity is validated at build time.
--- tools/fit_image.c | 38 ++++++++++++++++++++++++++++++++++++++ tools/mkimage.c | 7 ++++++- 2 files changed, 44 insertions(+), 1 deletion(-)
tools/fit_image.c +38 -0
@@ -627,6 +627,7 @@ static int fit_import_data(struct image_tool_params *params, const char *fname)struct stat sbuf;int ret;int images; +int confs;int node; fd =mmap_fdt (params->cmdname, fname,0 , &old_fdt, &sbuf, false, false);
@@ -695,6 +696,43 @@ static int fit_import_data(struct image_tool_params *params, const char *fname) } } + confs =fdt_path_offset (fdt,FIT_CONFS_PATH ); +static const char *const props[] = {FIT_KERNEL_PROP , +FIT_RAMDISK_PROP , +FIT_FDT_PROP , +FIT_LOADABLE_PROP , +FIT_FPGA_PROP , +FIT_FIRMWARE_PROP , +FIT_SCRIPT_PROP }; + +fdt_for_each_subnode (node, fdt, confs) { +const char *conf_name =fdt_get_name (fdt, node,NULL ); + +for (int i =0 ; i <ARRAY_SIZE (props); i++) { +int count =fdt_stringlist_count (fdt, node, props[i]); + +if (count <0 ) +continue ; + +for (int j =0 ; j < count; j++) { +const char *img_name = +fdt_stringlist_get (fdt, node, props[i], j,NULL ); +if (!img_name) +continue ; + +int img =fdt_subnode_offset (fdt, images, img_name); + +if (img <0 ) { +fprintf (stderr, +"Error: configuration '%s' references undefined image '%s' in property '%s'\n" , + conf_name, img_name, props[i]); + ret =FDT_ERR_NOTFOUND ; + goto err_munmap; + } + } + } + } +munmap (old_fdt, sbuf.st_size);/* Close the old fd so we can re-use it. */
tools/mkimage.c +6 -1
@@ -519,8 +519,13 @@ int main(int argc, char **argv)*/ retval = tparams->fflag_handle (¶ms); -if (retval !=EXIT_SUCCESS ) +if (retval !=EXIT_SUCCESS ) { +if (retval ==FDT_ERR_NOTFOUND ) { +// Already printed error, exit cleanly +exit (EXIT_FAILURE ); + }usage ("Bad parameters for FIT image type" ); + } }if (params.lflag || params.fflag) {
Signature · 1 line
2.43.0
PATCH v2 3/4 binman: test: Ensure all config references exist in /images node
In reply to Aristo ChenSeveral binman FIT test device trees reference image nodes such as atf and uboot in their /configurations sections, but those image nodes were not actually defined in the /images node. This mismatch can lead to validation errors when stricter consistency checks are introduced.
This patch adds minimal definitions for atf and uboot under the /images node in all relevant test DTS files.
--- tools/binman/test/170_fit_fdt.dts | 14 ++++++++++++++ tools/binman/test/220_fit_subentry_bintool.dts | 2 +- tools/binman/test/223_fit_fdt_oper.dts | 14 ++++++++++++++ tools/binman/test/284_fit_fdt_list.dts | 14 ++++++++++++++ tools/binman/test/333_fit_fdt_dir.dts | 14 ++++++++++++++ tools/binman/test/334_fit_fdt_compat.dts | 14 ++++++++++++++ tools/binman/test/335_fit_fdt_phase.dts | 14 ++++++++++++++ tools/binman/test/345_fit_fdt_name.dts | 14 ++++++++++++++ 8 files changed, 99 insertions(+), 1 deletion(-)
tools/binman/test/170_fit_fdt.dts +14 -0
@@ -15,6 +15,20 @@ fit,fdt-list = "of-list"; images { + atf { + description = "atf firmware"; + type = "firmware"; + compression = "none"; + load = <00000000>; + entry = <00000000>; + }; + uboot { + description = "U-Boot firmware"; + type = "firmware"; + compression = "none"; + load = <00000000>; + entry = <00000000>; + }; kernel { description = "Vanilla Linux kernel"; type = "kernel";
tools/binman/test/220_fit_subentry_bintool.dts +1 -1
@@ -12,7 +12,7 @@ #address-cells = <1>; images { - test { + kernel { description = "Something using a bintool"; type = "kernel"; arch = "arm";
tools/binman/test/223_fit_fdt_oper.dts +14 -0
@@ -15,6 +15,20 @@ fit,fdt-list = "of-list"; images { + atf { + description = "atf firmware"; + type = "firmware"; + compression = "none"; + load = <00000000>; + entry = <00000000>; + }; + uboot { + description = "U-Boot firmware"; + type = "firmware"; + compression = "none"; + load = <00000000>; + entry = <00000000>; + }; kernel { description = "Vanilla Linux kernel"; type = "kernel";
tools/binman/test/284_fit_fdt_list.dts +14 -0
@@ -15,6 +15,20 @@ fit,fdt-list-val = "test-fdt1", "test-fdt2"; images { + atf { + description = "atf firmware"; + type = "firmware"; + compression = "none"; + load = <00000000>; + entry = <00000000>; + }; + uboot { + description = "U-Boot firmware"; + type = "firmware"; + compression = "none"; + load = <00000000>; + entry = <00000000>; + }; kernel { description = "Vanilla Linux kernel"; type = "kernel";
tools/binman/test/333_fit_fdt_dir.dts +14 -0
@@ -15,6 +15,20 @@ fit,fdt-list-dir = "fdts"; images { + atf { + description = "atf firmware"; + type = "firmware"; + compression = "none"; + load = <00000000>; + entry = <00000000>; + }; + uboot { + description = "U-Boot firmware"; + type = "firmware"; + compression = "none"; + load = <00000000>; + entry = <00000000>; + }; kernel { description = "Vanilla Linux kernel"; type = "kernel";
tools/binman/test/334_fit_fdt_compat.dts +14 -0
@@ -15,6 +15,20 @@ fit,fdt-list = "of-list"; images { + atf { + description = "atf firmware"; + type = "firmware"; + compression = "none"; + load = <00000000>; + entry = <00000000>; + }; + uboot { + description = "U-Boot firmware"; + type = "firmware"; + compression = "none"; + load = <00000000>; + entry = <00000000>; + }; kernel { description = "Vanilla Linux kernel"; type = "kernel";
tools/binman/test/335_fit_fdt_phase.dts +14 -0
@@ -15,6 +15,20 @@ fit,fdt-list = "of-list"; images { + atf { + description = "atf firmware"; + type = "firmware"; + compression = "none"; + load = <00000000>; + entry = <00000000>; + }; + uboot { + description = "U-Boot firmware"; + type = "firmware"; + compression = "none"; + load = <00000000>; + entry = <00000000>; + }; kernel { description = "Vanilla Linux kernel"; type = "kernel";
tools/binman/test/345_fit_fdt_name.dts +14 -0
@@ -15,6 +15,20 @@ fit,fdt-list = "of-list"; images { + atf { + description = "atf firmware"; + type = "firmware"; + compression = "none"; + load = <00000000>; + entry = <00000000>; + }; + uboot { + description = "U-Boot firmware"; + type = "firmware"; + compression = "none"; + load = <00000000>; + entry = <00000000>; + }; kernel { description = "Vanilla Linux kernel"; type = "kernel";
Signature · 1 line
2.43.0
PATCH v2 4/4 test: py: add mkimage test for undefined image references in FIT configs
In reply to Aristo ChenAdd a test case to verify that mkimage correctly rejects a FIT source that references a non-existent image from a configuration node.
This test introduces a minimal ITS that defines a valid kernel image but references a missing "fdt" image under the /configurations section. The test asserts that mkimage fails with a clear error message, as introduced in the new validation logic.
This helps ensure the validation logic behaves correctly and prevents regressions in future FIT enhancements.
--- test/py/tests/test_fit_mkimage_validate.py | 58 ++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 test/py/tests/test_fit_mkimage_validate.py
test/py/tests/test_fit_mkimage_validate.py new file +58 -0
@@ -0,0 +1,58 @@ +# SPDX-License-Identifier: GPL-2.0+ +# Copyright (c) 2025 +# +# Test that mkimage validates image references in configurations + +import os +import subprocess +import pytest +import fit_util + [email protected]('sandbox') [email protected]('dtc') +def test_fit_invalid_image_reference(ubman): + """Test that mkimage fails when configuration references a missing image""" + + its_fname = fit_util.make_fname(ubman, "invalid.its") + itb_fname = fit_util.make_fname(ubman, "invalid.itb") + kernel = fit_util.make_kernel(ubman, 'kernel.bin', 'kernel') + + # Write ITS with an invalid reference to a nonexistent image + its_text = ''' +/dts-v1/; + +/ { + images { + kernel@1 { + description = "Test Kernel"; + data = /incbin/("kernel.bin"); + type = "kernel"; + arch = "sandbox"; + os = "linux"; + compression = "none"; + load = <0x40000>; + entry = <0x40000>; + }; + }; + + configurations { + default = "conf@1"; + conf@1 { + kernel = "kernel@1"; + fdt = "notexist"; + }; + }; +}; +''' + + with open(its_fname, 'w') as f: + f.write(its_text) + + mkimage = os.path.join(ubman.config.build_dir, 'tools/mkimage') + cmd = [mkimage, '-f', its_fname, itb_fname] + + result = subprocess.run(cmd, capture_output=True, text=True) + + assert result.returncode != 0, "mkimage should fail due to missing image reference" + assert "references undefined image 'notexist'" in result.stderr +
Signature · 1 line
2.43.0
v3 cover mkimage: validate image references in FIT configurations
In reply to Aristo ChenHi all,
I would like to apologize for the confusion caused by my v2 submission. Due to an issue in how I sent the patches, the series did not appear correctly grouped on Patchwork, making it harder to follow and review.
This series introduces a validation step in mkimage to ensure that all image names referenced under the /configurations node of a FIT source (ITS) are actually defined under the /images node.
### Motivation
When using mkimage to build FIT images, it's easy to mistakenly reference nonexistent image nodes in configurations (e.g., referencing a missing fdt or firmware node). Such issues are often not caught until runtime in U-Boot.
This series aims to catch these errors early during FIT image creation by validating the configuration references in mkimage itself.
### Changes in v3
- Series re-sent correctly as a single thread without code changes
### Changes in v2
- Use fdt_stringlist_count() and fdt_stringlist_get() to handle stringlist properties cleanly
- Validate additional properties (firmware, fpga, script)
- Improve error messages by including the failing configuration and property name
- Refactor error propagation in fit_handle_file() as a separate commit
- Update all affected binman test DTS files to include the missing atf and uboot image nodes
- Add a new Python test case under test/py/ to ensure mkimage correctly fails when an image is missing
Best regards,
Aristo Chen
Aristo Chen (4):
tools: mkimage: propagate error codes from fit_handle_file()
tools: mkimage: validate image references in FIT configurations
binman: test: Ensure all config references exist in /images node
test: py: add mkimage test for undefined image references in FIT
configs
test/py/tests/test_fit_mkimage_validate.py | 58 +++++++++++++++++++ tools/binman/test/170_fit_fdt.dts | 14 +++++ .../binman/test/220_fit_subentry_bintool.dts | 2 +- tools/binman/test/223_fit_fdt_oper.dts | 14 +++++ tools/binman/test/284_fit_fdt_list.dts | 14 +++++ tools/binman/test/333_fit_fdt_dir.dts | 14 +++++ tools/binman/test/334_fit_fdt_compat.dts | 14 +++++ tools/binman/test/335_fit_fdt_phase.dts | 14 +++++ tools/binman/test/345_fit_fdt_name.dts | 14 +++++ tools/fit_image.c | 42 +++++++++++++- tools/mkimage.c | 7 ++- 11 files changed, 203 insertions(+), 4 deletions(-) create mode 100644 test/py/tests/test_fit_mkimage_validate.py
Signature · 1 line
2.43.0
PATCH v3 1/4 tools: mkimage: propagate error codes from fit_handle_file()
The fit_handle_file() function previously returned a hardcoded -1 on error. This change updates the logic to return the actual error code stored in ret, allowing for error propagation.
This improves debuggability and enables downstream callers to distinguish different failure causes, such as FDT_ERR_NOTFOUND or other errors.
--- tools/fit_image.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/fit_image.c +2 -2
@@ -750,7 +750,7 @@ static int fit_handle_file(struct image_tool_params *params)char bakfile[MKIMAGE_MAX_TMPFILE_LEN +4 ] = {0 };char cmd[MKIMAGE_MAX_DTC_CMDLINE_LEN ];size_t size_inc; -int ret; +int ret =EXIT_FAILURE ;/* Flattened Image Tree (FIT) format handling */ debug ("FIT format handling\n" );
@@ -854,7 +854,7 @@ static int fit_handle_file(struct image_tool_params *params) err_system:unlink (tmpfile);unlink (bakfile); -return -1 ; +return ret; }/**
Signature · 1 line
2.43.0
PATCH v3 2/4 tools: mkimage: validate image references in FIT configurations
In reply to Aristo ChenWhen parsing a FIT image source (ITS), mkimage does not currently check whether the image names referenced in the /configurations section (e.g. "kernel", "fdt", "ramdisk", "loadables") actually exist in the /images node.
This patch introduces a validation step during FIT import that iterates over each configuration and verifies that all referenced image names are defined under /images. If a missing image is detected, an appropriate error is reported and mkimage exits with FDT_ERR_NOTFOUND.
This ensures that configuration integrity is validated at build time.
--- tools/fit_image.c | 38 ++++++++++++++++++++++++++++++++++++++ tools/mkimage.c | 7 ++++++- 2 files changed, 44 insertions(+), 1 deletion(-)
tools/fit_image.c +38 -0
@@ -627,6 +627,7 @@ static int fit_import_data(struct image_tool_params *params, const char *fname)struct stat sbuf;int ret;int images; +int confs;int node; fd =mmap_fdt (params->cmdname, fname,0 , &old_fdt, &sbuf, false, false);
@@ -695,6 +696,43 @@ static int fit_import_data(struct image_tool_params *params, const char *fname) } } + confs =fdt_path_offset (fdt,FIT_CONFS_PATH ); +static const char *const props[] = {FIT_KERNEL_PROP , +FIT_RAMDISK_PROP , +FIT_FDT_PROP , +FIT_LOADABLE_PROP , +FIT_FPGA_PROP , +FIT_FIRMWARE_PROP , +FIT_SCRIPT_PROP }; + +fdt_for_each_subnode (node, fdt, confs) { +const char *conf_name =fdt_get_name (fdt, node,NULL ); + +for (int i =0 ; i <ARRAY_SIZE (props); i++) { +int count =fdt_stringlist_count (fdt, node, props[i]); + +if (count <0 ) +continue ; + +for (int j =0 ; j < count; j++) { +const char *img_name = +fdt_stringlist_get (fdt, node, props[i], j,NULL ); +if (!img_name) +continue ; + +int img =fdt_subnode_offset (fdt, images, img_name); + +if (img <0 ) { +fprintf (stderr, +"Error: configuration '%s' references undefined image '%s' in property '%s'\n" , + conf_name, img_name, props[i]); + ret =FDT_ERR_NOTFOUND ; + goto err_munmap; + } + } + } + } +munmap (old_fdt, sbuf.st_size);/* Close the old fd so we can re-use it. */
tools/mkimage.c +6 -1
@@ -519,8 +519,13 @@ int main(int argc, char **argv)*/ retval = tparams->fflag_handle (¶ms); -if (retval !=EXIT_SUCCESS ) +if (retval !=EXIT_SUCCESS ) { +if (retval ==FDT_ERR_NOTFOUND ) { +// Already printed error, exit cleanly +exit (EXIT_FAILURE ); + }usage ("Bad parameters for FIT image type" ); + } }if (params.lflag || params.fflag) {
Signature · 1 line
2.43.0
PATCH v3 3/4 binman: test: Ensure all config references exist in /images node
In reply to Aristo ChenSeveral binman FIT test device trees reference image nodes such as atf and uboot in their /configurations sections, but those image nodes were not actually defined in the /images node. This mismatch can lead to validation errors when stricter consistency checks are introduced.
This patch adds minimal definitions for atf and uboot under the /images node in all relevant test DTS files.
--- tools/binman/test/170_fit_fdt.dts | 14 ++++++++++++++ tools/binman/test/220_fit_subentry_bintool.dts | 2 +- tools/binman/test/223_fit_fdt_oper.dts | 14 ++++++++++++++ tools/binman/test/284_fit_fdt_list.dts | 14 ++++++++++++++ tools/binman/test/333_fit_fdt_dir.dts | 14 ++++++++++++++ tools/binman/test/334_fit_fdt_compat.dts | 14 ++++++++++++++ tools/binman/test/335_fit_fdt_phase.dts | 14 ++++++++++++++ tools/binman/test/345_fit_fdt_name.dts | 14 ++++++++++++++ 8 files changed, 99 insertions(+), 1 deletion(-)
tools/binman/test/170_fit_fdt.dts +14 -0
@@ -15,6 +15,20 @@ fit,fdt-list = "of-list"; images { + atf { + description = "atf firmware"; + type = "firmware"; + compression = "none"; + load = <00000000>; + entry = <00000000>; + }; + uboot { + description = "U-Boot firmware"; + type = "firmware"; + compression = "none"; + load = <00000000>; + entry = <00000000>; + }; kernel { description = "Vanilla Linux kernel"; type = "kernel";
tools/binman/test/220_fit_subentry_bintool.dts +1 -1
@@ -12,7 +12,7 @@ #address-cells = <1>; images { - test { + kernel { description = "Something using a bintool"; type = "kernel"; arch = "arm";
tools/binman/test/223_fit_fdt_oper.dts +14 -0
@@ -15,6 +15,20 @@ fit,fdt-list = "of-list"; images { + atf { + description = "atf firmware"; + type = "firmware"; + compression = "none"; + load = <00000000>; + entry = <00000000>; + }; + uboot { + description = "U-Boot firmware"; + type = "firmware"; + compression = "none"; + load = <00000000>; + entry = <00000000>; + }; kernel { description = "Vanilla Linux kernel"; type = "kernel";
tools/binman/test/284_fit_fdt_list.dts +14 -0
@@ -15,6 +15,20 @@ fit,fdt-list-val = "test-fdt1", "test-fdt2"; images { + atf { + description = "atf firmware"; + type = "firmware"; + compression = "none"; + load = <00000000>; + entry = <00000000>; + }; + uboot { + description = "U-Boot firmware"; + type = "firmware"; + compression = "none"; + load = <00000000>; + entry = <00000000>; + }; kernel { description = "Vanilla Linux kernel"; type = "kernel";
tools/binman/test/333_fit_fdt_dir.dts +14 -0
@@ -15,6 +15,20 @@ fit,fdt-list-dir = "fdts"; images { + atf { + description = "atf firmware"; + type = "firmware"; + compression = "none"; + load = <00000000>; + entry = <00000000>; + }; + uboot { + description = "U-Boot firmware"; + type = "firmware"; + compression = "none"; + load = <00000000>; + entry = <00000000>; + }; kernel { description = "Vanilla Linux kernel"; type = "kernel";
tools/binman/test/334_fit_fdt_compat.dts +14 -0
@@ -15,6 +15,20 @@ fit,fdt-list = "of-list"; images { + atf { + description = "atf firmware"; + type = "firmware"; + compression = "none"; + load = <00000000>; + entry = <00000000>; + }; + uboot { + description = "U-Boot firmware"; + type = "firmware"; + compression = "none"; + load = <00000000>; + entry = <00000000>; + }; kernel { description = "Vanilla Linux kernel"; type = "kernel";
tools/binman/test/335_fit_fdt_phase.dts +14 -0
@@ -15,6 +15,20 @@ fit,fdt-list = "of-list"; images { + atf { + description = "atf firmware"; + type = "firmware"; + compression = "none"; + load = <00000000>; + entry = <00000000>; + }; + uboot { + description = "U-Boot firmware"; + type = "firmware"; + compression = "none"; + load = <00000000>; + entry = <00000000>; + }; kernel { description = "Vanilla Linux kernel"; type = "kernel";
tools/binman/test/345_fit_fdt_name.dts +14 -0
@@ -15,6 +15,20 @@ fit,fdt-list = "of-list"; images { + atf { + description = "atf firmware"; + type = "firmware"; + compression = "none"; + load = <00000000>; + entry = <00000000>; + }; + uboot { + description = "U-Boot firmware"; + type = "firmware"; + compression = "none"; + load = <00000000>; + entry = <00000000>; + }; kernel { description = "Vanilla Linux kernel"; type = "kernel";
Signature · 1 line
2.43.0
PATCH v3 4/4 test: py: add mkimage test for undefined image references in FIT configs
In reply to Aristo ChenAdd a test case to verify that mkimage correctly rejects a FIT source that references a non-existent image from a configuration node.
This test introduces a minimal ITS that defines a valid kernel image but references a missing "fdt" image under the /configurations section. The test asserts that mkimage fails with a clear error message, as introduced in the new validation logic.
This helps ensure the validation logic behaves correctly and prevents regressions in future FIT enhancements.
--- test/py/tests/test_fit_mkimage_validate.py | 58 ++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 test/py/tests/test_fit_mkimage_validate.py
test/py/tests/test_fit_mkimage_validate.py new file +58 -0
@@ -0,0 +1,58 @@ +# SPDX-License-Identifier: GPL-2.0+ +# Copyright (c) 2025 +# +# Test that mkimage validates image references in configurations + +import os +import subprocess +import pytest +import fit_util + [email protected]('sandbox') [email protected]('dtc') +def test_fit_invalid_image_reference(ubman): + """Test that mkimage fails when configuration references a missing image""" + + its_fname = fit_util.make_fname(ubman, "invalid.its") + itb_fname = fit_util.make_fname(ubman, "invalid.itb") + kernel = fit_util.make_kernel(ubman, 'kernel.bin', 'kernel') + + # Write ITS with an invalid reference to a nonexistent image + its_text = ''' +/dts-v1/; + +/ { + images { + kernel@1 { + description = "Test Kernel"; + data = /incbin/("kernel.bin"); + type = "kernel"; + arch = "sandbox"; + os = "linux"; + compression = "none"; + load = <0x40000>; + entry = <0x40000>; + }; + }; + + configurations { + default = "conf@1"; + conf@1 { + kernel = "kernel@1"; + fdt = "notexist"; + }; + }; +}; +''' + + with open(its_fname, 'w') as f: + f.write(its_text) + + mkimage = os.path.join(ubman.config.build_dir, 'tools/mkimage') + cmd = [mkimage, '-f', its_fname, itb_fname] + + result = subprocess.run(cmd, capture_output=True, text=True) + + assert result.returncode != 0, "mkimage should fail due to missing image reference" + assert "references undefined image 'notexist'" in result.stderr +
Signature · 1 line
2.43.0
Re: [PATCH v3 0/4] mkimage: validate image references in FIT configurations
In reply to Aristo ChenQuoted 10 lines · Aristo Chen
Hi all,
I would like to apologize for the confusion caused by my v2 submission. Due to an issue in how I sent the patches, the series did not appear correctly grouped on Patchwork, making it harder to follow and review.
This series introduces a validation step in mkimage to ensure that all image names referenced under the /configurations node of a FIT source (ITS) are actually defined under the /images node.
Quoted 8 lines
### Motivation
When using mkimage to build FIT images, it's easy to mistakenly reference nonexistent image nodes in configurations (e.g., referencing a missing
fdtorfirmwarenode). Such issues are often not caught until runtime in U-Boot.This series aims to catch these errors early during FIT image creation by validating the configuration references in mkimage itself.
This seems to introduce problems on a number of platforms such as evb-rk3288 and so it might be worthwhile to run v4 through CI before posting, thanks.
Signature · 1 line
Tom
v4 cover mkimage: validate image references in FIT configurations
In reply to Aristo ChenHi all,
This series introduces a validation step in mkimage to ensure that all image names referenced under the /configurations node of a FIT source (ITS) are actually defined under the /images node.
### Motivation
When using mkimage to build FIT images, it's easy to mistakenly reference nonexistent image nodes in configurations (e.g., referencing a missing fdt or firmware node). Such issues are often not caught until runtime in U-Boot.
This series aims to catch these errors early during FIT image creation by validating the configuration references in mkimage itself.
### Changes in v4
- The changes in v4 are for fixing errors in CI process
- In the FIT validation loop, updated image name check from:
```c
if (!img_name)
continue;
```
to:
```c
if (!img_name || !*img_name)
continue;
``` This ensures that both NULL pointers and empty strings ("") are ignored when validating image references in the /configurations node
- Resolves a regression on the phycore-am62x platform where mkimage reports an error due to missing image nodes referenced via the loadables property (e.g., "tifsstub-hs"). This patch adds the required tifsstub-hs, tifsstub-fs, and tifsstub-gp image nodes in the corresponding binman description, inspired by commit 622f826bf025 ("arm: dts: phycore-am62x: Package TIFS Stub").
### Changes in v3
- Series re-sent correctly as a single thread without code changes
### Changes in v2
- Use fdt_stringlist_count() and fdt_stringlist_get() to handle stringlist properties cleanly
- Validate additional properties (firmware, fpga, script)
- Improve error messages by including the failing configuration and property name
- Refactor error propagation in fit_handle_file() as a separate commit
- Update all affected binman test DTS files to include the missing atf and uboot image nodes
- Add a new Python test case under test/py/ to ensure mkimage correctly fails when an image is missing
Best regards,
Aristo Chen
Aristo Chen (5):
tools: mkimage: propagate error codes from fit_handle_file()
tools: mkimage: validate image references in FIT configurations
binman: test: Ensure all config references exist in /images node
test: py: add mkimage test for undefined image references in FIT
configs
arm: dts: phycore-am62x: Add missing tifsstub image nodes for FIT
loadables
arch/arm/dts/k3-am625-phycore-som-binman.dtsi | 94 +++++++++++++++++++ test/py/tests/test_fit_mkimage_validate.py | 58 ++++++++++++ tools/binman/test/170_fit_fdt.dts | 14 +++ .../binman/test/220_fit_subentry_bintool.dts | 2 +- tools/binman/test/223_fit_fdt_oper.dts | 14 +++ tools/binman/test/284_fit_fdt_list.dts | 14 +++ tools/binman/test/333_fit_fdt_dir.dts | 14 +++ tools/binman/test/334_fit_fdt_compat.dts | 14 +++ tools/binman/test/335_fit_fdt_phase.dts | 14 +++ tools/binman/test/345_fit_fdt_name.dts | 14 +++ tools/fit_image.c | 42 ++++++++- tools/mkimage.c | 7 +- 12 files changed, 297 insertions(+), 4 deletions(-) create mode 100644 test/py/tests/test_fit_mkimage_validate.py
Signature · 1 line
2.43.0
PATCH v4 1/5 tools: mkimage: propagate error codes from fit_handle_file()
The fit_handle_file() function previously returned a hardcoded -1 on error. This change updates the logic to return the actual error code stored in ret, allowing for error propagation.
This improves debuggability and enables downstream callers to distinguish different failure causes, such as FDT_ERR_NOTFOUND or other errors.
--- tools/fit_image.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/fit_image.c +2 -2
@@ -750,7 +750,7 @@ static int fit_handle_file(struct image_tool_params *params)char bakfile[MKIMAGE_MAX_TMPFILE_LEN +4 ] = {0 };char cmd[MKIMAGE_MAX_DTC_CMDLINE_LEN ];size_t size_inc; -int ret; +int ret =EXIT_FAILURE ;/* Flattened Image Tree (FIT) format handling */ debug ("FIT format handling\n" );
@@ -854,7 +854,7 @@ static int fit_handle_file(struct image_tool_params *params) err_system:unlink (tmpfile);unlink (bakfile); -return -1 ; +return ret; }/**
Signature · 1 line
2.43.0
PATCH v4 2/5 tools: mkimage: validate image references in FIT configurations
In reply to Aristo ChenWhen parsing a FIT image source (ITS), mkimage does not currently check whether the image names referenced in the /configurations section (e.g. "kernel", "fdt", "ramdisk", "loadables") actually exist in the /images node.
This patch introduces a validation step during FIT import that iterates over each configuration and verifies that all referenced image names are defined under /images. If a missing image is detected, an appropriate error is reported and mkimage exits with FDT_ERR_NOTFOUND.
This ensures that configuration integrity is validated at build time.
--- tools/fit_image.c | 38 ++++++++++++++++++++++++++++++++++++++ tools/mkimage.c | 7 ++++++- 2 files changed, 44 insertions(+), 1 deletion(-)
tools/fit_image.c +38 -0
@@ -627,6 +627,7 @@ static int fit_import_data(struct image_tool_params *params, const char *fname)struct stat sbuf;int ret;int images; +int confs;int node; fd =mmap_fdt (params->cmdname, fname,0 , &old_fdt, &sbuf, false, false);
@@ -695,6 +696,43 @@ static int fit_import_data(struct image_tool_params *params, const char *fname) } } + confs =fdt_path_offset (fdt,FIT_CONFS_PATH ); +static const char *const props[] = {FIT_KERNEL_PROP , +FIT_RAMDISK_PROP , +FIT_FDT_PROP , +FIT_LOADABLE_PROP , +FIT_FPGA_PROP , +FIT_FIRMWARE_PROP , +FIT_SCRIPT_PROP }; + +fdt_for_each_subnode (node, fdt, confs) { +const char *conf_name =fdt_get_name (fdt, node,NULL ); + +for (int i =0 ; i <ARRAY_SIZE (props); i++) { +int count =fdt_stringlist_count (fdt, node, props[i]); + +if (count <0 ) +continue ; + +for (int j =0 ; j < count; j++) { +const char *img_name = +fdt_stringlist_get (fdt, node, props[i], j,NULL ); +if (!img_name || !*img_name) +continue ; + +int img =fdt_subnode_offset (fdt, images, img_name); + +if (img <0 ) { +fprintf (stderr, +"Error: configuration '%s' references undefined image '%s' in property '%s'\n" , + conf_name, img_name, props[i]); + ret =FDT_ERR_NOTFOUND ; + goto err_munmap; + } + } + } + } +munmap (old_fdt, sbuf.st_size);/* Close the old fd so we can re-use it. */
tools/mkimage.c +6 -1
@@ -519,8 +519,13 @@ int main(int argc, char **argv)*/ retval = tparams->fflag_handle (¶ms); -if (retval !=EXIT_SUCCESS ) +if (retval !=EXIT_SUCCESS ) { +if (retval ==FDT_ERR_NOTFOUND ) { +// Already printed error, exit cleanly +exit (EXIT_FAILURE ); + }usage ("Bad parameters for FIT image type" ); + } }if (params.lflag || params.fflag) {
Signature · 1 line
2.43.0
PATCH v4 3/5 binman: test: Ensure all config references exist in /images node
In reply to Aristo ChenSeveral binman FIT test device trees reference image nodes such as atf and uboot in their /configurations sections, but those image nodes were not actually defined in the /images node. This mismatch can lead to validation errors when stricter consistency checks are introduced.
This patch adds minimal definitions for atf and uboot under the /images node in all relevant test DTS files.
--- tools/binman/test/170_fit_fdt.dts | 14 ++++++++++++++ tools/binman/test/220_fit_subentry_bintool.dts | 2 +- tools/binman/test/223_fit_fdt_oper.dts | 14 ++++++++++++++ tools/binman/test/284_fit_fdt_list.dts | 14 ++++++++++++++ tools/binman/test/333_fit_fdt_dir.dts | 14 ++++++++++++++ tools/binman/test/334_fit_fdt_compat.dts | 14 ++++++++++++++ tools/binman/test/335_fit_fdt_phase.dts | 14 ++++++++++++++ tools/binman/test/345_fit_fdt_name.dts | 14 ++++++++++++++ 8 files changed, 99 insertions(+), 1 deletion(-)
tools/binman/test/170_fit_fdt.dts +14 -0
@@ -15,6 +15,20 @@ fit,fdt-list = "of-list"; images { + atf { + description = "atf firmware"; + type = "firmware"; + compression = "none"; + load = <00000000>; + entry = <00000000>; + }; + uboot { + description = "U-Boot firmware"; + type = "firmware"; + compression = "none"; + load = <00000000>; + entry = <00000000>; + }; kernel { description = "Vanilla Linux kernel"; type = "kernel";
tools/binman/test/220_fit_subentry_bintool.dts +1 -1
@@ -12,7 +12,7 @@ #address-cells = <1>; images { - test { + kernel { description = "Something using a bintool"; type = "kernel"; arch = "arm";
tools/binman/test/223_fit_fdt_oper.dts +14 -0
@@ -15,6 +15,20 @@ fit,fdt-list = "of-list"; images { + atf { + description = "atf firmware"; + type = "firmware"; + compression = "none"; + load = <00000000>; + entry = <00000000>; + }; + uboot { + description = "U-Boot firmware"; + type = "firmware"; + compression = "none"; + load = <00000000>; + entry = <00000000>; + }; kernel { description = "Vanilla Linux kernel"; type = "kernel";
tools/binman/test/284_fit_fdt_list.dts +14 -0
@@ -15,6 +15,20 @@ fit,fdt-list-val = "test-fdt1", "test-fdt2"; images { + atf { + description = "atf firmware"; + type = "firmware"; + compression = "none"; + load = <00000000>; + entry = <00000000>; + }; + uboot { + description = "U-Boot firmware"; + type = "firmware"; + compression = "none"; + load = <00000000>; + entry = <00000000>; + }; kernel { description = "Vanilla Linux kernel"; type = "kernel";
tools/binman/test/333_fit_fdt_dir.dts +14 -0
@@ -15,6 +15,20 @@ fit,fdt-list-dir = "fdts"; images { + atf { + description = "atf firmware"; + type = "firmware"; + compression = "none"; + load = <00000000>; + entry = <00000000>; + }; + uboot { + description = "U-Boot firmware"; + type = "firmware"; + compression = "none"; + load = <00000000>; + entry = <00000000>; + }; kernel { description = "Vanilla Linux kernel"; type = "kernel";
tools/binman/test/334_fit_fdt_compat.dts +14 -0
@@ -15,6 +15,20 @@ fit,fdt-list = "of-list"; images { + atf { + description = "atf firmware"; + type = "firmware"; + compression = "none"; + load = <00000000>; + entry = <00000000>; + }; + uboot { + description = "U-Boot firmware"; + type = "firmware"; + compression = "none"; + load = <00000000>; + entry = <00000000>; + }; kernel { description = "Vanilla Linux kernel"; type = "kernel";
tools/binman/test/335_fit_fdt_phase.dts +14 -0
@@ -15,6 +15,20 @@ fit,fdt-list = "of-list"; images { + atf { + description = "atf firmware"; + type = "firmware"; + compression = "none"; + load = <00000000>; + entry = <00000000>; + }; + uboot { + description = "U-Boot firmware"; + type = "firmware"; + compression = "none"; + load = <00000000>; + entry = <00000000>; + }; kernel { description = "Vanilla Linux kernel"; type = "kernel";
tools/binman/test/345_fit_fdt_name.dts +14 -0
@@ -15,6 +15,20 @@ fit,fdt-list = "of-list"; images { + atf { + description = "atf firmware"; + type = "firmware"; + compression = "none"; + load = <00000000>; + entry = <00000000>; + }; + uboot { + description = "U-Boot firmware"; + type = "firmware"; + compression = "none"; + load = <00000000>; + entry = <00000000>; + }; kernel { description = "Vanilla Linux kernel"; type = "kernel";
Signature · 1 line
2.43.0
PATCH v4 4/5 test: py: add mkimage test for undefined image references in FIT configs
In reply to Aristo ChenAdd a test case to verify that mkimage correctly rejects a FIT source that references a non-existent image from a configuration node.
This test introduces a minimal ITS that defines a valid kernel image but references a missing "fdt" image under the /configurations section. The test asserts that mkimage fails with a clear error message, as introduced in the new validation logic.
This helps ensure the validation logic behaves correctly and prevents regressions in future FIT enhancements.
--- test/py/tests/test_fit_mkimage_validate.py | 58 ++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 test/py/tests/test_fit_mkimage_validate.py
test/py/tests/test_fit_mkimage_validate.py new file +58 -0
@@ -0,0 +1,58 @@ +# SPDX-License-Identifier: GPL-2.0+ +# Copyright (c) 2025 +# +# Test that mkimage validates image references in configurations + +import os +import subprocess +import pytest +import fit_util + [email protected]('sandbox') [email protected]('dtc') +def test_fit_invalid_image_reference(ubman): + """Test that mkimage fails when configuration references a missing image""" + + its_fname = fit_util.make_fname(ubman, "invalid.its") + itb_fname = fit_util.make_fname(ubman, "invalid.itb") + kernel = fit_util.make_kernel(ubman, 'kernel.bin', 'kernel') + + # Write ITS with an invalid reference to a nonexistent image + its_text = ''' +/dts-v1/; + +/ { + images { + kernel@1 { + description = "Test Kernel"; + data = /incbin/("kernel.bin"); + type = "kernel"; + arch = "sandbox"; + os = "linux"; + compression = "none"; + load = <0x40000>; + entry = <0x40000>; + }; + }; + + configurations { + default = "conf@1"; + conf@1 { + kernel = "kernel@1"; + fdt = "notexist"; + }; + }; +}; +''' + + with open(its_fname, 'w') as f: + f.write(its_text) + + mkimage = os.path.join(ubman.config.build_dir, 'tools/mkimage') + cmd = [mkimage, '-f', its_fname, itb_fname] + + result = subprocess.run(cmd, capture_output=True, text=True) + + assert result.returncode != 0, "mkimage should fail due to missing image reference" + assert "references undefined image 'notexist'" in result.stderr +
Signature · 1 line
2.43.0
PATCH v4 5/5 arm: dts: phycore-am62x: Add missing tifsstub image nodes for FIT loadables
In reply to Aristo ChenThe phycore-am62x build was broken due to mkimage reporting an undefined 'image "tifsstub-hs"' in the 'loadables' property of the FIT configuration. This occurred because the loadables field referenced tifsstub-hs, tifsstub-fs, and tifsstub-gp, but no corresponding nodes were defined under /images.
This patch was inspired by commit 622f826bf025704cbcc4f39252d4a83129a9cabb ("arm: dts: phycore-am62x: Package TIFS Stub"). It resolves the issue by adding proper Binman nodes for each TIFS variant (tifsstub-hs, tifsstub-fs, and tifsstub-gp).
--- arch/arm/dts/k3-am625-phycore-som-binman.dtsi | 94 +++++++++++++++++++ 1 file changed, 94 insertions(+)
arch/arm/dts/k3-am625-phycore-som-binman.dtsi +94 -0
@@ -405,11 +405,105 @@ }; &binman { + tifsstub-hs { + filename = "tifsstub.bin_hs"; + ti-secure-rom { + content = <&tifsstub_hs_cert>; + core = "secure"; + load = <0x40000>; + sw-rev = <CONFIG_K3_X509_SWRV>; + keyfile = "custMpk.pem"; + countersign; + tifsstub; + }; + tifsstub_hs_cert: tifsstub-hs-cert.bin { + filename = "ti-sysfw/ti-fs-stub-firmware-am62x-hs-cert.bin"; + type = "blob-ext"; + optional; + }; + tifsstub_hs_enc: tifsstub-hs-enc.bin { + filename = "ti-sysfw/ti-fs-stub-firmware-am62x-hs-enc.bin"; + type = "blob-ext"; + optional; + }; + }; + + tifsstub-fs { + filename = "tifsstub.bin_fs"; + tifsstub_fs_cert: tifsstub-fs-cert.bin { + filename = "ti-sysfw/ti-fs-stub-firmware-am62x-hs-cert.bin"; + type = "blob-ext"; + optional; + }; + tifsstub_fs_enc: tifsstub-fs-enc.bin { + filename = "ti-sysfw/ti-fs-stub-firmware-am62x-hs-enc.bin"; + type = "blob-ext"; + optional; + }; + + }; + + tifsstub-gp { + filename = "tifsstub.bin_gp"; + ti-secure-rom { + content = <&tifsstub_gp>; + core = "secure"; + load = <0x60000>; + sw-rev = <CONFIG_K3_X509_SWRV>; + keyfile = "ti-degenerate-key.pem"; + tifsstub; + }; + tifsstub_gp: tifsstub-gp.bin { + filename = "ti-sysfw/ti-fs-stub-firmware-am62x-gp.bin"; + type = "blob-ext"; + optional; + }; + }; + ti-spl_unsigned { insert-template = <&ti_spl_unsigned_template>; fit { images { + tifsstub-hs { + description = "TIFSSTUB"; + type = "firmware"; + arch = "arm32"; + compression = "none"; + os = "tifsstub-hs"; + load = <0x9dc00000>; + entry = <0x9dc00000>; + blob-ext { + filename = "tifsstub.bin_hs"; + }; + }; + + tifsstub-fs { + description = "TIFSSTUB"; + type = "firmware"; + arch = "arm32"; + compression = "none"; + os = "tifsstub-fs"; + load = <0x9dc00000>; + entry = <0x9dc00000>; + blob-ext { + filename = "tifsstub.bin_fs"; + }; + }; + + tifsstub-gp { + description = "TIFSSTUB"; + type = "firmware"; + arch = "arm32"; + compression = "none"; + os = "tifsstub-gp"; + load = <0x9dc00000>; + entry = <0x9dc00000>; + blob-ext { + filename = "tifsstub.bin_gp"; + }; + }; + dm { ti-dm { filename = "ti-dm/am62xx/ipc_echo_testb_mcu1_0_release_strip.xer5f";
Signature · 1 line
2.43.0
Re: [PATCH v4 0/5] mkimage: validate image references in FIT configurations
In reply to Aristo ChenQuoted 11 lines · Aristo Chen
This series introduces a validation step in mkimage to ensure that all image names referenced under the /configurations node of a FIT source (ITS) are actually defined under the /images node.
### Motivation
When using mkimage to build FIT images, it's easy to mistakenly reference nonexistent image nodes in configurations (e.g., referencing a missing
fdtorfirmwarenode). Such issues are often not caught until runtime in U-Boot.[...]
Applied to u-boot/next, thanks!
[1/5] tools: mkimage: propagate error codes from fit_handle_file()
commit: 21705d39144a51a50c0206c74588c6e9e4018e7a
[2/5] tools: mkimage: validate image references in FIT configurations
commit: 7a8b25a771f069819eab6134fd1c4df520ebc9ca
[3/5] binman: test: Ensure all config references exist in /images node
commit: 3071e264c9baba4d55aa6d1a07a60c969d57eccf
[4/5] test: py: add mkimage test for undefined image references in FIT configs
commit: 21f75eb7af40cd22ecee94554b2a226760fe9814
[5/5] arm: dts: phycore-am62x: Add missing tifsstub image nodes for FIT loadables
commit: 647931cfeda1ed594904e7dd4262783a264cb97aSignature · 1 line
Tom