refactor: re-use run config fragments for TC platform variants

Several platforms have multiple variants, yet, they share most of the
software binaries and hence can utilize common run fragments. This
removes the need to maintain run fragments on per-variant basis.

We do this by introducing an environment variable `plat_variant` that
is populated from build parameter `TARGET_PLATFORM`

Signed-off-by: Madhukar Pappireddy <madhukar.pappireddy@arm.com>
Change-Id: I4218942b33dd32440a1ce9f7e78627bbe6710a69
diff --git a/group/scp-boot-tests/fvp-tc0,fvp-tc0-tbb:fvp-linux.tc0-fip.tc0-tc0-debug b/group/scp-boot-tests/fvp-tc0,fvp-tc0-tbb:fvp-linux.tc-fip.tc-tc0-debug
similarity index 100%
rename from group/scp-boot-tests/fvp-tc0,fvp-tc0-tbb:fvp-linux.tc0-fip.tc0-tc0-debug
rename to group/scp-boot-tests/fvp-tc0,fvp-tc0-tbb:fvp-linux.tc-fip.tc-tc0-debug
diff --git a/group/scp-boot-tests/fvp-tc1,fvp-tc1-tbb:fvp-linux.tc1-fip.tc1-tc1-debug b/group/scp-boot-tests/fvp-tc1,fvp-tc1-tbb:fvp-linux.tc-fip.tc-tc1-debug
similarity index 100%
rename from group/scp-boot-tests/fvp-tc1,fvp-tc1-tbb:fvp-linux.tc1-fip.tc1-tc1-debug
rename to group/scp-boot-tests/fvp-tc1,fvp-tc1-tbb:fvp-linux.tc-fip.tc-tc1-debug
diff --git a/group/tf-l3-boot-tests-css/fvp-tc0-tbb:fvp-linux.tc-fip.tc-tc0-debug b/group/tf-l3-boot-tests-css/fvp-tc0-tbb:fvp-linux.tc-fip.tc-tc0-debug
new file mode 100644
index 0000000..ceff0fe
--- /dev/null
+++ b/group/tf-l3-boot-tests-css/fvp-tc0-tbb:fvp-linux.tc-fip.tc-tc0-debug
@@ -0,0 +1,6 @@
+#
+# Copyright (c) 2020-2021, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
diff --git a/group/tf-l3-boot-tests-css/fvp-tc0-tbb:fvp-linux.tc0-fip.tc0-tc0-debug b/group/tf-l3-boot-tests-css/fvp-tc0-tbb:fvp-linux.tc0-fip.tc0-tc0-debug
deleted file mode 100644
index d52947d..0000000
--- a/group/tf-l3-boot-tests-css/fvp-tc0-tbb:fvp-linux.tc0-fip.tc0-tc0-debug
+++ /dev/null
@@ -1,6 +0,0 @@
-#
-# Copyright (c) 2020, Arm Limited. All rights reserved.
-#
-# SPDX-License-Identifier: BSD-3-Clause
-#
-
diff --git a/group/tf-l3-boot-tests-css/fvp-tc1-tbb:fvp-linux.tc1-fip.tc1-tc1-debug b/group/tf-l3-boot-tests-css/fvp-tc1-tbb:fvp-linux.tc-fip.tc-tc1-debug
similarity index 100%
rename from group/tf-l3-boot-tests-css/fvp-tc1-tbb:fvp-linux.tc1-fip.tc1-tc1-debug
rename to group/tf-l3-boot-tests-css/fvp-tc1-tbb:fvp-linux.tc-fip.tc-tc1-debug
diff --git a/model/base-aemva-common.sh b/model/base-aemva-common.sh
index 01b6b20..5d31b91 100644
--- a/model/base-aemva-common.sh
+++ b/model/base-aemva-common.sh
@@ -17,6 +17,8 @@
 reset_var aarch64_only
 reset_var aarch32
 
+reset_var plat_variant
+
 #------------ GIC configuration --------------
 
 # GICv2 compatibility is not supported and GICD_CTLR.ARE_* is always one
diff --git a/run_config/fvp-fip.tc0 b/run_config/fvp-fip.tc
similarity index 75%
rename from run_config/fvp-fip.tc0
rename to run_config/fvp-fip.tc
index e885793..244b9f1 100644
--- a/run_config/fvp-fip.tc0
+++ b/run_config/fvp-fip.tc
@@ -1,6 +1,6 @@
 #!/usr/bin/env bash
 #
-# Copyright (c) 2020, Arm Limited. All rights reserved.
+# Copyright (c) 2020-2021, Arm Limited. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-3-Clause
 #
@@ -11,7 +11,7 @@
 
 	# Use SCP binary from SCP build if it exists, or fetch pre-built ones.
 	if [ ! -f "$archive/scp_ramfw.bin" ]; then
-		url="$scp_prebuilts/tc0/scp_ramfw.bin" fetch_file
+		url="$scp_prebuilts/tc$plat_variant/scp_ramfw.bin" fetch_file
 		archive_file "scp_ramfw.bin"
 	fi
 
