Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .github/workflows/test-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,17 @@ jobs:
run: |
sudo apt-get install -y gcc-arm-none-eabi gcc-aarch64-linux-gnu gcc-powerpc-linux-gnu gnu-efi

- name: Install Clang
if: |
inputs.config-file == './config/examples/stm32h7.config' ||
inputs.config-file == './config/examples/stm32h7-octospi.config' ||
inputs.config-file == './config/examples/stm32u5.config' ||
inputs.config-file == './config/examples/stm32u5-wolfcrypt-tz.config' ||
inputs.config-file == './config/examples/stm32u5-nonsecure-dualbank.config' ||
inputs.config-file == 'config/examples/stm32n567.config'
run: |
sudo apt-get install -y clang

- name: make clean
run: |
make distclean
Expand All @@ -92,3 +103,17 @@ jobs:
- name: Build wolfboot
run: |
make ${{inputs.make-args}}

- name: Rebuild wolfboot with Clang
if: |
inputs.config-file == './config/examples/stm32h7.config' ||
inputs.config-file == './config/examples/stm32h7-octospi.config' ||
inputs.config-file == './config/examples/stm32u5.config' ||
inputs.config-file == './config/examples/stm32u5-wolfcrypt-tz.config' ||
inputs.config-file == './config/examples/stm32u5-nonsecure-dualbank.config' ||
inputs.config-file == 'config/examples/stm32n567.config'
run: |
make distclean
cp ${{inputs.config-file}} .config
make -C tools/keytools && make -C tools/bin-assemble
make USE_CLANG=1 USE_GCC=0 ${{inputs.make-args}}
25 changes: 24 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ DEBUG_UART?=0
LIBS=
SIGN_ALG=
OBJCOPY_FLAGS=
OBJCOPY_BIN_FLAGS=
BIG_ENDIAN?=0
USE_CLANG?=0
ifeq ($(USE_CLANG),1)
Expand Down Expand Up @@ -196,6 +197,14 @@ ifeq ($(USE_GCC_HEADLESS),1)
LSCRIPT_FLAGS+=-T $(LSCRIPT)
OBJCOPY_FLAGS+=--gap-fill $(FILL_BYTE)
endif

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)
LSCRIPT_FLAGS+=--run_linker $(LSCRIPT)
endif
Expand Down Expand Up @@ -322,7 +331,21 @@ wolfboot.efi: wolfboot.elf

wolfboot.bin: wolfboot.elf
@echo "\t[BIN] $@"
$(Q)$(OBJCOPY) $(OBJCOPY_FLAGS) -O binary $^ $@
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
Expand Down
14 changes: 12 additions & 2 deletions arch.mk
Original file line number Diff line number Diff line change
Expand Up @@ -1282,15 +1282,25 @@ ifeq ($(USE_CLANG),1)
CLANG_NEWLIB_INCLUDE?=$(abspath $(dir $(CLANG_LIBC_A))/../include)

CC=$(CLANG_DRIVER)
LD=$(CLANG_DRIVER)
# Keep clang for compilation, but use the GNU linker driver so linker-script
# LMAs for RAM sections are preserved and objcopy does not emit sparse images.
LD=$(CLANG_GCC_NAME)
AS=$(CLANG_DRIVER)
AR=$(CROSS_COMPILE)ar
OBJCOPY?=$(CROSS_COMPILE)objcopy
SIZE=$(CROSS_COMPILE)size

CFLAGS+=-isystem $(CLANG_NEWLIB_INCLUDE)
CFLAGS+=-DWOLFSSL_NO_ATOMIC -DWOLFSSL_NO_ATOMICS
LDFLAGS+=-nostdlib
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)
# 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)
endif

ifeq ($(USE_GCC),1)
Expand Down
14 changes: 14 additions & 0 deletions hal/clang-discard.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
SECTIONS
{
/DISCARD/ :
{
*(.ARM.extab* .gnu.linkonce.armextab.*)
*(.eh_frame* .gcc_except_table*)
*(.preinit_array*)
*(.init_array*)
*(.fini_array*)
*(.ctors*)
*(.dtors*)
*(.jcr*)
}
}
1 change: 1 addition & 0 deletions hal/stm32l4.ld
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ SECTIONS
. = ALIGN(4);
_end_text = .;
} > FLASH

