build_package: decouple the RF-A build from the TF-A one

The rusted-firmware-a build system has recently been modified
so that it does not trigger a TF-A build.
Instead, the user should have their own integration scripts
that coordinate the TF-A build with the RF-A build to be able
to use the Rust BL31 alongside the C TF-A components.

 * Change the test scripts to handle this integration logic and
   be able to coordinate the builds.

Change-Id: I09718dd902cc3a1c7b085b2b276c732f6bb6d2f5
Signed-off-by: Tomás González <tomasagustin.gonzalezorlando@arm.com>
diff --git a/group/rfa-fvp/fvp,nil,fvp-rfa:fvp-rfa-fip.rfa b/group/rfa-fvp/fvp,nil,fvp-rfa:fvp-rfa-fip.rfa
new file mode 100644
index 0000000..126a88c
--- /dev/null
+++ b/group/rfa-fvp/fvp,nil,fvp-rfa:fvp-rfa-fip.rfa
@@ -0,0 +1,6 @@
+#!/usr/bin/env bash
+#
+# Copyright (c) 2025, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
diff --git a/group/rfa-fvp/fvp.rme,nil,fvp-rfa.rme:fvp-rfa.rme-fip.rfa b/group/rfa-fvp/fvp.rme,nil,fvp-rfa.rme:fvp-rfa.rme-fip.rfa
new file mode 100644
index 0000000..126a88c
--- /dev/null
+++ b/group/rfa-fvp/fvp.rme,nil,fvp-rfa.rme:fvp-rfa.rme-fip.rfa
@@ -0,0 +1,6 @@
+#!/usr/bin/env bash
+#
+# Copyright (c) 2025, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
diff --git a/group/rfa-fvp/fvp.rme:fvp-rfa.rme b/group/rfa-fvp/fvp.rme:fvp-rfa.rme
deleted file mode 100644
index e69de29..0000000
--- a/group/rfa-fvp/fvp.rme:fvp-rfa.rme
+++ /dev/null
diff --git a/group/rfa-fvp/fvp:fvp-rfa b/group/rfa-fvp/fvp:fvp-rfa
deleted file mode 100644
index e69de29..0000000
--- a/group/rfa-fvp/fvp:fvp-rfa
+++ /dev/null
diff --git a/rfa_config/fvp b/rfa_config/fvp
index 02e36c9..f25d21e 100644
--- a/rfa_config/fvp
+++ b/rfa_config/fvp
@@ -1,2 +1 @@
 PLAT=fvp
-TFA_FLAGS="FVP_TRUSTED_SRAM_SIZE=512 SPD=spmd SPMD_SPM_AT_SEL2=0 NEED_BL31=no"
diff --git a/rfa_config/fvp.rme b/rfa_config/fvp.rme
index ee9d8d0..b2dddbf 100644
--- a/rfa_config/fvp.rme
+++ b/rfa_config/fvp.rme
@@ -1,3 +1,2 @@
 PLAT=fvp
 FEATURES=sel2,rme
-TFA_FLAGS="FVP_TRUSTED_SRAM_SIZE=512 ENABLE_RME=1 NEED_BL31=no"
diff --git a/run_config/fvp-fip.rfa b/run_config/fvp-fip.rfa
new file mode 100644
index 0000000..3e791dc
--- /dev/null
+++ b/run_config/fvp-fip.rfa
@@ -0,0 +1,23 @@
+#!/usr/bin/env bash
+#
+# Copyright (c) 2025, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+pre_tf_build() {
+	# Only build bl1 and bl2 targets for this config
+	targets="bl1 bl2" set_tf_build_targets
+}
+
+post_rfa_archive() {
+	# Both BL32 and BL33 are STF binaries
+	build_fip BL33="${archive}/bl33.bin" BL32="${archive}/bl32.bin"
+
+	find $tf_build_root \( -name "fip.bin" \) -exec cp -t "${archive}" '{}' +
+
+	"$fiptool" update \
+		--soc-fw "$archive/bl31.bin" \
+		--out "$archive/fip.bin" \
+		"$archive/fip.bin"
+}
diff --git a/script/build_package.sh b/script/build_package.sh
index 8d3723e..3c6e0ee 100755
--- a/script/build_package.sh
+++ b/script/build_package.sh
@@ -648,9 +648,6 @@
 	# Always distclean when running on Jenkins. Skip distclean when running
 	# locally and explicitly requested.
 	if upon "$jenkins_run" || not_upon "$dont_clean"; then
-		echo "Cleaning TF-A..."
-		make -C "$tf_root" distclean &>>"$build_log" || fail_build
-
 		echo 'Cleaning RF-A...'
 		cargo clean &>>"$build_log" || fail_build
 	fi
@@ -666,9 +663,8 @@
 $(cargo --version 2>&1)
 EOF
 
-	# Build RF-A and TF-A. Since build output is being directed to the build
-	# log, have descriptor 3 point to the current terminal for build
-	# wrappers to vent.
+	# Build RF-A. Since build output is being directed to the build log, have
+	# descriptor 3 point to the current terminal for build wrappers to vent.
 	eval make $make_j_opts $(cat "$config_file") \
 	    DEBUG="$DEBUG" \
 		$build_targets 3>&1 &>>"$build_log" || fail_build
@@ -1748,84 +1744,6 @@
 			)
 	fi
 
