fix(build): fix incremental build issue with realm payload

On incremental build the tftf.bin gets appended again with realm payload
causing the old realm payload to be loaded during boot. This fix
recreates base tftf.bin for every build before appending it with the
realm payload.

This also fixes makefile warnings seen when ENABLE_REALM_PAYLOAD_TESTS=1
by removing duplicate MAKE_IMG,realm calls.

Signed-off-by: Arunachalam Ganapathy <arunachalam.ganapathy@arm.com>
Change-Id: Iaedfb27572a034d70ec2a402dc3074b0d4b8c660
diff --git a/Makefile b/Makefile
index 58af796..535edf1 100644
--- a/Makefile
+++ b/Makefile
@@ -599,25 +599,31 @@
   $(eval $(call MAKE_IMG,ivy))
 endif
 
-ifeq (${ENABLE_REALM_PAYLOAD_TESTS},1)
-  $(eval $(call MAKE_IMG,realm))
-endif
-
 .PHONY : tftf
   $(eval $(call MAKE_IMG,tftf))
 
+# Build flag 'ENABLE_REALM_PAYLOAD_TESTS=1' builds and pack Realm Payload Tests
+# (preferred method). The else part contains the deprecated `pack_realm` build
+# target and it will be removed in future commit.
 ifeq (${ENABLE_REALM_PAYLOAD_TESTS},1)
+  $(eval $(call MAKE_IMG,realm))
+
+# This forces to rebuild tftf.bin. For incremental build this re-creates tftf.bin
+# and removes the old realm payload packed by the last build.
+.PHONY : $(BUILD_PLAT)/tftf.bin
+
 tftf: realm
 	@echo "  PACK REALM PAYLOAD"
 	$(shell dd if=$(BUILD_PLAT)/realm.bin of=$(BUILD_PLAT)/tftf.bin obs=1 \
 	oflag=append conv=notrunc)
-endif
-
-ifeq (${ARCH}-${PLAT},aarch64-fvp)
+else ifeq (${ARCH}-${PLAT},aarch64-fvp)
 .PHONY : pack_realm
-$(eval $(call MAKE_IMG,realm))
+  $(eval $(call MAKE_IMG,realm))
+
+.PHONY : $(BUILD_PLAT)/tftf.bin
+
 pack_realm: realm tftf
-	@echo "  PACK REALM PAYLOAD"
+	@echo "  PACK REALM PAYLOAD (pack_realm method deprecated)"
 	$(shell dd if=$(BUILD_PLAT)/realm.bin of=$(BUILD_PLAT)/tftf.bin obs=1 \
 	oflag=append conv=notrunc)
 endif