new file mode 100644
@@ -0,0 +1,53 @@
+From 7988f1afe1324486e473874b22ed009c0d6d6806 Mon Sep 17 00:00:00 2001
+From: Dario Binacchi <dario.binacchi@amarulasolutions.com>
+Date: Wed, 9 Oct 2024 18:29:00 +0200
+Subject: [PATCH] fix(build): Set guess-gnu-gcc-ld properly
+
+With the commit 291e718229e7f ("build: skip toolchain detection for some
+targets"), the compiler was used instead of the linker:
+
++ guess-gnu-gcc-cpp = $(1)
++ guess-gnu-gcc-as = $(1)
++ guess-gnu-gcc-ld = $(1)
+
+This patch correctly references the linker for gnu-gcc.
+
+The patch was tested on the STM32MP157C-DK2 board.
+
+This is the error raised during the compilation of ARM Trusted Firmware
+v2.11 before applying the patch
+
+'buildroot/output/host/bin/arm-buildroot-linux-gnueabihf-gcc' -o buildroot/output/build/arm-trusted-firmware-custom/build/stm32mp1/release/tf-a-stm32mp157c-dk2.elf -Wl,--hash-style=gnu -Wl,--as-needed -nostartfiles -Wl,-Map=buildroot/output/build/arm-trusted-firmware-custom/build/stm32mp1/release/tf-a-stm32mp157c-dk2.map -Wl,-dT buildroot/output/build/arm-trusted-firmware-custom/build/stm32mp1/release/stm32mp1.ld buildroot/output/build/arm-trusted-firmware-custom/build/stm32mp1/release/stm32mp1-stm32mp157c-dk2.o
+buildroot/output/host/lib/gcc/arm-buildroot-linux-gnueabihf/13.3.0/../../../../arm-buildroot-linux-gnueabihf/bin/ld: buildroot/output/build/arm-trusted-firmware-custom/build/stm32mp1/release/tf-a-stm32mp157c-dk2.elf: error: PHDR segment not covered by LOAD segment
+collect2: error: ld returned 1 exit status
+
+Below, after applying the patch:
+
+'buildroot/output/host/lib/gcc/arm-buildroot-linux-gnueabihf/13.3.0/../../../../arm-buildroot-linux-gnueabihf/bin/ld' -o buildroot/output/build/arm-trusted-firmware-v2.11/build/stm32mp1/release/tf-a-stm32mp157c-dk2.elf --hash-style=gnu --as-needed -Map=buildroot/output/build/arm-trusted-firmware-v2.11/build/stm32mp1/release/tf-a-stm32mp157c-dk2.map --script buildroot/output/build/arm-trusted-firmware-v2.11/build/stm32mp1/release/stm32mp1.ld buildroot/output/build/arm-trusted-firmware-v2.11/build/stm32mp1/release/stm32mp1-stm32mp157c-dk2.o
+'buildroot/output/host/lib/gcc/arm-buildroot-linux-gnueabihf/13.3.0/../../../../arm-buildroot-linux-gnueabihf/bin/objcopy' -O binary buildroot/output/build/arm-trusted-firmware-v2.11/build/stm32mp1/release/tf-a-stm32mp157c-dk2.elf buildroot/output/build/arm-trusted-firmware-v2.11/build/stm32mp1/release/tf-a-stm32mp157c-dk2.bin
+
+Built /home/dario/projects/buildroot-10/output/build/arm-trusted-firmware-v2.11/build/stm32mp1/release/tf-a-stm32mp157c-dk2.bin successfully
+
+Fixes: 291e718229e7f ("build: skip toolchain detection for some targets")
+Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
+Upstream: backport from upstream https://review.trustedfirmware.org/c/TF-A/trusted-firmware-a/+/31746
+---
+ make_helpers/toolchain.mk | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/make_helpers/toolchain.mk b/make_helpers/toolchain.mk
+index 96e43a8b94cb..a81be3751d86 100644
+--- a/make_helpers/toolchain.mk
++++ b/make_helpers/toolchain.mk
+@@ -286,7 +286,7 @@ ifndef toolchain-mk
+
+ guess-gnu-gcc-cpp = $(1)
+ guess-gnu-gcc-as = $(1)
+- guess-gnu-gcc-ld = $(1)
++ guess-gnu-gcc-ld = $(shell $(1) --print-prog-name ld 2>$(nul))
+ guess-gnu-gcc-oc = $(shell $(1) --print-prog-name objcopy 2>$(nul))
+ guess-gnu-gcc-od = $(shell $(1) --print-prog-name objdump 2>$(nul))
+ guess-gnu-gcc-ar = $(call which,$(call decompat-path,$(patsubst %$(call file-name,$(1)),%$(subst gcc,gcc-ar,$(call file-name,$(1))),$(call compat-path,$(1)))))
+--
+2.43.0
+
Before applying this patch, the compiler was used instead of the linker as shown by the following error raised by the compilation of TF-A for the STM32MP157C-DK2 discovery board: 'buildroot/output/host/bin/arm-buildroot-linux-gnueabihf-gcc' -o buildroot/output/build/arm-trusted-firmware-custom/build/stm32mp1/release/tf-a-stm32mp157c-dk2.elf -Wl,--hash-style=gnu -Wl,--as-needed -nostartfiles -Wl,-Map=buildroot/output/build/arm-trusted-firmware-custom/build/stm32mp1/release/tf-a-stm32mp157c-dk2.map -Wl,-dT buildroot/output/build/arm-trusted-firmware-custom/build/stm32mp1/release/stm32mp1.ld buildroot/output/build/arm-trusted-firmware-custom/build/stm32mp1/release/stm32mp1-stm32mp157c-dk2.o buildroot/output/host/lib/gcc/arm-buildroot-linux-gnueabihf/13.3.0/../../../../arm-buildroot-linux-gnueabihf/bin/ld: buildroot/output/build/arm-trusted-firmware-custom/build/stm32mp1/release/tf-a-stm32mp157c-dk2.elf: error: PHDR segment not covered by LOAD segment collect2: error: ld returned 1 exit status Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com> --- Added in v2 ...-build-Set-guess-gnu-gcc-ld-properly.patch | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 boot/arm-trusted-firmware/v2.11/0001-fix-build-Set-guess-gnu-gcc-ld-properly.patch