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 { INVALID_ID, NULL, (unsigned int)(-1) } /* Terminator */
28 };
29
bl2_plat_mboot_init(void)30 void bl2_plat_mboot_init(void)
31 {
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);
59 }
60
bl2_plat_mboot_finish(void)61 void bl2_plat_mboot_finish(void)
62 {
63 int rc;
64
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
71 event_log_cur_size = event_log_get_cur_size((uint8_t *)event_log_base);
72
73 rc = arm_set_nt_fw_info(
74 #ifdef SPD_opteed
75 (uintptr_t)event_log_base,
76 #endif
77 event_log_cur_size, &ns_log_addr);
78 if (rc != 0) {
79 ERROR("%s(): Unable to update %s_FW_CONFIG\n",
80 __func__, "NT");
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
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.
87 */
88 panic();
89 }
90
91 /* Copy Event Log to Non-secure memory */
92 (void)memcpy((void *)ns_log_addr, (const void *)event_log_base,
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 */
100 rc = arm_set_tos_fw_info((uintptr_t)event_log_base,
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 }
107 #endif /* defined(SPD_tspd) || defined(SPD_spmd) */
108
109 dump_event_log((uint8_t *)event_log_base, event_log_cur_size);
110 }
111