AArch32: Enable build at top level Makefile for FVP

This patch enables the AArch32 build including SP_MIN in the
top level Makefile. The build flag `ARCH` now can specify either
`aarch64`(default) or `aarch32`. Currently only FVP AEM model is
supported for AArch32 build. Another new build flag `AARCH32_SP`
is introduced to specify the AArch32 secure payload to be built.

Change-Id: Ie1198cb9e52d7da1b79b93243338fc3868b08faa
diff --git a/Makefile b/Makefile
index eb593a7..bdfb4f0 100644
--- a/Makefile
+++ b/Makefile
@@ -45,7 +45,7 @@
 # Default values for build configurations
 ################################################################################
 
-# The Target build architecture.
+# The Target build architecture. Supported values are: aarch64, aarch32.
 ARCH				:= aarch64
 # Build verbosity
 V				:= 0
@@ -56,6 +56,8 @@
 PLAT				:= ${DEFAULT_PLAT}
 # SPD choice
 SPD				:= none
+# The AArch32 Secure Payload to be built as BL32 image
+AARCH32_SP			:= none
 # Base commit to perform code check on
 BASE_COMMIT			:= origin/master
 # NS timer register save and restore
@@ -200,14 +202,20 @@
 NM			:=	${CROSS_COMPILE}nm
 PP			:=	${CROSS_COMPILE}gcc -E
 
+ASFLAGS_aarch64		=	-mgeneral-regs-only
+TF_CFLAGS_aarch64	=	-mgeneral-regs-only -mstrict-align
+
+ASFLAGS_aarch32		=	-march=armv8-a
+TF_CFLAGS_aarch32	=	-march=armv8-a
+
 ASFLAGS			+= 	-nostdinc -ffreestanding -Wa,--fatal-warnings	\
 				-Werror -Wmissing-include-dirs			\
-				-mgeneral-regs-only -D__ASSEMBLY__		\
+				-D__ASSEMBLY__ $(ASFLAGS_$(ARCH))		\
 				${DEFINES} ${INCLUDES}
 TF_CFLAGS		+= 	-nostdinc -ffreestanding -Wall			\
 				-Werror -Wmissing-include-dirs			\
-				-mgeneral-regs-only -mstrict-align		\
 				-std=c99 -c -Os					\
+				$(TF_CFLAGS_$(ARCH))				\
 				${DEFINES} ${INCLUDES}
 TF_CFLAGS		+=	-ffunction-sections -fdata-sections
 
@@ -222,26 +230,26 @@
 
 BL_COMMON_SOURCES	+=	common/bl_common.c			\
 				common/tf_printf.c			\
-				common/aarch64/debug.S			\
-				lib/aarch64/cache_helpers.S		\
-				lib/aarch64/misc_helpers.S		\
-				plat/common/aarch64/platform_helpers.S	\
+				common/${ARCH}/debug.S			\
+				lib/${ARCH}/cache_helpers.S		\
+				lib/${ARCH}/misc_helpers.S		\
+				plat/common/${ARCH}/platform_helpers.S	\
 				${STDLIB_SRCS}
 
 INCLUDES		+=	-Iinclude/bl1				\
 				-Iinclude/bl31				\
 				-Iinclude/common			\
-				-Iinclude/common/aarch64		\
+				-Iinclude/common/${ARCH}		\
 				-Iinclude/drivers			\
 				-Iinclude/drivers/arm			\
 				-Iinclude/drivers/auth			\
 				-Iinclude/drivers/io			\
 				-Iinclude/drivers/ti/uart		\
 				-Iinclude/lib				\
-				-Iinclude/lib/aarch64			\
-				-Iinclude/lib/cpus/aarch64		\
+				-Iinclude/lib/${ARCH}			\
+				-Iinclude/lib/cpus/${ARCH}		\
 				-Iinclude/lib/el3_runtime		\
-				-Iinclude/lib/el3_runtime/aarch64	\
+				-Iinclude/lib/el3_runtime/${ARCH}	\
 				-Iinclude/lib/psci			\
 				-Iinclude/plat/common			\
 				-Iinclude/services			\
@@ -269,6 +277,9 @@
 ################################################################################
 
 ifneq (${SPD},none)
+ifeq (${ARCH},aarch32)
+	$(error "Error: SPD is incompatible with AArch32.")
+endif
 ifdef EL3_PAYLOAD_BASE
         $(warning "SPD and EL3_PAYLOAD_BASE are incompatible build options.")
         $(warning "The SPD and its BL32 companion will be present but ignored.")
@@ -301,6 +312,8 @@
 
 include ${PLAT_MAKEFILE_FULL}
 
+# Platform compatibility is not supported in AArch32
+ifneq (${ARCH},aarch32)
 # If the platform has not defined ENABLE_PLAT_COMPAT, then enable it by default
 ifndef ENABLE_PLAT_COMPAT
 ENABLE_PLAT_COMPAT := 1
@@ -310,6 +323,7 @@
 ifneq (${ENABLE_PLAT_COMPAT}, 0)
 include plat/compat/plat_compat.mk
 endif
+endif
 
 # Include the CPU specific operations makefile, which provides default
 # values for all CPU errata workarounds and CPU specific optimisations.
@@ -480,7 +494,8 @@
 ################################################################################
 # Include BL specific makefiles
 ################################################################################
-
+# BL31 is not needed and BL1, BL2 & BL2U are not currently supported in AArch32
+ifneq (${ARCH},aarch32)
 ifdef BL1_SOURCES
 NEED_BL1 := yes
 include bl1/bl1.mk
@@ -504,7 +519,27 @@
 include bl31/bl31.mk
 endif
 endif
+endif
 
+ifeq (${ARCH},aarch32)
+NEED_BL32 := yes
+
+################################################################################
+# Build `AARCH32_SP` as BL32 image for AArch32
+################################################################################
+ifneq (${AARCH32_SP},none)
+# We expect to locate an sp.mk under the specified AARCH32_SP directory
+AARCH32_SP_MAKE	:=	$(wildcard bl32/${AARCH32_SP}/${AARCH32_SP}.mk)
+
+ifeq (${AARCH32_SP_MAKE},)
+  $(error Error: No bl32/${AARCH32_SP}/${AARCH32_SP}.mk located)
+endif
+
+$(info Including ${AARCH32_SP_MAKE})
+include ${AARCH32_SP_MAKE}
+endif
+
+endif
 
 ################################################################################
 # Build targets
@@ -673,7 +708,8 @@
 	@echo "  bl2            Build the BL2 binary"
 	@echo "  bl2u           Build the BL2U binary"
 	@echo "  bl31           Build the BL31 binary"
-	@echo "  bl32           Build the BL32 binary"
+	@echo "  bl32           Build the BL32 binary. If ARCH=aarch32, then "
+	@echo "                 this builds secure payload specified by AARCH32_SP"
 	@echo "  certificates   Build the certificates (requires 'GENERATE_COT=1')"
 	@echo "  fip            Build the Firmware Image Package (FIP)"
 	@echo "  fwu_fip        Build the FWU Firmware Image Package (FIP)"