From 289e0dadbdc4dbe4ac78110f93262dc785d24418 Mon Sep 17 00:00:00 2001 From: Jeenu Viswambharan Date: Fri, 16 May 2014 11:38:10 +0100 Subject: [PATCH 1/4] Introduce convenience functions to build This patch introduces two convenience functions to the build system: - assert_boolean: asserts that a given option is assigned either 0 or 1 as values - add_define: helps add/append macro definitions to build tool command line. This also introduces the variable DEFINES which is used to collect and pass all relevant configurations to build tools Change-Id: I3126894b034470d39858ebb3bd183bda681c7126 --- Makefile | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 3064aa4e4..93f89415a 100644 --- a/Makefile +++ b/Makefile @@ -83,6 +83,19 @@ PLATFORMS := $(shell ls -I common plat/) SPDS := $(shell ls -I none services/spd) HELP_PLATFORMS := $(shell echo ${PLATFORMS} | sed 's/ /|/g') +# Convenience function for adding build definitions +# $(eval $(call add_define,FOO)) will have: +# -DFOO if $(FOO) is empty; -DFOO=$(FOO) otherwise +define add_define +DEFINES += -D$(1)$(if $(value $(1)),=$(value $(1)),) +endef + +# Convenience function for verifying option has a boolean value +# $(eval $(call assert_boolean,FOO)) will assert FOO is 0 or 1 +define assert_boolean +$(and $(patsubst 0,,$(value $(1))),$(patsubst 1,,$(value $(1))),$(error $(1) must be boolean)) +endef + ifeq (${PLAT},) $(error "Error: Unknown platform. Please use PLAT= to specify the platform.") endif @@ -131,7 +144,6 @@ endif .PHONY: all msg_start clean realclean distclean cscope locate-checkpatch checkcodebase checkpatch fiptool fip .SUFFIXES: - INCLUDES += -Iinclude/bl1 \ -Iinclude/bl2 \ -Iinclude/bl31 \ From e35c404599016a8ed09c12d54bf4d1aa9e527831 Mon Sep 17 00:00:00 2001 From: Jeenu Viswambharan Date: Thu, 15 May 2014 14:40:58 +0100 Subject: [PATCH 2/4] Reorganize build options At present, various build options are initialized at various places in the Makefile. This patch gathers all build option declarations at the top of the Makefile and assigns them default values. Change-Id: I9f527bc8843bf69c00cb754dc60377bdb407a951 --- Makefile | 68 +++++++++++++++++++++++++++----------------------------- 1 file changed, 33 insertions(+), 35 deletions(-) diff --git a/Makefile b/Makefile index 93f89415a..fc6c46914 100644 --- a/Makefile +++ b/Makefile @@ -28,13 +28,24 @@ # POSSIBILITY OF SUCH DAMAGE. # -# Decrease the verbosity of the make script -# can be made verbose by passing V=1 at the make command line -ifdef V - KBUILD_VERBOSE = ${V} -else - KBUILD_VERBOSE = 0 -endif +# +# Default values for build configurations +# + +# Build verbosity +V := 0 +# Debug build +DEBUG := 0 +# Build architecture +ARCH := aarch64 +# Build platform +DEFAULT_PLAT := fvp +PLAT := ${DEFAULT_PLAT} +# SPD choice +SPD := none +# Base commit to perform code check on +BASE_COMMIT := origin/master + # Checkpatch ignores CHECK_IGNORE = --ignore COMPLEX_MACRO @@ -42,17 +53,14 @@ CHECK_IGNORE = --ignore COMPLEX_MACRO CHECKPATCH_ARGS = --no-tree --no-signoff ${CHECK_IGNORE} CHECKCODE_ARGS = --no-patch --no-tree --no-signoff ${CHECK_IGNORE} -ifeq "${KBUILD_VERBOSE}" "0" +ifeq (${V},0) Q=@ CHECKCODE_ARGS += --no-summary --terse else Q= endif - export Q -DEBUG ?= 0 - ifneq (${DEBUG}, 0) BUILD_TYPE := debug else @@ -68,14 +76,6 @@ BL_COMMON_SOURCES := common/bl_common.c \ lib/io_storage.c \ plat/common/aarch64/platform_helpers.S -ARCH ?= aarch64 - -# By default, build fvp platform -DEFAULT_PLAT := fvp -PLAT ?= ${DEFAULT_PLAT} -# By default, build no SPD component -SPD ?= none - BUILD_BASE := ./build BUILD_PLAT := ${BUILD_BASE}/${PLAT}/${BUILD_TYPE} @@ -161,28 +161,28 @@ INCLUDES += -Iinclude/bl1 \ ${PLAT_INCLUDES} \ ${SPD_INCLUDES} +# Process DEBUG flag +$(eval $(call assert_boolean,DEBUG)) +$(eval $(call add_define,DEBUG)) +ifeq (${DEBUG},0) + $(eval $(call add_define,NDEBUG)) +else +CFLAGS += -g +ASFLAGS += -g -Wa,--gdwarf-2 +endif + ASFLAGS += -nostdinc -ffreestanding -Wa,--fatal-warnings \ - -mgeneral-regs-only -D__ASSEMBLY__ ${INCLUDES} \ - -DDEBUG=${DEBUG} -CFLAGS := -nostdinc -pedantic -ffreestanding -Wall \ + -mgeneral-regs-only -D__ASSEMBLY__ \ + ${DEFINES} ${INCLUDES} +CFLAGS += -nostdinc -pedantic -ffreestanding -Wall \ -Werror -mgeneral-regs-only -std=c99 -c -Os \ - -DDEBUG=${DEBUG} ${INCLUDES} ${CFLAGS} + ${DEFINES} ${INCLUDES} CFLAGS += -ffunction-sections -fdata-sections LDFLAGS += --fatal-warnings -O1 LDFLAGS += --gc-sections -ifneq (${DEBUG}, 0) -#CFLAGS += -g -O0 -CFLAGS += -g -# -save-temps -fverbose-asm -ASFLAGS += -g -Wa,--gdwarf-2 -else -CFLAGS += -DNDEBUG=1 -endif - - CC := ${CROSS_COMPILE}gcc CPP := ${CROSS_COMPILE}cpp AS := ${CROSS_COMPILE}gcc @@ -193,8 +193,6 @@ OD := ${CROSS_COMPILE}objdump NM := ${CROSS_COMPILE}nm PP := ${CROSS_COMPILE}gcc -E ${CFLAGS} -BASE_COMMIT ?= origin/master - # Variables for use with Firmware Image Package FIPTOOLPATH ?= tools/fip_create FIPTOOL ?= ${FIPTOOLPATH}/fip_create From c3c1e9b0abe1a879dad4400421ad00849231eb3c Mon Sep 17 00:00:00 2001 From: Jeenu Viswambharan Date: Thu, 15 May 2014 14:47:21 +0100 Subject: [PATCH 3/4] Document summary of build options in user guide Change-Id: I6bd077955bf3780168a874705974bbe72ea0f5f1 --- docs/user-guide.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/docs/user-guide.md b/docs/user-guide.md index 1bb0fe9d7..edf03f0a4 100644 --- a/docs/user-guide.md +++ b/docs/user-guide.md @@ -83,6 +83,9 @@ To build the software for the FVPs, follow these steps: BL33=/ \ make PLAT=fvp all fip + See the "Summary of build options" for information on available build + options. + By default this produces a release version of the build. To produce a debug version instead, refer to the "Debugging options" section below. UEFI can be used as the BL3-3 image, refer to the "Obtaining the normal world software" @@ -120,6 +123,34 @@ To build the software for the FVPs, follow these steps: make realclean +### Summary of build options + +ARM Trusted Firmware build system supports the following build options. Unless +mentioned otherwise, these options are expected to be specified at the build +command line and are not to be modified in any component makefiles. Note that +the build system doesn't track dependency for build options. Therefore, if any +of the build options are changed from a previous build, a clean build must be +performed. + +* `BL33`: Path to BL33 image in the host file system. This is mandatory for + `fip` target + +* `CROSS_COMPILE`: Prefix to tool chain binaries. Please refer to examples in + this document for usage + +* `DEBUG`: Chooses between a debug and release build. It can take either 0 + (release) or 1 (debug) as values. 0 is the default + +* `PLAT`: Choose a platform to build ARM Trusted Firmware for. The chosen + platform name must be the name of one of the directories under the `plat/` + directory other than `common` + +* `SPD`: Choose a Secure Payload Dispatcher component to be built into the + Trusted Firmware. The value should be the path to the directory containing + SPD source; the directory is expected to contain `spd.mk` makefile + +* `V`: Verbose build. If assigned anything other than 0, the build commands + are printed. Default is 0 ### Creating a Firmware Image Package From 2da8d8bfc0877b9c723514133554dfee4c0638f1 Mon Sep 17 00:00:00 2001 From: Jeenu Viswambharan Date: Mon, 12 May 2014 15:28:47 +0100 Subject: [PATCH 4/4] Add build configuration for timer save/restore At present, non-secure timer register contents are saved and restored as part of world switch by BL3-1. This effectively means that the non-secure timer stops, and non-secure timer interrupts are prevented from asserting until BL3-1 switches back, introducing latency for non-secure services. Often, secure world might depend on alternate sources for secure interrupts (secure timer or platform timer) instead of non-secure timers, in which case this save and restore is unnecessary. This patch introduces a boolean build-time configuration NS_TIMER_SWITCH to choose whether or not to save and restore non-secure timer registers upon world switch. The default choice is made not to save and restore them. Fixes ARM-software/tf-issues#148 Change-Id: I1b9d623606acb9797c3e0b02fb5ec7c0a414f37e --- Makefile | 6 ++++++ bl31/aarch64/context.S | 14 ++++++++++++-- docs/user-guide.md | 5 +++++ include/bl31/context.h | 9 +++++++++ 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index fc6c46914..94dde7f7e 100644 --- a/Makefile +++ b/Makefile @@ -45,6 +45,8 @@ PLAT := ${DEFAULT_PLAT} SPD := none # Base commit to perform code check on BASE_COMMIT := origin/master +# NS timer register save and restore +NS_TIMER_SWITCH := 0 # Checkpatch ignores @@ -171,6 +173,10 @@ CFLAGS += -g ASFLAGS += -g -Wa,--gdwarf-2 endif +# Process NS_TIMER_SWITCH flag +$(eval $(call assert_boolean,NS_TIMER_SWITCH)) +$(eval $(call add_define,NS_TIMER_SWITCH)) + ASFLAGS += -nostdinc -ffreestanding -Wa,--fatal-warnings \ -mgeneral-regs-only -D__ASSEMBLY__ \ ${DEFINES} ${INCLUDES} diff --git a/bl31/aarch64/context.S b/bl31/aarch64/context.S index 45d4a2255..d0bca64fc 100644 --- a/bl31/aarch64/context.S +++ b/bl31/aarch64/context.S @@ -172,6 +172,8 @@ func el1_sysregs_context_save mrs x9, vbar_el1 stp x17, x9, [x0, #CTX_CONTEXTIDR_EL1] + /* Save NS timer registers if the build has instructed so */ +#if NS_TIMER_SWITCH mrs x10, cntp_ctl_el0 mrs x11, cntp_cval_el0 stp x10, x11, [x0, #CTX_CNTP_CTL_EL0] @@ -181,8 +183,11 @@ func el1_sysregs_context_save stp x12, x13, [x0, #CTX_CNTV_CTL_EL0] mrs x14, cntkctl_el1 + str x14, [x0, #CTX_CNTKCTL_EL1] +#endif + mrs x15, fpexc32_el2 - stp x14, x15, [x0, #CTX_CNTKCTL_EL1] + str x15, [x0, #CTX_FP_FPEXC32_EL2] ret @@ -253,6 +258,8 @@ func el1_sysregs_context_restore msr contextidr_el1, x17 msr vbar_el1, x9 + /* Restore NS timer registers if the build has instructed so */ +#if NS_TIMER_SWITCH ldp x10, x11, [x0, #CTX_CNTP_CTL_EL0] msr cntp_ctl_el0, x10 msr cntp_cval_el0, x11 @@ -261,8 +268,11 @@ func el1_sysregs_context_restore msr cntv_ctl_el0, x12 msr cntv_cval_el0, x13 - ldp x14, x15, [x0, #CTX_CNTKCTL_EL1] + ldr x14, [x0, #CTX_CNTKCTL_EL1] msr cntkctl_el1, x14 +#endif + + ldr x15, [x0, #CTX_FP_FPEXC32_EL2] msr fpexc32_el2, x15 /* No explict ISB required here as ERET covers it */ diff --git a/docs/user-guide.md b/docs/user-guide.md index edf03f0a4..e7f0df54c 100644 --- a/docs/user-guide.md +++ b/docs/user-guide.md @@ -141,6 +141,11 @@ performed. * `DEBUG`: Chooses between a debug and release build. It can take either 0 (release) or 1 (debug) as values. 0 is the default +* `NS_TIMER_SWITCH`: Enable save and restore for non-secure timer register + contents upon world switch. It can take either 0 (don't save and restore) or + 1 (do save and restore). 0 is the default. An SPD could set this to 1 if it + wants the timer registers to be saved and restored + * `PLAT`: Choose a platform to build ARM Trusted Firmware for. The chosen platform name must be the name of one of the directories under the `plat/` directory other than `common` diff --git a/include/bl31/context.h b/include/bl31/context.h index 549fa2127..b0dfec15d 100644 --- a/include/bl31/context.h +++ b/include/bl31/context.h @@ -127,6 +127,11 @@ #define CTX_AFSR1_EL1 0xc8 #define CTX_CONTEXTIDR_EL1 0xd0 #define CTX_VBAR_EL1 0xd8 +/* + * If the timer registers aren't saved and restored, we don't have to reserve + * space for them in the context + */ +#if NS_TIMER_SWITCH #define CTX_CNTP_CTL_EL0 0xe0 #define CTX_CNTP_CVAL_EL0 0xe8 #define CTX_CNTV_CTL_EL0 0xf0 @@ -134,6 +139,10 @@ #define CTX_CNTKCTL_EL1 0x100 #define CTX_FP_FPEXC32_EL2 0x108 #define CTX_SYSREGS_END 0x110 +#else +#define CTX_FP_FPEXC32_EL2 0xe0 +#define CTX_SYSREGS_END 0xf0 +#endif /******************************************************************************* * Constants that allow assembler code to access members of and the 'fp_regs'