Skip to contentSkip to conversation

mkimage: validate default configuration reference

PATCH Superseded Aristo Chen 3 participants 10 messages Jul 15, 2025 – Jul 23, 2025 Arm (32-bit)

lore
Share & tools
lore
#0 lore raw

cover mkimage: validate default configuration reference

This patch series introduces a validation step in mkimage to ensure that the default property under the /configurations node in a FIT image references a valid subnode. If the referenced node does not exist, mkimage now prints an error and fails early. This helps prevent runtime failures when U-Boot attempts to boot using an undefined configuration.

The first patch implements the validation logic in fit_image.c. The second patch fixes an invalid default configuration reference exposed by this new check in the k3-am65-iot2050-boot-image.dtsi. The final patch adds a test case to verify that mkimage correctly fails when an invalid default configuration is present in the ITS file.

This series improves the robustness of FIT image generation and helps catch malformed image trees during build time.

Aristo Chen (3):
tools: fit_image: validate existence of default configuration node
arm: k3-am65-iot2050: Fix invalid default configuration reference
test: fit: add test case for invalid default configuration reference

 arch/arm/dts/k3-am65-iot2050-boot-image.dtsi |  4 +-
 test/py/tests/test_fit_mkimage_validate.py   | 45 ++++++++++++++++++++
 tools/fit_image.c                            | 10 +++++
 3 files changed, 57 insertions(+), 2 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/3 tools: fit_image: validate existence of default configuration node

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.

---
 tools/fit_image.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
tools/fit_image.c +10 -0
index 8717dc9a3b1..8a1f6c185dd 100644
@@ -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);
 
Signature · 1 line
2.43.0
#2 lore raw

PATCH 2/3 arm: k3-am65-iot2050: Fix invalid default configuration reference

In reply to Aristo Chen

mkimage introduced a validation step to ensure that the 'default' property under the /configurations node in a FIT image refers to a valid subnode. This exposed an issue in the k3-am65-iot2050-boot-image.dtsi, where the 'default' property was set to "ti/k3-am6528-iot2050-basic" and "ti/k3-am6528-iot2050-basic-pg2", which do not correspond to actual configuration node names.

This patch updates both /configurations nodes to reference the correct subnode.

Without this fix, mkimage will fail with an error:
"ERROR: Default configuration 'ti/k3-am6528-iot2050-basic' not found under /configurations"

---
 arch/arm/dts/k3-am65-iot2050-boot-image.dtsi | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm/dts/k3-am65-iot2050-boot-image.dtsi +2 -2
