@@ -16,7 +16,7 @@ TARGET_DBGSRC_DIR = "/share/opensbi/*/generic/firmware/"
TARGET_CC_ARCH += "${LDFLAGS}"
RISCV_SBI_FW_TEXT_START ??= "0x80000000"
-EXTRA_OEMAKE += "REPRODUCIBLE=y CROSS_COMPILE=${HOST_PREFIX} ELFFLAGS="${LDFLAGS}" PLATFORM=${RISCV_SBI_PLAT} I=${D} FW_TEXT_START=${RISCV_SBI_FW_TEXT_START}"
+EXTRA_OEMAKE += "REPRODUCIBLE=y CROSS_COMPILE=${HOST_PREFIX} PLATFORM=${RISCV_SBI_PLAT} I=${D} FW_TEXT_START=${RISCV_SBI_FW_TEXT_START}"
EXTRA_OEMAKE:append:toolchain-clang = " LLVM=y"
# If RISCV_SBI_PAYLOAD is set then include it as a payload
EXTRA_OEMAKE:append = " ${@riscv_get_extra_oemake_image(d)}"
@@ -50,4 +50,8 @@ FILES:${PN} += "/share/opensbi/*/${RISCV_SBI_PLAT}/firmware/fw_jump.*"
FILES:${PN} += "/share/opensbi/*/${RISCV_SBI_PLAT}/firmware/fw_payload.*"
FILES:${PN} += "/share/opensbi/*/${RISCV_SBI_PLAT}/firmware/fw_dynamic.*"
+# OpenSBI firmware ELFs are bare-metal M-mode binaries (--build-id=none,
+# no dynamic linker) and intentionally do not carry GNU_HASH.
+INSANE_SKIP += "ldflags"
+
COMPATIBLE_HOST = "(riscv64|riscv32).*"
opensbi_1.8.1.bb passes ELFFLAGS="${LDFLAGS}" via EXTRA_OEMAKE. Being a make command-line assignment, it overrides OpenSBI's in-Makefile "ELFFLAGS +=" and drops the mandatory firmware link flags: -Wl,--gc-sections -Wl,--exclude-libs,ALL -Wl,--build-id=none -Wl,--no-dynamic-linker -Wl,-pie Losing --gc-sections retains unused fdt_*/atomic_* code and grows .text; losing -pie/--no-dynamic-linker drops the M-mode firmware hardening. The distro LDFLAGS were not reaching the link regardless: OpenSBI rebuilds CC from CROSS_COMPILE (Makefile: CC = $(CROSS_COMPILE)gcc), so oe's CC and its TARGET_CC_ARCH += "${LDFLAGS}" do not apply, and passing them via ELFFLAGS was the only path in. They are also dynamic-linking flags with no role in bare-metal firmware, so drop the override; REPRODUCIBLE=y and CROSS_COMPILE stay. Removing it re-exposes an ldflags QA warning that the injected --hash-style=gnu had been satisfying. These firmware ELFs are bare-metal M-mode binaries (--build-id=none, no dynamic linker) that legitimately carry no GNU_HASH, so add INSANE_SKIP += "ldflags", as linux-firmware does. Tested on oe-core master (DISTRO=nodistro, MACHINE=qemuriscv64) via the oe-nodistro-master bitbake-setup config: bitbake opensbi grep -c gc-sections .../opensbi/*/temp/log.do_compile # 0 -> 4 Before, the fw_jump.elf link carries only the LDFLAGS content (-Wl,-O1, --hash-style=gnu, --as-needed, -z relro/now) with OpenSBI's flags absent, and do_package_qa reports ldflags errors on all three firmware ELFs. After, the link carries OpenSBI's flags (-Wl,--gc-sections, --exclude-libs,ALL, --build-id=none, --no-dynamic-linker, -pie) and QA passes. On a single-SoC defconfig, restoring --gc-sections roughly halves fw_jump.bin. Fixes: 9f95660886db ("opensbi: Pass CROSS_COMPILE and REPRODUCIBLE flags") AI-Generated: Uses Cursor Signed-off-by: Gustavo Henrique Nihei <gustavo.nihei@espressif.com> --- meta/recipes-bsp/opensbi/opensbi_1.8.1.bb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)