Add test config for enabling SPM tests on TC

This patch adds necessary TF-A, TFTF, SPM and run configs along
with test config for TC platform to run Cactus based tests.

Signed-off-by: Madhukar Pappireddy <madhukar.pappireddy@arm.com>
Change-Id: I5c259b080a8fa9c443eb5957032e90c0e0a46048
diff --git a/expect/spm-cactus-sp-uart1.exp b/expect/spm-cactus-sp-uart1.exp
new file mode 100644
index 0000000..8a136b3
--- /dev/null
+++ b/expect/spm-cactus-sp-uart1.exp
@@ -0,0 +1,22 @@
+#
+# Copyright (c) 2021, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+source [file join [file dirname [info script]] handle-arguments.inc]
+
+# Trusted Firmware boot section
+source [file join [file dirname [info script]] trusted-firmware.inc]
+
+expect {
+	"Booting Secure Partition"  {
+		puts "<<SP entry>>"
+	}
+	timeout {
+		exit_uart -1
+	}
+}
+
+# Hold UART until test completes
+source [file join [file dirname [info script]] uart-hold.inc]
diff --git a/expect/tftf-non-primary.exp b/expect/tftf-non-primary.exp
new file mode 100644
index 0000000..38536d3
--- /dev/null
+++ b/expect/tftf-non-primary.exp
@@ -0,0 +1,32 @@
+#
+# Copyright (c) 2021 Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+# Expect script for Trusted Firmware Test Framework
+#
+
+source [file join [file dirname [info script]] handle-arguments.inc]
+
+expect_string "Booting trusted firmware test framework" "Starting TFTF"
+expect_re "Running at NS-EL(1|2)"
+
+expect {
+	"Tests Failed  : 0" {
+		expect_string "Exiting tests." "<<TFTF Success>>"
+		exit_uart 0
+	}
+	"Tests Passed  : 0" {
+		puts "<<TFTF no tests passed>>"
+		exit_uart -1
+	}
+	-re "Tests Failed  : \[^0]" {
+		puts "<<TFTF Fail>>"
+		exit_uart -1
+	}
+	timeout {
+		exit_timeout
+	}
+}
+
+exit_uart -1
diff --git a/group/spm-l3-boot-tests/tc-default,fvp-tc0-spm,fvp-tc0-spm:fvp-tc0.spm.tftf-debug b/group/spm-l3-boot-tests/tc-default,fvp-tc0-spm,fvp-tc0-spm:fvp-tc0.spm.tftf-debug
new file mode 100644
index 0000000..33f3ae7
--- /dev/null
+++ b/group/spm-l3-boot-tests/tc-default,fvp-tc0-spm,fvp-tc0-spm:fvp-tc0.spm.tftf-debug
@@ -0,0 +1,6 @@
+#
+# Copyright (c) 2021, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
diff --git a/run_config/fvp-tc0.spm.tftf b/run_config/fvp-tc0.spm.tftf
new file mode 100644
index 0000000..02dbcdc
--- /dev/null
+++ b/run_config/fvp-tc0.spm.tftf
@@ -0,0 +1,41 @@
+#!/usr/bin/env bash
+#
+# Copyright (c) 2021, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+post_tf_build() {
+	if [ ! -f "$archive/scp_ram.bin" ]; then
+		url="$scp_prebuilts/tc$plat_variant/release/scp_bl2.bin" saveas="scp_ram.bin" fetch_file
+		archive_file "scp_ram.bin"
+	fi
+
+	build_fip BL33="$archive/tftf.bin" BL32="$archive/secure_hafnium.bin" SCP_BL2="$archive/scp_ram.bin"
+}
+
+fetch_tf_resource() {
+	# Expect scripts
+	uart="0" set_payload_uart="1" file="tftf-non-primary.exp" track_expect
+	uart="1" set_primary="1" file="spm-cactus-sp-uart1.exp" track_expect
+
+	payload_type="tftf" gen_fvp_yaml_template
+
+	# Use SCP binary from SCP build if it exists, or fetch pre-built ones.
+	if [ ! -f "$archive/scp_rom.bin" ]; then
+		# Pick the appropriate binary based on target platform variant
+		url="$scp_prebuilts/tc$plat_variant/release/scp_bl1.bin" saveas="scp_rom.bin" fetch_file
+		archive_file "scp_rom.bin"
+	fi
+}
+
+post_fetch_tf_resource() {
+        local model="tc0"
+
+	model="$model" gen_model_params
+
+	set_run_env "ports_script" "$ci_root/model/tc-ports.awk"
+	set_run_env "num_uarts" "2"
+	uart="1" set_expect_variable "num_cpus" "8"
+	model="$model" gen_fvp_yaml
+}
diff --git a/script/build_package.sh b/script/build_package.sh
index e15eaf4..a2461c6 100755
--- a/script/build_package.sh
+++ b/script/build_package.sh
@@ -207,13 +207,13 @@
 # Collect SPM/hafnium artefacts with "secure_" appended to the files
 # generated for SPM(secure hafnium).
 collect_spm_artefacts() {
-	if [ ! -d "${non_secure_from:?}" ] || [ ! -d "${secure_from:?}" ]; then
-		return
+	if [ -d "${non_secure_from:?}" ]; then
+		find "$non_secure_from" \( -name "*.bin" -o -name '*.elf' \) -exec cp -t "${to:?}" '{}' +
 	fi
 
-	find "$non_secure_from" \( -name "*.bin" -o -name '*.elf' \) -exec cp -t "${to:?}" '{}' +
-
-	for f in $(find "$secure_from" \( -name "*.bin" -o -name '*.elf' \)); do cp -- "$f" "${to:?}"/secure_$(basename $f); done
+	if [ -d "${secure_from:?}" ]; then
+		for f in $(find "$secure_from" \( -name "*.bin" -o -name '*.elf' \)); do cp -- "$f" "${to:?}"/secure_$(basename $f); done
+	fi
 }
 
 # Map the UART ID used for expect with the UART descriptor and port
