blob: 9d137e8f0283c97c909913c9ff93e1460a101e00 [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)"
18
19expect {
20 # Parse the event log from the debug logs and store the digests
21 # so they can be matched later with what the fTPM read.
22
23 -re "Digest(\\s|\\w)*:\\s(\\w{2}\\s){16}|\
24 : (\\w{2}\\s){16}|\
25 Event(\\s|\\w)*:\\s\\w+\\s" {
26 puts $digest_log $expect_out(0,string)
27 exp_continue
28 }
29
30 -exact "Booting BL31" {
31 close $digest_log
32 }
33
34 timeout {
35 exit_timeout
36 }
37}
38
39expect {
40 "login" {
41 send "root\n"
42 }
43
44 timeout {
45 exit_timeout
46 }
47}
48
49expect {
50 "#" {
51 # Load the fTPM driver and retrieves PCR0
52 send "ftpm\n"
53 }
54
55 timeout {
56 exit_timeout
57 }
58}
59
60expect {
61 # Pass condition: PCR0 must not be all zeros.
62
63 -re $non_zero_pcr {
64 exp_continue
65 }
66
67 "#" { }
68
69 timeout {
70 exit_timeout
71 }
72}
73
74# Iterate over the rest of PCRs and check that they all are zeros.
75for {set i 1} {$i < 11} {incr i} {
76 send "pcrread -ha $i\n"
77
78 expect {
79 -re "(\\s00){16}\\s+(00\\s){16}" { }
80
81 -re $non_zero_pcr {
82 exit_uart -1
83 }
84
85 timeout {
86 exit_timeout
87 }
88 }
89}
90
91# Match the previously stored digest with the one generated by the
92# fTPM service. The pass criteria is that both digests must match,
93# meaning that TF-A successfully passed the event log to the TPM service.
94expect {
95 "#" {
96 spawn diff -s $TFA_DIGEST ftpm_event_log
97 }
98
99 timeout {
100 exit_timeout
101 }
102}
103
104expect {
105 -exact "are identical" {
106 exit_uart 0
107 }
108}
109
110exit_uart -1