From bcd4d8b9e61841387fc20d0924a06bfb555e4847 Mon Sep 17 00:00:00 2001 From: Daniele Lacamera Date: Tue, 24 Mar 2026 10:24:51 +0100 Subject: [PATCH] Fixed Clang sections in TZEN images --- Makefile | 22 +++++++++++++++++++--- arch.mk | 6 +++--- test-app/Makefile | 4 +++- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 41b6876e..a287aa98 100644 --- a/Makefile +++ b/Makefile @@ -199,9 +199,11 @@ ifeq ($(USE_GCC_HEADLESS),1) OBJCOPY_FLAGS+=--gap-fill $(FILL_BYTE) endif -ifeq ($(USE_CLANG),1) - ifeq ($(ARCH),ARM) - OBJCOPY_BIN_FLAGS+=$(CLANG_ARM_OBJCOPY_FLASH_FLAGS_BOOT) +ifeq ($(ARCH),ARM) + ifeq ($(USE_CLANG),1) + ifneq ($(TZEN),1) + OBJCOPY_BIN_FLAGS+=$(CLANG_ARM_OBJCOPY_FLASH_FLAGS_BOOT) + endif endif endif ifeq ($(TARGET),ti_hercules) @@ -333,7 +335,21 @@ wolfboot.efi: wolfboot.elf wolfboot.bin: wolfboot.elf @echo "\t[BIN] $@" +ifeq ($(USE_CLANG),1) +ifeq ($(TZEN),1) + $(Q)last_load="$$($(CROSS_COMPILE)readelf -Wl $< | awk '/ LOAD / { line = $$0 } END { print line }')"; \ + set -- $$last_load; \ + last_phys=$$(printf '%d' $$4); \ + last_filesz=$$(printf '%d' $$5); \ + padded_filesz=$$((($$last_filesz + 0xff) & ~0xff)); \ + pad_to=$$((last_phys + padded_filesz)); \ + $(OBJCOPY) $(OBJCOPY_FLAGS) $(OBJCOPY_BIN_FLAGS) --pad-to=$$(printf '0x%x' $$pad_to) -O binary $< $@ +else $(Q)$(OBJCOPY) $(OBJCOPY_FLAGS) $(OBJCOPY_BIN_FLAGS) -O binary $^ $@ +endif +else + $(Q)$(OBJCOPY) $(OBJCOPY_FLAGS) $(OBJCOPY_BIN_FLAGS) -O binary $^ $@ +endif @echo @echo "\t[SIZE]" $(Q)$(SIZE) wolfboot.elf diff --git a/arch.mk b/arch.mk index e8fbf8ec..bc587020 100644 --- a/arch.mk +++ b/arch.mk @@ -1301,9 +1301,9 @@ ifeq ($(USE_CLANG),1) CFLAGS+=-Wno-unknown-attributes -Wno-error=unknown-attributes CFLAGS+=-fno-unwind-tables -fno-asynchronous-unwind-tables LSCRIPT_FLAGS+=-T $(abspath $(WOLFBOOT_ROOT)/hal/clang-discard.ld) - # Keep Clang-specific raw-image section selection in one place. Both the - # bootloader and test-app need flash-backed sections only, but the bootloader - # has a few extra output sections that must be preserved. + # Clang-built ARM raw images may otherwise expand ELF loadable gaps into + # oversized binaries on some targets. Keep the section selection scoped to + # the Clang workaround paths only. CLANG_ARM_OBJCOPY_FLASH_FLAGS_BASE:=-j .text -j .edidx CLANG_ARM_OBJCOPY_FLASH_FLAGS_BOOT:=$(CLANG_ARM_OBJCOPY_FLASH_FLAGS_BASE) -j .ramcode -j .keystore -j .gnu.sgstubs CLANG_ARM_OBJCOPY_FLASH_FLAGS_APP:=$(CLANG_ARM_OBJCOPY_FLASH_FLAGS_BASE) diff --git a/test-app/Makefile b/test-app/Makefile index a81069bc..c051d7ab 100644 --- a/test-app/Makefile +++ b/test-app/Makefile @@ -108,7 +108,9 @@ ifeq ($(USE_CLANG),1) # Clang-built ARM ELFs can keep RAM sections as loadable segments, and raw # objcopy output then expands the flash-to-RAM gap into a huge sparse image. # The app image only needs the flash-backed output sections. - OBJCOPY_IMAGE_FLAGS+=$(CLANG_ARM_OBJCOPY_FLASH_FLAGS_APP) + ifneq ($(TZEN),1) + OBJCOPY_IMAGE_FLAGS+=$(CLANG_ARM_OBJCOPY_FLASH_FLAGS_APP) + endif endif ifeq ($(DEBUG_UART),1)