.edidx :
{
. = ALIGN(4);
Expand Down
3 changes: 3 additions & 0 deletions options.mk
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ ifeq ($(USE_CLANG),1)
ifeq ($(USE_GCC),1)
$(error USE_CLANG=1 is incompatible with USE_GCC=1; set USE_GCC=0)
endif
ifeq ($(ARMORED),1)
$(error USE_CLANG=1 requires ARMORED=0)
endif
endif

# Support for Built-in ROT into OTP flash memory
Expand Down
31 changes: 24 additions & 7 deletions test-app/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ endif
include ../arch.mk

ifeq ($(USE_CLANG),1)
APP_OBJS+=../src/string.o
APP_NEEDS_STRING:=1
endif

# Optional alias for clearer TZ PSA selection in app builds.
Expand All @@ -102,9 +102,23 @@ LDFLAGS+=-T $(LSCRIPT) -Wl,-gc-sections -Wl,-Map=image.map -nostartfiles

# Setup default objcopy flags
OBJCOPY_FLAGS+=--gap-fill $(FILL_BYTE)
OBJCOPY_IMAGE_FLAGS:=

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.
ifneq ($(TZEN),1)
OBJCOPY_IMAGE_FLAGS+=$(CLANG_ARM_OBJCOPY_FLASH_FLAGS_APP)
endif
endif

ifeq ($(DEBUG_UART),1)
CFLAGS+=-DDEBUG_UART
APP_NEEDS_STRING:=1
endif

ifeq ($(APP_NEEDS_STRING),1)
APP_OBJS+=../src/string.o
endif

Expand Down Expand Up @@ -288,7 +302,10 @@ ifeq ($(TZEN),1)
endif
endif
endif
CFLAGS+=-DWOLFBOOT_SECURE_CALLS -Wstack-usage=19184
CFLAGS+=-DWOLFBOOT_SECURE_CALLS
ifneq ($(USE_CLANG),1)
CFLAGS+=-Wstack-usage=19184
endif
LDFLAGS+=--specs=nosys.specs -u _printf_float
endif
ifeq ($(WOLFCRYPT_TZ_PSA),1)
Expand Down Expand Up @@ -899,15 +916,15 @@ delta-extra-data:LDFLAGS=-Wl,-Map=image.map

image.bin: image.elf
@echo "\t[BIN] $@"
$(Q)$(OBJCOPY) $(OBJCOPY_FLAGS) -O binary $^ $@
$(Q)$(OBJCOPY) $(OBJCOPY_FLAGS) $(OBJCOPY_IMAGE_FLAGS) -O binary $^ $@

image.hex: image.elf
@echo "\t[HEX] $@"
$(Q)$(OBJCOPY) $(OBJCOPY_FLAGS) -O ihex $^ $@
$(Q)$(OBJCOPY) $(OBJCOPY_FLAGS) $(OBJCOPY_IMAGE_FLAGS) -O ihex $^ $@

image.srec: image.elf
@echo "\t[SREC] $@"
$(Q)$(OBJCOPY) $(OBJCOPY_FLAGS) -O srec $^ $@
$(Q)$(OBJCOPY) $(OBJCOPY_FLAGS) $(OBJCOPY_IMAGE_FLAGS) -O srec $^ $@

APP_OBJS := $(patsubst $(WOLFBOOT_LIB_WOLFSSL)/%, \
$(WOLFSSL_LOCAL_OBJDIR)/%, $(APP_OBJS))
Expand All @@ -917,7 +934,7 @@ ifeq ($(ELF_FLASH_SCATTER),1)
SQUASHELF_TOOL = ../tools/squashelf/squashelf
image-orig.elf: $(APP_OBJS) $(LSCRIPT)
@echo "\t[LD] $@"
$(Q)$(LD) $(LDFLAGS) $(APP_OBJS) $(LIBS) $(OUTPUT_FLAG) $@
$(Q)$(LD) $(LDFLAGS) $(LSCRIPT_FLAGS) $(APP_OBJS) $(LIBS) $(OUTPUT_FLAG) $@

image.elf: image-orig.elf
@echo "\t[SQUASHELF] $@"
Expand All @@ -926,7 +943,7 @@ else
# Default behavior when ELF_FLASH_SCATTER is not set
image.elf: $(APP_OBJS) $(LSCRIPT)
@echo "\t[LD] $@"
$(Q)$(LD) $(LDFLAGS) $(APP_OBJS) $(LIBS) $(OUTPUT_FLAG) $@
$(Q)$(LD) $(LDFLAGS) $(LSCRIPT_FLAGS) $(APP_OBJS) $(LIBS) $(OUTPUT_FLAG) $@
endif

standalone: image.bin
Expand Down
Loading