Javier Almansa Sobrino | 98de503 | 2020-09-17 12:47:05 +0100 | [diff] [blame] | 1 | # |
Sandrine Bailleux | 0bcf413 | 2022-03-31 11:15:51 +0200 | [diff] [blame] | 2 | # Copyright (c) 2020-2022, Arm Limited. All rights reserved. |
Javier Almansa Sobrino | 98de503 | 2020-09-17 12:47:05 +0100 | [diff] [blame] | 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"] |
Javier Almansa Sobrino | 98de503 | 2020-09-17 12:47:05 +0100 | [diff] [blame] | 14 | |
| 15 | # regexp for non-zero PCR0 |
| 16 | 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] | 17 | set zero_pcr "(\\s00){16}\\s+(00\\s){16}" |
Javier Almansa Sobrino | 98de503 | 2020-09-17 12:47:05 +0100 | [diff] [blame] | 18 | |
| 19 | expect { |
Sandrine Bailleux | 0bcf413 | 2022-03-31 11:15:51 +0200 | [diff] [blame] | 20 | # Wait for the start of the event log dump. |
| 21 | "TCG_EfiSpecIDEvent:" { |
| 22 | set digest_log [open $TFA_DIGEST w] |
| 23 | } |
Sandrine Bailleux | 0bcf413 | 2022-03-31 11:15:51 +0200 | [diff] [blame] | 24 | } |
| 25 | |
| 26 | expect { |
Javier Almansa Sobrino | 98de503 | 2020-09-17 12:47:05 +0100 | [diff] [blame] | 27 | # Parse the event log from the debug logs and store the digests |
Sandrine Bailleux | 0bcf413 | 2022-03-31 11:15:51 +0200 | [diff] [blame] | 28 | # so they can be matched later with what the fTPM reads. |
Javier Almansa Sobrino | 98de503 | 2020-09-17 12:47:05 +0100 | [diff] [blame] | 29 | |
| 30 | -re "Digest(\\s|\\w)*:\\s(\\w{2}\\s){16}|\ |
| 31 | : (\\w{2}\\s){16}|\ |
| 32 | Event(\\s|\\w)*:\\s\\w+\\s" { |
| 33 | puts $digest_log $expect_out(0,string) |
| 34 | exp_continue |
| 35 | } |
| 36 | |
| 37 | -exact "Booting BL31" { |
| 38 | close $digest_log |
| 39 | } |
Javier Almansa Sobrino | 98de503 | 2020-09-17 12:47:05 +0100 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | expect { |
| 43 | "login" { |
| 44 | send "root\n" |
| 45 | } |
Javier Almansa Sobrino | 98de503 | 2020-09-17 12:47:05 +0100 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | expect { |
| 49 | "#" { |
| 50 | # Load the fTPM driver and retrieves PCR0 |
| 51 | send "ftpm\n" |
| 52 | } |
Javier Almansa Sobrino | 98de503 | 2020-09-17 12:47:05 +0100 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | expect { |
| 56 | # Pass condition: PCR0 must not be all zeros. |
| 57 | |
| 58 | -re $non_zero_pcr { |
| 59 | exp_continue |
| 60 | } |
| 61 | |
Manish V Badarkhe | fc146c4 | 2021-11-24 15:34:00 +0000 | [diff] [blame] | 62 | "#" { |
| 63 | # get PCR1 value |
| 64 | send "pcrread -ha 1\n" |
| 65 | } |
Manish V Badarkhe | fc146c4 | 2021-11-24 15:34:00 +0000 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | expect { |
| 69 | # Pass condition: PCR1 must not be all zeros. |
| 70 | |
| 71 | -re $non_zero_pcr { |
| 72 | exp_continue |
| 73 | } |
| 74 | |
Javier Almansa Sobrino | 98de503 | 2020-09-17 12:47:05 +0100 | [diff] [blame] | 75 | "#" { } |
Javier Almansa Sobrino | 98de503 | 2020-09-17 12:47:05 +0100 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | # 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] | 79 | for {set i 2} {$i < 11} {incr i} { |
Javier Almansa Sobrino | 98de503 | 2020-09-17 12:47:05 +0100 | [diff] [blame] | 80 | send "pcrread -ha $i\n" |
| 81 | |
| 82 | expect { |
Manish V Badarkhe | fc146c4 | 2021-11-24 15:34:00 +0000 | [diff] [blame] | 83 | -re $zero_pcr { } |
Javier Almansa Sobrino | 98de503 | 2020-09-17 12:47:05 +0100 | [diff] [blame] | 84 | |
| 85 | -re $non_zero_pcr { |
| 86 | exit_uart -1 |
| 87 | } |
Javier Almansa Sobrino | 98de503 | 2020-09-17 12:47:05 +0100 | [diff] [blame] | 88 | } |
| 89 | } |
| 90 | |
Chris Kay | 07756bc | 2022-11-24 17:21:48 +0000 | [diff] [blame] | 91 | expect_string "#" "finished reading PCRs" |
| 92 | |
Javier Almansa Sobrino | 98de503 | 2020-09-17 12:47:05 +0100 | [diff] [blame] | 93 | # Match the previously stored digest with the one generated by the |
| 94 | # fTPM service. The pass criteria is that both digests must match, |
| 95 | # 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] | 96 | if {[catch {exec diff -s $TFA_DIGEST ftpm_event_log} result options] == 0} { |
| 97 | message "tests succeeded, digests matched" |
| 98 | } else { |
| 99 | message "tests failed, digests did not match" |
| 100 | exit_uart -1 |
Javier Almansa Sobrino | 98de503 | 2020-09-17 12:47:05 +0100 | [diff] [blame] | 101 | } |