qemu: add linux boot tests

Add some basic boot tests for QEMU and supporting scripts to automate
the generation of dependencies. Currently, there are no tests in CI that
utilise the platform. This makes it easier to do testing in CI without
the need for a complex hardware setup.

Change-Id: I98e43ecc56dc44a767590c73963ded7b2cee1cff
Signed-off-by: Harrison Mutai <harrison.mutai@arm.com>
diff --git a/qemu_utils.sh b/qemu_utils.sh
new file mode 100644
index 0000000..29b8e61
--- /dev/null
+++ b/qemu_utils.sh
@@ -0,0 +1,84 @@
+#!/usr/bin/env bash
+#
+# Copyright (c) 2022 Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+set -u
+
+rootfs_url="$tfa_downloads/linux_boot/busybox.cpio.gz"
+uefi_url="$tfa_downloads/linux_boot/qemu/QEMU_EFI.fd"
+
+# Default QEMU model variables
+default_model_dtb="dtb.bin"
+
+# QEMU Kernel URLs
+declare -A plat_kernel_list=(
+	[qemu-busybox]="$tfa_downloads/linux_boot/Image.gz"
+)
+
+gen_qemu_yaml(){
+	model="${model:?}"
+	model_bin="${model_bin:qemu-system-aarch64}"
+
+	yaml_template_file="$workspace/qemu_template.yaml"
+	yaml_file="$workspace/qemu.yaml"
+	yaml_job_file="$workspace/job.yaml"
+	lava_model_params="$workspace/lava_model_params"
+
+	# this function expects a template, quit if it is not present
+	if [ ! -f "$yaml_template_file" ]; then
+		return
+	fi
+
+	prompt="${prompt:-root@tf-busyboot:/root#}"
+
+	# Any addition on this array requires an addition in the qemu
+	# templates.
+	declare -A qemu_artefact_urls=(
+		[kernel]="$(gen_bin_url kernel.bin)"
+		[bios]="$(gen_bin_url qemu_bios.bin)"
+		[initrd]="$(gen_bin_url rootfs.bin.gz)"
+		[uboot]="$(gen_bin_url uboot.bin)"
+	)
+
+	declare -A qemu_artefact_filters=(
+		[kernel]="kernel.bin"
+		[bios]="qemu_bios.bin"
+		[initrd]="rootfs.bin"
+		[uboot]="uboot.bin"
+	)
+
+	declare -A qemu_artefact_macros=(
+		["kernel.bin"]="{kernel}"
+		["qemu_bios.bin"]="{bios}"
+		["rootfs.bin"]="{initrd}"
+		["uboot.bin"]="{uboot}"
+	)
+
+	declare -a qemu_artefacts
+	filter_artefacts qemu_artefacts qemu_artefact_filters
+
+	lava_model_params="${lava_model_params}" \
+		gen_lava_model_params qemu_artefact_macros
+
+	yaml_template_file="$yaml_template_file" \
+	yaml_file="$yaml_file" \
+	yaml_job_file="$yaml_job_file" \
+		gen_lava_job_def qemu_artefacts qemu_artefact_urls
+}
+
+gen_qemu_image(){
+	local image=${image:?}
+	local bl1_path=${bl1_path:?}
+	local fip_path=${fip_path:?}
+
+	# Cocatenate bl1 and fip images to create a single BIOS consumed by QEMU.
+	cp $bl1_path "$image"
+	dd if=$fip_path of="$image" bs=64k seek=4
+
+	archive_file "$image"
+}
+
+set +u