Skip to contentSkip to conversation

mkimage: detect FIT image load address overlaps

PATCH In review Aristo Chen via U-Boot 3 participants 12 messages Jul 31 – Aug 14 Arm (32-bit)

lore
Share & tools
lore
#0 lore raw

v4 cover mkimage: detect FIT image load address overlaps

This series brings back the FIT load address overlap detection that was applied to next in September 2025 and reverted a day later in commit e482fdbbca93 ("Revert "Merge patch series "mkimage: Detect FIT image load address overlaps and fix related test/DTS issues""").

The v2 revert had two causes. On TI AM62x family boards the tispl FIT image references the mutually exclusive tifsstub variants at a single shared load address, and v2 tried to satisfy the checker by moving the variants 64 KiB apart. Neha had warned in the v1 review that this address is fixed by the platform and that moving the images would break tifsstub selection, and that feedback was regrettably still unaddressed when the series was applied. Nishanth then hit exactly this class of failure in the K3 upstream boot build with real firmware binaries, where am62px_evm, a board v2 had not even touched, failed the new check on tifsstub-hs and tifsstub-fs sharing 0x9ca00000. Separately, E Shattow reported an overlap on the StarFive VisionFive 2, which we later narrowed down to OpenSBI fw_payload.bin having been passed to the build instead of the documented fw_dynamic.bin. With fw_dynamic.bin the board has no overlap, as confirmed on the list in January 2026.

Since then the structural fix for the tifsstub case has landed. The series merged as commit 4e7a9bb0885e ("Merge patch series "arm: k3:
replace tifsstub runtime filter with per-state FIT configurations"") gives each K3 security state its own FIT configuration referencing only the matching tifsstub variant, so a per configuration overlap check sees no conflict while the variants keep their required common load address. That series was written precisely to unblock this one. The underlying semantics, that overlap is a property of a single configuration and that images referenced by different configurations never coexist in memory, were discussed with the FIT spec folks in flat-image-tree issue #32 [1].

The check itself is unchanged in spirit: for every configuration, collect the load regions of all referenced images that have both a load address and data, and fail the build if any two regions within that configuration intersect. Images referenced only by different configurations may freely share addresses.

Verification done for this version:

Running the new mkimage in reprocess mode over every FIT produced by current master builds of am62x_evm, verdin-am62 and phycore_am62x (A53 and R5 each) flags exactly one problem: the phycore u-boot FIT, where the four SPL devicetree overlays are loaded simultaneously from one configuration but are spaced only 4 KiB apart while each packaged image measures 5.9 to 6.1 KiB including its ti-secure certificate. That is a real overlap shipping today and patch 4 widens the spacing. All tispl FITs with the per-state tifsstub configurations pass.

buildman with binman missing blob handling, matching CI, builds all of phycore_am62x, phycore_am62ax, phycore_am64x, am62x_evm, am62ax_evm, am62px_evm, am64x_evm, verdin-am62, verdin-am62p and am62x_beagleplay (A53 and R5 each) plus starfive_visionfive2 with the check active, since binman invokes the freshly built mkimage during these builds. starfive_visionfive2 was additionally built with a real OpenSBI 1.7 fw_dynamic.bin passed via OPENSBI and completes cleanly.

The binman functional test suite shows no new failures compared to master in the same environment. The nine tests whose fixtures are touched by patches 1 to 3, including the OpenSSL engine and PKCS11 signing tests that only run when softhsm2 and opensc are available, all pass. The mkimage validation pytests, including the two new ones, pass against a sandbox build.

Changes in v4:
- collect the review and test tags from Simon and Wadim
- patch 3: reword the commit message into imperative mood and add a comment in elf_sections_tee.lds noting that it mirrors elf_sections.lds at a higher base, so the two stay in sync (Simon)
- patch 6: also assert that the configuration name appears in the overlap error message (Simon)
- patch 7: add blank lines around the command examples so the generated documentation renders each one on its own line, and note that the overlap check compares packaged data sizes and so assumes uncompressed images (Simon)

Changes in v3:
- rebase on master, on top of the per-state tifsstub configuration series
- drop the k3-am6xx tifsstub load address changes, obsolete after the per-state configuration series
- add a patch widening the phyCORE SPL overlay slot spacing, a real overlap the checker found (see above)
- extend the binman fixture fixes to the signing fixtures added since v2 (OpenSSL engine, PKCS11, multiple key paths, key name hint directory); their tests only run where the signing tools exist, so local testing without those tools missed them and GitLab CI caught them
- drop the "not able to get load" warning printed for every image without a load address, it was noise in every build log
- name the configuration in the overlap error message, matching the neighbouring reference validation messages
- move the test into the existing test_fit_mkimage_validate.py and add a companion test asserting that images may share a load address when no single configuration references both
- move the fit,load documentation into the binman fit etype docstring as Jonas asked for in v2; entries.rst is generated by Sphinx at doc build time since commit 090a7eb9cf36 ("binman: Remove pre-generated entries.rst and bintools.rst"), so the note can only live there now. Simon gave a Reviewed-by in v2 conditional on exactly this move, but given how long ago that was and how much the patch changed shape, I have not carried the tag and would welcome a fresh look
- drop the review tags collected on the v1 posting last year for the binman fixture patches for the same reason, only Dhruva's tag on the unchanged one line typo patch is kept
- collect regions with a dynamically grown array shared across configurations instead of per configuration allocations