index f49d6f262f2..b3d64485249 100644
@@ -208,7 +208,7 @@
 			fit,fdt-list-val = "ti/k3-am6528-iot2050-basic", "ti/k3-am6548-iot2050-advanced";
 
 			configurations {
-				default = "ti/k3-am6528-iot2050-basic";
+				default = "config-1";
 				@config-SEQ {
 					loadables =
 #ifdef CONFIG_WDT_K3_RTI_FW_FILE
@@ -265,7 +265,7 @@
 			};
 
 			configurations {
-				default = "ti/k3-am6528-iot2050-basic-pg2";
+				default = "config-1";
 				@config-SEQ {
 					loadables =
 #ifdef CONFIG_WDT_K3_RTI_FW_FILE
Signature · 1 line
2.43.0
#3 lore raw

Re: [PATCH v1 2/3] arm: k3-am65-iot2050: Fix invalid default configuration reference

Hi Aristo,

Quoted 7 lines · Aristo Chen

mkimage introduced a validation step to ensure that the 'default' property under the /configurations node in a FIT image refers to a valid subnode. This exposed an issue in the k3-am65-iot2050-boot-image.dtsi, where the 'default' property was set to "ti/k3-am6528-iot2050-basic" and "ti/k3-am6528-iot2050-basic-pg2", which do not correspond to actual configuration node names.

Quoted 8 lines

This patch updates both /configurations nodes to reference the correct subnode.

Without this fix, mkimage will fail with an error:
"ERROR: Default configuration 'ti/k3-am6528-iot2050-basic' not found under /configurations"

Please reorder the patches so that the builds still pass when applying patch 1.

You can simply update the last sentence of the commit log to say that an upcoming commit will validate the default configuration exists and would therefore fail the build (as it should).

Cheers,
Quentin

#4 lore raw

PATCH 3/3 test: fit: add test case for invalid default configuration reference

In reply to Aristo Chen

Recent changes to mkimage introduced a validation step to ensure that the 'default' property under the /configurations node in a FIT image references a valid configuration subnode. If the referenced node is missing, mkimage will now return an error.

This patch adds a Python test case to verify that mkimage correctly fails when the 'default' configuration does not exist. The test creates a minimal ITS with an invalid default reference and checks that mkimage produces the expected error message.

---
 test/py/tests/test_fit_mkimage_validate.py | 45 ++++++++++++++++++++++
 1 file changed, 45 insertions(+)
test/py/tests/test_fit_mkimage_validate.py +45 -0
index af56f08ca10..ef974c8c762 100644
@@ -7,6 +7,7 @@ import os
 import subprocess
 import pytest
 import fit_util
+import re
 
 @pytest.mark.boardspec('sandbox')
 @pytest.mark.requiredtool('dtc')
@@ -56,3 +57,47 @@ def test_fit_invalid_image_reference(ubman):
     assert result.returncode != 0, "mkimage should fail due to missing image reference"
     assert "references undefined image 'notexist'" in result.stderr
 
+def test_fit_invalid_default_config(ubman):
+    """Test that mkimage fails when default config is missing"""
+
+    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 default config
+    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@2 {
+            kernel = "kernel@1";
+        };
+    };
+};
+'''
+
+    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 default config"
+    assert re.search(r"Default configuration '.*' not found under /configurations", result.stderr)
Signature · 1 line
2.43.0
#5 lore raw

v2 cover mkimage: validate default configuration reference

In reply to Aristo Chen

This patch series introduces a validation step in mkimage to ensure that the default property under the /configurations node in a FIT image references a valid subnode. If the referenced node does not exist, mkimage now prints an error and fails early. This helps prevent runtime failures when U-Boot attempts to boot using an undefined configuration.

The first patch implements the validation logic in fit_image.c. The second patch fixes an invalid default configuration reference exposed by this new check in the k3-am65-iot2050-boot-image.dtsi. The final patch adds a test case to verify that mkimage correctly fails when an invalid default configuration is present in the ITS file.

This series improves the robustness of FIT image generation and helps catch malformed image trees during build time.

### Changes in v2
- Modify the order of the commits, code is not changed

Aristo Chen (3):
arm: k3-am65-iot2050: Fix invalid default configuration reference
tools: fit_image: validate existence of default configuration node
test: fit: add test case for invalid default configuration reference

 arch/arm/dts/k3-am65-iot2050-boot-image.dtsi |  4 +-
 test/py/tests/test_fit_mkimage_validate.py   | 45 ++++++++++++++++++++
 tools/fit_image.c                            | 10 +++++
 3 files changed, 57 insertions(+), 2 deletions(-)
Signature · 1 line
2.43.0
#6 lore raw

PATCH v2 1/3 arm: k3-am65-iot2050: Fix invalid default configuration reference

mkimage introduced a validation step to ensure that the 'default' property under the /configurations node in a FIT image refers to a valid subnode. This exposed an issue in the k3-am65-iot2050-boot-image.dtsi, where the 'default' property was set to "ti/k3-am6528-iot2050-basic" and "ti/k3-am6528-iot2050-basic-pg2", which do not correspond to actual configuration node names.

This patch updates both /configurations nodes to reference the correct subnode.

Without this fix, mkimage will fail with an error:
"ERROR: Default configuration 'ti/k3-am6528-iot2050-basic' not found under /configurations"

An upcoming commit will validate the if the default configuration exists

---
 arch/arm/dts/k3-am65-iot2050-boot-image.dtsi | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm/dts/k3-am65-iot2050-boot-image.dtsi +2 -2
index f49d6f262f2..b3d64485249 100644
@@ -208,7 +208,7 @@
 			fit,fdt-list-val = "ti/k3-am6528-iot2050-basic", "ti/k3-am6548-iot2050-advanced";
 
 			configurations {
-				default = "ti/k3-am6528-iot2050-basic";
+				default = "config-1";
 				@config-SEQ {
 					loadables =
 #ifdef CONFIG_WDT_K3_RTI_FW_FILE
@@ -265,7 +265,7 @@
 			};
 
 			configurations {
-				default = "ti/k3-am6528-iot2050-basic-pg2";
+				default = "config-1";
 				@config-SEQ {
 					loadables =
 #ifdef CONFIG_WDT_K3_RTI_FW_FILE
Signature · 1 line
2.43.0
#7 lore raw

PATCH v2 2/3 tools: fit_image: validate existence of default configuration node

In reply to Aristo Chen

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.

---
 tools/fit_image.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
tools/fit_image.c +10 -0
index 8717dc9a3b1..8a1f6c185dd 100644
@@ -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);
 
Signature · 1 line
2.43.0
#8 lore raw

PATCH v2 3/3 test: fit: add test case for invalid default configuration reference

In reply to Aristo Chen

Recent changes to mkimage introduced a validation step to ensure that the 'default' property under the /configurations node in a FIT image references a valid configuration subnode. If the referenced node is missing, mkimage will now return an error.

This patch adds a Python test case to verify that mkimage correctly fails when the 'default' configuration does not exist. The test creates a minimal ITS with an invalid default reference and checks that mkimage produces the expected error message.

---
 test/py/tests/test_fit_mkimage_validate.py | 45 ++++++++++++++++++++++
 1 file changed, 45 insertions(+)
test/py/tests/test_fit_mkimage_validate.py +45 -0
index af56f08ca10..ef974c8c762 100644
@@ -7,6 +7,7 @@ import os
 import subprocess
 import pytest
 import fit_util
+import re
 
 @pytest.mark.boardspec('sandbox')
 @pytest.mark.requiredtool('dtc')
@@ -56,3 +57,47 @@ def test_fit_invalid_image_reference(ubman):
     assert result.returncode != 0, "mkimage should fail due to missing image reference"
     assert "references undefined image 'notexist'" in result.stderr
 
+def test_fit_invalid_default_config(ubman):
+    """Test that mkimage fails when default config is missing"""
+
+    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 default config
+    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@2 {
+            kernel = "kernel@1";
+        };
+    };
+};
+'''
+
+    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 default config"
+    assert re.search(r"Default configuration '.*' not found under /configurations", result.stderr)
Signature · 1 line
2.43.0
#9 lore raw
In reply to Aristo Chen
Quoted 6 lines · Aristo Chen

This patch series introduces a validation step in mkimage to ensure that the default property under the /configurations node in a FIT image references a valid subnode. If the referenced node does not exist, mkimage now prints an error and fails early. This helps prevent runtime failures when U-Boot attempts to boot using an undefined configuration.

Quoted 7 lines

The first patch implements the validation logic in fit_image.c. The second patch fixes an invalid default configuration reference exposed by this new check in the k3-am65-iot2050-boot-image.dtsi. The final patch adds a test case to verify that mkimage correctly fails when an invalid default configuration is present in the ITS file.

[...]

Applied to u-boot/master, thanks!

[1/3] arm: k3-am65-iot2050: Fix invalid default configuration reference

      commit: f7b03695d46d7301fe78eed0fe8f8df9c08c33a4
[2/3] tools: fit_image: validate existence of default configuration node
      commit: edb4bf38688bb232ba0739585693aa94be5246f5
[3/3] test: fit: add test case for invalid default configuration reference
      commit: 93d09d3bd8ea941eff860443db2d8628cdbfe7e8
Signature · 1 line
Tom