blob: 5ebfedea0e6e2f89d60b28aaadf64212b4937301 [file] [log] [blame]
Alexei Fedorov61369a22020-07-13 14:59:02 +01001/*
Manish V Badarkhe7ca9d652021-09-14 22:41:46 +01002 * Copyright (c) 2021, Arm Limited. All rights reserved.
Alexei Fedorov61369a22020-07-13 14:59:02 +01003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
Manish V Badarkhe5797b802021-08-06 09:26:20 +01007#include <stdint.h>
8
Sandrine Bailleux3c2db6f2021-07-07 14:47:08 +02009#include <drivers/measured_boot/event_log/event_log.h>
Alexei Fedorov61369a22020-07-13 14:59:02 +010010#include <plat/arm/common/plat_arm.h>
Manish V Badarkhe7ca9d652021-09-14 22:41:46 +010011
12/* Event Log data */
Manish V Badarkhe4edf4bd2021-08-11 10:45:03 +010013static uint64_t event_log_base;
Alexei Fedorov61369a22020-07-13 14:59:02 +010014
15/* FVP table with platform specific image IDs, names and PCRs */
Manish V Badarkhe7ca9d652021-09-14 22:41:46 +010016const event_log_metadata_t fvp_event_log_metadata[] = {
Manish V Badarkhe72e03692021-09-08 20:04:24 +010017 { 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 Fedorov61369a22020-07-13 14:59:02 +010027 { INVALID_ID, NULL, (unsigned int)(-1) } /* Terminator */
28};
29
Manish V Badarkhe5797b802021-08-06 09:26:20 +010030void bl2_plat_mboot_init(void)
31{
Manish V Badarkhe4edf4bd2021-08-11 10:45:03 +010032 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 Badarkhe5797b802021-08-06 09:26:20 +010059}
60
61void bl2_plat_mboot_finish(void)
62{
Manish V Badarkhe5797b802021-08-06 09:26:20 +010063 int rc;
64
Manish V Badarkhe7ca9d652021-09-14 22:41:46 +010065 /* 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 Badarkhe4edf4bd2021-08-11 10:45:03 +010071 event_log_cur_size = event_log_get_cur_size((uint8_t *)event_log_base);
Manish V Badarkhe7ca9d652021-09-14 22:41:46 +010072
73 rc = arm_set_nt_fw_info(
74#ifdef SPD_opteed
Manish V Badarkhe4edf4bd2021-08-11 10:45:03 +010075 (uintptr_t)event_log_base,
Manish V Badarkhe7ca9d652021-09-14 22:41:46 +010076#endif
77 event_log_cur_size, &ns_log_addr);
Manish V Badarkhe5797b802021-08-06 09:26:20 +010078 if (rc != 0) {
Manish V Badarkhe7ca9d652021-09-14 22:41:46 +010079 ERROR("%s(): Unable to update %s_FW_CONFIG\n",
80 __func__, "NT");
Manish V Badarkhe5797b802021-08-06 09:26:20 +010081 /*
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 Badarkhe7ca9d652021-09-14 22:41:46 +010084 * 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 Badarkhe5797b802021-08-06 09:26:20 +010087 */
88 panic();
89 }
Manish V Badarkhe7ca9d652021-09-14 22:41:46 +010090
91 /* Copy Event Log to Non-secure memory */
Manish V Badarkhe4edf4bd2021-08-11 10:45:03 +010092 (void)memcpy((void *)ns_log_addr, (const void *)event_log_base,
Manish V Badarkhe7ca9d652021-09-14 22:41:46 +010093 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 Badarkhe4edf4bd2021-08-11 10:45:03 +0100100 rc = arm_set_tos_fw_info((uintptr_t)event_log_base,
Manish V Badarkhe7ca9d652021-09-14 22:41:46 +0100101 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 Badarkhe4edf4bd2021-08-11 10:45:03 +0100107#endif /* defined(SPD_tspd) || defined(SPD_spmd) */
Manish V Badarkhe5797b802021-08-06 09:26:20 +0100108
Manish V Badarkhe4edf4bd2021-08-11 10:45:03 +0100109 dump_event_log((uint8_t *)event_log_base, event_log_cur_size);
Manish V Badarkhe5797b802021-08-06 09:26:20 +0100110}