[1] https://github.com/open-source-firmware/flat-image-tree/issues/32

Link to v2: https://lore.kernel.org/u-boot/[email protected]/
Link to the revert: https://lore.kernel.org/u-boot/20250924135139.GH197373@bill-the-cat/

Aristo Chen (7):
binman: Fix typo for the test case name
binman: Fix FIT image overlap issues
binman: Fix FIT image overlap issues for testFitSplitElf
arm: dts: k3: phycore: widen SPL overlay load address spacing
tools: mkimage: detect overlapping load regions in FIT configurations
test: fit: cover mkimage load address overlap detection
binman: fit: document how ELF load addresses are determined

 arch/arm/dts/k3-am625-phycore-som-binman.dtsi |   6 +-
 arch/arm/dts/k3-am62a-phycore-som-binman.dtsi |   6 +-
 arch/arm/dts/k3-am642-phycore-som-binman.dtsi |   6 +-
 test/py/tests/test_fit_mkimage_validate.py    | 136 ++++++++++++++++++
 tools/binman/etype/fit.py                     |  26 ++++
 tools/binman/ftest.py                         |   4 +-
 tools/binman/test/Makefile                    |   8 +-
 tools/binman/test/elf_sections_tee.c          |   1 +
 tools/binman/test/elf_sections_tee.lds        |  35 +++++
 tools/binman/test/fit/firmware_loadables.dts  |   4 +-
 .../test/fit/key_name_hint_dir_signature.dts  |   4 +-
 tools/binman/test/fit/signature.dts           |   4 +-
 tools/binman/test/fit/signature_engine.dts    |   4 +-
 .../test/fit/signature_engine_encrypt.dts     |   4 +-
 .../test/fit/signature_engine_pkcs11.dts      |   4 +-
 .../fit/signature_engine_pkcs11_object.dts    |   4 +-
 tools/binman/test/fit/signature_multi_key.dts |   4 +-
 tools/binman/test/fit/signature_no_nodes.dts  |   4 +-
 tools/fit_image.c                             |  99 +++++++++++++
 tools/mkimage.c                               |   3 +-
 20 files changed, 334 insertions(+), 32 deletions(-)
 create mode 120000 tools/binman/test/elf_sections_tee.c
 create mode 100644 tools/binman/test/elf_sections_tee.lds
Signature · 1 line
2.43.0
#1 lore raw

PATCH v4 1/7 binman: Fix typo for the test case name

Fix typo from Singature to Signature

---
 tools/binman/ftest.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/binman/ftest.py +1 -1
index 9553eb6b736..b5e56707c83 100644
@@ -8466,7 +8466,7 @@ fdt         fdtmap                Extract the devicetree blob from the fdtmap
             'Node \'/binman/fit\': multiple key paths found',
             str(e.exception))
 
-    def testFitSignNoSingatureNodes(self):
+    def testFitSignNoSignatureNodes(self):
         """Test that fit,sign doens't raise error if no signature nodes found"""
         if not elf.ELF_TOOLS:
             self.skipTest('Python elftools not available')
Signature · 1 line
2.43.0
#2 lore raw

PATCH v4 2/7 binman: Fix FIT image overlap issues

In reply to Aristo Chen via U-Boot

Several binman test fixtures describe FIT images whose configuration references both a u-boot firmware image loaded at address 0x0 with a size of 0x2e bytes and a split-elf atf image whose first segment is loaded at 0x10, so the two images overlap in memory. The upcoming mkimage load address overlap check refuses to build such images, which makes the tests that run these fixtures through mkimage fail.

Move the u-boot load and entry addresses to 0x2000, clear of the atf segments taken from elf_sections.lds, in the fixtures used by testFitFirmwareLoadables, testFitSignSimple, testFitSignNoSignatureNodes, testFitSignEngineSimple, testFitSignEncryptEngine, testFitSignPKCS11Simple, testFitSignPKCS11Object, testFitSignMultipleKeyPaths and testKeyNameHintIsPathSimpleFit.

---
 tools/binman/test/fit/firmware_loadables.dts             | 4 ++--
 tools/binman/test/fit/key_name_hint_dir_signature.dts    | 4 ++--
 tools/binman/test/fit/signature.dts                      | 4 ++--
 tools/binman/test/fit/signature_engine.dts               | 4 ++--
 tools/binman/test/fit/signature_engine_encrypt.dts       | 4 ++--
 tools/binman/test/fit/signature_engine_pkcs11.dts        | 4 ++--
 tools/binman/test/fit/signature_engine_pkcs11_object.dts | 4 ++--
 tools/binman/test/fit/signature_multi_key.dts            | 4 ++--
 tools/binman/test/fit/signature_no_nodes.dts             | 4 ++--
 9 files changed, 18 insertions(+), 18 deletions(-)
tools/binman/test/fit/firmware_loadables.dts +2 -2
index 2f79cdc9bb8..d344036a11a 100644
@@ -19,8 +19,8 @@
 					arch = "arm64";
 					os = "u-boot";
 					compression = "none";
-					load = <0x00000000>;
-					entry = <0x00000000>;
+					load = <0x00002000>;
+					entry = <0x00002000>;
 
 					u-boot-nodtb {
 					};
