blob: 8aff8ceb84acd6fb88d2e75cc0bb1e06398741e0 [file] [log] [blame]
Javier Almansa Sobrino98de5032020-09-17 12:47:05 +01001#
Sandrine Bailleux0bcf4132022-03-31 11:15:51 +02002# Copyright (c) 2020-2022, Arm Limited. All rights reserved.
Javier Almansa Sobrino98de5032020-09-17 12:47:05 +01003#
4# SPDX-License-Identifier: BSD-3-Clause
5#
6# Expect script for Linux/Buildroot using Measured Boot & fTPM
7#
8
9source [file join [file dirname [info script]] utils.inc]
10source [file join [file dirname [info script]] handle-arguments.inc]
11
12# File to store the event log from the ftpm service.
13set TFA_DIGEST [get_param tfa_digest "tfa_event_log"]
Javier Almansa Sobrino98de5032020-09-17 12:47:05 +010014
15# regexp for non-zero PCR0
16set non_zero_pcr "(?!(\\s00){16})((\\s(\[0-9a-f\]){2}){16}\\s)"
Manish V Badarkhefc146c42021-11-24 15:34:00 +000017set zero_pcr "(\\s00){16}\\s+(00\\s){16}"
Javier Almansa Sobrino98de5032020-09-17 12:47:05 +010018
19expect {
Sandrine Bailleux0bcf4132022-03-31 11:15:51 +020020 # Wait for the start of the event log dump.
21 "TCG_EfiSpecIDEvent:" {
22 set digest_log [open $TFA_DIGEST w]
23 }
Sandrine Bailleux0bcf4132022-03-31 11:15:51 +020024}
25
26expect {
Javier Almansa Sobrino98de5032020-09-17 12:47:05 +010027 # Parse the event log from the debug logs and store the digests
Sandrine Bailleux0bcf4132022-03-31 11:15:51 +020028 # so they can be matched later with what the fTPM reads.
Javier Almansa Sobrino98de5032020-09-17 12:47:05 +010029
30 -re "Digest(\\s|\\w)*:\\s(\\w{2}\\s){16}|\
31 : (\\w{2}\\s){16}|\
32 Event(\\s|\\w)*:\\s\\w+\\s" {
33 puts $digest_log $expect_out(0,string)
34 exp_continue
35 }
36
37 -exact "Booting BL31" {
38 close $digest_log
39 }
Javier Almansa Sobrino98de5032020-09-17 12:47:05 +010040}
41
42expect {
43 "login" {
44 send "root\n"
45 }
Javier Almansa Sobrino98de5032020-09-17 12:47:05 +010046}
47
48expect {
49 "#" {
50 # Load the fTPM driver and retrieves PCR0
51 send "ftpm\n"
52 }
Javier Almansa Sobrino98de5032020-09-17 12:47:05 +010053}
54
55expect {
56 # Pass condition: PCR0 must not be all zeros.
57
58 -re $non_zero_pcr {
59 exp_continue
60 }
61
Manish V Badarkhefc146c42021-11-24 15:34:00 +000062 "#" {
63 # get PCR1 value
64 send "pcrread -ha 1\n"
65 }
Manish V Badarkhefc146c42021-11-24 15:34:00 +000066}
67
68expect {
69 # Pass condition: PCR1 must not be all zeros.
70
71 -re $non_zero_pcr {
72 exp_continue
73 }
74
Javier Almansa Sobrino98de5032020-09-17 12:47:05 +010075 "#" { }
Javier Almansa Sobrino98de5032020-09-17 12:47:05 +010076}
77
78# Iterate over the rest of PCRs and check that they all are zeros.
Manish V Badarkhefc146c42021-11-24 15:34:00 +000079for {set i 2} {$i < 11} {incr i} {
Javier Almansa Sobrino98de5032020-09-17 12:47:05 +010080 send "pcrread -ha $i\n"
81
82 expect {
Manish V Badarkhefc146c42021-11-24 15:34:00 +000083 -re $zero_pcr { }
Javier Almansa Sobrino98de5032020-09-17 12:47:05 +010084
85 -re $non_zero_pcr {
86 exit_uart -1
87 }
Javier Almansa Sobrino98de5032020-09-17 12:47:05 +010088 }
89}
90
Chris Kayc4875b62022-11-24 17:21:48 +000091expect_string "#" "finished reading PCRs"
92
Javier Almansa Sobrino98de5032020-09-17 12:47:05 +010093# Match the previously stored digest with the one generated by the
94# fTPM service. The pass criteria is that both digests must match,
95# meaning that TF-A successfully passed the event log to the TPM service.
Chris Kayc4875b62022-11-24 17:21:48 +000096if {[catch {exec diff -s $TFA_DIGEST ftpm_event_log} result options] == 0} {
97 message "tests succeeded, digests matched"
98} else {
99 message "tests failed, digests did not match"
100 exit_uart -1
Javier Almansa Sobrino98de5032020-09-17 12:47:05 +0100101}