1 /*
2 * Copyright (c) 2021-2025, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7 #include <stdint.h>
8
9 #if TRANSFER_LIST
10 #include <tpm_event_log.h>
11 #endif
12 #include <plat/arm/common/plat_arm.h>
13
14 #include <drivers/auth/crypto_mod.h>
15 #include <drivers/measured_boot/metadata.h>
16 #include <event_measure.h>
17 #include <event_print.h>
18 #include <tools_share/zero_oid.h>
19
20 /* Event Log data */
21 #if TRANSFER_LIST
22 static uint8_t *event_log;
23 #else
24 static uint8_t event_log[PLAT_ARM_EVENT_LOG_MAX_SIZE];
25 #endif
26
27 static const struct event_log_hash_info crypto_hash_info = {
28 .func = crypto_mod_calc_hash,
29 .ids = (const uint32_t[]){ CRYPTO_MD_ID },
30 .count = 1U,
31 };
32
33 /* FVP table with platform specific image IDs, names and PCRs */
34 const event_log_metadata_t fvp_event_log_metadata[] = {
35 { FW_CONFIG_ID, MBOOT_FW_CONFIG_STRING, PCR_0 },
36 { TB_FW_CONFIG_ID, MBOOT_TB_FW_CONFIG_STRING, PCR_0 },
37 { BL2_IMAGE_ID, MBOOT_BL2_IMAGE_STRING, PCR_0 },
38
39 { EVLOG_INVALID_ID, NULL, (unsigned int)(-1) } /* Terminator */
40 };
41
bl1_plat_mboot_init(void)42 void bl1_plat_mboot_init(void)
43 {
44 size_t event_log_max_size;
45 int rc;
46
47 #if TRANSFER_LIST
48 event_log_max_size = PLAT_ARM_EVENT_LOG_MAX_SIZE;
49
50 event_log =
51 transfer_list_event_log_extend(secure_tl, event_log_max_size);
52 assert(event_log != NULL);
53 #else
54 event_log_max_size = sizeof(event_log);
55 #endif
56
57 rc = event_log_init_and_reg(event_log, event_log + event_log_max_size,
58 &crypto_hash_info);
59 if (rc < 0) {
60 ERROR("Failed to initialize event log (%d).\n", rc);
61 panic();
62 }
63
64 rc = event_log_write_header();
65 if (rc < 0) {
66 ERROR("Failed to write event log header (%d).\n", rc);
67 panic();
68 }
69 }
70
bl1_plat_mboot_finish(void)71 void bl1_plat_mboot_finish(void)
72 {
73 size_t event_log_cur_size = event_log_get_cur_size(event_log);
74
75 #if TRANSFER_LIST
76 uint8_t *rc = transfer_list_event_log_finish(
77 secure_tl, (uintptr_t)event_log + event_log_cur_size);
78
79 /* Ensure changes are visible to the next stage. */
80 flush_dcache_range((uintptr_t)secure_tl, secure_tl->size);
81
82 if (rc != NULL) {
83 return;
84 }
85 #else
86 int rc = arm_set_tb_fw_info((uintptr_t)event_log, event_log_cur_size,
87 PLAT_ARM_EVENT_LOG_MAX_SIZE);
88 if (rc == 0) {
89 return;
90 }
91 #endif
92
93 /*
94 * Panic if we fail to set up the event log for the next stage. This is a fatal
95 * error because, on the FVP platform, BL2 software assumes that a valid
96 * Event Log buffer exists and will use the same Event Log buffer to append image
97 * measurements.
98 */
99 panic();
100 }
101