tools/binman/test/fit/key_name_hint_dir_signature.dts +2 -2
index 96e2126dadb..33b4ff8ea02 100644
@@ -20,8 +20,8 @@
 					arch = "arm64";
 					os = "u-boot";
 					compression = "none";
-					load = <0x00000000>;
-					entry = <0x00000000>;
+					load = <0x00002000>;
+					entry = <0x00002000>;
 
 					u-boot-nodtb {
 					};
tools/binman/test/fit/signature.dts +2 -2
index 9dce62e52de..1c25d52cba4 100644
@@ -20,8 +20,8 @@
 					arch = "arm64";
 					os = "u-boot";
 					compression = "none";
-					load = <0x00000000>;
-					entry = <0x00000000>;
+					load = <0x00002000>;
+					entry = <0x00002000>;
 
 					u-boot-nodtb {
 					};
tools/binman/test/fit/signature_engine.dts +2 -2
index fd374e0edd2..ba4df53a0c0 100644
@@ -21,8 +21,8 @@
 					arch = "arm64";
 					os = "u-boot";
 					compression = "none";
-					load = <0x00000000>;
-					entry = <0x00000000>;
+					load = <0x00002000>;
+					entry = <0x00002000>;
 
 					u-boot-nodtb {
 					};
tools/binman/test/fit/signature_engine_encrypt.dts +2 -2
index fbcde342c65..40090431459 100644
@@ -22,8 +22,8 @@
 					arch = "arm64";
 					os = "u-boot";
 					compression = "none";
-					load = <0x00000000>;
-					entry = <0x00000000>;
+					load = <0x00002000>;
+					entry = <0x00002000>;
 
 					u-boot-nodtb {
 					};
tools/binman/test/fit/signature_engine_pkcs11.dts +2 -2
index 60ba04c13d4..8d86c994afe 100644
@@ -21,8 +21,8 @@
 					arch = "arm64";
 					os = "u-boot";
 					compression = "none";
-					load = <0x00000000>;
-					entry = <0x00000000>;
+					load = <0x00002000>;
+					entry = <0x00002000>;
 
 					u-boot-nodtb {
 					};
tools/binman/test/fit/signature_engine_pkcs11_object.dts +2 -2
index 5226ab4c6cf..48cd963476d 100644
@@ -22,8 +22,8 @@
 					arch = "arm64";
 					os = "u-boot";
 					compression = "none";
-					load = <0x00000000>;
-					entry = <0x00000000>;
+					load = <0x00002000>;
+					entry = <0x00002000>;
 
 					u-boot-nodtb {
 					};
tools/binman/test/fit/signature_multi_key.dts +2 -2
index 77bec8df1e5..3b8da190b42 100644
@@ -20,8 +20,8 @@
 					arch = "arm64";
 					os = "u-boot";
 					compression = "none";
-					load = <0x00000000>;
-					entry = <0x00000000>;
+					load = <0x00002000>;
+					entry = <0x00002000>;
 
 					u-boot-nodtb {
 					};
tools/binman/test/fit/signature_no_nodes.dts +2 -2
index 267105d0f68..2ac600b1c70 100644
@@ -20,8 +20,8 @@
 					arch = "arm64";
 					os = "u-boot";
 					compression = "none";
-					load = <0x00000000>;
-					entry = <0x00000000>;
+					load = <0x00002000>;
+					entry = <0x00002000>;
 
 					u-boot-nodtb {
 					};
Signature · 1 line
2.43.0
#3 lore raw

PATCH v4 3/7 binman: Fix FIT image overlap issues for testFitSplitElf

In reply to Aristo Chen via U-Boot

testFitSplitElf builds both the ATF and TEE test images from the same elf_sections binary, so the split-elf nodes generated for the two images end up with identical load addresses and overlap in memory. An upcoming commit teaches mkimage to validate whether the memory regions referenced by a configuration overlap, which makes this test fail.

Update the test to use a non-overlapping memory layout so the two images no longer collide:

1. Add elf_sections_tee.lds, which mirrors elf_sections.lds with the section addresses shifted up by 0x100000 for the TEE image.
2. Build an elf_sections_tee binary from it in the test Makefile.
3. Update ftest.py to use the separate ELF file for the TEE component in split-elf operations.

---
 tools/binman/ftest.py                  |  2 +-
 tools/binman/test/Makefile             |  8 ++++--
 tools/binman/test/elf_sections_tee.c   |  1 +
 tools/binman/test/elf_sections_tee.lds | 35 ++++++++++++++++++++++++++
 4 files changed, 43 insertions(+), 3 deletions(-)
 create mode 120000 tools/binman/test/elf_sections_tee.c
 create mode 100644 tools/binman/test/elf_sections_tee.lds
tools/binman/ftest.py +1 -1
index b5e56707c83..3c391361a6a 100644
@@ -253,7 +253,7 @@ class TestFunctional(unittest.TestCase):
         TestFunctional._MakeInputFile('bl31.elf',
             tools.read_file(cls.ElfTestFile('elf_sections')))
         TestFunctional.tee_elf_path = TestFunctional._MakeInputFile('tee.elf',
-            tools.read_file(cls.ElfTestFile('elf_sections')))
+            tools.read_file(cls.ElfTestFile('elf_sections_tee')))
 
         # Newer OP_TEE file in v1 binary format
         cls.make_tee_bin('tee.bin')
