Skip to content

Commit 5d22025

Browse files
committed
Fixed Clang sections in TZEN images
1 parent 55e8f95 commit 5d22025

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

Makefile

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,11 @@ ifeq ($(USE_GCC_HEADLESS),1)
199199
OBJCOPY_FLAGS+=--gap-fill $(FILL_BYTE)
200200
endif
201201

202-
ifeq ($(USE_CLANG),1)
203-
ifeq ($(ARCH),ARM)
204-
OBJCOPY_BIN_FLAGS+=$(CLANG_ARM_OBJCOPY_FLASH_FLAGS_BOOT)
202+
ifeq ($(ARCH),ARM)
203+
ifeq ($(USE_CLANG),1)
204+
ifneq ($(TZEN),1)
205+
OBJCOPY_BIN_FLAGS+=$(CLANG_ARM_OBJCOPY_FLASH_FLAGS_BOOT)
206+
endif
205207
endif
206208
endif
207209
ifeq ($(TARGET),ti_hercules)
@@ -333,7 +335,21 @@ wolfboot.efi: wolfboot.elf
333335

334336
wolfboot.bin: wolfboot.elf
335337
@echo "\t[BIN] $@"
338+
ifeq ($(USE_CLANG),1)
339+
ifeq ($(TZEN),1)
340+
$(Q)last_load="$$($(CROSS_COMPILE)readelf -Wl $< | awk '/ LOAD / { line = $$0 } END { print line }')"; \
341+
set -- $$last_load; \
342+
last_phys=$$(printf '%d' $$4); \
343+
last_filesz=$$(printf '%d' $$5); \
344+
padded_filesz=$$((($$last_filesz + 0xff) & ~0xff)); \
345+
pad_to=$$((last_phys + padded_filesz)); \
346+
$(OBJCOPY) $(OBJCOPY_FLAGS) $(OBJCOPY_BIN_FLAGS) --pad-to=$$(printf '0x%x' $$pad_to) -O binary $< $@
347+
else
336348
$(Q)$(OBJCOPY) $(OBJCOPY_FLAGS) $(OBJCOPY_BIN_FLAGS) -O binary $^ $@
349+
endif
350+
else
351+
$(Q)$(OBJCOPY) $(OBJCOPY_FLAGS) $(OBJCOPY_BIN_FLAGS) -O binary $^ $@
352+
endif
337353
@echo
338354
@echo "\t[SIZE]"
339355
$(Q)$(SIZE) wolfboot.elf

arch.mk

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,9 +1301,9 @@ ifeq ($(USE_CLANG),1)
13011301
CFLAGS+=-Wno-unknown-attributes -Wno-error=unknown-attributes
13021302
CFLAGS+=-fno-unwind-tables -fno-asynchronous-unwind-tables
13031303
LSCRIPT_FLAGS+=-T $(abspath $(WOLFBOOT_ROOT)/hal/clang-discard.ld)
1304-
# Keep Clang-specific raw-image section selection in one place. Both the
1305-
# bootloader and test-app need flash-backed sections only, but the bootloader
1306-
# has a few extra output sections that must be preserved.
1304+
# Clang-built ARM raw images may otherwise expand ELF loadable gaps into
1305+
# oversized binaries on some targets. Keep the section selection scoped to
1306+
# the Clang workaround paths only.
13071307
CLANG_ARM_OBJCOPY_FLASH_FLAGS_BASE:=-j .text -j .edidx
13081308
CLANG_ARM_OBJCOPY_FLASH_FLAGS_BOOT:=$(CLANG_ARM_OBJCOPY_FLASH_FLAGS_BASE) -j .ramcode -j .keystore -j .gnu.sgstubs
13091309
CLANG_ARM_OBJCOPY_FLASH_FLAGS_APP:=$(CLANG_ARM_OBJCOPY_FLASH_FLAGS_BASE)

test-app/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@ ifeq ($(USE_CLANG),1)
108108
# Clang-built ARM ELFs can keep RAM sections as loadable segments, and raw
109109
# objcopy output then expands the flash-to-RAM gap into a huge sparse image.
110110
# The app image only needs the flash-backed output sections.
111-
OBJCOPY_IMAGE_FLAGS+=$(CLANG_ARM_OBJCOPY_FLASH_FLAGS_APP)
111+
ifneq ($(TZEN),1)
112+
OBJCOPY_IMAGE_FLAGS+=$(CLANG_ARM_OBJCOPY_FLASH_FLAGS_APP)
113+
endif
112114
endif
113115

114116
ifeq ($(DEBUG_UART),1)

0 commit comments

Comments
 (0)