Skip to content

Commit 4eca085

Browse files
committed
Added USE_CLANG option to Makefile
1 parent 19d562d commit 4eca085

File tree

6 files changed

+79
-11
lines changed

6 files changed

+79
-11
lines changed

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@ LIBS=
2525
SIGN_ALG=
2626
OBJCOPY_FLAGS=
2727
BIG_ENDIAN?=0
28+
USE_CLANG?=0
29+
ifeq ($(USE_CLANG),1)
30+
USE_GCC?=0
31+
else
2832
USE_GCC?=1
33+
endif
2934
USE_GCC_HEADLESS?=1
3035
FLASH_OTP_KEYSTORE?=0
3136
BOOTLOADER_PARTITION_SIZE?=$$(( $(WOLFBOOT_PARTITION_BOOT_ADDRESS) - $(ARCH_FLASH_OFFSET)))

arch.mk

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,10 @@ ifeq ($(ARCH),ARM)
137137
CFLAGS+=-mthumb -mlittle-endian
138138
LDFLAGS+=-mthumb -mlittle-endian
139139
ifeq ($(USE_GCC),1)
140+
ifeq ($(findstring clang,$(notdir $(CC))),)
140141
CFLAGS+=-mthumb-interwork
141142
LDFLAGS+=-mthumb-interwork
143+
endif
142144
endif
143145

144146
## Target specific configuration
@@ -1220,6 +1222,29 @@ ifeq ($(TARGET),psoc6)
12201222
endif
12211223
endif
12221224

1225+
ifeq ($(USE_CLANG),1)
1226+
ifneq ($(ARCH),ARM)
1227+
$(error USE_CLANG=1 is currently supported only for ARCH=ARM)
1228+
endif
1229+
CLANG?=clang
1230+
CLANG_GCC_NAME?=$(CROSS_COMPILE)gcc
1231+
CLANG_TARGET?=arm-none-eabi
1232+
CLANG_DRIVER:=$(CLANG) --target=$(CLANG_TARGET) -ccc-gcc-name $(CLANG_GCC_NAME)
1233+
CLANG_LIBC_A?=$(shell $(CLANG_GCC_NAME) -print-file-name=libc.a)
1234+
CLANG_NEWLIB_INCLUDE?=$(abspath $(dir $(CLANG_LIBC_A))/../include)
1235+
1236+
CC=$(CLANG_DRIVER)
1237+
LD=$(CLANG_DRIVER)
1238+
AS=$(CLANG_DRIVER)
1239+
AR=$(CROSS_COMPILE)ar
1240+
OBJCOPY?=$(CROSS_COMPILE)objcopy
1241+
SIZE=$(CROSS_COMPILE)size
1242+
1243+
CFLAGS+=-isystem $(CLANG_NEWLIB_INCLUDE)
1244+
CFLAGS+=-DWOLFSSL_NO_ATOMIC -DWOLFSSL_NO_ATOMICS
1245+
LDFLAGS+=-nostdlib
1246+
endif
1247+
12231248
ifeq ($(USE_GCC),1)
12241249
## Toolchain setup
12251250
CC=$(CROSS_COMPILE)gcc

