plat(fvp): use generic image fetching functions

Some generic functions have been provided for fetching prebuilt images -
use these for FVP runs.

Signed-off-by: Harrison Mutai <harrison.mutai@arm.com>
Change-Id: I785890c9b0370279230dfd6f71a54bcdc0ebc9c3
diff --git a/fvp_utils.sh b/fvp_utils.sh
index d62137c..7c651fa 100644
--- a/fvp_utils.sh
+++ b/fvp_utils.sh
@@ -33,7 +33,11 @@
 backup_fip_addr="${backup_fip_addr:-0x09000000}"
 romlib_addr="${romlib_addr:-0x03ff2000}"
 
+uefi_downloads="${uefi_downloads:-http://files.oss.arm.com/downloads/uefi}"
+uefi_ci_bin_url="${uefi_ci_bin_url:-$uefi_downloads/Artifacts/Linux/github/fvp/static/DEBUG_GCC5/FVP_AARCH64_EFI.fd}"
+
 uboot32_fip_url="$linaro_release/fvp32-latest-busybox-uboot/fip.bin"
+uboot_url="$linaro_release/fvp-latest-busybox-uboot/bl33-uboot.bin"
 
 rootfs_url="$linaro_release/lt-vexpress64-openembedded_minimal-armv8-gcc-5.2_20170127-761.img.gz"
 
@@ -116,8 +120,8 @@
 
 
 # FVP Kernel URLs
