Alexei Fedorov | 61369a2 | 2020-07-13 14:59:02 +0100 | [diff] [blame] | 1 | /* |
Manish V Badarkhe | 7ca9d65 | 2021-09-14 22:41:46 +0100 | [diff] [blame] | 2 | * Copyright (c) 2021, Arm Limited. All rights reserved. |
Alexei Fedorov | 61369a2 | 2020-07-13 14:59:02 +0100 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
Manish V Badarkhe | 5797b80 | 2021-08-06 09:26:20 +0100 | [diff] [blame] | 7 | #include <stdint.h> |
| 8 | |
Sandrine Bailleux | 3c2db6f | 2021-07-07 14:47:08 +0200 | [diff] [blame] | 9 | #include <drivers/measured_boot/event_log/event_log.h> |
Alexei Fedorov | 61369a2 | 2020-07-13 14:59:02 +0100 | [diff] [blame] | 10 | #include <plat/arm/common/plat_arm.h> |
Manish V Badarkhe | 7ca9d65 | 2021-09-14 22:41:46 +0100 | [diff] [blame] | 11 | |
| 12 | /* Event Log data */ |
Manish V Badarkhe | 4edf4bd | 2021-08-11 10:45:03 +0100 | [diff] [blame] | 13 | static uint64_t event_log_base; |
Alexei Fedorov | 61369a2 | 2020-07-13 14:59:02 +0100 | [diff] [blame] | 14 | |
| 15 | /* FVP table with platform specific image IDs, names and PCRs */ |
Manish V Badarkhe | 7ca9d65 | 2021-09-14 22:41:46 +0100 | [diff] [blame] | 16 | const event_log_metadata_t fvp_event_log_metadata[] = { |
Manish V Badarkhe | 72e0369 | 2021-09-08 20:04:24 +0100 | [diff] [blame] | 17 | { BL31_IMAGE_ID, EVLOG_BL31_STRING, PCR_0 }, |
| 18 | { BL32_IMAGE_ID, EVLOG_BL32_STRING, PCR_0 }, |
| 19 | { BL32_EXTRA1_IMAGE_ID, EVLOG_BL32_EXTRA1_STRING, PCR_0 }, |
| 20 | { BL32_EXTRA2_IMAGE_ID, EVLOG_BL32_EXTRA2_STRING, PCR_0 }, |
| 21 | { BL33_IMAGE_ID, EVLOG_BL33_STRING, PCR_0 }, |
| 22 | { HW_CONFIG_ID, EVLOG_HW_CONFIG_STRING, PCR_0 }, |
| 23 | { NT_FW_CONFIG_ID, EVLOG_NT_FW_CONFIG_STRING, PCR_0 }, |
| 24 | { SCP_BL2_IMAGE_ID, EVLOG_SCP_BL2_STRING, PCR_0 }, |
| 25 | { SOC_FW_CONFIG_ID, EVLOG_SOC_FW_CONFIG_STRING, PCR_0 }, |
| 26 | { TOS_FW_CONFIG_ID, EVLOG_TOS_FW_CONFIG_STRING, PCR_0 }, |
Alexei Fedorov | 61369a2 | 2020-07-13 14:59:02 +0100 | [diff] [blame] | 27 | { INVALID_ID, NULL, (unsigned int)(-1) } /* Terminator */ |
| 28 | }; |
| 29 | |
Manish V Badarkhe | 5797b80 | 2021-08-06 09:26:20 +0100 | [diff] [blame] | 30 | void bl2_plat_mboot_init(void) |
| 31 | { |
Manish V Badarkhe | 4edf4bd | 2021-08-11 10:45:03 +0100 | [diff] [blame] | 32 | uint8_t *event_log_start; |
| 33 | uint8_t *event_log_finish; |
| 34 | size_t bl1_event_log_size; |
| 35 | int rc; |
| 36 | |
| 37 | rc = arm_get_tb_fw_info(&event_log_base, &bl1_event_log_size); |
| 38 | if (rc != 0) { |
| 39 | ERROR("%s(): Unable to get Event Log info from TB_FW_CONFIG\n", |
| 40 | __func__); |
| 41 | /* |
| 42 | * It is a fatal error because on FVP platform, BL2 software |
| 43 | * assumes that a valid Event Log buffer exist and it will use |
| 44 | * same Event Log buffer to append image measurements. |
| 45 | */ |
| 46 | panic(); |
| 47 | } |
| 48 | |
| 49 | /* |
| 50 | * BL1 and BL2 share the same Event Log buffer and that BL2 will |
| 51 | * append its measurements after BL1's |
| 52 | */ |
| 53 | event_log_start = (uint8_t *)((uintptr_t)event_log_base + |
| 54 | bl1_event_log_size); |
| 55 | event_log_finish = (uint8_t *)((uintptr_t)event_log_base + |
| 56 | PLAT_ARM_EVENT_LOG_MAX_SIZE); |
| 57 | |
| 58 | event_log_init((uint8_t *)event_log_start, event_log_finish); |
Manish V Badarkhe | 5797b80 | 2021-08-06 09:26:20 +0100 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | void bl2_plat_mboot_finish(void) |
| 62 | { |
Manish V Badarkhe | 5797b80 | 2021-08-06 09:26:20 +0100 | [diff] [blame] | 63 | int rc; |
| 64 | |
Manish V Badarkhe | 7ca9d65 | 2021-09-14 22:41:46 +0100 | [diff] [blame] | 65 | /* Event Log address in Non-Secure memory */ |
| 66 | uintptr_t ns_log_addr; |
| 67 | |
| 68 | /* Event Log filled size */ |
| 69 | size_t event_log_cur_size; |
| 70 | |
Manish V Badarkhe | 4edf4bd | 2021-08-11 10:45:03 +0100 | [diff] [blame] | 71 | event_log_cur_size = event_log_get_cur_size((uint8_t *)event_log_base); |
Manish V Badarkhe | 7ca9d65 | 2021-09-14 22:41:46 +0100 | [diff] [blame] | 72 | |
| 73 | rc = arm_set_nt_fw_info( |
| 74 | #ifdef SPD_opteed |
Manish V Badarkhe | 4edf4bd | 2021-08-11 10:45:03 +0100 | [diff] [blame] | 75 | (uintptr_t)event_log_base, |
Manish V Badarkhe | 7ca9d65 | 2021-09-14 22:41:46 +0100 | [diff] [blame] | 76 | #endif |
| 77 | event_log_cur_size, &ns_log_addr); |
Manish V Badarkhe | 5797b80 | 2021-08-06 09:26:20 +0100 | [diff] [blame] | 78 | if (rc != 0) { |
Manish V Badarkhe | 7ca9d65 | 2021-09-14 22:41:46 +0100 | [diff] [blame] | 79 | ERROR("%s(): Unable to update %s_FW_CONFIG\n", |
| 80 | __func__, "NT"); |
Manish V Badarkhe | 5797b80 | 2021-08-06 09:26:20 +0100 | [diff] [blame] | 81 | /* |
| 82 | * It is a fatal error because on FVP secure world software |
| 83 | * assumes that a valid event log exists and will use it to |
Manish V Badarkhe | 7ca9d65 | 2021-09-14 22:41:46 +0100 | [diff] [blame] | 84 | * record the measurements into the fTPM. |
| 85 | * Note: In FVP platform, OP-TEE uses nt_fw_config to get the |
| 86 | * secure Event Log buffer address. |
Manish V Badarkhe | 5797b80 | 2021-08-06 09:26:20 +0100 | [diff] [blame] | 87 | */ |
| 88 | panic(); |
| 89 | } |
Manish V Badarkhe | 7ca9d65 | 2021-09-14 22:41:46 +0100 | [diff] [blame] | 90 | |
| 91 | /* Copy Event Log to Non-secure memory */ |
Manish V Badarkhe | 4edf4bd | 2021-08-11 10:45:03 +0100 | [diff] [blame] | 92 | (void)memcpy((void *)ns_log_addr, (const void *)event_log_base, |
Manish V Badarkhe | 7ca9d65 | 2021-09-14 22:41:46 +0100 | [diff] [blame] | 93 | event_log_cur_size); |
| 94 | |
| 95 | /* Ensure that the Event Log is visible in Non-secure memory */ |
| 96 | flush_dcache_range(ns_log_addr, event_log_cur_size); |
| 97 | |
| 98 | #if defined(SPD_tspd) || defined(SPD_spmd) |
| 99 | /* Set Event Log data in TOS_FW_CONFIG */ |
Manish V Badarkhe | 4edf4bd | 2021-08-11 10:45:03 +0100 | [diff] [blame] | 100 | rc = arm_set_tos_fw_info((uintptr_t)event_log_base, |
Manish V Badarkhe | 7ca9d65 | 2021-09-14 22:41:46 +0100 | [diff] [blame] | 101 | event_log_cur_size); |
| 102 | if (rc != 0) { |
| 103 | ERROR("%s(): Unable to update %s_FW_CONFIG\n", |
| 104 | __func__, "TOS"); |
| 105 | panic(); |
| 106 | } |
Manish V Badarkhe | 4edf4bd | 2021-08-11 10:45:03 +0100 | [diff] [blame] | 107 | #endif /* defined(SPD_tspd) || defined(SPD_spmd) */ |
Manish V Badarkhe | 5797b80 | 2021-08-06 09:26:20 +0100 | [diff] [blame] | 108 | |
Manish V Badarkhe | 4edf4bd | 2021-08-11 10:45:03 +0100 | [diff] [blame] | 109 | dump_event_log((uint8_t *)event_log_base, event_log_cur_size); |
Manish V Badarkhe | 5797b80 | 2021-08-06 09:26:20 +0100 | [diff] [blame] | 110 | } |