include/wolfboot/wolfboot.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,16 @@ extern "C" {
4646
#ifndef RAMFUNCTION
4747
# if defined(__WOLFBOOT) && defined(RAM_CODE)
4848
# if defined(ARCH_ARM)
49-
# if defined(__clang__)
50-
# define RAMFUNCTION __attribute__((used,section(".ramcode")))
51-
# else
49+
# if defined(__has_attribute)
50+
# if __has_attribute(long_call)
51+
# define RAMFUNCTION __attribute__((used,section(".ramcode"),long_call))
52+
# else
53+
# define RAMFUNCTION __attribute__((used,section(".ramcode")))
54+
# endif
55+
# elif defined(__GNUC__)
5256
# define RAMFUNCTION __attribute__((used,section(".ramcode"),long_call))
57+
# else
58+
# define RAMFUNCTION __attribute__((used,section(".ramcode")))
5359
# endif
5460
# elif defined(ARCH_PPC)
5561
# define RAMFUNCTION __attribute__((used,section(".ramcode"),longcall))

options.mk

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
11
WOLFCRYPT_OBJS+=$(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/asn.o
2-
USE_GCC?=1
2+
USE_CLANG?=0
3+
ifeq ($(USE_CLANG),1)
4+
USE_GCC?=0
5+
else
6+
USE_GCC?=1
7+
endif
38
WOLFBOOT_TEST_FILLER?=0
49
WOLFBOOT_TIME_TEST?=0
510

11+
ifeq ($(USE_CLANG),1)
12+
ifeq ($(USE_GCC),1)
13+
$(error USE_CLANG=1 is incompatible with USE_GCC=1; set USE_GCC=0)
14+
endif
15+
endif
16+
617
# Support for Built-in ROT into OTP flash memory
718
ifeq ($(FLASH_OTP_KEYSTORE),1)
819
CFLAGS+=-D"FLASH_OTP_KEYSTORE"
@@ -722,7 +733,9 @@ ifeq ($(DEBUG_SYMBOLS),1)
722733
ifeq ($(USE_GCC),1)
723734
CFLAGS+=-ggdb3
724735
else ifneq ($(ARCH),AURIX_TC3)
736+
ifneq ($(USE_CLANG),1)
725737
CFLAGS+=-gstabs
738+
endif
726739
endif
727740
endif
728741

@@ -1031,9 +1044,11 @@ OBJS+=$(OBJS_EXTRA)
10311044

10321045
ifeq ($(USE_GCC_HEADLESS),1)
10331046
ifeq ($(USE_GCC),1)
1034-
ifneq ($(ARCH),RENESAS_RX)
1035-
ifneq ($(ARCH),AURIX_TC3)
1036-
CFLAGS+="-Wstack-usage=$(STACK_USAGE)"
1047+
ifneq ($(USE_CLANG),1)
1048+
ifneq ($(ARCH),RENESAS_RX)
1049+
ifneq ($(ARCH),AURIX_TC3)
1050+
CFLAGS+="-Wstack-usage=$(STACK_USAGE)"
1051+
endif
10371052
endif
10381053
endif
10391054
endif

src/update_flash.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,8 @@ static int wolfBoot_delta_update(struct wolfBoot_image *boot,
757757
# if defined(__GNUC__) && !defined(__clang__)
758758
# pragma GCC push_options
759759
# pragma GCC optimize("O0")
760+
# elif defined(__clang__)
761+
# pragma clang optimize off
760762
# elif defined(__IAR_SYSTEMS_ICC__)
761763
# pragma optimize=none
762764
# endif
@@ -1476,6 +1478,8 @@ void RAMFUNCTION wolfBoot_start(void)
14761478
#ifdef WOLFBOOT_ARMORED
14771479
# if defined(__GNUC__) && !defined(__clang__)
14781480
# pragma GCC pop_options
1481+
# elif defined(__clang__)
1482+
# pragma clang optimize on
14791483
# elif defined(__IAR_SYSTEMS_ICC__)
14801484
# pragma optimize=default
14811485
# endif

test-app/Makefile

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@ endif
2222
CFLAGS+=-I. -I..
2323
DEBUG?=1
2424
DELTA_DATA_SIZE?=2000
25-
USE_GCC?=1
25+
USE_CLANG?=0
26+
ifeq ($(USE_CLANG),1)
27+
USE_GCC?=0
28+
else
29+
USE_GCC?=1
30+
endif
2631
USE_GCC_HEADLESS?=1
2732
BOOTLOADER_PARTITION_SIZE?=$$(( $(WOLFBOOT_PARTITION_BOOT_ADDRESS) - $(ARCH_FLASH_OFFSET)))
2833

@@ -57,14 +62,18 @@ else
5762
CFLAGS+=-Wall -ffreestanding -Wno-unused
5863
# Stack usage computation not supported on TriCore
5964
ifneq ($(ARCH),AURIX_TC3)
60-
CFLAGS+=-Wstack-usage=1024 -nostartfiles
65+
ifneq ($(USE_CLANG),1)
66+
CFLAGS+=-Wstack-usage=1024
67+
endif
6168
endif
6269
CFLAGS+=-DTARGET_$(TARGET) -I../include
6370
CFLAGS+=-g
6471
ifeq ($(USE_GCC),1)
6572
CFLAGS+=-ggdb3
6673
else ifneq ($(ARCH),AURIX_TC3)
67-
CFLAGS+=-gstabs
74+
ifneq ($(USE_CLANG),1)
75+
CFLAGS+=-gstabs
76+
endif
6877
endif
6978

7079
ifeq ($(ARCH),RENESAS_RX)
@@ -78,14 +87,18 @@ endif
7887

7988
include ../arch.mk
8089

90+
ifeq ($(USE_CLANG),1)
91+
APP_OBJS+=../src/string.o
92+
endif
93+
8194
# Optional alias for clearer TZ PSA selection in app builds.
8295
ifeq ($(WOLFCRYPT_TZ_PSA),1)
8396
WOLFCRYPT_TZ=1
8497
WOLFCRYPT_TZ_PSA=1
8598
endif
8699

87100
# Setup default linker flags
88-
LDFLAGS+=-T $(LSCRIPT) -Wl,-gc-sections -Wl,-Map=image.map
101+
LDFLAGS+=-T $(LSCRIPT) -Wl,-gc-sections -Wl,-Map=image.map -nostartfiles
89102

90103
# Setup default objcopy flags
91104
OBJCOPY_FLAGS+=--gap-fill $(FILL_BYTE)

0 commit comments

Comments
 (0)