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 uint8_t event_log[PLAT_ARM_EVENT_LOG_MAX_SIZE]; 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, BL31_STRING, PCR_0 }, 18 { BL32_IMAGE_ID, BL32_STRING, PCR_0 }, 19 { BL32_EXTRA1_IMAGE_ID, BL32_EXTRA1_IMAGE_STRING, PCR_0 }, 20 { BL32_EXTRA2_IMAGE_ID, BL32_EXTRA2_IMAGE_STRING, PCR_0 }, 21 { BL33_IMAGE_ID, BL33_STRING, PCR_0 }, 22 { HW_CONFIG_ID, HW_CONFIG_STRING, PCR_0 }, 23 { NT_FW_CONFIG_ID, NT_FW_CONFIG_STRING, PCR_0 }, 24 { SCP_BL2_IMAGE_ID, SCP_BL2_IMAGE_STRING, PCR_0 }, 25 { SOC_FW_CONFIG_ID, SOC_FW_CONFIG_STRING, PCR_0 }, 26 { TOS_FW_CONFIG_ID, TOS_FW_CONFIG_STRING, PCR_0 }, 27 { INVALID_ID, NULL, (unsigned int)(-1) } /* Terminator */ 28 }; 29 30 void bl2_plat_mboot_init(void) 31 { 32 event_log_init(event_log, event_log + sizeof(event_log)); 33 event_log_write_header(); 34 } 35 36 void bl2_plat_mboot_finish(void) 37 { 38 int rc; 39 40 /* Event Log address in Non-Secure memory */ 41 uintptr_t ns_log_addr; 42 43 /* Event Log filled size */ 44 size_t event_log_cur_size; 45 46 event_log_cur_size = event_log_get_cur_size(event_log); 47 48 rc = arm_set_nt_fw_info( 49 #ifdef SPD_opteed 50 (uintptr_t)event_log, 51 #endif 52 event_log_cur_size, &ns_log_addr); 53 if (rc != 0) { 54 ERROR("%s(): Unable to update %s_FW_CONFIG\n", 55 __func__, "NT"); 56 /* 57 * It is a fatal error because on FVP secure world software 58 * assumes that a valid event log exists and will use it to 59 * record the measurements into the fTPM. 60 * Note: In FVP platform, OP-TEE uses nt_fw_config to get the 61 * secure Event Log buffer address. 62 */ 63 panic(); 64 } 65 66 /* Copy Event Log to Non-secure memory */ 67 (void)memcpy((void *)ns_log_addr, (const void *)event_log, 68 event_log_cur_size); 69 70 /* Ensure that the Event Log is visible in Non-secure memory */ 71 flush_dcache_range(ns_log_addr, event_log_cur_size); 72 73 #if defined(SPD_tspd) || defined(SPD_spmd) 74 /* Set Event Log data in TOS_FW_CONFIG */ 75 rc = arm_set_tos_fw_info((uintptr_t)event_log, 76 event_log_cur_size); 77 if (rc != 0) { 78 ERROR("%s(): Unable to update %s_FW_CONFIG\n", 79 __func__, "TOS"); 80 panic(); 81 } 82 #endif 83 84 dump_event_log(event_log, event_log_cur_size); 85 } 86