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 /* FVP table with platform specific image IDs, names and PCRs */
28 const event_log_metadata_t fvp_event_log_metadata[] = {
29 { FW_CONFIG_ID, MBOOT_FW_CONFIG_STRING, PCR_0 },
30 { TB_FW_CONFIG_ID, MBOOT_TB_FW_CONFIG_STRING, PCR_0 },
31 { BL2_IMAGE_ID, MBOOT_BL2_IMAGE_STRING, PCR_0 },
32
33 { EVLOG_INVALID_ID, NULL, (unsigned int)(-1) } /* Terminator */
34 };
35
bl1_plat_mboot_init(void)36 void bl1_plat_mboot_init(void)
37 {
38 size_t event_log_max_size;
39 int rc;
40 tpm_alg_id algos[] = {
41 #ifdef TPM_ALG_ID
42 TPM_ALG_ID,
43 #else
44 /*
45 * TODO: with MEASURED_BOOT=1 several algorithms are now compiled into
46 * Mbed-TLS, we ought to query the backend to figure out what algorithms
47 * to use.
48 */
49 TPM_ALG_SHA256,
50 TPM_ALG_SHA384,
51 TPM_ALG_SHA512,
52 #endif
53 };
54
55 #if TRANSFER_LIST
56 event_log_max_size = PLAT_ARM_EVENT_LOG_MAX_SIZE;
57
58 event_log =
59 transfer_list_event_log_extend(secure_tl, event_log_max_size);
60 assert(event_log != NULL);
61 #else
62 event_log_max_size = sizeof(event_log);
63 #endif
64
65 rc = event_log_init_and_reg(event_log, event_log + event_log_max_size,
66 0U, crypto_mod_tcg_hash);
67 if (rc < 0) {
68 ERROR("Failed to initialize event log (%d).\n", rc);
69 panic();
70 }
71
72 rc = event_log_write_header(algos, ARRAY_SIZE(algos), 0, NULL, 0);
73 if (rc < 0) {
74 ERROR("Failed to write event log header (%d).\n", rc);
75 panic();
76 }
77 }
78
bl1_plat_mboot_finish(void)79 void bl1_plat_mboot_finish(void)
80 {
81 size_t event_log_cur_size = event_log_get_cur_size(event_log);
82
83 #if TRANSFER_LIST
84 uint8_t *rc = transfer_list_event_log_finish(
85 secure_tl, (uintptr_t)event_log + event_log_cur_size);
86
87 /* Ensure changes are visible to the next stage. */
88 flush_dcache_range((uintptr_t)secure_tl, secure_tl->size);
89
90 if (rc != NULL) {
91 return;
92 }
93 #else
94 int rc = arm_set_tb_fw_info((uintptr_t)event_log, event_log_cur_size,
95 PLAT_ARM_EVENT_LOG_MAX_SIZE);
96 if (rc == 0) {
97 return;
98 }
99 #endif
100
101 /*
102 * Panic if we fail to set up the event log for the next stage. This is a fatal
103 * error because, on the FVP platform, BL2 software assumes that a valid
104 * Event Log buffer exists and will use the same Event Log buffer to append image
105 * measurements.
106 */
107 panic();
108 }
109