Add build and run configs to exercise ARM_LINUX_KERNEL_AS_BL33 feature

This patch also adds test configurations that boot Linux kernel
directly without a normal world bootloader such as U-Boot

Refer to the following patches which fix the false dependency of
ARM_LINUX_KERNEL_AS_BL33 on RESET_TO_BL31 feature:

https://review.trustedfirmware.org/c/TF-A/trusted-firmware-a/+/8353
https://review.trustedfirmware.org/c/TF-A/trusted-firmware-a/+/8352

Signed-off-by: Madhukar Pappireddy <madhukar.pappireddy@arm.com>
Change-Id: I2eb1dfcc3ee6b4417a887c0bd3840f3d9da20dd0
diff --git a/expect/linux-bl33.exp b/expect/linux-bl33.exp
new file mode 100644
index 0000000..2de23bd
--- /dev/null
+++ b/expect/linux-bl33.exp
@@ -0,0 +1,27 @@
+#
+# Copyright (c) 2021 Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+# Expect script for Trusted Firmware + Linux boot process
+#
+# Refer to handle-arguments.inc for the list of parameters.
+#
+
+source [file join [file dirname [info script]] handle-arguments.inc]
+
+# Trusted Firmware boot section
+source [file join [file dirname [info script]] trusted-firmware.inc]
+
+# Linux kernel boot section
+expect_string "Booting Linux on physical CPU" "Booting Linux"
+expect_string "Linux version" "Linux starting"
+
+# The kernel prints some information it takes from the preloaded DTB.
+# Check for following information to see that we actually got the right DTB.
+# 1. Machine model
+# 2. Command line passed via the "/chosen" node
+expect_re "Machine model: FVP (Base|Foundation)" "Machine identified"
+expect_string "Kernel command line: console=ttyAMA0" "Kernel command line"
+
+exit_uart 0
diff --git a/group/tf-l1-boot-tests-misc/fvp-linux-as-bl33:fvp-linux.bl33-dtb-aemv8a.linux.bl33-debug b/group/tf-l1-boot-tests-misc/fvp-linux-as-bl33:fvp-linux.bl33-dtb-aemv8a.linux.bl33-debug
new file mode 100644
index 0000000..45065d8
--- /dev/null
+++ b/group/tf-l1-boot-tests-misc/fvp-linux-as-bl33:fvp-linux.bl33-dtb-aemv8a.linux.bl33-debug
@@ -0,0 +1,6 @@
+#
+# Copyright (c) 2021 Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
diff --git a/group/tf-l1-boot-tests-misc/fvp-linux-as-bl33:fvp-linux.bl33-dtb.foundation-foundationv8.linux.bl33-debug b/group/tf-l1-boot-tests-misc/fvp-linux-as-bl33:fvp-linux.bl33-dtb.foundation-foundationv8.linux.bl33-debug
new file mode 100644
index 0000000..45065d8
--- /dev/null
+++ b/group/tf-l1-boot-tests-misc/fvp-linux-as-bl33:fvp-linux.bl33-dtb.foundation-foundationv8.linux.bl33-debug
@@ -0,0 +1,6 @@
+#
+# Copyright (c) 2021 Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
diff --git a/run_config/fvp-aemv8a.linux.bl33 b/run_config/fvp-aemv8a.linux.bl33
new file mode 100644
index 0000000..8fcbd3f
--- /dev/null
+++ b/run_config/fvp-aemv8a.linux.bl33
@@ -0,0 +1,19 @@
+#!/usr/bin/env bash
+#
+# Copyright (c) 2021 Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+post_tf_build() {
+	# Build FIP without any BL33 image (it is preloaded)
+	build_fip
+}
+
+post_fetch_tf_resource() {
+        local model="base-aemv8a"
+
+	kernel_addr="0x80080000" dtb_addr="0x80070000" \
+		model="$model" gen_model_params
+
+	model="$model" gen_fvp_yaml
+}
diff --git a/run_config/fvp-foundationv8.linux.bl33 b/run_config/fvp-foundationv8.linux.bl33
new file mode 100644
index 0000000..7133969
--- /dev/null
+++ b/run_config/fvp-foundationv8.linux.bl33
@@ -0,0 +1,22 @@
+#!/usr/bin/env bash
+#
+# Copyright (c) 2021 Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+post_tf_build() {
+	# Build FIP without any BL33 image (it is preloaded)
+	build_fip
+}
+
+post_fetch_tf_resource() {
+        local model="foundationv8"
+
+	kernel_addr="0x80080000" dtb_addr="0x80070000" \
+		model="$model" gen_model_params
+
+	uart="0" set_expect_variable "num_cpus" "4"
+	model="model" gen_fvp_yaml
+}
+
diff --git a/run_config/fvp-linux.bl33 b/run_config/fvp-linux.bl33
new file mode 100644
index 0000000..a8dfe51
--- /dev/null
+++ b/run_config/fvp-linux.bl33
@@ -0,0 +1,13 @@
+#!/usr/bin/env bash
+#
+# Copyright (c) 2021 Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+fetch_tf_resource() {
+	kernel_type="fvp-busybox-uboot" get_kernel
+	uart="0" file="linux-bl33.exp" track_expect
+
+	payload_type="linux" gen_fvp_yaml_template
+}
diff --git a/script/build_package.sh b/script/build_package.sh
index f4ea34b..1bfaee2 100755
--- a/script/build_package.sh
+++ b/script/build_package.sh
@@ -412,9 +412,12 @@
 # Update hw-config in FIP, and remove the original DTB afterwards.
 update_fip_hw_config() {
 	# The DTB needs to be loaded by the model (and not updated in the FIP)
-	# in configs where BL2 isn't present
+	# in configs:
+	#            1. Where BL2 isn't present
+	#            2. Where we boot to Linux directly as BL33
 	case "1" in
 		"$(get_tf_opt RESET_TO_BL31)" | \
+		"$(get_tf_opt ARM_LINUX_KERNEL_AS_BL33)" | \
 		"$(get_tf_opt RESET_TO_SP_MIN)" | \
 		"$(get_tf_opt BL2_AT_EL3)")
 			return 0;;
diff --git a/tf_config/fvp-linux-as-bl33 b/tf_config/fvp-linux-as-bl33
new file mode 100644
index 0000000..f61d1f5
--- /dev/null
+++ b/tf_config/fvp-linux-as-bl33
@@ -0,0 +1,5 @@
+ARM_PRELOADED_DTB_BASE=0x80070000
+ARM_LINUX_KERNEL_AS_BL33=1
+CROSS_COMPILE=aarch64-none-elf-
+PLAT=fvp
+PRELOADED_BL33_BASE=0x80080000