From 6139d5f2521593edc64421976d7830e44121745b Mon Sep 17 00:00:00 2001 From: Ilias Apalodimas Date: Tue, 12 Aug 2025 09:03:25 +0300 Subject: tools: fit_info: Make usage() static The function is only used locally so declare it as static. Signed-off-by: Ilias Apalodimas --- tools/fit_info.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools') diff --git a/tools/fit_info.c b/tools/fit_info.c index b2642ec5b76..c9e4236d09f 100644 --- a/tools/fit_info.c +++ b/tools/fit_info.c @@ -26,7 +26,7 @@ #include #include -void usage(char *cmdname) +static void usage(char *cmdname) { fprintf(stderr, "Usage: %s -f fit file -n node -p property\n" " -f ==> set fit file which is used'\n" -- cgit v1.2.3 From 544bf0aa599f9afd8ac5224b005edd4b5bb374ed Mon Sep 17 00:00:00 2001 From: Ilias Apalodimas Date: Tue, 12 Aug 2025 09:10:20 +0300 Subject: tools: aisimage: Make aisimage_check_params() static We are trying to enable -Wmissing-prototypes and this functiion is only used locally. Mark it as static. Signed-off-by: Ilias Apalodimas --- tools/aisimage.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools') diff --git a/tools/aisimage.c b/tools/aisimage.c index c5b33b559b0..7a44b2d6ab6 100644 --- a/tools/aisimage.c +++ b/tools/aisimage.c @@ -387,7 +387,7 @@ static void aisimage_set_header(void *ptr, struct stat *sbuf, int ifd, { } -int aisimage_check_params(struct image_tool_params *params) +static int aisimage_check_params(struct image_tool_params *params) { if (!params) return CFG_INVALID; -- cgit v1.2.3 From d95c4bebf40cddff5b284abfb591eb47f84ebb12 Mon Sep 17 00:00:00 2001 From: Ilias Apalodimas Date: Tue, 12 Aug 2025 09:08:06 +0300 Subject: tools: imx8image: Make imx8image_check_params() static We are trying to enable -Wmissing-prototypes and this functiion is only used locally. Mark it as static. Signed-off-by: Ilias Apalodimas Acked-by: Peng Fan --- tools/imx8image.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools') diff --git a/tools/imx8image.c b/tools/imx8image.c index 5a76643c06e..3cea536b8e8 100644 --- a/tools/imx8image.c +++ b/tools/imx8image.c @@ -23,7 +23,7 @@ static uint8_t cntr_version; static uint32_t custom_partition; static uint32_t scfw_flags; -int imx8image_check_params(struct image_tool_params *params) +static int imx8image_check_params(struct image_tool_params *params) { return 0; } -- cgit v1.2.3 From ae84ef8c625f6454747b5d13192e1a16649761b2 Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Sat, 23 Aug 2025 13:29:49 +0200 Subject: tools: Drop meaningless comment from Makefile Introduced by 245b1029e1af, probably a debug left-over. Signed-off-by: Jan Kiszka Reviewed-by: Heiko Schocher --- tools/Makefile | 1 - 1 file changed, 1 deletion(-) (limited to 'tools') diff --git a/tools/Makefile b/tools/Makefile index 02297e8c93a..7eb17f92116 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -344,7 +344,6 @@ $(LOGO_DATA_H): $(obj)/bmp_logo $(LOGO_BMP) else $(LOGO_DATA_H): $(obj)/bmp_logo $(LOGO_BMP) $(obj)/bmp_logo --gen-data $(LOGO_BMP) > $@ -#endif endif # Let clean descend into subdirs -- cgit v1.2.3 From 3c34fd46b6efd0501662ba3f0aeff2aeac9a584d Mon Sep 17 00:00:00 2001 From: Ilias Apalodimas Date: Fri, 29 Aug 2025 11:16:15 +0300 Subject: tools: fdtgrep: Mark util_version() as static The function is only used locally. Enabling -Wmissing-prototypes triggers a warning. Mark it as static. Signed-off-by: Ilias Apalodimas --- tools/fdtgrep.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools') diff --git a/tools/fdtgrep.c b/tools/fdtgrep.c index 037176bc9ef..6372defedc2 100644 --- a/tools/fdtgrep.c +++ b/tools/fdtgrep.c @@ -1109,7 +1109,7 @@ void util_usage(const char *errmsg, const char *synopsis, util_usage(errmsg, usage_synopsis, usage_short_opts, \ usage_long_opts, usage_opts_help) -void util_version(void) +static void util_version(void) { printf("Version: %s\n", "(U-Boot)"); exit(0); -- cgit v1.2.3 From 9fe4e088f3d2ba15323ae4bff7f6b592152e326c Mon Sep 17 00:00:00 2001 From: Ilias Apalodimas Date: Fri, 29 Aug 2025 11:16:16 +0300 Subject: tools: fdtgrep: Mark util_usage() as static The function is only used locally. Enabling -Wmissing-prototypes triggers a warning. Mark it as static. Signed-off-by: Ilias Apalodimas --- tools/fdtgrep.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools') diff --git a/tools/fdtgrep.c b/tools/fdtgrep.c index 6372defedc2..b4c041070f5 100644 --- a/tools/fdtgrep.c +++ b/tools/fdtgrep.c @@ -1040,7 +1040,7 @@ static const char * const usage_opts_help[] = { #define util_getopt_long() getopt_long(argc, argv, usage_short_opts, \ usage_long_opts, NULL) -void util_usage(const char *errmsg, const char *synopsis, +static void util_usage(const char *errmsg, const char *synopsis, const char *short_opts, struct option const long_opts[], const char * const opts_help[]) { -- cgit v1.2.3 From 867d762bc515850b00245cbcf21cf2b2d39a2a5d Mon Sep 17 00:00:00 2001 From: Ilias Apalodimas Date: Fri, 29 Aug 2025 11:16:17 +0300 Subject: tools: mkimage: Mark copy_datafile() as static The function is only used locally. Enabling -Wmissing-prototypes triggers a warning. Mark it as static. Signed-off-by: Ilias Apalodimas --- tools/mkimage.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools') diff --git a/tools/mkimage.c b/tools/mkimage.c index 361711c53b2..847453970ab 100644 --- a/tools/mkimage.c +++ b/tools/mkimage.c @@ -445,7 +445,7 @@ static void verify_image(const struct image_type_params *tparams) (void)close(ifd); } -void copy_datafile(int ifd, char *file) +static void copy_datafile(int ifd, char *file) { if (!file) return; -- cgit v1.2.3 From 3ae031135da1f21ec22e20fac5d7ba9776487166 Mon Sep 17 00:00:00 2001 From: Ilias Apalodimas Date: Fri, 29 Aug 2025 11:16:18 +0300 Subject: tools: rkcommon: Mark rkcommon_is_header_v2() as static The function is only used locally. Enabling -Wmissing-prototypes triggers a warning. Mark it as static. Signed-off-by: Ilias Apalodimas Reviewed-by: Quentin Schulz --- tools/rkcommon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools') diff --git a/tools/rkcommon.c b/tools/rkcommon.c index a0caa029cc0..d191ea72c63 100644 --- a/tools/rkcommon.c +++ b/tools/rkcommon.c @@ -279,7 +279,7 @@ bool rkcommon_need_rc4_spl(struct image_tool_params *params) return info->spl_rc4; } -bool rkcommon_is_header_v2(struct image_tool_params *params) +static bool rkcommon_is_header_v2(struct image_tool_params *params) { struct spl_info *info = rkcommon_get_spl_info(params->imagename); -- cgit v1.2.3 From 5ab15814e8f051968a4da8c96339ff0c80c5f811 Mon Sep 17 00:00:00 2001 From: Ilias Apalodimas Date: Fri, 29 Aug 2025 11:16:19 +0300 Subject: tool: fit_info: Mark usage() as static The function is only used locally. Enabling -Wmissing-prototypes triggers a warning. Mark it as static. Signed-off-by: Ilias Apalodimas --- tools/fit_info.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools') diff --git a/tools/fit_info.c b/tools/fit_info.c index b2642ec5b76..c9e4236d09f 100644 --- a/tools/fit_info.c +++ b/tools/fit_info.c @@ -26,7 +26,7 @@ #include #include -void usage(char *cmdname) +static void usage(char *cmdname) { fprintf(stderr, "Usage: %s -f fit file -n node -p property\n" " -f ==> set fit file which is used'\n" -- cgit v1.2.3 From 39f7af39bb2e7e03ea4621e57a976d41dcaaf0a6 Mon Sep 17 00:00:00 2001 From: Ilias Apalodimas Date: Fri, 29 Aug 2025 11:16:20 +0300 Subject: tools: fit_check_sign: Mark usage() as static The function is only used locally. Enabling -Wmissing-prototypes triggers a warning. Mark it as static. Signed-off-by: Ilias Apalodimas --- tools/fit_check_sign.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools') diff --git a/tools/fit_check_sign.c b/tools/fit_check_sign.c index 32d0fdb8829..ab3266aff20 100644 --- a/tools/fit_check_sign.c +++ b/tools/fit_check_sign.c @@ -23,7 +23,7 @@ #include #include -void usage(char *cmdname) +static void usage(char *cmdname) { fprintf(stderr, "Usage: %s -f fit file -k key file -c config name\n" " -f ==> set fit file which should be checked'\n" -- cgit v1.2.3 From f006837eada06cdf41b9935eb6c73618e4ae0bf0 Mon Sep 17 00:00:00 2001 From: Ilias Apalodimas Date: Fri, 29 Aug 2025 11:16:21 +0300 Subject: tools: imx8mimage: Mark build_image() as static The function is only used locally. Enabling -Wmissing-prototypes triggers a warning. Mark it as static. Signed-off-by: Ilias Apalodimas --- tools/imx8mimage.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools') diff --git a/tools/imx8mimage.c b/tools/imx8mimage.c index 0f24ba75c0f..fe1aff35b4d 100644 --- a/tools/imx8mimage.c +++ b/tools/imx8mimage.c @@ -475,7 +475,7 @@ static int generate_fspi_header (int ifd) } #endif -void build_image(int ofd) +static void build_image(int ofd) { int file_off, header_hdmi_off = 0, header_image_off; -- cgit v1.2.3 From 1e73651a71d1cf2a718b9a8250a794d626b9eecb Mon Sep 17 00:00:00 2001 From: Ilias Apalodimas Date: Fri, 29 Aug 2025 11:16:22 +0300 Subject: tools: imx8image: Mark imx8mimage_check_params() as static The function is only used locally. Enabling -Wmissing-prototypes triggers a warning. Mark it as static. Signed-off-by: Ilias Apalodimas --- tools/imx8mimage.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools') diff --git a/tools/imx8mimage.c b/tools/imx8mimage.c index fe1aff35b4d..3e974923652 100644 --- a/tools/imx8mimage.c +++ b/tools/imx8mimage.c @@ -49,7 +49,7 @@ static uint32_t get_cfg_value(char *token, char *name, int linenr) return value; } -int imx8mimage_check_params(struct image_tool_params *params) +static int imx8mimage_check_params(struct image_tool_params *params) { return 0; } -- cgit v1.2.3 From 371a76e845504c9ba7ca216b6edfb4ae4ec14e56 Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Sat, 23 Aug 2025 17:21:09 +0200 Subject: tools: Do not generate logo when cross-building This cannot work (unless qemu-user is registered in binfmt_misc) as the tools will be for a different architecture. Fixes "make cross_tools" in case CONFIG_VIDEO_LOGO is enabled. Signed-off-by: Jan Kiszka Reviewed-by: Tom Rini --- tools/Makefile | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tools') diff --git a/tools/Makefile b/tools/Makefile index 7eb17f92116..ae6a3052646 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -333,7 +333,9 @@ HOST_EXTRACFLAGS += -include $(srctree)/include/compiler.h \ -D__KERNEL_STRICT_NAMES \ -D_GNU_SOURCE +ifeq ($(CROSS_BUILD_TOOLS),) __build: $(LOGO-y) +endif $(LOGO_H): $(obj)/bmp_logo $(LOGO_BMP) $(obj)/bmp_logo --gen-info $(LOGO_BMP) > $@ -- cgit v1.2.3 From 6dfd14e1228e6e14462f377987bc896d6b7f1dd5 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Wed, 3 Sep 2025 00:01:55 +0200 Subject: mkimage: Add support for bundling TFA BL31 in mkimage -f auto Introduce two new parameters to be used with mkimage -f auto to bundle TFA BL31 image into fitImage, using auto-generated fitImage. Add -y to specify TFA BL31 file name and -Y to specify TFA BL31 load and entry point address. This is meant to be used with systems which boot all of TFA BL31, Linux and its DT from a single fitImage, all booted by U-Boot. Example invocation: " $ mkimage -E -A arm64 -C none -e 0x50200000 -a 0x50200000 -f auto \ -d arch/arm64/boot/Image \ -b arch/arm64/boot/dts/renesas/r8a779g3-sparrow-hawk.dtb \ -y ../tfa/build/rcar_gen4/release/bl31.bin -Y 0x46400000 \ /path/to/output/fitImage " Documentation update and test are also included, the test validates both positive and negative test cases, where fitImage does not include TFA BL31 and does include TFA BL31 blobs. Signed-off-by: Marek Vasut --- tools/fit_image.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++-- tools/imagetool.h | 2 ++ tools/mkimage.c | 15 ++++++++++++++- 3 files changed, 66 insertions(+), 3 deletions(-) (limited to 'tools') diff --git a/tools/fit_image.c b/tools/fit_image.c index 331be5ae71d..10849733816 100644 --- a/tools/fit_image.c +++ b/tools/fit_image.c @@ -173,6 +173,13 @@ static int fit_calc_size(struct image_tool_params *params) total_size += size; } + if (params->fit_tfa_bl31) { + size = imagetool_get_filesize(params, params->fit_tfa_bl31); + if (size < 0) + return -1; + total_size += size; + } + for (cont = params->content_head; cont; cont = cont->next) { size = imagetool_get_filesize(params, cont->fname); if (size < 0) @@ -402,6 +409,30 @@ static int fit_write_images(struct image_tool_params *params, char *fdt) fdt_end_node(fdt); } + /* And a TFA BL31 file if available */ + if (params->fit_tfa_bl31) { + fdt_begin_node(fdt, FIT_TFA_BL31_PROP "-1"); + + fdt_property_string(fdt, FIT_TYPE_PROP, FIT_TFA_BL31_PROP); + fdt_property_string(fdt, FIT_OS_PROP, + genimg_get_os_short_name(params->os)); + fdt_property_string(fdt, FIT_ARCH_PROP, + genimg_get_arch_short_name(params->arch)); + get_basename(str, sizeof(str), params->fit_tfa_bl31); + fdt_property_string(fdt, FIT_DESC_PROP, str); + + ret = fdt_property_file(params, fdt, FIT_DATA_PROP, + params->fit_tfa_bl31); + if (ret) + return ret; + fdt_property_u32(fdt, FIT_LOAD_PROP, params->fit_tfa_bl31_addr); + fdt_property_u32(fdt, FIT_ENTRY_PROP, params->fit_tfa_bl31_addr); + fit_add_hash_or_sign(params, fdt, true); + if (ret) + return ret; + fdt_end_node(fdt); + } + fdt_end_node(fdt); return 0; @@ -421,7 +452,7 @@ static void fit_write_configs(struct image_tool_params *params, char *fdt) struct content_info *cont; const char *typename; char str[100]; - int upto; + int upto, len; fdt_begin_node(fdt, "configurations"); fdt_property_string(fdt, FIT_DEFAULT_PROP, "conf-1"); @@ -439,8 +470,16 @@ static void fit_write_configs(struct image_tool_params *params, char *fdt) typename = genimg_get_type_short_name(params->fit_image_type); snprintf(str, sizeof(str), "%s-1", typename); + len = strlen(str); fdt_property_string(fdt, typename, str); - fdt_property_string(fdt, FIT_LOADABLE_PROP, str); + + if (params->fit_tfa_bl31) { + snprintf(str, sizeof(str), "%s-1." FIT_TFA_BL31_PROP "-1", typename); + str[len] = 0; + len += strlen(FIT_TFA_BL31_PROP "-1") + 1; + } + + fdt_property(fdt, FIT_LOADABLE_PROP, str, len + 1); if (params->fit_ramdisk) fdt_property_string(fdt, FIT_RAMDISK_PROP, @@ -456,8 +495,17 @@ static void fit_write_configs(struct image_tool_params *params, char *fdt) fdt_begin_node(fdt, "conf-1"); typename = genimg_get_type_short_name(params->fit_image_type); snprintf(str, sizeof(str), "%s-1", typename); + len = strlen(str); fdt_property_string(fdt, typename, str); + if (params->fit_tfa_bl31) { + snprintf(str, sizeof(str), "%s-1." FIT_TFA_BL31_PROP "-1", typename); + str[len] = 0; + len += strlen(FIT_TFA_BL31_PROP "-1") + 1; + } + + fdt_property(fdt, FIT_LOADABLE_PROP, str, len + 1); + if (params->fit_ramdisk) fdt_property_string(fdt, FIT_RAMDISK_PROP, FIT_RAMDISK_PROP "-1"); diff --git a/tools/imagetool.h b/tools/imagetool.h index 57be608210a..866b8834fd7 100644 --- a/tools/imagetool.h +++ b/tools/imagetool.h @@ -99,6 +99,8 @@ struct image_tool_params { const char *engine_id; /* Engine to use for signing */ bool reset_timestamp; /* Reset the timestamp on an existing image */ struct image_summary summary; /* results of signing process */ + char *fit_tfa_bl31; /* TFA BL31 file to include */ + unsigned int fit_tfa_bl31_addr; /* TFA BL31 load and entry point address */ }; /* diff --git a/tools/mkimage.c b/tools/mkimage.c index 847453970ab..12183270776 100644 --- a/tools/mkimage.c +++ b/tools/mkimage.c @@ -160,7 +160,7 @@ static int add_content(int type, const char *fname) } static const char optstring[] = - "a:A:b:B:c:C:d:D:e:Ef:Fg:G:i:k:K:ln:N:o:O:p:qrR:stT:vVx"; + "a:A:b:B:c:C:d:D:e:Ef:Fg:G:i:k:K:ln:N:o:O:p:qrR:stT:vVxy:Y:"; static const struct option longopts[] = { { "load-address", required_argument, NULL, 'a' }, @@ -196,6 +196,8 @@ static const struct option longopts[] = { { "verbose", no_argument, NULL, 'v' }, { "version", no_argument, NULL, 'V' }, { "xip", no_argument, NULL, 'x' }, + { "tfa-bl31-file", no_argument, NULL, 'y' }, + { "tfa-bl31-addr", no_argument, NULL, 'Y' }, { /* sentinel */ }, }; @@ -367,6 +369,17 @@ static void process_args(int argc, char **argv) case 'x': params.xflag++; break; + case 'y': + params.fit_tfa_bl31 = optarg; + break; + case 'Y': + params.fit_tfa_bl31_addr = strtoull(optarg, &ptr, 16); + if (*ptr) { + fprintf(stderr, "%s: invalid TFA BL31 address %s\n", + params.cmdname, optarg); + exit(EXIT_FAILURE); + } + break; default: usage("Invalid option"); } -- cgit v1.2.3 From aa711ac815618bdc2c992c4b3869f6ef27b80202 Mon Sep 17 00:00:00 2001 From: Javier Tia Date: Fri, 5 Sep 2025 14:53:45 -0600 Subject: tools: zynqmp_psu_init_minimize.sh: Switch to clang-format Replace the use of scripts/Lindent with clang-format in zynqmp_psu_init_minimize.sh. This change is made to align with the rest of the codebase that uses clang-format for code formatting. This ensures consistency across all scripts in terms of code style and formatting. Tested-by: Michal Simek Signed-off-by: Javier Tia --- tools/zynqmp_psu_init_minimize.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools') diff --git a/tools/zynqmp_psu_init_minimize.sh b/tools/zynqmp_psu_init_minimize.sh index 5c8b73703bf..f8b729ebc97 100755 --- a/tools/zynqmp_psu_init_minimize.sh +++ b/tools/zynqmp_psu_init_minimize.sh @@ -82,7 +82,7 @@ for i in $FUNCS_TO_REMOVE; do sed -i "/$i/,/^}$/d" ${OUT} done -scripts/Lindent ${OUT} +clang-format -i -style=file ${OUT} # Prepend 'static' to internal functions sed -i 's/^.*data(void)$/static &/g' ${OUT} -- cgit v1.2.3 From 88392a59bf87bf2c1c5aedc0b76f459d702f71a7 Mon Sep 17 00:00:00 2001 From: Aristo Chen Date: Sun, 14 Sep 2025 10:59:26 +0000 Subject: 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(-) (limited to 'tools') 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') -- cgit v1.2.3 From dade54edaff659c4ed6fc40db0b2dd446714c573 Mon Sep 17 00:00:00 2001 From: Aristo Chen Date: Sun, 14 Sep 2025 10:59:27 +0000 Subject: 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(-) (limited to 'tools') 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 { }; -- cgit v1.2.3 From a06733fc83f07dd975a9e220a44392f3455c7c21 Mon Sep 17 00:00:00 2001 From: Aristo Chen Date: Sun, 14 Sep 2025 10:59:28 +0000 Subject: 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 (limited to 'tools') 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*) + } +} -- cgit v1.2.3 From 588094f2c8ec9a4f7d2dcda11ffae8db8462149c Mon Sep 17 00:00:00 2001 From: Aristo Chen Date: Sun, 14 Sep 2025 10:59:30 +0000 Subject: 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(-) (limited to 'tools') 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); } -- cgit v1.2.3 From 4907a920e8292e9e38ddab4d211dfd5499097a8c Mon Sep 17 00:00:00 2001 From: Aristo Chen Date: Sun, 14 Sep 2025 10:59:32 +0000 Subject: 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(+) (limited to 'tools') 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 -- cgit v1.2.3 From e482fdbbca935de32400054eb532de45b1cc01cb Mon Sep 17 00:00:00 2001 From: Tom Rini Date: Wed, 24 Sep 2025 07:50:44 -0600 Subject: Revert "Merge patch series "mkimage: Detect FIT image load address overlaps and fix related test/DTS issues"" This reverts commit 4d84fa1261eb27d57687f2e4c404a78b8653c183, reversing changes made to b82a1fa7ddc7f3be2f3b75898d5dc44c34420bdd. I had missed some feedback on this series from earlier, and we have since had reports of regressions due to this as well. For now, revert this. Signed-off-by: Tom Rini --- tools/binman/entries.rst | 18 ----- tools/binman/ftest.py | 4 +- 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 +- tools/binman/test/Makefile | 6 +- tools/binman/test/elf_sections_tee.c | 1 - tools/binman/test/elf_sections_tee.lds | 32 --------- tools/fit_image.c | 90 +----------------------- tools/mkimage.c | 3 +- 10 files changed, 11 insertions(+), 155 deletions(-) delete mode 120000 tools/binman/test/elf_sections_tee.c delete mode 100644 tools/binman/test/elf_sections_tee.lds (limited to 'tools') diff --git a/tools/binman/entries.rst b/tools/binman/entries.rst index 173b7eef6cc..8922d6cd070 100644 --- a/tools/binman/entries.rst +++ b/tools/binman/entries.rst @@ -1050,24 +1050,6 @@ 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 diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index 0c2dbf333c0..925c39a530e 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_tee'))) + tools.read_file(cls.ElfTestFile('elf_sections'))) # Newer OP_TEE file in v1 binary format cls.make_tee_bin('tee.bin') @@ -7997,7 +7997,7 @@ fdt fdtmap Extract the devicetree blob from the fdtmap 'Node \'/binman/fit\': multiple key paths found', str(e.exception)) - def testFitSignNoSignatureNodes(self): + def testFitSignNoSingatureNodes(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') diff --git a/tools/binman/test/276_fit_firmware_loadables.dts b/tools/binman/test/276_fit_firmware_loadables.dts index d344036a11a..2f79cdc9bb8 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 = <0x00002000>; - entry = <0x00002000>; + load = <0x00000000>; + entry = <0x00000000>; u-boot-nodtb { }; diff --git a/tools/binman/test/340_fit_signature.dts b/tools/binman/test/340_fit_signature.dts index 1c25d52cba4..9dce62e52de 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 = <0x00002000>; - entry = <0x00002000>; + load = <0x00000000>; + entry = <0x00000000>; u-boot-nodtb { }; diff --git a/tools/binman/test/342_fit_signature.dts b/tools/binman/test/342_fit_signature.dts index 2ac600b1c70..267105d0f68 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 = <0x00002000>; - entry = <0x00002000>; + load = <0x00000000>; + entry = <0x00000000>; u-boot-nodtb { }; diff --git a/tools/binman/test/Makefile b/tools/binman/test/Makefile index 66279e0e207..4d152eee9c0 100644 --- a/tools/binman/test/Makefile +++ b/tools/binman/test/Makefile @@ -30,13 +30,12 @@ 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 elf_sections_tee blob_syms.bin + u_boot_binman_embed u_boot_binman_embed_sm elf_sections blob_syms.bin all: $(TARGETS) @@ -85,9 +84,6 @@ 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 deleted file mode 120000 index 01b200a365e..00000000000 --- a/tools/binman/test/elf_sections_tee.c +++ /dev/null @@ -1 +0,0 @@ -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 deleted file mode 100644 index 97e5e5f5d94..00000000000 --- a/tools/binman/test/elf_sections_tee.lds +++ /dev/null @@ -1,32 +0,0 @@ -/* 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*) - } -} diff --git a/tools/fit_image.c b/tools/fit_image.c index 12f4cdb2875..10849733816 100644 --- a/tools/fit_image.c +++ b/tools/fit_image.c @@ -22,20 +22,6 @@ #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) @@ -837,12 +823,9 @@ 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 (unsigned int i = 0; i < ARRAY_SIZE(props); i++) { + for (int i = 0; i < ARRAY_SIZE(props); i++) { int count = fdt_stringlist_count(fdt, node, props[i]); if (count < 0) @@ -863,79 +846,8 @@ 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 e96fb7e42db..12183270776 100644 --- a/tools/mkimage.c +++ b/tools/mkimage.c @@ -533,8 +533,7 @@ int main(int argc, char **argv) retval = tparams->fflag_handle(¶ms); if (retval != EXIT_SUCCESS) { - if (retval == FDT_ERR_NOTFOUND || - retval == FDT_ERR_BADSTRUCTURE) { + if (retval == FDT_ERR_NOTFOUND) { // Already printed error, exit cleanly exit(EXIT_FAILURE); } -- cgit v1.2.3