tools/binman/test/Makefile +6 -2
index 6b42db6559f..783bb4f62cd 100644
@@ -30,13 +30,14 @@ LDS_BINMAN_BAD := -T $(SRC)u_boot_binman_syms_bad.lds
 LDS_BINMAN_X86 := -T $(SRC)u_boot_binman_syms_x86.lds
 LDS_BINMAN_EMBED := -T $(SRC)u_boot_binman_embed.lds
 LDS_EFL_SECTIONS := -T $(SRC)elf_sections.lds
+LDS_EFL_SECTIONS_TEE := -T $(SRC)elf_sections_tee.lds
 LDS_BLOB := -T $(SRC)blob_syms.lds
 
 TARGETS = u_boot_ucode_ptr u_boot_no_ucode_ptr bss_data bss_data_zero \
 	u_boot_binman_syms u_boot_binman_syms.bin u_boot_binman_syms_bad \
 	u_boot_binman_syms_size u_boot_binman_syms_x86 embed_data \
-	u_boot_binman_embed u_boot_binman_embed_sm elf_sections blob_syms.bin \
-	dummy-rsa-engine.so
+	u_boot_binman_embed u_boot_binman_embed_sm elf_sections \
+	elf_sections_tee blob_syms.bin dummy-rsa-engine.so
 
 all: $(TARGETS)
 
@@ -85,6 +86,9 @@ blob_syms: blob_syms.c
 elf_sections: CFLAGS += $(LDS_EFL_SECTIONS)
 elf_sections: elf_sections.c
 
+elf_sections_tee: CFLAGS += $(LDS_EFL_SECTIONS_TEE)
+elf_sections_tee: elf_sections_tee.c
+
 dummy-rsa-engine.so: $(SRC)fit/dummy-rsa-engine.c
 	$(CC) -fPIC -shared -lcrypto -lssl -o $@ $<
 
tools/binman/test/elf_sections_tee.c new file +1 -0
new file mode 120000
index 00000000000..01b200a365e
@@ -0,0 +1 @@
+elf_sections.c
\ No newline at end of file
tools/binman/test/elf_sections_tee.lds new file +35 -0
new file mode 100644
index 00000000000..6074b45a1f9
@@ -0,0 +1,35 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (c) 2016 Google, Inc
+ * Copyright (c) 2026 Canonical Ltd.
+ *
+ * Mirrors elf_sections.lds with the addresses shifted up by 0x100000 so
+ * the TEE image does not overlap the ATF image; keep the two in sync.
+ */
+
+OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386")
+OUTPUT_ARCH(i386)
+ENTRY(_start)
+
+SECTIONS
+{
+	. = 0x00100010;
+	_start = .;
+
+	. = ALIGN(4);
+	.text :
+	{
+		*(.text*)
+	}
+
+	. = 0x00101000;
+	.sram :
+	{
+		*(.sram*)
+	}
+
+	/DISCARD/ : {
+		*(.comment)
+		*(.dyn*)
+	}
+}
Signature · 1 line
2.43.0
Reviewed-by on v4 3/7
#4 lore raw

Re: [PATCH v4 3/7] binman: Fix FIT image overlap issues for testFitSplitElf

Quoted 18 lines · Aristo Chen

binman: Fix FIT image overlap issues for testFitSplitElf

testFitSplitElf builds both the ATF and TEE test images from the same elf_sections binary, so the split-elf nodes generated for the two images end up with identical load addresses and overlap in memory. An upcoming commit teaches mkimage to validate whether the memory regions referenced by a configuration overlap, which makes this test fail.

Update the test to use a non-overlapping memory layout so the two images no longer collide:

1. Add elf_sections_tee.lds, which mirrors elf_sections.lds with the section addresses shifted up by 0x100000 for the TEE image.
2. Build an elf_sections_tee binary from it in the test Makefile.
3. Update ftest.py to use the separate ELF file for the TEE component in split-elf operations.

Quoted 7 lines

tools/binman/ftest.py | 2 +-

 tools/binman/test/Makefile             |  8 ++++++--
 tools/binman/test/elf_sections_tee.c   |  1 +
 tools/binman/test/elf_sections_tee.lds | 35 ++++++++++++++++++++++++++++++++++
 4 files changed, 43 insertions(+), 3 deletions(-)
#5 lore raw

PATCH v4 4/7 arm: dts: k3: phycore: widen SPL overlay load address spacing

In reply to Aristo Chen via U-Boot

The phyCORE AM62x, AM62Ax and AM64x u-boot FIT images carry four devicetree overlays (som-no-rtc, som-no-spi, som-no-eth, som-qspi) that SPL loads simultaneously as loadables of the same configuration. Their load addresses are spaced only 4 KiB apart, but each packaged image is larger than that. Measured on a phycore_am62x build, every overlay is between 6035 and 6163 bytes including the prepended ti-secure certificate, and the raw dtbo that remains in memory after the certificate is stripped is still around 4.2 to 4.4 KiB.

Loading the images back to back therefore overwrites the tail of the previously loaded overlay, so by the time the board code applies the overlays from the recorded /fit-images addresses the earlier ones are already corrupted.

Space the overlay slots 16 KiB apart so each image has comfortable headroom. The addresses are only consumed through the /fit-images records that SPL writes while loading the images, so no other code needs to change. This also allows the upcoming mkimage load address overlap check to pass for these boards.

