From 22fa58cbfaa99a6458247c713bd03c2cac2a68fe Mon Sep 17 00:00:00 2001 From: dp-arm Date: Fri, 5 May 2017 12:21:03 +0100 Subject: [PATCH 01/10] Use a callee-saved register to be AAPCS-compliant x8 is not a callee-saved register and can be corrupted. Use x19 instead to be AAPCS-compliant. Fixes ARM-software/tf-issues#478 Change-Id: Ib4f114c36f4c11351ae856f953c45dca92b27c3b Signed-off-by: dp-arm --- lib/cpus/aarch64/cpu_helpers.S | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/cpus/aarch64/cpu_helpers.S b/lib/cpus/aarch64/cpu_helpers.S index 7ad0bc755..238455341 100644 --- a/lib/cpus/aarch64/cpu_helpers.S +++ b/lib/cpus/aarch64/cpu_helpers.S @@ -259,8 +259,8 @@ func print_errata_status /* * Printing errata status requires atomically testing the printed flag. */ - stp x8, x30, [sp, #-16]! - mov x8, x0 + stp x19, x30, [sp, #-16]! + mov x19, x0 /* * Load pointers to errata lock and printed flag. Call @@ -270,8 +270,8 @@ func print_errata_status ldr x0, [x1, #CPU_ERRATA_LOCK] ldr x1, [x1, #CPU_ERRATA_PRINTED] bl errata_needs_reporting - mov x1, x8 - ldp x8, x30, [sp], #16 + mov x1, x19 + ldp x19, x30, [sp], #16 cbnz x0, .Lprint #endif .Lnoprint: From c243e30babd0cc0ac392bf79006171256d3a4d01 Mon Sep 17 00:00:00 2001 From: dp-arm Date: Tue, 2 May 2017 11:49:33 +0100 Subject: [PATCH 02/10] Include missing header in arm_bl2_setup.c Change-Id: I4108ce8d1fe7d3fd51a5a96d43b9134c23b8399b Signed-off-by: dp-arm --- plat/arm/common/arm_bl2_setup.c | 1 + 1 file changed, 1 insertion(+) diff --git a/plat/arm/common/arm_bl2_setup.c b/plat/arm/common/arm_bl2_setup.c index ffec66425..e5619b7f4 100644 --- a/plat/arm/common/arm_bl2_setup.c +++ b/plat/arm/common/arm_bl2_setup.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include From 0851cb2468e76c5274d6cb8a98139a50a9091fcd Mon Sep 17 00:00:00 2001 From: dp-arm Date: Tue, 2 May 2017 12:35:24 +0100 Subject: [PATCH 03/10] fvp: Remove unnecessary default case The default case is impossible to hit as the `power_level` is already checked earlier. Avoids a clang warning. Change-Id: I707463c843adc748ee9aa1d2313f9ab7dab3a8ab Signed-off-by: dp-arm --- plat/arm/board/fvp/fvp_pm.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/plat/arm/board/fvp/fvp_pm.c b/plat/arm/board/fvp/fvp_pm.c index 449c580f1..f4df658a7 100644 --- a/plat/arm/board/fvp/fvp_pm.c +++ b/plat/arm/board/fvp/fvp_pm.c @@ -296,8 +296,6 @@ static int fvp_node_hw_state(u_register_t target_cpu, case ARM_PWR_LVL1: ret = (psysr & PSYSR_AFF_L1) ? HW_ON : HW_OFF; break; - default: - assert(0); } return ret; From 9bedc6d3bdebe3ef4318c59a05a04be6783cfe19 Mon Sep 17 00:00:00 2001 From: dp-arm Date: Tue, 2 May 2017 12:39:19 +0100 Subject: [PATCH 04/10] Remove plat_match_rotpk reference This function was removed long ago. Remove remaining pragma reference. Change-Id: I66c556863d47dc17d2ffdc6c23aa524df6aade80 Signed-off-by: dp-arm --- plat/arm/board/common/board_arm_trusted_boot.c | 1 - 1 file changed, 1 deletion(-) diff --git a/plat/arm/board/common/board_arm_trusted_boot.c b/plat/arm/board/common/board_arm_trusted_boot.c index 391ae45cd..5df1cc014 100644 --- a/plat/arm/board/common/board_arm_trusted_boot.c +++ b/plat/arm/board/common/board_arm_trusted_boot.c @@ -12,7 +12,6 @@ #include /* Weak definition may be overridden in specific platform */ -#pragma weak plat_match_rotpk #pragma weak plat_get_nv_ctr #pragma weak plat_set_nv_ctr From 7c7dffd8aa63f168cd61770d9a6aa7923f8718af Mon Sep 17 00:00:00 2001 From: dp-arm Date: Wed, 3 May 2017 12:14:10 +0100 Subject: [PATCH 05/10] plat/arm: Compile out impossible conditional for AArch32 Since ARM_DRAM2_BASE is above the 32-bit limit, the condition is always false. Wrap this condition in an ifndef to avoid warnings during compilation. Change-Id: Ideabb6c65de6c62474ed03eb29df4b049d5316be Signed-off-by: dp-arm --- plat/arm/common/arm_pm.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plat/arm/common/arm_pm.c b/plat/arm/common/arm_pm.c index 2369e0cc7..cc131a9fe 100644 --- a/plat/arm/common/arm_pm.c +++ b/plat/arm/common/arm_pm.c @@ -122,9 +122,11 @@ int arm_validate_ns_entrypoint(uintptr_t entrypoint) if ((entrypoint >= ARM_NS_DRAM1_BASE) && (entrypoint < (ARM_NS_DRAM1_BASE + ARM_NS_DRAM1_SIZE))) return PSCI_E_SUCCESS; +#ifndef AARCH32 if ((entrypoint >= ARM_DRAM2_BASE) && (entrypoint < (ARM_DRAM2_BASE + ARM_DRAM2_SIZE))) return PSCI_E_SUCCESS; +#endif return PSCI_E_INVALID_ADDRESS; } From 344af65608262b9ee9d71617c5f5e087c82bd7c4 Mon Sep 17 00:00:00 2001 From: dp-arm Date: Wed, 3 May 2017 16:30:54 +0100 Subject: [PATCH 06/10] Switch default C environment from c99 to gnu99 Since TF uses GCC extensions, switch the C environment from c99 to gnu99. This change allows armclang to build TF. Change-Id: Iaacb2726ba1458af59faf607ae9405d6eedb9962 Signed-off-by: dp-arm --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index d9a29bd65..5396c0ed5 100644 --- a/Makefile +++ b/Makefile @@ -135,8 +135,8 @@ ASFLAGS += $(CPPFLAGS) $(ASFLAGS_$(ARCH)) \ -D__ASSEMBLY__ -ffreestanding \ -Wa,--fatal-warnings TF_CFLAGS += $(CPPFLAGS) $(TF_CFLAGS_$(ARCH)) \ - -ffreestanding -fno-builtin -Wall -std=c99 -Os \ - -ffunction-sections -fdata-sections + -ffreestanding -fno-builtin -Wall -std=gnu99 \ + -Os -ffunction-sections -fdata-sections LDFLAGS += --fatal-warnings -O1 LDFLAGS += --gc-sections From 72610c4102990d4f17bd654acad9a415733f795b Mon Sep 17 00:00:00 2001 From: dp-arm Date: Tue, 2 May 2017 11:09:11 +0100 Subject: [PATCH 07/10] build: Introduce HOSTCC flag Tools are built using the compiler specified in `HOSTCC` instead of reusing the `CC` variable. By default, gcc is used. Change-Id: I83636a375c61f4804b4e80784db9d061fe20af87 Signed-off-by: dp-arm --- Makefile | 3 +++ tools/cert_create/Makefile | 6 +++--- tools/fiptool/Makefile | 6 +++--- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 5396c0ed5..15d418290 100644 --- a/Makefile +++ b/Makefile @@ -113,6 +113,9 @@ endif # Toolchain ################################################################################ +HOSTCC := gcc +export HOSTCC + CC := ${CROSS_COMPILE}gcc CPP := ${CROSS_COMPILE}cpp AS := ${CROSS_COMPILE}gcc diff --git a/tools/cert_create/Makefile b/tools/cert_create/Makefile index 8a216495b..efd1f25d5 100644 --- a/tools/cert_create/Makefile +++ b/tools/cert_create/Makefile @@ -64,7 +64,7 @@ INC_DIR := -I ./include -I ${PLAT_INCLUDE} -I ${OPENSSL_DIR}/include LIB_DIR := -L ${OPENSSL_DIR}/lib LIB := -lssl -lcrypto -CC := gcc +HOSTCC ?= gcc .PHONY: all clean realclean @@ -75,11 +75,11 @@ ${BINARY}: ${OBJECTS} Makefile @echo 'const char build_msg[] = "Built : "__TIME__", "__DATE__; \ const char platform_msg[] = "${PLAT_MSG}";' | \ ${CC} -c ${CFLAGS} -xc - -o src/build_msg.o - ${Q}${CC} src/build_msg.o ${OBJECTS} ${LIB_DIR} ${LIB} -o $@ + ${Q}${HOSTCC} src/build_msg.o ${OBJECTS} ${LIB_DIR} ${LIB} -o $@ %.o: %.c @echo " CC $<" - ${Q}${CC} -c ${CFLAGS} ${INC_DIR} $< -o $@ + ${Q}${HOSTCC} -c ${CFLAGS} ${INC_DIR} $< -o $@ clean: $(call SHELL_DELETE_ALL, src/build_msg.o ${OBJECTS}) diff --git a/tools/fiptool/Makefile b/tools/fiptool/Makefile index 29eac2a79..ee674b7f9 100644 --- a/tools/fiptool/Makefile +++ b/tools/fiptool/Makefile @@ -29,7 +29,7 @@ endif INCLUDE_PATHS := -I. -I../../include/tools_share -CC := gcc +HOSTCC ?= gcc .PHONY: all clean distclean @@ -37,7 +37,7 @@ all: ${PROJECT} fip_create ${PROJECT}: ${OBJECTS} Makefile @echo " LD $@" - ${Q}${CC} ${OBJECTS} -o $@ ${LDLIBS} + ${Q}${HOSTCC} ${OBJECTS} -o $@ ${LDLIBS} @${ECHO_BLANK_LINE} @echo "Built $@ successfully" @${ECHO_BLANK_LINE} @@ -48,7 +48,7 @@ fip_create: fip_create.sh %.o: %.c %.h Makefile @echo " CC $<" - ${Q}${CC} -c ${CPPFLAGS} ${CFLAGS} ${INCLUDE_PATHS} $< -o $@ + ${Q}${HOSTCC} -c ${CPPFLAGS} ${CFLAGS} ${INCLUDE_PATHS} $< -o $@ clean: $(call SHELL_DELETE_ALL, ${PROJECT} ${OBJECTS} fip_create) From d5461857ac66ed4f5ad002936efd9bd8cf99d22f Mon Sep 17 00:00:00 2001 From: dp-arm Date: Tue, 2 May 2017 12:00:08 +0100 Subject: [PATCH 08/10] build: Introduce clang support Only the compiler is switched to clang. The assembler and linker are provided by the GCC toolchain. clang is used to build TF when the base name of the path assigned to `CC` contains the string 'clang'. `CROSS_COMPILE` is still needed and should point to the appropriate GCC toolchain. Tested with clang 3.9.x and 4.0.x. Change-Id: I53236d64e3c83ad27fc843bae5fcdae30f2e325e Signed-off-by: dp-arm --- Makefile | 13 ++++++++++--- include/lib/aarch32/arch_helpers.h | 4 ++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 15d418290..44d4933b8 100644 --- a/Makefile +++ b/Makefile @@ -126,11 +126,18 @@ OD := ${CROSS_COMPILE}objdump NM := ${CROSS_COMPILE}nm PP := ${CROSS_COMPILE}gcc -E -ASFLAGS_aarch64 = -mgeneral-regs-only -TF_CFLAGS_aarch64 = -mgeneral-regs-only -mstrict-align +ifneq ($(findstring clang,$(notdir $(CC))),) +TF_CFLAGS_aarch32 = -target armv8a-none-eabi +TF_CFLAGS_aarch64 = -target aarch64-elf +else +TF_CFLAGS_aarch32 = -march=armv8-a +TF_CFLAGS_aarch64 = -march=armv8-a +endif + +TF_CFLAGS_aarch64 += -mgeneral-regs-only -mstrict-align ASFLAGS_aarch32 = -march=armv8-a -TF_CFLAGS_aarch32 = -march=armv8-a +ASFLAGS_aarch64 = -march=armv8-a CPPFLAGS = ${DEFINES} ${INCLUDES} -nostdinc \ -Wmissing-include-dirs -Werror diff --git a/include/lib/aarch32/arch_helpers.h b/include/lib/aarch32/arch_helpers.h index af498ca5f..e652a59ec 100644 --- a/include/lib/aarch32/arch_helpers.h +++ b/include/lib/aarch32/arch_helpers.h @@ -36,8 +36,8 @@ static inline u_register_t read_ ## _name(void) \ * systems for GCC versions < 4.6. Above GCC 4.6, both Little Endian and * Big Endian systems generate the right instruction encoding. */ -#if !(__GNUC__ > (4) || __GNUC__ == (4) && __GNUC_MINOR__ >= (6)) -#error "GCC 4.6 or above is required to build AArch32 Trusted Firmware" +#if !(__clang__ || __GNUC__ > (4) || __GNUC__ == (4) && __GNUC_MINOR__ >= (6)) +#error "clang or GCC 4.6 or above is required to build AArch32 Trusted Firmware" #endif #define _DEFINE_COPROCR_WRITE_FUNC_64(_name, coproc, opc1, CRm) \ From 7559633b9c3004ee58744c8d554808bea7bc09a4 Mon Sep 17 00:00:00 2001 From: dp-arm Date: Wed, 3 May 2017 16:30:32 +0100 Subject: [PATCH 09/10] build: Introduce ARM Compiler 6 support Only the compiler is switched to ARM Compiler 6. The assembler and linker are provided by the GCC toolchain. ARM Compiler 6 is used to build TF when the base name of the path assigned to `CC` matches the string 'armclang'. `CROSS_COMPILE` is still needed and should point to the appropriate GCC toolchain. Tested with ARM CC 6.7. Change-Id: Ib359bf9c1e8aeed3f662668e44830864f3fe7b4a Signed-off-by: dp-arm --- Makefile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 44d4933b8..299ff3038 100644 --- a/Makefile +++ b/Makefile @@ -126,7 +126,10 @@ OD := ${CROSS_COMPILE}objdump NM := ${CROSS_COMPILE}nm PP := ${CROSS_COMPILE}gcc -E -ifneq ($(findstring clang,$(notdir $(CC))),) +ifeq ($(notdir $(CC)),armclang) +TF_CFLAGS_aarch32 = -target arm-arm-none-eabi -march=armv8-a +TF_CFLAGS_aarch64 = -target aarch64-arm-none-eabi -march=armv8-a +else ifneq ($(findstring clang,$(notdir $(CC))),) TF_CFLAGS_aarch32 = -target armv8a-none-eabi TF_CFLAGS_aarch64 = -target aarch64-elf else From 8237708368f0e206eb0cb2d6dafef95dd6c83b36 Mon Sep 17 00:00:00 2001 From: dp-arm Date: Mon, 15 May 2017 13:50:51 +0100 Subject: [PATCH 10/10] docs: Add note on how to build TF using clang or armclang Change-Id: I92fd2fb920fcfc31bfcdadae787d8c84c5ca463b Signed-off-by: dp-arm --- docs/user-guide.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/docs/user-guide.md b/docs/user-guide.md index 85ece9305..5165000d3 100644 --- a/docs/user-guide.md +++ b/docs/user-guide.md @@ -74,6 +74,9 @@ The [Linaro Release Notes][Linaro Release Notes] documents which version of the compiler to use for a given Linaro Release. Also, these [Linaro instructions][Linaro SW Instructions] provide further guidance. +Optionally, Trusted Firmware can be built using clang or ARM Compiler 6. +See instructions below on how to switch the default compiler. + In addition, the following optional packages and tools may be needed: * `device-tree-compiler` package if you need to rebuild the Flattened Device @@ -104,6 +107,28 @@ Download the Trusted Firmware source code from Github: export CROSS_COMPILE=/bin/arm-linux-gnueabihf- + It is possible to build Trusted Firmware using clang or ARM Compiler 6. + To do so `CC` needs to point to the clang or armclang binary. Only the + compiler is switched; the assembler and linker need to be provided by + the GNU toolchain, thus `CROSS_COMPILE` should be set as described above. + + ARM Compiler 6 will be selected when the base name of the path assigned + to `CC` matches the string 'armclang'. + + For AArch64 using ARM Compiler 6: + + export CROSS_COMPILE=/bin/aarch64-linux-gnu- + make CC=/bin/armclang PLAT= all + + Clang will be selected when the base name of the path assigned to `CC` + contains the string 'clang'. This is to allow both clang and clang-X.Y + to work. + + For AArch64 using clang: + + export CROSS_COMPILE=/bin/aarch64-linux-gnu- + make CC=/bin/clang PLAT= all + * Change to the root directory of the Trusted Firmware source tree and build. For AArch64: