Add support to test TF-A Measured Boot through an external TPM service.
Perform automatic tests to ensure that Measured Boot functionality on
TF-A can interact with an external TPM service.
This patch performs the following tests:
1.- Check that PCR0 Digest is not all zeros
2.- Check that the rest of PCRs are all zero
3.- Check that the event log written by TF-A is the same as read by
the TPM service.
The patch is not meant to test whether the digests are correct or not
(testing if the TPM service is buggy or not is beyond the scope of
this test). It just tests that an external TPM service is able to
access the TPM event log generated by TF-A and that it can be properly
processed.
Change-Id: I5fba87005886ff549345bd92675d2f2a9fe44e79
Signed-off-by: Javier Almansa Sobrino <javier.almansasobrino@arm.com>
diff --git a/expect/linux-tpm.exp b/expect/linux-tpm.exp
new file mode 100644
index 0000000..9d137e8
--- /dev/null
+++ b/expect/linux-tpm.exp
@@ -0,0 +1,110 @@
+#
+# Copyright (c) 2020, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+# Expect script for Linux/Buildroot using Measured Boot & fTPM
+#
+
+source [file join [file dirname [info script]] utils.inc]
+source [file join [file dirname [info script]] handle-arguments.inc]
+
+# File to store the event log from the ftpm service.
+set TFA_DIGEST [get_param tfa_digest "tfa_event_log"]
+set digest_log [open $TFA_DIGEST w]
+
+# regexp for non-zero PCR0
+set non_zero_pcr "(?!(\\s00){16})((\\s(\[0-9a-f\]){2}){16}\\s)"
+
+expect {
+ # Parse the event log from the debug logs and store the digests
+ # so they can be matched later with what the fTPM read.
+
+ -re "Digest(\\s|\\w)*:\\s(\\w{2}\\s){16}|\
+ : (\\w{2}\\s){16}|\
+ Event(\\s|\\w)*:\\s\\w+\\s" {
+ puts $digest_log $expect_out(0,string)
+ exp_continue
+ }
+
+ -exact "Booting BL31" {
+ close $digest_log
+ }
+
+ timeout {
+ exit_timeout
+ }
+}
+
+expect {
+ "login" {
+ send "root\n"
+ }
+
+ timeout {
+ exit_timeout
+ }
+}
+
+expect {
+ "#" {
+ # Load the fTPM driver and retrieves PCR0
+ send "ftpm\n"
+ }
+
+ timeout {
+ exit_timeout
+ }
+}
+
+expect {
+ # Pass condition: PCR0 must not be all zeros.
+
+ -re $non_zero_pcr {
+ exp_continue
+ }
+
+ "#" { }
+
+ timeout {
+ exit_timeout
+ }
+}
+
+# Iterate over the rest of PCRs and check that they all are zeros.
+for {set i 1} {$i < 11} {incr i} {
+ send "pcrread -ha $i\n"
+
+ expect {
+ -re "(\\s00){16}\\s+(00\\s){16}" { }
+
+ -re $non_zero_pcr {
+ exit_uart -1
+ }
+
+ timeout {
+ exit_timeout
+ }
+ }
+}
+
+# Match the previously stored digest with the one generated by the
+# fTPM service. The pass criteria is that both digests must match,
+# meaning that TF-A successfully passed the event log to the TPM service.
+expect {
+ "#" {
+ spawn diff -s $TFA_DIGEST ftpm_event_log
+ }
+
+ timeout {
+ exit_timeout
+ }
+}
+
+expect {
+ -exact "are identical" {
+ exit_uart 0
+ }
+}
+
+exit_uart -1
diff --git a/expect/tpm-logs.exp b/expect/tpm-logs.exp
new file mode 100644
index 0000000..7ed4479
--- /dev/null
+++ b/expect/tpm-logs.exp
@@ -0,0 +1,33 @@
+#
+# Copyright (c) 2020, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+# Expect script for fTPM debug logs
+#
+
+source [file join [file dirname [info script]] utils.inc]
+source [file join [file dirname [info script]] handle-arguments.inc]
+
+# File to store the event log from the ftpm service.
+set FTPM_DIGEST [get_param ftpm_digest "ftpm_event_log"]
+set event_log [open $FTPM_DIGEST w]
+
+expect -exact "Event log size"
+
+expect {
+ # Parse the event log from the debug logs and store the digests
+ # so they can be matched later with what TF-A stored on the event log.
+ -re "Digest(\\s|\\w)*:\\s(\\w{2}\\s){16}|\
+ : (\\w{2}\\s){16}|\
+ Event(\\s|\\w)*:\\s\\w+\\s" {
+ puts $event_log $expect_out(0,string)
+ exp_continue
+ }
+
+ -exact "returned value" {
+ close $event_log
+ }
+}
+
+source [file join [file dirname [info script]] uart-hold.inc]
diff --git a/fvp_utils.sh b/fvp_utils.sh
index 42434dc..8c146cd 100644
--- a/fvp_utils.sh
+++ b/fvp_utils.sh
@@ -58,6 +58,22 @@
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() {
+ url="${nfs_volume}/pdsw/downloads/tf-a/ftpm/optee/tee-header_v2.bin" \
+ saveas="bl32.bin" fetch_file
+ archive_file "bl32.bin"
+
+ url="${nfs_volume}/pdsw/downloads/tf-a/ftpm/optee/tee-pager_v2.bin" \
+ saveas="bl32_extra1.bin" fetch_file
+ archive_file "bl32_extra1.bin"
+
+ url="${nfs_volume}/pdsw/downloads/tf-a/ftpm/optee/tee-pageable_v2.bin" \
+ saveas="bl32_extra2.bin" fetch_file
+ archive_file "bl32_extra2.bin"
+}
+
get_uboot32_bin() {
local tmpdir="$(mktempdir)"
diff --git a/group/measured-boot-ftpm/fvp-mb-256:fvp-optee.mb-linux.rootfs+ftpm-fip.ftpm-foundationv8.8_0 b/group/measured-boot-ftpm/fvp-mb-256:fvp-optee.mb-linux.rootfs+ftpm-fip.ftpm-foundationv8.8_0
new file mode 100644
index 0000000..0a342ff
--- /dev/null
+++ b/group/measured-boot-ftpm/fvp-mb-256:fvp-optee.mb-linux.rootfs+ftpm-fip.ftpm-foundationv8.8_0
@@ -0,0 +1,5 @@
+#
+# Copyright (c) 2020, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
diff --git a/model/ftpm-ports.awk b/model/ftpm-ports.awk
new file mode 100644
index 0000000..515258f
--- /dev/null
+++ b/model/ftpm-ports.awk
@@ -0,0 +1,14 @@
+#
+# Copyright (c) 2020, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+/terminal_0/ { ports[0] = $NF }
+/terminal_1/ { ports[1] = $NF }
+END {
+ for (i = 0; i < num_uarts; i++) {
+ if (ports[i] != "")
+ print "ports[" i "]=" ports[i]
+ }
+}
diff --git a/run_config/fvp-fip.ftpm b/run_config/fvp-fip.ftpm
new file mode 100644
index 0000000..a9e5a4a
--- /dev/null
+++ b/run_config/fvp-fip.ftpm
@@ -0,0 +1,12 @@
+#!/usr/bin/env bash
+#
+# Copyright (c) 2020, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+post_tf_build() {
+ build_fip BL33="$archive/edk2.bin" BL32="$archive/bl32.bin" \
+ BL32_EXTRA1="$archive/bl32_extra1.bin" \
+ BL32_EXTRA2="$archive/bl32_extra2.bin"
+}
diff --git a/run_config/fvp-linux.rootfs+ftpm b/run_config/fvp-linux.rootfs+ftpm
new file mode 100644
index 0000000..bc8fa4b
--- /dev/null
+++ b/run_config/fvp-linux.rootfs+ftpm
@@ -0,0 +1,20 @@
+#!/usr/bin/env bash
+#
+# Copyright (c) 2020, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+post_tf_build() {
+ # Get the images for the test.
+ edk_url="${nfs_volume}/pdsw/downloads/tf-a/ftpm/FVP_AARCH64_EFI.fd"
+ rootfs_url="${nfs_volume}/pdsw/downloads/tf-a/ftpm/boot-fat.uefi.img" get_rootfs
+ url="$edk_url" saveas="edk2.bin" fetch_file
+ archive_file "edk2.bin"
+
+ # Configure the uarts for tracking.
+ uart="0" timeout="300" file="linux-tpm.exp" track_expect
+ uart="1" timeout="300" file="tpm-logs.exp" track_expect
+ set_run_env "ports_script" "$ci_root/model/ftpm-ports.awk"
+ set_run_env "num_uarts" "2"
+}
diff --git a/run_config/fvp-optee.mb b/run_config/fvp-optee.mb
new file mode 100644
index 0000000..4dae2da
--- /dev/null
+++ b/run_config/fvp-optee.mb
@@ -0,0 +1,10 @@
+#!/usr/bin/env bash
+#
+# Copyright (c) 2020, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+post_tf_build() {
+ get_ftpm_optee_bin
+}
\ No newline at end of file
diff --git a/tf_config/fvp-mb-256 b/tf_config/fvp-mb-256
index ad1a754..615d411 100644
--- a/tf_config/fvp-mb-256
+++ b/tf_config/fvp-mb-256
@@ -1,8 +1,11 @@
ARM_ROTPK_LOCATION=devel_rsa
+ARM_TSP_RAM_LOCATION=tdram
CROSS_COMPILE=aarch64-none-elf-
+EVENT_LOG_LEVEL=20
GENERATE_COT=1
MEASURED_BOOT=1
PLAT=fvp
ROT_KEY=plat/arm/board/common/rotpk/arm_rotprivk_rsa.pem
+SPD=opteed
TPM_HASH_ALG=sha256
TRUSTED_BOARD_BOOT=1