diff --git a/run_config/fvp-fip.tc1 b/run_config/fvp-fip.tc1
deleted file mode 100644
index e5b630e..0000000
--- a/run_config/fvp-fip.tc1
+++ /dev/null
@@ -1,19 +0,0 @@
-#!/usr/bin/env bash
-#
-# Copyright (c) 2021, Arm Limited. All rights reserved.
-#
-# SPDX-License-Identifier: BSD-3-Clause
-#
-
-post_tf_build() {
-	url="$tc_prebuilts/u-boot.bin" fetch_file
-	archive_file "u-boot.bin"
-
-	# Use SCP binary from SCP build if it exists, or fetch pre-built ones.
-	if [ ! -f "$archive/scp_ramfw.bin" ]; then
-		url="$scp_prebuilts/tc1/scp_ramfw.bin" fetch_file
-		archive_file "scp_ramfw.bin"
-	fi
-
-	build_fip BL33="$archive/u-boot.bin" SCP_BL2="$archive/scp_ramfw.bin"
-}
diff --git a/run_config/fvp-linux.tc b/run_config/fvp-linux.tc
new file mode 100644
index 0000000..206a248
--- /dev/null
+++ b/run_config/fvp-linux.tc
@@ -0,0 +1,23 @@
+#!/usr/bin/env bash
+#
+# Copyright (c) 2019-2021 Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+fetch_tf_resource() {
+	kernel_type="fvp-tc-kernel" get_kernel
+	initrd_type="fvp-tc-ramdisk" get_initrd
+	uart="1" set_primary="1" file="linux-rd-busybox.exp" track_expect
+
+	payload_type="linux" gen_fvp_yaml_template
+	# Use SCP binary from SCP build if it exists, or fetch pre-built ones.
+	if [ ! -f "$archive/scp_romfw.bin" ]; then
+		# Pick the appropriate binary based on target platform variant
+		url="$scp_prebuilts/tc$plat_variant/scp_romfw.bin" fetch_file
+		archive_file "scp_romfw.bin"
+	fi
+
+	# Hold scp terminal_s0
+	uart="0" file="hold_uart.exp" track_expect
+}
diff --git a/run_config/fvp-linux.tc0 b/run_config/fvp-linux.tc0
deleted file mode 100644
index 09eea98..0000000
--- a/run_config/fvp-linux.tc0
+++ /dev/null
@@ -1,14 +0,0 @@
-#!/usr/bin/env bash
-#
-# Copyright (c) 2019-2020 Arm Limited. All rights reserved.
-#
-# SPDX-License-Identifier: BSD-3-Clause
-#
-
-fetch_tf_resource() {
-	kernel_type="fvp-tc-kernel" get_kernel
-	initrd_type="fvp-tc-ramdisk" get_initrd
-	uart="1" set_primary="1" file="linux-rd-busybox.exp" track_expect
-
-	payload_type="linux" gen_fvp_yaml_template
-}
diff --git a/run_config/fvp-linux.tc1 b/run_config/fvp-linux.tc1
deleted file mode 100644
index a2ca995..0000000
--- a/run_config/fvp-linux.tc1
+++ /dev/null
@@ -1,14 +0,0 @@
-#!/usr/bin/env bash
-#
-# Copyright (c) 2020 Arm Limited. All rights reserved.
-#
-# SPDX-License-Identifier: BSD-3-Clause
-#
-
-fetch_tf_resource() {
-	kernel_type="fvp-tc-kernel" get_kernel
-	initrd_type="fvp-tc-ramdisk" get_initrd
-	uart="1" set_primary="1" file="linux-rd-busybox.exp" track_expect
-
-	payload_type="linux" gen_fvp_yaml_template
-}
diff --git a/run_config/fvp-tc0 b/run_config/fvp-tc0
index d6c6b57..5932f25 100644
--- a/run_config/fvp-tc0
+++ b/run_config/fvp-tc0
@@ -1,21 +1,10 @@
 #!/usr/bin/env bash
 #
-# Copyright (c) 2019-2020, Arm Limited. All rights reserved.
+# Copyright (c) 2019-2021, Arm Limited. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-3-Clause
 #
 
-fetch_tf_resource() {
-	# Use SCP binary from SCP build if it exists, or fetch pre-built ones.
-	if [ ! -f "$archive/scp_romfw.bin" ]; then
-		url="$scp_prebuilts/tc0/scp_romfw.bin" fetch_file
-		archive_file "scp_romfw.bin"
-	fi
-
-	# Hold scp terminal_s0
-	uart="0" file="hold_uart.exp" track_expect
-}
-
 post_fetch_tf_resource() {
         local model="tc0"
 
diff --git a/run_config/fvp-tc1 b/run_config/fvp-tc1
index af37cde..8f96eb6 100644
--- a/run_config/fvp-tc1
+++ b/run_config/fvp-tc1
@@ -5,17 +5,6 @@
 # SPDX-License-Identifier: BSD-3-Clause
 #
 
-fetch_tf_resource() {
-	# Use SCP binary from SCP build if it exists, or fetch pre-built ones.
-	if [ ! -f "$archive/scp_romfw.bin" ]; then
-		url="$scp_prebuilts/tc1/scp_romfw.bin" fetch_file
-		archive_file "scp_romfw.bin"
-	fi
-
-	# Hold scp terminal_s0
-	uart="0" file="hold_uart.exp" track_expect
-}
-
 post_fetch_tf_resource() {
         local model="tc1"
 
diff --git a/script/build_package.sh b/script/build_package.sh
index 099a82a..10d1df4 100755
--- a/script/build_package.sh
+++ b/script/build_package.sh
@@ -1,6 +1,6 @@
 #!/usr/bin/env bash
 #
-# Copyright (c) 2019-2020 Arm Limited. All rights reserved.
+# Copyright (c) 2019-2021 Arm Limited. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-3-Clause
 #
@@ -1371,6 +1371,8 @@
 		echo "##########"
 
 		plat_utils="$(get_tf_opt PLAT_UTILS)"
+		export plat_variant="$(get_tf_opt TARGET_PLATFORM)"
+
 		if [ -z ${plat_utils} ]; then
 			# Source platform-specific utilities.
 			plat="$(get_tf_opt PLAT)"