feat(fwu): ensure boot fails with corrupted BL2 FIP partition
The test case populate the BL2 partition entry
with random number, to ensure a failure in boot
process with valid FIP_A and FIP_B.
Signed-off-by: Xialin Liu <xialin.liu@arm.com>
Change-Id: I6fb6f87d88b5bbc4623e19d7e32dddb12d8413cd
diff --git a/expect-lava/fwu_invalid_bl2.exp b/expect-lava/fwu_invalid_bl2.exp
new file mode 100644
index 0000000..540eeeb
--- /dev/null
+++ b/expect-lava/fwu_invalid_bl2.exp
@@ -0,0 +1,12 @@
+#
+# Copyright (c) 2025, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+# Expect script for Trusted Firmware Test Framework
+#
+
+expect_string+=('i;NS_BL1U: Invalid image size')
+expect_string+=('i;NS_BL1U: Invalid SMC')
+expect_string+=('i;NS_BL1U: IMAGE_COPY with invalid image_id')
+expect_string+=('i;PANIC in file')
diff --git a/expect/fwu_invalid_bl2.exp b/expect/fwu_invalid_bl2.exp
new file mode 100644
index 0000000..2fbd8e1
--- /dev/null
+++ b/expect/fwu_invalid_bl2.exp
@@ -0,0 +1,16 @@
+#
+# Copyright (c) 2025, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+# Expect script for Trusted Firmware Test Framework
+#
+
+source [file join [file dirname [info script]] handle-arguments.inc]
+
+expect_string "NS_BL1U: Invalid image size"
+expect_string "NS_BL1U: Invalid SMC"
+expect_string "NS_BL1U: IMAGE_COPY with invalid image_id"
+expect_string "PANIC in file"
+
+exit_uart 0
diff --git a/group/tftf-l2-fvp/fvp-tbb-psa-mbedtls-romlib-fwu,fvp-default:fvp-tftf.fwu_invalid_bl2-aemv8a.gpt-debug b/group/tftf-l2-fvp/fvp-tbb-psa-mbedtls-romlib-fwu,fvp-default:fvp-tftf.fwu_invalid_bl2-aemv8a.gpt-debug
new file mode 100644
index 0000000..8e0db6b
--- /dev/null
+++ b/group/tftf-l2-fvp/fvp-tbb-psa-mbedtls-romlib-fwu,fvp-default:fvp-tftf.fwu_invalid_bl2-aemv8a.gpt-debug
@@ -0,0 +1,5 @@
+#
+# Copyright (c) 2025, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
diff --git a/run_config/fvp-tftf.fwu_invalid_bl2 b/run_config/fvp-tftf.fwu_invalid_bl2
new file mode 100644
index 0000000..d7cbbf6
--- /dev/null
+++ b/run_config/fvp-tftf.fwu_invalid_bl2
@@ -0,0 +1,33 @@
+#!/usr/bin/env bash
+#
+# Copyright (c) 2025, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+corrupt_bl2_gpt(){
+ echo "Corrupting BL2 FIP GPT partition in $1"
+ fip_max_size=$1
+ sector_size=512
+ gpt_image="$archive/fip_gpt.bin"
+ num_sectors_bl2_fip=$(expr $fip_max_size / $sector_size)
+
+ dd if=/dev/urandom of=$gpt_image bs=$sector_size seek=$(gdisk -l $gpt_image | grep " FIP_BL2$" | awk '{print $2}') count=$num_sectors_bl2_fip conv=notrunc
+}
+
+post_tf_build() {
+ build_fip BL33="$archive/tftf.bin"
+}
+
+post_tf_archive() {
+ # Maximum FIP size is 2MiB = 2097152
+ gen_gpt_bin "$archive/fip.bin" 2097152
+
+ corrupt_bl2_gpt 2097152
+}
+
+generate_lava_job_template() {
+ uart="0" timeout=60 file="fwu_invalid_bl2.exp" track_expect
+
+ payload_type="tftf" gen_yaml_template
+}