---
 arch/arm/dts/k3-am625-phycore-som-binman.dtsi | 6 +++---
 arch/arm/dts/k3-am62a-phycore-som-binman.dtsi | 6 +++---
 arch/arm/dts/k3-am642-phycore-som-binman.dtsi | 6 +++---
 3 files changed, 9 insertions(+), 9 deletions(-)
arch/arm/dts/k3-am625-phycore-som-binman.dtsi +3 -3
index 6d57a5d9ffa..d0eaa7dd992 100644
@@ -368,7 +368,7 @@
 					description = "k3-am6xx-phycore-disable-spi-nor";
 					type = "flat_dt";
 					compression = "none";
-					load = <0x8F001000>;
+					load = <0x8F004000>;
 					arch = "arm";
 					ti-secure {
 						content = <&am6xx_phycore_disable_spi_not_dtbo>;
@@ -383,7 +383,7 @@
 					description = "k3-am6xx-phycore-disable-eth-phy";
 					type = "flat_dt";
 					compression = "none";
-					load = <0x8F002000>;
+					load = <0x8F008000>;
 					arch = "arm";
 					ti-secure {
 						content = <&am6xx_phycore_disable_eth_phy_dtbo>;
@@ -398,7 +398,7 @@
 					description = "k3-am6xx-phycore-qspi-nor";
 					type = "flat_dt";
 					compression = "none";
-					load = <0x8F003000>;
+					load = <0x8F00C000>;
 					arch = "arm";
 					ti-secure {
 						content = <&am6xx_phycore_disable_qspi_nor_dtbo>;
arch/arm/dts/k3-am62a-phycore-som-binman.dtsi +3 -3
index cdc9a100a04..2c98e16b00b 100644
@@ -295,7 +295,7 @@
 					description = "k3-am6xx-phycore-disable-spi-nor";
 					type = "flat_dt";
 					compression = "none";
-					load = <0x8F001000>;
+					load = <0x8F004000>;
 					arch = "arm";
 					ti-secure {
 						content = <&am6xx_phycore_disable_spi_not_dtbo>;
@@ -310,7 +310,7 @@
 					description = "k3-am6xx-phycore-disable-eth-phy";
 					type = "flat_dt";
 					compression = "none";
-					load = <0x8F002000>;
+					load = <0x8F008000>;
 					arch = "arm";
 					ti-secure {
 						content = <&am6xx_phycore_disable_eth_phy_dtbo>;
@@ -325,7 +325,7 @@
 					description = "k3-am6xx-phycore-qspi-nor";
 					type = "flat_dt";
 					compression = "none";
-					load = <0x8F003000>;
+					load = <0x8F00C000>;
 					arch = "arm";
 					ti-secure {
 						content = <&am6xx_phycore_disable_qspi_nor_dtbo>;
arch/arm/dts/k3-am642-phycore-som-binman.dtsi +3 -3
index 07cb79fd04a..64679195e72 100644
@@ -402,7 +402,7 @@
 					description = "k3-am6xx-phycore-disable-spi-nor";
 					type = "flat_dt";
 					compression = "none";
-					load = <0x8F001000>;
+					load = <0x8F004000>;
 					arch = "arm";
 					ti-secure {
 						content = <&am6xx_phycore_disable_spi_not_dtbo>;
@@ -417,7 +417,7 @@
 					description = "k3-am6xx-phycore-disable-eth-phy";
 					type = "flat_dt";
 					compression = "none";
-					load = <0x8F002000>;
+					load = <0x8F008000>;
 					arch = "arm";
 					ti-secure {
 						content = <&am6xx_phycore_disable_eth_phy_dtbo>;
@@ -432,7 +432,7 @@
 					description = "k3-am6xx-phycore-qspi-nor";
 					type = "flat_dt";
 					compression = "none";
-					load = <0x8F003000>;
+					load = <0x8F00C000>;
 					arch = "arm";
 					ti-secure {
 						content = <&am6xx_phycore_disable_qspi_nor_dtbo>;
Signature · 1 line
2.43.0
#6 lore raw

PATCH v4 5/7 tools: mkimage: detect overlapping load regions in FIT configurations

In reply to Aristo Chen via U-Boot

Add a validation step to mkimage that checks, for every configuration of a FIT image, whether the images referenced by that configuration declare overlapping load regions. Images that are loaded together must not share memory, and such conflicts currently go unnoticed until the resulting image corrupts memory at runtime.

The check is strictly per configuration. Images that share a load address while being referenced by different configurations are not reported, because only one configuration is selected at boot. This matches the layout used by the TI K3 tispl images since commit c85bf61b14f9 ("arm: k3: select tifsstub via board_fit_config_name_match"), where the mutually exclusive tifsstub variants moved into per security state configurations precisely so that static tooling can reason about each configuration on its own.

Images without a load address or without data are skipped, since nothing is copied anywhere for them. Compared to the previously reverted version of this check, the missing load address case no longer prints a warning, as FDT images routinely have no load address and the warning only added noise to every build. An image referenced through several properties of the same configuration, for example listed in both firmware and loadables, is only counted once.

When an overlap is found mkimage prints the configuration name together with both image names and their regions, then fails with FDT_ERR_BADSTRUCTURE. Teach main() to exit cleanly for that value the same way it already does for FDT_ERR_NOTFOUND, since the error message has already been printed.

---
 tools/fit_image.c | 99 +++++++++++++++++++++++++++++++++++++++++++++++
 tools/mkimage.c   |  3 +-
 2 files changed, 101 insertions(+), 1 deletion(-)
tools/fit_image.c +99 -0
index 7e59bc43b77..f0fe68894d6 100644
@@ -24,6 +24,18 @@
 
 static struct legacy_img_hdr header;
 
+struct fit_region {
+	ulong load;
+	ulong size;
+	const char *name;
+};
+
+static bool fit_regions_overlap(const struct fit_region *a,
+				const struct fit_region *b)
+{
+	return a->load < b->load + b->size && b->load < a->load + a->size;
+}
+
 static int fit_estimate_hash_sig_size(struct image_tool_params *params, const char *fname)
 {
 	bool signing = IMAGE_ENABLE_SIGN &&
@@ -905,6 +917,8 @@ static int fit_import_data(struct image_tool_params *params, const char *fname)
 	int images;
 	int confs;
 	int node;
+	struct fit_region *regions = NULL;
+	unsigned int regions_alloc = 0;
 
 	fd = mmap_fdt(params->cmdname, fname, 0, &old_fdt, &sbuf, false, false);
 	if (fd < 0)
@@ -1009,6 +1023,7 @@ static int fit_import_data(struct image_tool_params *params, const char *fname)
 
 	fdt_for_each_subnode(node, fdt, confs) {
 		const char *conf_name = fdt_get_name(fdt, node, NULL);
+		unsigned int reg_count = 0;
 
 		for (int i = 0; i < ARRAY_SIZE(props); i++) {
 			int count = fdt_stringlist_count(fdt, node, props[i]);
@@ -1017,6 +1032,11 @@ static int fit_import_data(struct image_tool_params *params, const char *fname)
 				continue;
 
 			for (int j = 0; j < count; j++) {
+				const char *img_data;
+				ulong img_load;
+				int img_size;
+				unsigned int k;
+
 				const char *img_name =
 					fdt_stringlist_get(fdt, node, props[i], j, NULL);
 				if (!img_name || !*img_name)
@@ -1031,10 +1051,88 @@ static int fit_import_data(struct image_tool_params *params, const char *fname)
 					ret = FDT_ERR_NOTFOUND;
 					goto err_munmap;
 				}
+
+				/*
+				 * Collect the memory region the image is
+				 * loaded to. Images without a load address or
+				 * without data are never copied anywhere, so
+				 * they cannot conflict.
+				 */
+				if (fit_image_get_load(fdt, img, &img_load))
+					continue;
+				img_data = fdt_getprop(fdt, img, FIT_DATA_PROP,
+						       &img_size);
+				if (!img_data || img_size <= 0)
+					continue;
+
+				/*
+				 * A configuration may reference one image
+				 * through several properties, for example
+				 * both "firmware" and "loadables". Count
+				 * each image only once.
+				 */
+				for (k = 0; k < reg_count; k++) {
+					if (!strcmp(regions[k].name, img_name))
+						break;
+				}
+				if (k < reg_count)
+					continue;
+
+				if (reg_count == regions_alloc) {
+					struct fit_region *tmp;
+
+					regions_alloc = regions_alloc ?
+						regions_alloc * 2 : 8;
+					tmp = realloc(regions, regions_alloc *
+						      sizeof(*regions));
+					if (!tmp) {
+						fprintf(stderr,
+							"%s: Out of memory for %u load regions\n",
+							params->cmdname,
+							regions_alloc);
+						ret = -ENOMEM;
+						goto err_munmap;
+					}
+					regions = tmp;
+				}
+
+				regions[reg_count].load = img_load;
+				regions[reg_count].size = img_size;
+				regions[reg_count].name = img_name;
+				reg_count++;
+			}
+		}
+
+		/*
+		 * All images referenced by one configuration are loaded
+		 * together, so no two of them may claim overlapping memory
+		 * regions. Images sharing a load address across different
+		 * configurations are fine, since only one configuration is
+		 * selected at runtime.
+		 */
+		for (unsigned int i = 0; i < reg_count; i++) {
+			for (unsigned int j = i + 1; j < reg_count; j++) {
+				if (!fit_regions_overlap(&regions[i],
+							 &regions[j]))
+					continue;
+				fprintf(stderr,
+					"Error: configuration '%s' has overlapping load regions:\n"
+					"  - %s: [0x%lx - 0x%lx]\n"
+					"  - %s: [0x%lx - 0x%lx]\n",
+					conf_name,
+					regions[i].name, regions[i].load,
+					regions[i].load + regions[i].size,
+					regions[j].name, regions[j].load,
+					regions[j].load + regions[j].size);
+				ret = FDT_ERR_BADSTRUCTURE;
+				goto err_munmap;
 			}
 		}
 	}
 
+	free(regions);
+	regions = NULL;
+
 	munmap(old_fdt, sbuf.st_size);
 
 	/* Close the old fd so we can re-use it. */
@@ -1067,6 +1165,7 @@ static int fit_import_data(struct image_tool_params *params, const char *fname)
 err_munmap:
 	munmap(old_fdt, sbuf.st_size);
 err:
+	free(regions);
 	free(fdt);
 	close(fd);
 	return ret;
tools/mkimage.c +2 -1
index 3c43962807d..6b3fd60adbf 100644
@@ -550,7 +550,8 @@ int main(int argc, char **argv)
 			retval = tparams->fflag_handle(&params);
 
 		if (retval != EXIT_SUCCESS) {
-			if (retval == FDT_ERR_NOTFOUND) {
+			if (retval == FDT_ERR_NOTFOUND ||
+			    retval == FDT_ERR_BADSTRUCTURE) {
 				// Already printed error, exit cleanly
 				exit(EXIT_FAILURE);
 			}
Signature · 1 line
2.43.0
#7 lore raw

PATCH v4 6/7 test: fit: cover mkimage load address overlap detection

In reply to Aristo Chen via U-Boot

Add a test that mkimage rejects a FIT image whose configuration references a kernel and an FDT with the same load address, and that the error message names the offending configuration and images.

Also add a companion test for the intended escape hatch: two images may use the same load address as long as no single configuration references both of them. Only one configuration is selected at runtime, so such images never coexist in memory. This mirrors the TI K3 tispl layout after commit c85bf61b14f9 ("arm: k3: select tifsstub via board_fit_config_name_match"), where each security state has its own configuration and all tifsstub variants share one load address.

---
 test/py/tests/test_fit_mkimage_validate.py | 136 +++++++++++++++++++++
 1 file changed, 136 insertions(+)
test/py/tests/test_fit_mkimage_validate.py +136 -0
index 5922f071dd8..7c9213b2796 100644
@@ -160,3 +160,139 @@ def test_fit_auto_basename_dotted_directory(ubman, dtb_relpath, expected_desc):
     assert desc == expected_desc, (
         f"Expected /images/fdt-1 description {expected_desc!r}, got {desc!r}"
     )
+
[email protected]('sandbox')
[email protected]('dtc')
+def test_fit_load_addr_overlap(ubman):
+    """Test that mkimage fails when images in one config overlap in memory"""
+
+    its_fname = fit_util.make_fname(ubman, "overlap.its")
+    itb_fname = fit_util.make_fname(ubman, "overlap.itb")
+    kernel = fit_util.make_kernel(ubman, 'kernel.bin', 'kernel')
+    fdt = fit_util.make_dtb(ubman, '''
+/dts-v1/;
+/ {
+    model = "Test FDT";
+    compatible = "test";
+};
+''', 'test')
+
+    # Write ITS with kernel and FDT sharing the same load address
+    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>;
+        };
+        fdt@1 {
+            description = "Test FDT";
+            data = /incbin/("test.dtb");
+            type = "flat_dt";
+            arch = "sandbox";
+            os = "linux";
+            compression = "none";
+            load = <0x40000>;
+            entry = <0x40000>;
+        };
+    };
+
+    configurations {
+        default = "conf@1";
+        conf@1 {
+            kernel = "kernel@1";
+            fdt = "fdt@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 memory overlap"
+    assert "has overlapping load regions" in result.stderr
+    # Check that it identifies the configuration and the specific
+    # overlapping components
+    assert "conf@1" in result.stderr
+    assert "kernel@1" in result.stderr and "fdt@1" in result.stderr
+
[email protected]('sandbox')
[email protected]('dtc')
+def test_fit_same_load_addr_different_configs(ubman):
+    """Test that images may share a load address across configurations
+
+    Only one configuration is selected at runtime, so images that are
+    referenced by different configurations never coexist in memory. This
+    mirrors the TI K3 tispl layout, where each security state has its own
+    configuration and all tifsstub variants use the same load address.
+    """
+
+    its_fname = fit_util.make_fname(ubman, "exclusive.its")
+    itb_fname = fit_util.make_fname(ubman, "exclusive.itb")
+    kernel = fit_util.make_kernel(ubman, 'kernel.bin', 'kernel')
+
+    its_text = '''
+/dts-v1/;
+
+/ {
+    images {
+        kernel@1 {
+            description = "Test Kernel HS";
+            data = /incbin/("kernel.bin");
+            type = "kernel";
+            arch = "sandbox";
+            os = "linux";
+            compression = "none";
+            load = <0x40000>;
+            entry = <0x40000>;
+        };
+        kernel@2 {
+            description = "Test Kernel GP";
+            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";
+        };
+        conf@2 {
+            kernel = "kernel@2";
+        };
+    };
+};
+'''
+
+    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, (
+        f"mkimage should accept same load address in different configs:\n"
+        f"stderr:\n{result.stderr}"
+    )
Signature · 1 line
2.43.0
Reviewed-by on v4 6/7
#8 lore raw

Re: [PATCH v4 6/7] test: fit: cover mkimage load address overlap detection

Quoted 14 lines · Aristo Chen

test: fit: cover mkimage load address overlap detection

Add a test that mkimage rejects a FIT image whose configuration references a kernel and an FDT with the same load address, and that the error message names the offending configuration and images.

Also add a companion test for the intended escape hatch: two images may use the same load address as long as no single configuration references both of them. Only one configuration is selected at runtime, so such images never coexist in memory. This mirrors the TI K3 tispl layout after commit c85bf61b14f9 ("arm: k3: select tifsstub via board_fit_config_name_match"), where each security state has its own configuration and all tifsstub variants share one load address.

Quoted 4 lines

test/py/tests/test_fit_mkimage_validate.py | 136 +++++++++++++++++++++++++++++

 1 file changed, 136 insertions(+)
#9 lore raw

PATCH v4 7/7 binman: fit: document how ELF load addresses are determined

In reply to Aristo Chen via U-Boot

The fit,load property confuses users because the load address is taken from the ELF file rather than being specified in the binman node. Document how to inspect an ELF file to find out where its segments will be loaded, using readelf, the linker script or objdump, and point at the elf_sections and elf_sections_tee test linker scripts as examples of two components placed to avoid overlapping memory. Also note that the mkimage load address overlap check works on packaged data sizes and therefore assumes uncompressed images.

Compared to the previously applied version of this change, the text now lives in the fit etype docstring. The entry documentation is produced from docstrings by the binman_docs Sphinx extension at documentation build time, so no pre-generated file needs updating.

---
 tools/binman/etype/fit.py | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
tools/binman/etype/fit.py +26 -0
index 32caa03a7e1..4657ed1fd76 100644
@@ -319,6 +319,32 @@ class Entry_fit(Entry_section):
             Generates a `load = <...>` property with the load address of the
             segment
 
+            Note: The load address comes from the ELF file's program headers.
+            To determine where an ELF file will be loaded, you can:
+
+            1. Use readelf to examine the program headers:
+
+               ``readelf -l your_elf_file.elf``
+
+               Look for the LOAD segments and their VirtAddr (Virtual Address)
+
+            2. Check the linker script (.lds file) used to build the ELF:
+               look for the `. = <address>;` statements which set the location
+               counter and determine load addresses for different sections
+
+            3. Use objdump to see section addresses:
+
+               ``objdump -h your_elf_file.elf``
+
+            For example, in binman tests, elf_sections.lds sets the ATF load
+            address to 0x00000010, while elf_sections_tee.lds sets the TEE
+            load address to 0x00100010 to avoid memory overlap conflicts.
+
+            Note that the mkimage load address overlap check compares the
+            packaged data size of each image, so it assumes uncompressed
+            images: a compressed image occupies more memory after
+            decompression than the check accounts for.
+
         fit,entry
             Generates a `entry = <...>` property with the entry address of the
             ELF. This is only produced for the first entry
Signature · 1 line
2.43.0
Reviewed-by on v4 7/7
#10 lore raw

Re: [PATCH v4 7/7] binman: fit: document how ELF load addresses are determined

Quoted 16 lines · Aristo Chen

binman: fit: document how ELF load addresses are determined

The fit,load property confuses users because the load address is taken from the ELF file rather than being specified in the binman node. Document how to inspect an ELF file to find out where its segments will be loaded, using readelf, the linker script or objdump, and point at the elf_sections and elf_sections_tee test linker scripts as examples of two components placed to avoid overlapping memory. Also note that the mkimage load address overlap check works on packaged data sizes and therefore assumes uncompressed images.

Compared to the previously applied version of this change, the text now lives in the fit etype docstring. The entry documentation is produced from docstrings by the binman_docs Sphinx extension at documentation build time, so no pre-generated file needs updating.

Quoted 4 lines

tools/binman/etype/fit.py | 26 ++++++++++++++++++++++++++

 1 file changed, 26 insertions(+)
#11 lore raw
In reply to Aristo Chen via U-Boot
Quoted 21 lines · Aristo Chen via U-Boot

This series brings back the FIT load address overlap detection that was applied to next in September 2025 and reverted a day later in commit e482fdbbca93 ("Revert "Merge patch series "mkimage: Detect FIT image load address overlaps and fix related test/DTS issues""").

The v2 revert had two causes. On TI AM62x family boards the tispl FIT image references the mutually exclusive tifsstub variants at a single shared load address, and v2 tried to satisfy the checker by moving the variants 64 KiB apart. Neha had warned in the v1 review that this address is fixed by the platform and that moving the images would break tifsstub selection, and that feedback was regrettably still unaddressed when the series was applied. Nishanth then hit exactly this class of failure in the K3 upstream boot build with real firmware binaries, where am62px_evm, a board v2 had not even touched, failed the new check on tifsstub-hs and tifsstub-fs sharing 0x9ca00000. Separately, E Shattow reported an overlap on the StarFive VisionFive 2, which we later narrowed down to OpenSBI fw_payload.bin having been passed to the build instead of the documented fw_dynamic.bin. With fw_dynamic.bin the board has no overlap, as confirmed on the list in January 2026.

Quoted 1 line

[...]

Applied to u-boot/next, thanks!

[1/7] binman: Fix typo for the test case name

      commit: 5d1aba89f305366dd1ee59c5fd00e69cc9517cb8
[2/7] binman: Fix FIT image overlap issues
      commit: 6ac5492d596dd28aa53c16106abae4a743cb5651
[3/7] binman: Fix FIT image overlap issues for testFitSplitElf
      commit: 4a65f3eb67f43201df5834dea776aec15b6b64f1
[4/7] arm: dts: k3: phycore: widen SPL overlay load address spacing
      commit: a3112b4fe4f827a76605828d0c20de4c3895468d
[5/7] tools: mkimage: detect overlapping load regions in FIT configurations
      commit: 21bb6417641b26bfc6738ff9cbf006a47d317c27
[6/7] test: fit: cover mkimage load address overlap detection
      commit: 8e14d88252313f24257adcb74b49285e811f7ef0
[7/7] binman: fit: document how ELF load addresses are determined
      commit: dbe1b57e16caa3587c14a4abcf63559a6833742a
Signature · 1 line
Tom