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