feat: tftf realm extension

This patch adds Realm payload management capabilities to TFTF
to act as a NS Host, it includes creation and destruction of a Realm,
mapping of protected data and creation of all needed RTT levels,
sharing of NS memory buffer from Host to Realm by mapping of
unprotected IPA, create REC and auxiliary granules, exit Realm
using RSI_HOST_CALL ABI.

Older realm_payload name is used now for only R-EL1 test cases,
RMI and SPM test cases have been moved to new file tests-rmi-spm.

New TFTF_MAX_IMAGE_SIZE argument added to FVP platform.mk,
as an offset from where R-EL1 payload memory resources start.

Signed-off-by: Nabil Kahlouche <nabil.kahlouche@arm.com>
Change-Id: Ida4cfd334795879d55924bb33b9b77182a3dcef7
diff --git a/Makefile b/Makefile
index 55f9690..4af1b2a 100644
--- a/Makefile
+++ b/Makefile
@@ -119,6 +119,7 @@
 ifeq (${ARCH}-${PLAT},aarch64-fvp)
 include spm/cactus_mm/cactus_mm.mk
 include spm/quark/quark.mk
+include realm/realm.mk
 endif
 
 # cactus and ivy are supported on platforms: fvp, tc0
@@ -306,6 +307,11 @@
 QUARK_ASFLAGS		+= ${COMMON_ASFLAGS}
 QUARK_LDFLAGS		+= ${COMMON_LDFLAGS}
 
+REALM_SOURCES		+= ${LIBC_SRCS}
+REALM_CFLAGS		+= ${COMMON_CFLAGS} -fpie
+REALM_ASFLAGS		+= ${COMMON_ASFLAGS}
+REALM_LDFLAGS		+= ${COMMON_LDFLAGS} $(PIE_LDFLAGS)
+
 .PHONY: locate-checkpatch
 locate-checkpatch:
 ifndef CHECKPATCH
@@ -382,6 +388,16 @@
 quark:
 	@echo "ERROR: $@ is supported only on AArch64 FVP."
 	@exit 1
+
+.PHONY: realm
+realm:
+	@echo "ERROR: $@ is supported only on AArch64 FVP."
+	@exit 1
+
+.PHONY: pack_realm
+pack_realm:
+	@echo "Nothing to be done"
+	@exit 1
 endif
 
 ifneq (${ARCH}-${PLAT},$(filter ${ARCH}-${PLAT},aarch64-fvp aarch64-tc0))
@@ -531,6 +547,15 @@
   $(eval $(call MAKE_IMG,cactus))
   $(eval $(call MAKE_IMG,ivy))
   $(eval $(call MAKE_IMG,quark))
+  $(eval $(call MAKE_IMG,realm))
+endif
+
+ifeq (${ARCH}-${PLAT},aarch64-fvp)
+.PHONY : pack_realm
+pack_realm: realm tftf
+	@echo "  PACK REALM PAYLOAD"
+	$(shell dd if=$(BUILD_PLAT)/realm.bin of=$(BUILD_PLAT)/tftf.bin obs=1 \
+	seek=$(TFTF_MAX_IMAGE_SIZE))
 endif
 
 ifeq (${ARCH}-${PLAT},aarch64-tc0)
@@ -569,7 +594,7 @@
 .SILENT: help
 help:
 	echo "usage: ${MAKE} PLAT=<${PLATFORMS}> \
-<all|tftf|ns_bl1u|ns_bl2u|cactus|ivy|quark|el3_payload|distclean|clean|checkcodebase|checkpatch|help_tests>"
+<all|tftf|ns_bl1u|ns_bl2u|cactus|ivy|quark|realm|pack_realm|el3_payload|distclean|clean|checkcodebase|checkpatch|help_tests>"
 	echo ""
 	echo "PLAT is used to specify which platform you wish to build."
 	echo "If no platform is specified, PLAT defaults to: ${DEFAULT_PLAT}"
@@ -581,6 +606,8 @@
 	echo "  ns_bl1u        Build the NS_BL1U image"
 	echo "  ns_bl2u        Build the NS_BL2U image"
 	echo "  cactus         Build the Cactus image (Test S-EL0 payload) and resource description."
+	echo "  realm          Build the Realm image (Test R-EL1 payload)."
+	echo "  pack_realm     Pack the realm image to tftf.bin."
 	echo "  cactus_mm      Build the Cactus-MM image (Test S-EL0 payload)."
 	echo "  ivy            Build the Ivy image (Test S-EL0 payload) and resource description."
 	echo "  quark          Build the Quark image (Test S-EL0 payload) and resource description."