ci(n1sdp): refactor fip fragment for specificity

The ``n1sdp-fip`` fragment builds the fip image with UEFI. Replace the
fragment to target this specific use case as we also want to generate
fip images with other NS workloads i.e. TFTF. Move parts of the code for
creating a fip image with xCP firmware to a generic location so it may
be used by other fragments.

Signed-off-by: Harrison Mutai <harrison.mutai@arm.com>
Change-Id: I37433e32f1bc235e4c524ceed5730b0bc4c63ddd
diff --git a/n1sdp_utils.sh b/n1sdp_utils.sh
index 0f88c21..f0c196a 100644
--- a/n1sdp_utils.sh
+++ b/n1sdp_utils.sh
@@ -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
 #
@@ -16,7 +16,30 @@
         archive_file "n1sdp-board-firmware.zip"
 }
 
-gen_recovery_image_n1sdp() {
+fetch_prebuilt_fw_images() {
+        url="$n1sdp_prebuilts/n1sdp-board-firmware.zip" filename="n1sdp-board-firmware.zip" \
+                fetch_and_archive
+
+        #Fetch pre-built SCP/MCP binaries if they haven't been built
+        if [ ! -f "$archive/mcp_rom.bin" ]; then
+                url="$scp_mcp_prebuilts/mcp_romfw.bin" filename="mcp_rom.bin" \
+                        fetch_and_archive
+        fi
+        if [ ! -f "$archive/scp_rom.bin" ]; then
+                url="$scp_mcp_prebuilts/scp_romfw.bin" filename="scp_rom.bin" \
+                        fetch_and_archive
+        fi
+        if [ ! -f "$archive/scp_ram.bin" ]; then
+                url="$scp_mcp_prebuilts/scp_ramfw.bin" filename="scp_ram.bin" \
+                        fetch_and_archive
+        fi
+        if [ ! -f "$archive/mcp_ram.bin" ]; then
+                url="$scp_mcp_prebuilts/mcp_ramfw.bin" filename="mcp_ram.bin" \
+                        fetch_and_archive
+        fi
+}
+
+gen_recovery_image() {
         local zip_dir="$workspace/$mode/n1sdp-board-firmware_primary"
         local zip_file="${zip_dir}.zip"
 
@@ -24,26 +47,46 @@
 
         extract_tarball "$archive/n1sdp-board-firmware.zip" "$zip_dir"
 
+        scp_uuid="cfacc2c4-15e8-4668-82be-430a38fad705"
+        mcp_uuid="54464222-a4cf-4bf8-b1b6-cee7dade539e"
+
+        # Create FIP for SCP
+        "$fiptool" create --blob \
+                uuid=$scp_uuid,file=$tf_build_root/n1sdp/$bin_mode/bl1.bin \
+                --scp-fw "$archive/scp_ram.bin" "scp_fw.bin"
+
+        archive_file "scp_fw.bin"
+
+        # Create FIP for MCP, this needs fixed uuid for now
+        "$fiptool" create --blob \
+                uuid=$mcp_uuid,file="$archive/mcp_ram.bin" "mcp_fw.bin"
+
+        archive_file "mcp_fw.bin"
+
         cp -Rp --no-preserve=ownership "$archive/mcp_fw.bin" "$zip_dir/SOFTWARE"
         cp -Rp --no-preserve=ownership "$archive/mcp_rom.bin" "$zip_dir/SOFTWARE"
         cp -Rp --no-preserve=ownership "$archive/scp_fw.bin" "$zip_dir/SOFTWARE"
         cp -Rp --no-preserve=ownership "$archive/scp_rom.bin" "$zip_dir/SOFTWARE"
         cp -Rp --no-preserve=ownership "$archive/fip.bin" "$zip_dir/SOFTWARE"
 
-        (cd "$zip_dir" && zip -rq "$zip_file" -- *)
+        (cd "$zip_dir" && zip -rq "$zip_file" -x \.* -- *)
 
         archive_file "$zip_file"
 }
 
 gen_n1sdp_yaml() {
-        local yaml_file="$workspace/n1sdp.yaml"
-        local job_file="$workspace/job.yaml"
-        local payload_type="${payload_type:?}"
+        yaml_template_file="$workspace/n1sdp_template.yaml"
+        yaml_file="$workspace/n1sdp.yaml"
+        yaml_job_file="$workspace/job.yaml"
 
-        bin_mode="$mode" \
-                "$ci_root/script/gen_n1sdp_${payload_type}_yaml.sh" > "$yaml_file"
+        # this function expects a template, quit if it is not present
+        if [ ! -f "$yaml_template_file" ]; then
+                return
+        fi
 
-        cp "$yaml_file" "$job_file"
-        archive_file "$yaml_file"
-        archive_file "$job_file"
+        yaml_template_file="$yaml_template_file" \
+        yaml_file="$yaml_file" \
+        yaml_job_file="$yaml_job_file" \
+        recovery_img_url="$(gen_bin_url n1sdp-board-firmware_primary.zip)" \
+                gen_lava_job_def
 }