blob: de3498893de18e97e79ef952458de81bc3478cca [file] [log] [blame]
Javier Almansa Sobrino98de5032020-09-17 12:47:05 +01001#
2# Copyright (c) 2020, Arm Limited. All rights reserved.
3#
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"]
14set digest_log [open $TFA_DIGEST w]
15
16# regexp for non-zero PCR0
17set non_zero_pcr "(?!(\\s00){16})((\\s(\[0-9a-f\]){2}){16}\\s)"
Manish V Badarkhefc146c42021-11-24 15:34:00 +000018set zero_pcr "(\\s00){16}\\s+(00\\s){16}"
Javier Almansa Sobrino98de5032020-09-17 12:47:05 +010019
20expect {
21 # Parse the event log from the debug logs and store the digests
22 # so they can be matched later with what the fTPM read.
23
24 -re "Digest(\\s|\\w)*:\\s(\\w{2}\\s){16}|\
25 : (\\w{2}\\s){16}|\
26 Event(\\s|\\w)*:\\s\\w+\\s" {
27 puts $digest_log $expect_out(0,string)
28 exp_continue
29 }
30
31 -exact "Booting BL31" {
32 close $digest_log
33 }
34
35 timeout {
36 exit_timeout
37 }
38}
39
40expect {
41 "login" {
42 send "root\n"
43 }
44
45 timeout {
46 exit_timeout
47 }
48}
49
50expect {
51 "#" {
52 # Load the fTPM driver and retrieves PCR0
53 send "ftpm\n"
54 }
55
56 timeout {
57 exit_timeout
58 }
59}
60
61expect {
62 # Pass condition: PCR0 must not be all zeros.
63
64 -re $non_zero_pcr {
65 exp_continue
66 }
67
Manish V Badarkhefc146c42021-11-24 15:34:00 +000068 "#" {
69 # get PCR1 value
70 send "pcrread -ha 1\n"
71 }
72
73 timeout {
74 exit_timeout
75 }
76}
77
78expect {
79 # Pass condition: PCR1 must not be all zeros.
80
81 -re $non_zero_pcr {
82 exp_continue
83 }
84
Javier Almansa Sobrino98de5032020-09-17 12:47:05 +010085 "#" { }
86
87 timeout {
88 exit_timeout
89 }
90}
91
92# Iterate over the rest of PCRs and check that they all are zeros.
Manish V Badarkhefc146c42021-11-24 15:34:00 +000093for {set i 2} {$i < 11} {incr i} {
Javier Almansa Sobrino98de5032020-09-17 12:47:05 +010094 send "pcrread -ha $i\n"
95
96 expect {
Manish V Badarkhefc146c42021-11-24 15:34:00 +000097 -re $zero_pcr { }
Javier Almansa Sobrino98de5032020-09-17 12:47:05 +010098
99 -re $non_zero_pcr {
100 exit_uart -1
101 }
102
103 timeout {
104 exit_timeout
105 }
106 }
107}
108
109# Match the previously stored digest with the one generated by the
110# fTPM service. The pass criteria is that both digests must match,
111# meaning that TF-A successfully passed the event log to the TPM service.
112expect {
113 "#" {
114 spawn diff -s $TFA_DIGEST ftpm_event_log
115 }
116
117 timeout {
118 exit_timeout
119 }
120}
121
122expect {
123 -exact "are identical" {
124 exit_uart 0
125 }
126}
127
128exit_uart -1