From 88392a59bf87bf2c1c5aedc0b76f459d702f71a7 Mon Sep 17 00:00:00 2001 From: Aristo Chen Date: Sun, 14 Sep 2025 10:59:26 +0000 Subject: [PATCH 1/7] binman: Fix typo for the test case name Fix typo from `Singature` to `Signature` Signed-off-by: Aristo Chen Reviewed-by: Dhruva Gole --- tools/binman/ftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index a90db3c9351..6ed8b8637cd 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -7986,7 +7986,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') From dade54edaff659c4ed6fc40db0b2dd446714c573 Mon Sep 17 00:00:00 2001 From: Aristo Chen Date: Sun, 14 Sep 2025 10:59:27 +0000 Subject: [PATCH 2/7] binman: Fix FIT image overlap issues Fix three binman tests that has memory region overlap issue, the test cases needed to be updated to use non-overlapping memory layouts. * Tests fixed: - testFitFirmwareLoadables - testFitSignSimple - testFitSignNoSignatureNodes * Changes made: Updated DTB test files to change U-Boot load addresses from 0x0 to 0x2000 to avoid overlapping with ATF in the 0x10-0xfc range: - 276_fit_firmware_loadables.dts - 340_fit_signature.dts - 342_fit_signature.dts An upcoming commit will validate if the memory region is overlapped Signed-off-by: Aristo Chen Reviewed-by: Neha Malcom Francis --- tools/binman/test/276_fit_firmware_loadables.dts | 4 ++-- tools/binman/test/340_fit_signature.dts | 4 ++-- tools/binman/test/342_fit_signature.dts | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tools/binman/test/276_fit_firmware_loadables.dts b/tools/binman/test/276_fit_firmware_loadables.dts index 2f79cdc9bb8..d344036a11a 100644 --- a/tools/binman/test/276_fit_firmware_loadables.dts +++ b/tools/binman/test/276_fit_firmware_loadables.dts @@ -19,8 +19,8 @@ arch = "arm64"; os = "u-boot"; compression = "none"; - load = <0x00000000>; - entry = <0x00000000>; + load = <0x00002000>; + entry = <0x00002000>; u-boot-nodtb { }; diff --git a/tools/binman/test/340_fit_signature.dts b/tools/binman/test/340_fit_signature.dts index 9dce62e52de..1c25d52cba4 100644 --- a/tools/binman/test/340_fit_signature.dts +++ b/tools/binman/test/340_fit_signature.dts @@ -20,8 +20,8 @@ arch = "arm64"; os = "u-boot"; compression = "none"; - load = <0x00000000>; - entry = <0x00000000>; + load = <0x00002000>; + entry = <0x00002000>; u-boot-nodtb { }; diff --git a/tools/binman/test/342_fit_signature.dts b/tools/binman/test/342_fit_signature.dts index 267105d0f68..2ac600b1c70 100644 --- a/tools/binman/test/342_fit_signature.dts +++ b/tools/binman/test/342_fit_signature.dts @@ -20,8 +20,8 @@ arch = "arm64"; os = "u-boot"; compression = "none"; - load = <0x00000000>; - entry = <0x00000000>; + load = <0x00002000>; + entry = <0x00002000>; u-boot-nodtb { }; From a06733fc83f07dd975a9e220a44392f3455c7c21 Mon Sep 17 00:00:00 2001 From: Aristo Chen Date: Sun, 14 Sep 2025 10:59:28 +0000 Subject: [PATCH 3/7] binman: Fix FIT image overlap issues for testFitSplitElf Fix one binman test that has memory region overlap issue, the test case needed to be updated to use non-overlapping memory layouts. * Tests fixed: - testFitSplitElf * Changes made: 1. ELF section layouts: added elf_sections_tee.lds with different address for TEE to avoid overlap with ATF address defined in elf_sections.lds 2. Makefile to properly build elf_sections_tee binary 3. Updat ftest.py to use separate ELF files for TEE vs ATF components in split-elf operations. An upcoming commit will validate if the memory region is overlapped Signed-off-by: Aristo Chen --- tools/binman/ftest.py | 2 +- tools/binman/test/Makefile | 6 ++++- tools/binman/test/elf_sections_tee.c | 1 + tools/binman/test/elf_sections_tee.lds | 32 ++++++++++++++++++++++++++ 4 files changed, 39 insertions(+), 2 deletions(-) create mode 120000 tools/binman/test/elf_sections_tee.c create mode 100644 tools/binman/test/elf_sections_tee.lds diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index 6ed8b8637cd..0252b175242 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -252,7 +252,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') diff --git a/tools/binman/test/Makefile b/tools/binman/test/Makefile index 4d152eee9c0..66279e0e207 100644 --- a/tools/binman/test/Makefile +++ b/tools/binman/test/Makefile @@ -30,12 +30,13 @@ 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 + u_boot_binman_embed u_boot_binman_embed_sm elf_sections elf_sections_tee blob_syms.bin all: $(TARGETS) @@ -84,6 +85,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 + clean: rm -f $(TARGETS) diff --git a/tools/binman/test/elf_sections_tee.c b/tools/binman/test/elf_sections_tee.c new file mode 120000 index 00000000000..01b200a365e --- /dev/null +++ b/tools/binman/test/elf_sections_tee.c @@ -0,0 +1 @@ +elf_sections.c \ No newline at end of file diff --git a/tools/binman/test/elf_sections_tee.lds b/tools/binman/test/elf_sections_tee.lds new file mode 100644 index 00000000000..97e5e5f5d94 --- /dev/null +++ b/tools/binman/test/elf_sections_tee.lds @@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright (c) 2016 Google, Inc + * Copyright (c) 2025 Canonical Ltd. + */ + +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*) + } +} From cbc4da1dce3f8dd828a2e613676fdceefd87e1ea Mon Sep 17 00:00:00 2001 From: Aristo Chen Date: Sun, 14 Sep 2025 10:59:29 +0000 Subject: [PATCH 4/7] arm: dts: k3-am6xx: Fix FIT image memory overlap in binman configurations Fix memory overlaps in FIT image configurations for TI AM62x and AM64x PHYCore and SK boards. The overlaps occurred in two categories: 1. TI firmware stub images (tifsstub-hs, tifsstub-fs, tifsstub-gp): These mutually exclusive firmware variants were incorrectly assigned the same load address within FIT configurations, causing overlap detection to fail. Adjust addresses with 64KB spacing: - tifsstub-hs: Keep original address - tifsstub-fs: Move to +64KB offset - tifsstub-gp: Move to +128KB offset 2. Device tree overlay images (som-no-rtc, som-no-spi, som-no-eth): These overlay files had insufficient spacing between load addresses, causing actual memory overlaps. Increase spacing to 8KB boundaries to accommodate overlay sizes safely. An upcoming commit will validate if the memory region is overlapped Signed-off-by: Aristo Chen --- arch/arm/dts/k3-am625-phycore-som-binman.dtsi | 22 +++++++++---------- arch/arm/dts/k3-am625-sk-binman.dtsi | 16 +++++++------- .../dts/k3-am625-verdin-wifi-dev-binman.dtsi | 16 +++++++------- arch/arm/dts/k3-am62a-phycore-som-binman.dtsi | 10 ++++----- arch/arm/dts/k3-am62a-sk-binman.dtsi | 4 ++-- arch/arm/dts/k3-am642-phycore-som-binman.dtsi | 6 ++--- 6 files changed, 37 insertions(+), 37 deletions(-) diff --git a/arch/arm/dts/k3-am625-phycore-som-binman.dtsi b/arch/arm/dts/k3-am625-phycore-som-binman.dtsi index a9bd5a2be84..4344cefeba3 100644 --- a/arch/arm/dts/k3-am625-phycore-som-binman.dtsi +++ b/arch/arm/dts/k3-am625-phycore-som-binman.dtsi @@ -234,8 +234,8 @@ arch = "arm32"; compression = "none"; os = "tifsstub-fs"; - load = <0x9dc00000>; - entry = <0x9dc00000>; + load = <0x9dc10000>; + entry = <0x9dc10000>; blob-ext { filename = "tifsstub.bin_fs"; }; @@ -247,8 +247,8 @@ arch = "arm32"; compression = "none"; os = "tifsstub-gp"; - load = <0x9dc00000>; - entry = <0x9dc00000>; + load = <0x9dc20000>; + entry = <0x9dc20000>; blob-ext { filename = "tifsstub.bin_gp"; }; @@ -322,7 +322,7 @@ description = "k3-am6xx-phycore-disable-spi-nor"; type = "flat_dt"; compression = "none"; - load = <0x8F001000>; + load = <0x8F002000>; arch = "arm"; ti-secure { content = <&am6xx_phycore_disable_spi_not_dtbo>; @@ -337,7 +337,7 @@ description = "k3-am6xx-phycore-disable-eth-phy"; type = "flat_dt"; compression = "none"; - load = <0x8F002000>; + load = <0x8F004000>; arch = "arm"; ti-secure { content = <&am6xx_phycore_disable_eth_phy_dtbo>; @@ -352,7 +352,7 @@ description = "k3-am6xx-phycore-qspi-nor"; type = "flat_dt"; compression = "none"; - load = <0x8F003000>; + load = <0x8F006000>; arch = "arm"; ti-secure { content = <&am6xx_phycore_disable_qspi_nor_dtbo>; @@ -479,8 +479,8 @@ arch = "arm32"; compression = "none"; os = "tifsstub-fs"; - load = <0x9dc00000>; - entry = <0x9dc00000>; + load = <0x9dc10000>; + entry = <0x9dc10000>; blob-ext { filename = "tifsstub.bin_fs"; }; @@ -492,8 +492,8 @@ arch = "arm32"; compression = "none"; os = "tifsstub-gp"; - load = <0x9dc00000>; - entry = <0x9dc00000>; + load = <0x9dc20000>; + entry = <0x9dc20000>; blob-ext { filename = "tifsstub.bin_gp"; }; diff --git a/arch/arm/dts/k3-am625-sk-binman.dtsi b/arch/arm/dts/k3-am625-sk-binman.dtsi index f743c4353b4..1619f733a0d 100644 --- a/arch/arm/dts/k3-am625-sk-binman.dtsi +++ b/arch/arm/dts/k3-am625-sk-binman.dtsi @@ -231,8 +231,8 @@ arch = "arm32"; compression = "none"; os = "tifsstub-fs"; - load = <0x9dc00000>; - entry = <0x9dc00000>; + load = <0x9dc10000>; + entry = <0x9dc10000>; blob-ext { filename = "tifsstub.bin_fs"; }; @@ -244,8 +244,8 @@ arch = "arm32"; compression = "none"; os = "tifsstub-gp"; - load = <0x9dc00000>; - entry = <0x9dc00000>; + load = <0x9dc20000>; + entry = <0x9dc20000>; blob-ext { filename = "tifsstub.bin_gp"; }; @@ -362,8 +362,8 @@ arch = "arm32"; compression = "none"; os = "tifsstub-fs"; - load = <0x9dc00000>; - entry = <0x9dc00000>; + load = <0x9dc10000>; + entry = <0x9dc10000>; blob-ext { filename = "tifsstub.bin_fs"; }; @@ -375,8 +375,8 @@ arch = "arm32"; compression = "none"; os = "tifsstub-gp"; - load = <0x9dc00000>; - entry = <0x9dc00000>; + load = <0x9dc20000>; + entry = <0x9dc20000>; blob-ext { filename = "tifsstub.bin_gp"; }; diff --git a/arch/arm/dts/k3-am625-verdin-wifi-dev-binman.dtsi b/arch/arm/dts/k3-am625-verdin-wifi-dev-binman.dtsi index 65fef6e4790..6c4ad72d936 100644 --- a/arch/arm/dts/k3-am625-verdin-wifi-dev-binman.dtsi +++ b/arch/arm/dts/k3-am625-verdin-wifi-dev-binman.dtsi @@ -219,8 +219,8 @@ arch = "arm32"; compression = "none"; os = "tifsstub-fs"; - load = <0x9dc00000>; - entry = <0x9dc00000>; + load = <0x9dc10000>; + entry = <0x9dc10000>; blob-ext { filename = "tifsstub.bin_fs"; }; @@ -232,8 +232,8 @@ arch = "arm32"; compression = "none"; os = "tifsstub-gp"; - load = <0x9dc00000>; - entry = <0x9dc00000>; + load = <0x9dc20000>; + entry = <0x9dc20000>; blob-ext { filename = "tifsstub.bin_gp"; }; @@ -346,8 +346,8 @@ arch = "arm32"; compression = "none"; os = "tifsstub-fs"; - load = <0x9dc00000>; - entry = <0x9dc00000>; + load = <0x9dc10000>; + entry = <0x9dc10000>; blob-ext { filename = "tifsstub.bin_fs"; }; @@ -359,8 +359,8 @@ arch = "arm32"; compression = "none"; os = "tifsstub-gp"; - load = <0x9dc00000>; - entry = <0x9dc00000>; + load = <0x9dc20000>; + entry = <0x9dc20000>; blob-ext { filename = "tifsstub.bin_gp"; }; diff --git a/arch/arm/dts/k3-am62a-phycore-som-binman.dtsi b/arch/arm/dts/k3-am62a-phycore-som-binman.dtsi index a284226320c..786c7a2d458 100644 --- a/arch/arm/dts/k3-am62a-phycore-som-binman.dtsi +++ b/arch/arm/dts/k3-am62a-phycore-som-binman.dtsi @@ -184,8 +184,8 @@ arch = "arm32"; compression = "none"; os = "tifsstub-fs"; - load = <0x9ca00000>; - entry = <0x9ca00000>; + load = <0x9ca10000>; + entry = <0x9ca10000>; blob-ext { filename = "tifsstub.bin_fs"; }; @@ -260,7 +260,7 @@ description = "k3-am6xx-phycore-disable-spi-nor"; type = "flat_dt"; compression = "none"; - load = <0x8F001000>; + load = <0x8F002000>; arch = "arm"; ti-secure { content = <&am6xx_phycore_disable_spi_not_dtbo>; @@ -275,7 +275,7 @@ description = "k3-am6xx-phycore-disable-eth-phy"; type = "flat_dt"; compression = "none"; - load = <0x8F002000>; + load = <0x8F004000>; arch = "arm"; ti-secure { content = <&am6xx_phycore_disable_eth_phy_dtbo>; @@ -290,7 +290,7 @@ description = "k3-am6xx-phycore-qspi-nor"; type = "flat_dt"; compression = "none"; - load = <0x8F003000>; + load = <0x8F006000>; arch = "arm"; ti-secure { content = <&am6xx_phycore_disable_qspi_nor_dtbo>; diff --git a/arch/arm/dts/k3-am62a-sk-binman.dtsi b/arch/arm/dts/k3-am62a-sk-binman.dtsi index e64c165ecbf..214acd7f0f7 100644 --- a/arch/arm/dts/k3-am62a-sk-binman.dtsi +++ b/arch/arm/dts/k3-am62a-sk-binman.dtsi @@ -168,8 +168,8 @@ arch = "arm32"; compression = "none"; os = "tifsstub-fs"; - load = <0x9ca00000>; - entry = <0x9ca00000>; + load = <0x9ca10000>; + entry = <0x9ca10000>; blob-ext { filename = "tifsstub.bin_fs"; }; diff --git a/arch/arm/dts/k3-am642-phycore-som-binman.dtsi b/arch/arm/dts/k3-am642-phycore-som-binman.dtsi index 966905bd64d..59d8902bf48 100644 --- a/arch/arm/dts/k3-am642-phycore-som-binman.dtsi +++ b/arch/arm/dts/k3-am642-phycore-som-binman.dtsi @@ -371,7 +371,7 @@ description = "k3-am6xx-phycore-disable-spi-nor"; type = "flat_dt"; compression = "none"; - load = <0x8F001000>; + load = <0x8F002000>; arch = "arm"; ti-secure { content = <&am6xx_phycore_disable_spi_not_dtbo>; @@ -386,7 +386,7 @@ description = "k3-am6xx-phycore-disable-eth-phy"; type = "flat_dt"; compression = "none"; - load = <0x8F002000>; + load = <0x8F004000>; arch = "arm"; ti-secure { content = <&am6xx_phycore_disable_eth_phy_dtbo>; @@ -401,7 +401,7 @@ description = "k3-am6xx-phycore-qspi-nor"; type = "flat_dt"; compression = "none"; - load = <0x8F003000>; + load = <0x8F006000>; arch = "arm"; ti-secure { content = <&am6xx_phycore_disable_qspi_nor_dtbo>; From 588094f2c8ec9a4f7d2dcda11ffae8db8462149c Mon Sep 17 00:00:00 2001 From: Aristo Chen Date: Sun, 14 Sep 2025 10:59:30 +0000 Subject: [PATCH 5/7] tools: mkimage: detect overlapping load regions in FIT configurations This patch adds a validation step in mkimage to detect memory region overlaps between images specified in the same configuration of a FIT image. If any overlaps are found, the tool prints an error and aborts the build. This helps prevent runtime memory corruption caused by conflicting load addresses between images. Signed-off-by: Aristo Chen --- tools/fit_image.c | 90 ++++++++++++++++++++++++++++++++++++++++++++++- tools/mkimage.c | 3 +- 2 files changed, 91 insertions(+), 2 deletions(-) diff --git a/tools/fit_image.c b/tools/fit_image.c index 331be5ae71d..bd849110646 100644 --- a/tools/fit_image.c +++ b/tools/fit_image.c @@ -22,6 +22,20 @@ #include #include +struct fit_region { + ulong load; + ulong size; + const char *name; +}; + +static int regions_overlap(const struct fit_region *a, const struct fit_region *b) +{ + ulong a_end = a->load + a->size; + ulong b_end = b->load + b->size; + + return !(a_end <= b->load || b_end <= a->load); +} + static struct legacy_img_hdr header; static int fit_estimate_hash_sig_size(struct image_tool_params *params, const char *fname) @@ -775,9 +789,12 @@ static int fit_import_data(struct image_tool_params *params, const char *fname) } fdt_for_each_subnode(node, fdt, confs) { + struct fit_region *regions = NULL; + unsigned int img_count = 0; + unsigned int regions_allocated = 0; const char *conf_name = fdt_get_name(fdt, node, NULL); - for (int i = 0; i < ARRAY_SIZE(props); i++) { + for (unsigned int i = 0; i < ARRAY_SIZE(props); i++) { int count = fdt_stringlist_count(fdt, node, props[i]); if (count < 0) @@ -798,8 +815,79 @@ static int fit_import_data(struct image_tool_params *params, const char *fname) ret = FDT_ERR_NOTFOUND; goto err_munmap; } + + ulong img_load = 0; + int img_size = 0; + + if (fit_image_get_load(fdt, img, &img_load)) { + fprintf(stderr, + "Warning: not able to get `load` of node '%s'\n", + img_name); + // Skip checking the components that do not have a + // definition for `load` + continue; + } + const char *img_data = fdt_getprop(fdt, img, + FIT_DATA_PROP, + &img_size); + + if (!img_data || !img_size) + continue; + + // Check if we've already added this image to avoid duplicates + for (unsigned int k = 0; k < img_count; k++) { + if (!strcmp(regions[k].name, img_name)) + goto next_node; + } + + // Expand regions array if needed + if (img_count >= regions_allocated) { + unsigned int new_size = regions_allocated ? + regions_allocated * 2 : 8; + struct fit_region *new_regions = realloc(regions, + new_size * sizeof(struct fit_region)); + if (!new_regions) { + fprintf(stderr, + "Failed to allocate memory for regions in config %s\n", + fdt_get_name(fdt, node, NULL)); + free(regions); + ret = -ENOMEM; + goto err_munmap; + } + regions = new_regions; + regions_allocated = new_size; + } + + regions[img_count].load = img_load; + regions[img_count].size = img_size; + regions[img_count].name = img_name; + img_count++; +next_node:; } } + + // Check for overlap within this config only + for (unsigned int i = 0; i < img_count; i++) { + for (unsigned int j = i + 1; j < img_count; j++) { + if (regions_overlap(®ions[i], ®ions[j])) { + fprintf(stderr, + "[Config: %s] Error: Overlap detected:\n" + " - %s: [0x%lx - 0x%lx]\n" + " - %s: [0x%lx - 0x%lx]\n", + fdt_get_name(fdt, node, NULL), + 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; + free(regions); + goto err_munmap; + } + } + } + + // Clean up allocated memory for this configuration + free(regions); } munmap(old_fdt, sbuf.st_size); diff --git a/tools/mkimage.c b/tools/mkimage.c index 361711c53b2..3f28918f5cf 100644 --- a/tools/mkimage.c +++ b/tools/mkimage.c @@ -520,7 +520,8 @@ int main(int argc, char **argv) retval = tparams->fflag_handle(¶ms); 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); } From 8f3d3510e31ebc7b2057f431322a7174b6b60ea6 Mon Sep 17 00:00:00 2001 From: Aristo Chen Date: Sun, 14 Sep 2025 10:59:31 +0000 Subject: [PATCH 6/7] test: Add test case for FIT image load address overlap detection Add a new test case to verify that mkimage properly detects and reports memory region overlaps in FIT image configurations. The test creates a FIT image with kernel and FDT components that have the same load address (0x40000), which should trigger the overlap detection logic and cause mkimage to fail with an appropriate error message. Test verifies: - mkimage returns non-zero exit code when overlap is detected - Error message contains "Error: Overlap detected:" - Error message identifies the specific overlapping components (kernel@1 and fdt@1) This test ensures the overlap detection feature works correctly and prevents deployment of FIT images with conflicting memory layouts that could cause runtime failures. Signed-off-by: Aristo Chen --- test/py/tests/test_fit_mkimage_validate.py | 65 ++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/test/py/tests/test_fit_mkimage_validate.py b/test/py/tests/test_fit_mkimage_validate.py index 170b2a8cbbb..27299a58f33 100644 --- a/test/py/tests/test_fit_mkimage_validate.py +++ b/test/py/tests/test_fit_mkimage_validate.py @@ -103,3 +103,68 @@ def test_fit_invalid_default_config(ubman): assert result.returncode != 0, "mkimage should fail due to missing default config" assert re.search(r"Default configuration '.*' not found under /configurations", result.stderr) + +def test_fit_load_addr_overlap(ubman): + """Test that mkimage fails when load address overlap""" + + 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') + fdt = fit_util.make_dtb(ubman, ''' +/dts-v1/; +/ { + model = "Test FDT"; + compatible = "test"; +}; +''', 'test') + + # 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>; + }; + 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 "Error: Overlap detected:" in result.stderr + # Check that it identifies the specific overlapping components + assert "kernel@1" in result.stderr and "fdt@1" in result.stderr From 4907a920e8292e9e38ddab4d211dfd5499097a8c Mon Sep 17 00:00:00 2001 From: Aristo Chen Date: Sun, 14 Sep 2025 10:59:32 +0000 Subject: [PATCH 7/7] doc: binman: Add guidance for determining ELF load addresses Add documentation to help users understand how to determine where ELF files will be loaded when using binman's 'fit,load' property. This addresses the common confusion about how load addresses are determined from ELF files. The documentation explains three methods: 1. Using readelf to examine program headers 2. Checking the linker script (.lds file) 3. Using objdump to see section addresses Also includes a specific example from binman tests showing how elf_sections.lds sets ATF load address to 0x00000010 and elf_sections_tee.lds sets TEE load address to 0x00100010 to avoid memory overlap conflicts. This helps users debug memory layout conflicts more efficiently when working with FIT images containing multiple ELF components. Signed-off-by: Aristo Chen --- tools/binman/entries.rst | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tools/binman/entries.rst b/tools/binman/entries.rst index 12a39d070e4..f6a5465ca44 100644 --- a/tools/binman/entries.rst +++ b/tools/binman/entries.rst @@ -1050,6 +1050,24 @@ split-elf Generates a `load = <...>` property with the load address of the segment + Note: The load address comes from the ELF file's program header or + linker script. 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 `. =
;` 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 ATF load address + to 0x00000010, while elf_sections_tee.lds sets TEE load address to + 0x00100010 to avoid memory overlap conflicts. + fit,entry Generates a `entry = <...>` property with the entry address of the ELF. This is only produced for the first entry