-	# RF-A build
-	if config_valid "$rfa_config"; then
-		(
-		echo "##########"
-
-		plat="$(get_rfa_opt PLAT)"
-		plat_utils="$ci_root/${plat}_utils.sh"
-		if [ -f "$plat_utils" ]; then
-		    source "$plat_utils"
-		fi
-
-		fvp_tsram_size="$(get_rfa_opt FVP_TRUSTED_SRAM_SIZE)"
-		fvp_tsram_size="${fvp_tsram_size:-256}"
-
-		archive="$build_archive"
-
-		# Clone TF-A repo if required. Save its path into the
-		# special variable "TFA", which is used by RF-A build
-		# system.
-		export TFA="${TFA:-$tf_root}"
-		if assert_can_git_clone "TFA"; then
-			echo "Cloning TF-A..."
-			clone_url="$tf_src_repo_url" where="$TFA" clone_repo
-		fi
-		show_head "$TFA"
-		poetry -C "$TFA" install --without docs
-
-		rfa_build_root="$rfa_root/target"
-		echo "Building Rusted Firmware ($mode) ..." |& log_separator
-
-		if not_upon "$local_ci"; then
-			# In the CI Dockerfile, rustup is installed by the root user in the
-			# non-default location /usr/local/rustup, so $RUSTUP_HOME is required to
-			# access rust config e.g. default toolchains and run cargo
-			#
-			# Leave $CARGO_HOME blank so when this script is run in CI by the buildslave
-			# user, it uses the default /home/buildslave/.cargo directory which it has
-			# write permissions for - that allows it to download new crates during
-			# compilation
-			#
-			# The buildslave user does not have write permissions to the default
-			# $CARGO_HOME=/usr/local/cargo dir and so will error when trying to download
-			# new crates otherwise
-			#
-			# note: $PATH still contains /usr/local/cargo/bin at this point so cargo is
-			# still run via the root installation
-			#
-			# see https://github.com/rust-lang/rustup/issues/1085
-			set_hook_var "RUSTUP_HOME" "/usr/local/rustup"
-		fi
-
-		# Call pre-build hook
-		call_hook pre_rfa_build
-
-		build_rfa
-
-		# Call post-build hook
-		call_hook post_rfa_build
-
-		# Pre-archive hook
-		call_hook pre_rfa_archive
-
-		from="$rfa_build_root" to="$archive" collect_rfa_artefacts
-
-		# Post-archive hook
-		call_hook post_rfa_archive
-
-		call_hook fetch_rfa_resource
-		call_hook post_fetch_rfa_resource
-
-		# Generate LAVA job files if necessary
-		call_hook generate_lava_job_template
-		call_hook generate_lava_job
-
-		echo "##########"
-		)
-	fi
-
 	# TF build
 	if config_valid "$tf_config"; then
 		(
@@ -1888,6 +1806,72 @@
 		)
 	fi
 
+	# RF-A build
+	if config_valid "$rfa_config"; then
+		(
+		echo "##########"
+
+		plat="$(get_rfa_opt PLAT)"
+		plat_utils="$ci_root/${plat}_utils.sh"
+		if [ -f "$plat_utils" ]; then
+		    source "$plat_utils"
+		fi
+
+		archive="$build_archive"
+
+		tf_build_root="$tf_root/build"
+		rfa_build_root="$rfa_root/target"
+
+		echo "Building Rusted Firmware ($mode) ..." |& log_separator
+
+		if not_upon "$local_ci"; then
+			# In the CI Dockerfile, rustup is installed by the root user in the
+			# non-default location /usr/local/rustup, so $RUSTUP_HOME is required to
+			# access rust config e.g. default toolchains and run cargo
+			#
+			# Leave $CARGO_HOME blank so when this script is run in CI by the buildslave
+			# user, it uses the default /home/buildslave/.cargo directory which it has
+			# write permissions for - that allows it to download new crates during
+			# compilation
+			#
+			# The buildslave user does not have write permissions to the default
+			# $CARGO_HOME=/usr/local/cargo dir and so will error when trying to download
+			# new crates otherwise
+			#
+			# note: $PATH still contains /usr/local/cargo/bin at this point so cargo is
+			# still run via the root installation
+			#
+			# see https://github.com/rust-lang/rustup/issues/1085
+			set_hook_var "RUSTUP_HOME" "/usr/local/rustup"
+		fi
+
+		# Call pre-build hook
+		call_hook pre_rfa_build
+
+		build_rfa
+
+		# Call post-build hook
+		call_hook post_rfa_build
+
+		# Pre-archive hook
+		call_hook pre_rfa_archive
+
+		from="$rfa_build_root" to="$archive" collect_rfa_artefacts
+
+		# Post-archive hook
+		call_hook post_rfa_archive
+
+		call_hook fetch_rfa_resource
+		call_hook post_fetch_rfa_resource
+
+		# Generate LAVA job files if necessary
+		call_hook generate_lava_job_template
+		call_hook generate_lava_job
+
+		echo "##########"
+		)
+	fi
+
 	echo
 	echo
 done
diff --git a/tf_config/fvp-rfa b/tf_config/fvp-rfa
new file mode 100644
index 0000000..d8d8614
--- /dev/null
+++ b/tf_config/fvp-rfa
@@ -0,0 +1,5 @@
+PLAT=fvp
+FVP_TRUSTED_SRAM_SIZE=512
+SPD=spmd
+SPMD_SPM_AT_SEL2=0
+NEED_BL31=no
diff --git a/tf_config/fvp-rfa.rme b/tf_config/fvp-rfa.rme
new file mode 100644
index 0000000..f7b80fd
--- /dev/null
+++ b/tf_config/fvp-rfa.rme
@@ -0,0 +1,4 @@
+PLAT=fvp
+FVP_TRUSTED_SRAM_SIZE=512
+ENABLE_RME=1
+NEED_BL31=no
diff --git a/tf_config/qemu-rfa b/tf_config/qemu-rfa
new file mode 100644
index 0000000..bd44437
--- /dev/null
+++ b/tf_config/qemu-rfa
@@ -0,0 +1,2 @@
+PLAT=qemu
+NEED_BL31=no