@@ -1364,7 +1364,13 @@
 		build_spm
 
 		# Show SPM/Hafnium binary details
-		cksum $spm_build_root/hafnium.bin $hafnium_build_root/hafnium.bin
+		cksum $spm_build_root/hafnium.bin
+
+		# Some platforms only have secure configuration enabled. Hence,
+		# non secure hanfnium binary might not be built.
+		if [ -f $hafnium_build_root/hafnium.bin ]; then
+			cksum $hafnium_build_root/hafnium.bin
+		fi
 
 		secure_from="$spm_build_root" non_secure_from="$hafnium_build_root" to="$archive" collect_spm_artefacts
 
diff --git a/spm_config/tc-default b/spm_config/tc-default
new file mode 100644
index 0000000..7d8d20b
--- /dev/null
+++ b/spm_config/tc-default
@@ -0,0 +1 @@
+PROJECT=reference
diff --git a/tc_utils.sh b/tc_utils.sh
index c2f5f92..71cb535 100644
--- a/tc_utils.sh
+++ b/tc_utils.sh
@@ -18,3 +18,10 @@
 initrd_addr=0x8000000
 kernel_addr=0x80000
 scp_ram_addr=0x0bd80000
+
+# Hafnium build repo containing Secure hafnium binaries
+spm_secure_out_dir=secure_tc_clang
+
+# TC platform doesnt have non secure hafnium build configuration. Hence, we
+# set it to an arbitrary name.
+spm_non_secure_out_dir=not_found
diff --git a/tf_config/fvp-tc0-spm b/tf_config/fvp-tc0-spm
new file mode 100644
index 0000000..ba746ab
--- /dev/null
+++ b/tf_config/fvp-tc0-spm
@@ -0,0 +1,11 @@
+ARM_ARCH_MINOR=5
+BRANCH_PROTECTION=1
+CROSS_COMPILE=aarch64-none-elf-
+CTX_INCLUDE_EL2_REGS=1
+CTX_INCLUDE_PAUTH_REGS=1
+ENABLE_SVE_FOR_SWD=1
+PLAT=tc
+SCP_BL2=/dev/null
+SPD=spmd
+SP_LAYOUT_FILE=${tftf_root}/build/tc0/${bin_mode}/sp_layout.json
+TARGET_PLATFORM=0
diff --git a/tftf_config/fvp-tc0-spm b/tftf_config/fvp-tc0-spm
new file mode 100644
index 0000000..ebc8b20
--- /dev/null
+++ b/tftf_config/fvp-tc0-spm
@@ -0,0 +1,3 @@
+CROSS_COMPILE=aarch64-none-elf-
+PLAT=tc0
+TESTS=spm