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 | } |
Sandrine Bailleux | 0bcf413 | 2022-03-31 11:15:51 +0200 | [diff] [blame] | 25 | } |
| 26 | |
| 27 | expect { |
Manish V Badarkhe | b87f37b | 2021-11-10 18:53:05 +0000 | [diff] [blame] | 28 | # Parse the event log from the debug logs and store the digests |
Sandrine Bailleux | 0bcf413 | 2022-03-31 11:15:51 +0200 | [diff] [blame] | 29 | # so they can be matched later with what the fTPM reads. |
Manish V Badarkhe | b87f37b | 2021-11-10 18:53:05 +0000 | [diff] [blame] | 30 | |
| 31 | -re "Digest(\\s|\\w)*:\\s(\\w{2}\\s){16}|\ |
| 32 | : (\\w{2}\\s){16}|\ |
| 33 | Event(\\s|\\w)*:\\s\\w+\\s" { |
| 34 | puts $digest_log $expect_out(0,string) |
| 35 | exp_continue |
| 36 | } |
| 37 | |
| 38 | -exact "Booting BL31" { |
| 39 | close $digest_log |
| 40 | } |
Manish V Badarkhe | b87f37b | 2021-11-10 18:53:05 +0000 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | expect { |
| 44 | "login" { |
| 45 | send "root\n" |
| 46 | } |
Manish V Badarkhe | b87f37b | 2021-11-10 18:53:05 +0000 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | expect { |
| 50 | "#" { |
| 51 | # Load the fTPM driver |
| 52 | send "ftpm\n" |
| 53 | } |
Manish V Badarkhe | b87f37b | 2021-11-10 18:53:05 +0000 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | expect { |
| 57 | "#" { } |
Manish V Badarkhe | b87f37b | 2021-11-10 18:53:05 +0000 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | # Iterate over the rest of PCRs and check that they all are zeros. |
| 61 | for {set i 1} {$i < 11} {incr i} { |
| 62 | send "pcrread -ha $i\n" |
| 63 | |
| 64 | expect { |
| 65 | -re "(\\s00){16}\\s+(00\\s){16}" { } |
| 66 | |
| 67 | -re $non_zero_pcr { |
| 68 | exit_uart -1 |
| 69 | } |
Manish V Badarkhe | b87f37b | 2021-11-10 18:53:05 +0000 | [diff] [blame] | 70 | } |
| 71 | } |
| 72 | |
Chris Kay | 07756bc | 2022-11-24 17:21:48 +0000 | [diff] [blame] | 73 | expect_string "#" "finished reading PCRs" |
| 74 | |
Manish V Badarkhe | b87f37b | 2021-11-10 18:53:05 +0000 | [diff] [blame] | 75 | # Match the previously stored digest with the one generated by the |
| 76 | # fTPM service. The pass criteria is that both digests must match, |
| 77 | # meaning that TF-A successfully passed the event log to the TPM service. |
Chris Kay | 07756bc | 2022-11-24 17:21:48 +0000 | [diff] [blame] | 78 | if {[catch {exec diff -s $TFA_DIGEST ftpm_event_log} result options] == 0} { |
| 79 | message "tests succeeded, digests matched" |
| 80 | } else { |
| 81 | message "tests failed, digests did not match" |
| 82 | exit_uart -1 |
Manish V Badarkhe | b87f37b | 2021-11-10 18:53:05 +0000 | [diff] [blame] | 83 | } |