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