cactus: generate JSON file required by TF-A

Generate JSON file which is being passed as "SP_LAYOUT_FILE" build
parameter to TF-A build.
Two instances of cactus is used to demonstrate functioning of multiple
SP's. cactus-secondary dts is same as cactus dts except for UUID and
load address.

Signed-off-by: Manish Pandey <manish.pandey2@arm.com>
Change-Id: Ib6d8f7d5d4894495754da0ce39f663263eeb182f
diff --git a/spm/cactus/cactus-secondary.dts b/spm/cactus/cactus-secondary.dts
new file mode 100644
index 0000000..041cd31
--- /dev/null
+++ b/spm/cactus/cactus-secondary.dts
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2019-2020, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ * This file is a Partition Manifest (PM) for a minimal Secure Partition (SP)
+ * that has additional optional properties defined.
+ *
+ */
+
+/dts-v1/;
+
+/ {
+	compatible = "arm,spci-manifest-1.0";
+
+	/* Properties */
+	description = "Base-1";
+	spci-version = <0x00000009>; /* 31:16 - Major, 15:0 - Minor */
+	uuid = <0xd1582309 0xf02347b9 0x827c4464 0xf5578fc8>;
+	id = <2>;
+	auxiliary-id = <0xae>;
+	stream-endpoint-ids = <0 1 2 3>;
+	execution-ctx-count = <1>;
+	exception-level = <2>; /* S-EL1 */
+	execution-state = <0>; /* AARCH64 */
+	load-address = <0x7100000>;
+	entrypoint-offset = <0x00001000>;
+	xlat-granule = <0>; /* 4KiB */
+	boot-order = <0>;
+	messaging-method = <0>; /* Direct messaging only */
+	run-time-model = <0>; /* Run to completion */
+
+	/* Boot protocol */
+	gp-register-num = <0x0>;
+
+	rx_tx-info {
+		compatible = "arm,spci-manifest-rx_tx-buffer";
+
+		description = "NS RX/TX Buffer";
+		pages-count = <1>;
+		attributes = <0x0>;
+		base-address = <0x7200000>;
+	};
+
+	memory-regions {
+		compatible = "arm,spci-manifest-memory-regions";
+		test-memory {
+			description = "Test Memory";
+			pages-count = <32>; /* 128KiB with 4KiB pages */
+			base-address = <0x00000000 0x21000000>;
+			attributes = <0x0>;
+		};
+	};
+
+	device-regions {
+		compatible = "arm,spci-manifest-device-regions";
+		attributes = <0x0>;
+		test-reg {
+			reg = <0x10000008 0x00000001 1>; /* Arbitrary test address */
+			smmu-id = <1>;
+			stream-ids = <0x0 0x1>;
+			interrupts = <0x2 0x3>,
+					<0x4 0x5>;
+		};
+	};
+
+};
diff --git a/spm/cactus/cactus.mk b/spm/cactus/cactus.mk
index c588267..c0b98f4 100644
--- a/spm/cactus/cactus.mk
+++ b/spm/cactus/cactus.mk
@@ -70,6 +70,8 @@
 	@echo "  DTBGEN  spm/cactus/cactus.dts"
 	${Q}tools/generate_dtb/generate_dtb.sh \
 		cactus spm/cactus/cactus.dts $(BUILD_PLAT)
+	${Q}tools/generate_json/generate_json.sh \
+		cactus $(PLAT) $(BUILD_TYPE)
 	@echo
 	@echo "Built $@ successfully"
 	@echo
diff --git a/tools/generate_json/generate_json.sh b/tools/generate_json/generate_json.sh
new file mode 100755
index 0000000..8dd2630
--- /dev/null
+++ b/tools/generate_json/generate_json.sh
@@ -0,0 +1,32 @@
+#!/bin/bash
+
+#
+# Copyright (c) 2020, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+# Generate a JSON file which will be fed to TF-A as SPM_LAYOUT_FILE to package
+# Secure Partitions as part of FIP.
+
+# $1 = Secure Partition (cactus)
+# $2 = Platform (fvp)
+# $3 = Build Type
+# Output = build/plat/<Build Type>/sp_layout.json
+
+GENERATED_JSON=build/$2/$3/sp_layout.json
+
+# To demonstrate communication between SP's, two cactus S-EL1 instances used.
+# cactus-primary and cactus-secondary has same binary but different
+# partition manifest.
+if [ "$1" == "cactus" ]; then
+	echo -e "{\n\t\"$1-primary\" : {\n \
+	\t\"image\": \"$1.bin\",\n \
+	\t\"pm\": \"../../../spm/$1/$1.dts\"\n\t},\n\n\t\"$1-secondary\" : {\n \
+	\t\"image\": \"$1.bin\",\n \
+	\t\"pm\": \"../../../spm/$1/$1-secondary.dts\" \n \
+	}\n}" \
+	> "$GENERATED_JSON"
+else
+	echo -e "\nWarning: Only Cactus is supported as Secure Partition\n"
+fi