blob: 1aa70b922c1e5ff8dec0633115969c2678fd1925 [file] [log] [blame]
Manish V Badarkheb87f37b2021-11-10 18:53:05 +00001#
2# Copyright (c) 2021, 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# It is a copy of linux-tpm.exp which doesn't check PCR0 value,
8# as that doesn't apply to this config
9#
10
11source [file join [file dirname [info script]] utils.inc]
12source [file join [file dirname [info script]] handle-arguments.inc]
13
14# File to store the event log from the ftpm service.
15set TFA_DIGEST [get_param tfa_digest "tfa_event_log"]
16set digest_log [open $TFA_DIGEST w]
17
18# regexp for non-zero PCR0
19set non_zero_pcr "(?!(\\s00){16})((\\s(\[0-9a-f\]){2}){16}\\s)"
20
21expect {
22 # Parse the event log from the debug logs and store the digests
23 # so they can be matched later with what the fTPM read.
24
25 -re "Digest(\\s|\\w)*:\\s(\\w{2}\\s){16}|\
26 : (\\w{2}\\s){16}|\
27 Event(\\s|\\w)*:\\s\\w+\\s" {
28 puts $digest_log $expect_out(0,string)
29 exp_continue
30 }
31
32 -exact "Booting BL31" {
33 close $digest_log
34 }
35
36 timeout {
37 exit_timeout
38 }
39}
40
41expect {
42 "login" {
43 send "root\n"
44 }
45
46 timeout {
47 exit_timeout
48 }
49}
50
51expect {
52 "#" {
53 # Load the fTPM driver
54 send "ftpm\n"
55 }
56
57 timeout {
58 exit_timeout
59 }
60}
61
62expect {
63 "#" { }
64
65 timeout {
66 exit_timeout
67 }
68}
69
70# Iterate over the rest of PCRs and check that they all are zeros.
71for {set i 1} {$i < 11} {incr i} {
72 send "pcrread -ha $i\n"
73
74 expect {
75 -re "(\\s00){16}\\s+(00\\s){16}" { }
76
77 -re $non_zero_pcr {
78 exit_uart -1
79 }
80
81 timeout {
82 exit_timeout
83 }
84 }
85}
86
87# Match the previously stored digest with the one generated by the
88# fTPM service. The pass criteria is that both digests must match,
89# meaning that TF-A successfully passed the event log to the TPM service.
90expect {
91 "#" {
92 spawn diff -s $TFA_DIGEST ftpm_event_log
93 }
94
95 timeout {
96 exit_timeout
97 }
98}
99
100expect {
101 -exact "are identical" {
102 exit_uart 0
103 }
104}
105
106exit_uart -1