Javier Almansa Sobrino | 98de503 | 2020-09-17 12:47:05 +0100 | [diff] [blame] | 1 | # |
| 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 | |
| 9 | source [file join [file dirname [info script]] utils.inc] |
| 10 | source [file join [file dirname [info script]] handle-arguments.inc] |
| 11 | |
| 12 | # File to store the event log from the ftpm service. |
| 13 | set TFA_DIGEST [get_param tfa_digest "tfa_event_log"] |
| 14 | set digest_log [open $TFA_DIGEST w] |
| 15 | |
| 16 | # regexp for non-zero PCR0 |
| 17 | set non_zero_pcr "(?!(\\s00){16})((\\s(\[0-9a-f\]){2}){16}\\s)" |
Manish V Badarkhe | fc146c4 | 2021-11-24 15:34:00 +0000 | [diff] [blame] | 18 | set zero_pcr "(\\s00){16}\\s+(00\\s){16}" |
Javier Almansa Sobrino | 98de503 | 2020-09-17 12:47:05 +0100 | [diff] [blame] | 19 | |
| 20 | expect { |
| 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 | |
| 40 | expect { |
| 41 | "login" { |
| 42 | send "root\n" |
| 43 | } |
| 44 | |
| 45 | timeout { |
| 46 | exit_timeout |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | expect { |
| 51 | "#" { |
| 52 | # Load the fTPM driver and retrieves PCR0 |
| 53 | send "ftpm\n" |
| 54 | } |
| 55 | |
| 56 | timeout { |
| 57 | exit_timeout |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | expect { |
| 62 | # Pass condition: PCR0 must not be all zeros. |
| 63 | |
| 64 | -re $non_zero_pcr { |
| 65 | exp_continue |
| 66 | } |
| 67 | |
Manish V Badarkhe | fc146c4 | 2021-11-24 15:34:00 +0000 | [diff] [blame] | 68 | "#" { |
| 69 | # get PCR1 value |
| 70 | send "pcrread -ha 1\n" |
| 71 | } |
| 72 | |
| 73 | timeout { |
| 74 | exit_timeout |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | expect { |
| 79 | # Pass condition: PCR1 must not be all zeros. |
| 80 | |
| 81 | -re $non_zero_pcr { |
| 82 | exp_continue |
| 83 | } |
| 84 | |
Javier Almansa Sobrino | 98de503 | 2020-09-17 12:47:05 +0100 | [diff] [blame] | 85 | "#" { } |
| 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 Badarkhe | fc146c4 | 2021-11-24 15:34:00 +0000 | [diff] [blame] | 93 | for {set i 2} {$i < 11} {incr i} { |
Javier Almansa Sobrino | 98de503 | 2020-09-17 12:47:05 +0100 | [diff] [blame] | 94 | send "pcrread -ha $i\n" |
| 95 | |
| 96 | expect { |
Manish V Badarkhe | fc146c4 | 2021-11-24 15:34:00 +0000 | [diff] [blame] | 97 | -re $zero_pcr { } |
Javier Almansa Sobrino | 98de503 | 2020-09-17 12:47:05 +0100 | [diff] [blame] | 98 | |
| 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. |
| 112 | expect { |
| 113 | "#" { |
| 114 | spawn diff -s $TFA_DIGEST ftpm_event_log |
| 115 | } |
| 116 | |
| 117 | timeout { |
| 118 | exit_timeout |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | expect { |
| 123 | -exact "are identical" { |
| 124 | exit_uart 0 |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | exit_uart -1 |