-declare -A fvp_kernels
-fvp_kernels=(
+declare -A kernel_list
+kernel_list=(
 [fvp-aarch32-zimage]="$linaro_release/fvp32-latest-busybox-uboot/Image"
 [fvp-busybox-uboot]="$linaro_release/fvp-latest-busybox-uboot/Image"
 [fvp-oe-uboot32]="$linaro_release/fvp32-latest-oe-uboot/Image"
@@ -126,20 +130,14 @@
 )
 
 # FVP initrd URLs
-declare -A fvp_initrd_urls
-fvp_initrd_urls=(
+declare -A initrd_list
+initrd_list=(
 [aarch32-ramdisk]="$linaro_release/fvp32-latest-busybox-uboot/ramdisk.img"
 [dummy-ramdisk]="$linaro_release/fvp-latest-oe-uboot/ramdisk.img"
 [dummy-ramdisk32]="$linaro_release/fvp32-latest-oe-uboot/ramdisk.img"
 [default]="$linaro_release/fvp-latest-busybox-uboot/ramdisk.img"
 )
 
-get_optee_bin() {
-	url="$tfa_downloads/optee/tee.bin" \
-           saveas="bl32.bin" fetch_file
-	archive_file "bl32.bin"
-}
-
 # For Measured Boot tests using a TA based on OPTEE, it is necessary to use a
 # specific build rather than the default one generated by Jenkins.
 get_ftpm_optee_bin() {
@@ -157,47 +155,6 @@
 	archive_file "bl32_extra2.bin"
 }
 
-get_uboot32_bin() {
-	local tmpdir="$(mktempdir)"
-
-	pushd "$tmpdir"
-	extract_fip "$uboot32_fip_url"
-	mv "nt-fw.bin" "uboot.bin"
-	archive_file "uboot.bin"
-	popd
-}
-
-get_uboot_bin() {
-	local uboot_url="$linaro_release/fvp-latest-busybox-uboot/bl33-uboot.bin"
-
-	url="$uboot_url" saveas="uboot.bin" fetch_file
-	archive_file "uboot.bin"
-}
-
-get_uefi_bin() {
-	uefi_downloads="${uefi_downloads:-http://files.oss.arm.com/downloads/uefi}"
-	uefi_ci_bin_url="${uefi_ci_bin_url:-$uefi_downloads/Artifacts/Linux/github/fvp/static/DEBUG_GCC5/FVP_AARCH64_EFI.fd}"
-
-	url=$uefi_ci_bin_url saveas="uefi.bin" fetch_file
-	archive_file "uefi.bin"
-}
-
-get_kernel() {
-	local kernel_type="${kernel_type:?}"
-	local url="${fvp_kernels[$kernel_type]}"
-
-	url="${url:?}" saveas="kernel.bin" fetch_file
-	archive_file "kernel.bin"
-}
-
-get_initrd() {
-	local initrd_type="${initrd_type:?}"
-	local url="${fvp_initrd_urls[$initrd_type]}"
-
-	url="${url:?}" saveas="initrd.bin" fetch_file
-	archive_file "initrd.bin"
-}
-
 get_dtb() {
 	local dtb_type="${dtb_type:?}"
 	local dtb_url
diff --git a/rde1edge_utils.sh b/rde1edge_utils.sh
index 662cd8f..ba0b416 100644
--- a/rde1edge_utils.sh
+++ b/rde1edge_utils.sh
@@ -9,8 +9,8 @@
 
 sgi_prebuilts="${sgi_prebuilts:-$css_downloads/sgi/rde1edge}"
 
-fvp_kernels[fvp-sgi-busybox]="$sgi_prebuilts/Image"
-fvp_initrd_urls[fvp-sgi-ramdisk]="$sgi_prebuilts/ramdisk-busybox.img"
+kernel_list[sgi-busybox]="$sgi_prebuilts/Image"
+initrd_list[sgi-ramdisk]="$sgi_prebuilts/ramdisk-busybox.img"
 
 scp_ram_addr=0x0bd80000
 mcp_ram_addr=0x0be00000
diff --git a/rdn1edge_utils.sh b/rdn1edge_utils.sh
index 3195717..6152a3c 100644
--- a/rdn1edge_utils.sh
+++ b/rdn1edge_utils.sh
@@ -12,8 +12,8 @@
 # Pre-built SCP/MCP binaries
 scp_mcp_prebuilts="${scp_mcp_prebuilts:-$scp_mcp_downloads/rdn1e1/release}"
 
-fvp_kernels[fvp-sgi-busybox]="$sgi_prebuilts/Image"
-fvp_initrd_urls[fvp-sgi-ramdisk]="$sgi_prebuilts/ramdisk-busybox.img"
+kernel_list[sgi-busybox]="$sgi_prebuilts/Image"
+initrd_list[sgi-ramdisk]="$sgi_prebuilts/ramdisk-busybox.img"
 
 scp_ram_addr=0x0bd80000
 mcp_ram_addr=0x0be00000
diff --git a/rdv1_utils.sh b/rdv1_utils.sh
index 7884aeb..7ef0e44 100644
--- a/rdv1_utils.sh
+++ b/rdv1_utils.sh
@@ -1,6 +1,6 @@
 #!/usr/bin/env bash
 #
-# Copyright (c) 2020-2021, Arm Limited. All rights reserved.
+# Copyright (c) 2020-2023, Arm Limited. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-3-Clause
 #
@@ -13,8 +13,8 @@
 scp_mcp_prebuilts="${scp_mcp_prebuilts:-$scp_mcp_downloads/rdv1/release}"
 
 
-fvp_kernels[fvp-sgi-busybox]="$sgi_prebuilts/Image"
-fvp_initrd_urls[fvp-sgi-ramdisk]="$sgi_prebuilts/ramdisk-busybox.img"
+kernel_list[sgi-busybox]="$sgi_prebuilts/Image"
+initrd_list[sgi-ramdisk]="$sgi_prebuilts/ramdisk-busybox.img"
 
 scp_ram_addr=0x0bd80000
 mcp_ram_addr=0x0BF80000
diff --git a/run_config/fvp-aemv8a.memprotect b/run_config/fvp-aemv8a.memprotect
index efaa0c9..b9b3450 100644
--- a/run_config/fvp-aemv8a.memprotect
+++ b/run_config/fvp-aemv8a.memprotect
@@ -1,12 +1,12 @@
 #!/usr/bin/env bash
 #
-# Copyright (c) 2019-2022, Arm Limited. All rights reserved.
+# Copyright (c) 2019-2023, Arm Limited. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-3-Clause
 #
 
 post_tf_build() {
-	get_uboot_bin
+	url="$uboot_url" filename="uboot.bin" fetch_and_archive
 }
 
 generate_lava_job() {
diff --git a/run_config/fvp-aemv8a.rst31 b/run_config/fvp-aemv8a.rst31
index dcf81d5..1d71848 100644
--- a/run_config/fvp-aemv8a.rst31
+++ b/run_config/fvp-aemv8a.rst31
@@ -1,12 +1,12 @@
 #!/usr/bin/env bash
 #
-# Copyright (c) 2019-2022, Arm Limited. All rights reserved.
+# Copyright (c) 2019-2023, Arm Limited. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-3-Clause
 #
 
 post_tf_build() {
-	get_uboot_bin
+	url="$uboot_url" filename="uboot.bin" fetch_and_archive
 }
 
 generate_lava_job() {
diff --git a/run_config/fvp-cortexa57x4a53x4.rst31 b/run_config/fvp-cortexa57x4a53x4.rst31
index f1bfab8..cb132be 100644
--- a/run_config/fvp-cortexa57x4a53x4.rst31
+++ b/run_config/fvp-cortexa57x4a53x4.rst31
@@ -1,12 +1,12 @@
 #!/usr/bin/env bash
 #
-# Copyright (c) 2019-2022, Arm Limited. All rights reserved.
+# Copyright (c) 2019-2023, Arm Limited. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-3-Clause
 #
 
 post_tf_build() {
-	get_uboot_bin
+	url="$uboot_url" filename="uboot.bin" fetch_and_archive
 }
 
 generate_lava_job() {
diff --git a/run_config/fvp-fip.morello b/run_config/fvp-fip.morello
index 31e6a98..60090c2 100644
--- a/run_config/fvp-fip.morello
+++ b/run_config/fvp-fip.morello
@@ -1,6 +1,6 @@
 #!/usr/bin/env bash
 #
-# Copyright (c) 2021-2022 Arm Limited. All rights reserved.
+# Copyright (c) 2021-2023 Arm Limited. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-3-Clause
 #
@@ -35,7 +35,7 @@
 	archive_file "mcp_fw.bin"
 
 	# Fetch BL33 [uefi.bin] for Morello
-	uefi_ci_bin_url="$morello_prebuilts/uefi.bin" get_uefi_bin
+	url="$morello_prebuilts/uefi.bin" filename="uefi.bin" fetch_and_archive
 
 	# Create FIP for BL2, BL31, and BL33
 	build_fip BL31="$bl31" BL2="$bl2" BL33="$archive/uefi.bin"
diff --git a/run_config/fvp-fip.uboot b/run_config/fvp-fip.uboot
index 62957a9..562fa2a 100644
--- a/run_config/fvp-fip.uboot
+++ b/run_config/fvp-fip.uboot
@@ -6,6 +6,6 @@
 #
 
 post_tf_build() {
-	get_uboot_bin
+	url="$uboot_url" filename="uboot.bin" fetch_and_archive
 	build_fip BL33="$archive/uboot.bin"
 }
diff --git a/run_config/fvp-fip.uboot+bl32 b/run_config/fvp-fip.uboot+bl32
index 3c74921..d32a65a 100644
--- a/run_config/fvp-fip.uboot+bl32
+++ b/run_config/fvp-fip.uboot+bl32
@@ -6,7 +6,7 @@
 #
 
 post_tf_build() {
-	get_uboot_bin
-	get_optee_bin
+	url="$uboot_url" filename="uboot.bin" fetch_and_archive
+	url="$tfa_downloads/optee/tee.bin" filename="bl32.bin" fetch_and_archive
 	build_fip BL33="$archive/uboot.bin" BL32="$archive/bl32.bin"
 }
diff --git a/run_config/fvp-fip.uboot32 b/run_config/fvp-fip.uboot32
index 98259ef..e03b8fc 100644
--- a/run_config/fvp-fip.uboot32
+++ b/run_config/fvp-fip.uboot32
@@ -6,6 +6,7 @@
 #
 
 post_tf_build() {
-	get_uboot32_bin
+	url="${uboot32_fip_url}" image="nt-fw.bin" output_name="uboot.bin" \
+	 get_boot_image_from_fip
 	build_fip BL33="$archive/uboot.bin"
 }
diff --git a/run_config/fvp-fip.uefi b/run_config/fvp-fip.uefi
index a7c3441..1257df8 100644
--- a/run_config/fvp-fip.uefi
+++ b/run_config/fvp-fip.uefi
@@ -6,8 +6,7 @@
 #
 
 post_tf_build() {
-
-	uefi_build_type="RELEASE" get_uefi_bin
+	url="$uefi_ci_bin_url" filename="uefi.bin" fetch_and_archive
 
 	build_fip BL33="$archive/uefi.bin"
 }
diff --git a/run_config/fvp-fip.uefi.debug b/run_config/fvp-fip.uefi.debug
index f7e0a79..1257df8 100644
--- a/run_config/fvp-fip.uefi.debug
+++ b/run_config/fvp-fip.uefi.debug
@@ -6,8 +6,7 @@
 #
 
 post_tf_build() {
-
-	get_uefi_bin
+	url="$uefi_ci_bin_url" filename="uefi.bin" fetch_and_archive
 
 	build_fip BL33="$archive/uefi.bin"
 }
diff --git a/run_config/fvp-linux b/run_config/fvp-linux
index 9c5f8bf..dd4391b 100644
--- a/run_config/fvp-linux
+++ b/run_config/fvp-linux
@@ -6,8 +6,8 @@
 #
 
 fetch_tf_resource() {
-	kernel_type="fvp-busybox-uboot" get_kernel
-	initrd_type="default" get_initrd
+	image="kernel" type="fvp-busybox-uboot" get_boot_image
+	image="initrd" type="default" get_boot_image
 }
 
 generate_lava_job_template() {
diff --git a/run_config/fvp-linux.bl33 b/run_config/fvp-linux.bl33
index 07ec712..f023adc 100644
--- a/run_config/fvp-linux.bl33
+++ b/run_config/fvp-linux.bl33
@@ -6,7 +6,7 @@
 #
 
 fetch_tf_resource() {
-	kernel_type="fvp-busybox-uboot" get_kernel
+	image="kernel" type="fvp-busybox-uboot" get_boot_image
 }
 
 generate_lava_job_template() {
diff --git a/run_config/fvp-linux.quad b/run_config/fvp-linux.quad
index 860a395..5d275ea 100644
--- a/run_config/fvp-linux.quad
+++ b/run_config/fvp-linux.quad
@@ -6,8 +6,8 @@
 #
 
 fetch_tf_resource() {
-	kernel_type="fvp-quad-busybox-uboot" get_kernel
-	initrd_type="default" get_initrd
+	image="kernel" type="fvp-quad-busybox-uboot" get_boot_image
+	image="initrd" type="default" get_boot_image
 }
 
 generate_lava_job_template() {
diff --git a/run_config/fvp-linux.rootfs b/run_config/fvp-linux.rootfs
index c5cf3c0..4a32b61 100644
--- a/run_config/fvp-linux.rootfs
+++ b/run_config/fvp-linux.rootfs
@@ -6,8 +6,8 @@
 #
 
 fetch_tf_resource() {
-	kernel_type="fvp-oe-uboot" get_kernel
-	initrd_type="dummy-ramdisk" get_initrd
+	image="kernel" type="fvp-oe-uboot" get_boot_image
+	image="initrd" type="dummy-ramdisk" get_boot_image
 	get_rootfs
 }
 
diff --git a/run_config/fvp-linux.rootfs+rst31 b/run_config/fvp-linux.rootfs+rst31
index 87c63c5..49283a0 100644
--- a/run_config/fvp-linux.rootfs+rst31
+++ b/run_config/fvp-linux.rootfs+rst31
@@ -6,8 +6,8 @@
 #
 
 fetch_tf_resource() {
-	kernel_type="fvp-oe-uboot" get_kernel
-	initrd_type="dummy-ramdisk" get_initrd
+	image="kernel" type="fvp-oe-uboot" get_boot_image
+	image="initrd" type="dummy-ramdisk" get_boot_image
 	get_rootfs
 }
 
diff --git a/run_config/fvp-linux.rst31 b/run_config/fvp-linux.rst31
index 268916b..bb42fd7 100644
--- a/run_config/fvp-linux.rst31
+++ b/run_config/fvp-linux.rst31
@@ -6,8 +6,8 @@
 #
 
 fetch_tf_resource() {
-	kernel_type="fvp-busybox-uboot" get_kernel
-	initrd_type="default" get_initrd
+	image="kernel" type="fvp-busybox-uboot" get_boot_image
+	image="initrd" type="default" get_boot_image
 }
 
 generate_lava_job_template() {
diff --git a/run_config/fvp-linux.sgi b/run_config/fvp-linux.sgi
index 24502cf..467602b 100644
--- a/run_config/fvp-linux.sgi
+++ b/run_config/fvp-linux.sgi
@@ -6,8 +6,8 @@
 #
 
 fetch_tf_resource() {
-	kernel_type="fvp-sgi-busybox" get_kernel
-	initrd_type="fvp-sgi-ramdisk" get_initrd
+	image="kernel" type="sgi-busybox" get_boot_image
+	image="initrd" type="sgi-ramdisk" get_boot_image
 
 	url="$sgi_prebuilts/grub-busybox.img" saveas="busybox.bin" fetch_file
 	url="$sgi_prebuilts/ramdisk-busybox.img" saveas="ramdisk.bin" fetch_file
diff --git a/run_config/fvp-linux.stress b/run_config/fvp-linux.stress
index 01a23a3..803235d 100644
--- a/run_config/fvp-linux.stress
+++ b/run_config/fvp-linux.stress
@@ -6,8 +6,8 @@
 #
 
 fetch_tf_resource() {
-	kernel_type="fvp-oe-uboot" get_kernel
-	initrd_type="dummy-ramdisk" get_initrd
+	image="kernel" type="fvp-oe-uboot" get_boot_image
+	image="initrd" type="dummy-ramdisk" get_boot_image
 
 	tmp_dir="$(mktempdir)"
 	ln -s "${img_file:?}" "$archive/rootfs.bin"
diff --git a/run_config/fvp-linux.tc b/run_config/fvp-linux.tc
index 6f18b36..206edcd 100644
--- a/run_config/fvp-linux.tc
+++ b/run_config/fvp-linux.tc
@@ -100,8 +100,8 @@
 }
 
 fetch_tf_resource() {
-	kernel_type="fvp-tc-kernel" get_kernel
-	initrd_type="fvp-tc-ramdisk" get_initrd
+	image="kernel" type="tc-kernel" get_boot_image
+	image="initrd" type="tc-ramdisk" get_boot_image
 
 	# Use SCP binary from SCP build if it exists, or fetch pre-built ones.
 	if [ ! -f "$archive/scp_rom.bin" ]; then
diff --git a/run_config/fvp-linux32 b/run_config/fvp-linux32
index ded67c5..a138b47 100644
--- a/run_config/fvp-linux32
+++ b/run_config/fvp-linux32
@@ -6,8 +6,8 @@
 #
 
 fetch_tf_resource() {
-	kernel_type="fvp-aarch32-zimage" get_kernel
-	initrd_type="aarch32-ramdisk" get_initrd
+	image="kernel" type="fvp-aarch32-zimage" get_boot_image
+	image="initrd" type="aarch32-ramdisk" get_boot_image
 }
 
 generate_lava_job_template() {
diff --git a/run_config/fvp-linux32.rstspmin b/run_config/fvp-linux32.rstspmin
index a71fb63..99d6fda 100644
--- a/run_config/fvp-linux32.rstspmin
+++ b/run_config/fvp-linux32.rstspmin
@@ -6,8 +6,8 @@
 #
 
 fetch_tf_resource() {
-	kernel_type="fvp-aarch32-zimage" get_kernel
-	initrd_type="aarch32-ramdisk" get_initrd
+	image="kernel" type="fvp-aarch32-zimage" get_boot_image
+	image="initrd" type="aarch32-ramdisk" get_boot_image
 }
 
 generate_lava_job_template() {
diff --git a/run_config/fvp-linux32.stress b/run_config/fvp-linux32.stress
index 8f623cf..8bda1c1 100644
--- a/run_config/fvp-linux32.stress
+++ b/run_config/fvp-linux32.stress
@@ -6,8 +6,8 @@
 #
 
 fetch_tf_resource() {
-	kernel_type="fvp-oe-uboot32" get_kernel
-	initrd_type="dummy-ramdisk32" get_initrd
+	image="kernel" type="fvp-oe-uboot32" get_boot_image
+	image="initrd" type="dummy-ramdisk32" get_boot_image
 
 	tmp_dir="$(mktempdir)"
 	ln -s "${img_file:?}" "$archive/rootfs.bin"
diff --git a/run_config/fvp-optee b/run_config/fvp-optee
index 4419064..85e71c3 100644
--- a/run_config/fvp-optee
+++ b/run_config/fvp-optee
@@ -6,5 +6,5 @@
 #
 
 post_tf_build() {
-	get_optee_bin
+	url="$tfa_downloads/optee/tee.bin" filename="bl32.bin" fetch_and_archive
 }
diff --git a/sgi575_utils.sh b/sgi575_utils.sh
index 0e20b8d..c8a2d23 100644
--- a/sgi575_utils.sh
+++ b/sgi575_utils.sh
@@ -12,8 +12,8 @@
 # Pre-built SCP/MCP binaries
 scp_mcp_prebuilts="${scp_mcp_prebuilts:-$scp_mcp_downloads/sgi575/release}"
 
-fvp_kernels[fvp-sgi-busybox]="$sgi_prebuilts/Image"
-fvp_initrd_urls[fvp-sgi-ramdisk]="$sgi_prebuilts/ramdisk-busybox.img"
+kernel_list[sgi-busybox]="$sgi_prebuilts/Image"
+initrd_list[sgi-ramdisk]="$sgi_prebuilts/ramdisk-busybox.img"
 
 scp_ram_addr=0x0bd80000
 mcp_ram_addr=0x0be00000
diff --git a/tc_utils.sh b/tc_utils.sh
index 634dac4..ea3989e 100644
--- a/tc_utils.sh
+++ b/tc_utils.sh
@@ -1,6 +1,6 @@
 #!/usr/bin/env bash
 #
-# Copyright (c) 2020-2022, Arm Limited. All rights reserved.
+# Copyright (c) 2020-2023, Arm Limited. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-3-Clause
 #
@@ -19,8 +19,8 @@
         ;;
 esac
 
-fvp_kernels[fvp-tc-kernel]="$tc_prebuilts/Image"
-fvp_initrd_urls[fvp-tc-ramdisk]="$tc_prebuilts/uInitrd-busybox.0x88000000"
+kernel_list[tc-kernel]="$tc_prebuilts/Image"
+initrd_list[tc-ramdisk]="$tc_prebuilts/uInitrd-busybox.0x88000000"
 
 initrd_addr=0x8000000
 kernel_addr=0x80000