1 /*
2 * Copyright (c) 2025, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7 #include <stdint.h>
8
9 #include <common/tbbr/tbbr_img_def.h>
10 #if TRANSFER_LIST
11 #include <tpm_event_log.h>
12 #endif
13 #include <plat/arm/common/plat_arm.h>
14 #include <plat/common/common_def.h>
15
16 #include <drivers/auth/crypto_mod.h>
17 #include <drivers/measured_boot/metadata.h>
18 #include <event_measure.h>
19 #include <event_print.h>
20 #if defined(ARM_COT_cca)
21 #include <tools_share/cca_oid.h>
22 #else
23 #include <tools_share/tbbr_oid.h>
24 #endif /* ARM_COT_cca */
25
26 /* Event Log data */
27 static uint8_t *event_log_base;
28
29 /* table with platform specific image IDs, names and PCRs */
30 const event_log_metadata_t juno_event_log_metadata[] = {
31 { BL31_IMAGE_ID, MBOOT_BL31_IMAGE_STRING, PCR_0 },
32 { BL32_IMAGE_ID, MBOOT_BL32_IMAGE_STRING, PCR_0 },
33 { BL32_EXTRA1_IMAGE_ID, MBOOT_BL32_EXTRA1_IMAGE_STRING, PCR_0 },
34 { BL32_EXTRA2_IMAGE_ID, MBOOT_BL32_EXTRA2_IMAGE_STRING, PCR_0 },
35 { BL33_IMAGE_ID, MBOOT_BL33_IMAGE_STRING, PCR_0 },
36 { HW_CONFIG_ID, MBOOT_HW_CONFIG_STRING, PCR_0 },
37 { NT_FW_CONFIG_ID, MBOOT_NT_FW_CONFIG_STRING, PCR_0 },
38 { SCP_BL2_IMAGE_ID, MBOOT_SCP_BL2_IMAGE_STRING, PCR_0 },
39 { SOC_FW_CONFIG_ID, MBOOT_SOC_FW_CONFIG_STRING, PCR_0 },
40 { TOS_FW_CONFIG_ID, MBOOT_TOS_FW_CONFIG_STRING, PCR_0 },
41 { EVLOG_INVALID_ID, NULL, (unsigned int)(-1) } /* Terminator */
42 };
43
bl2_plat_mboot_init(void)44 void bl2_plat_mboot_init(void)
45 {
46 #if TRANSFER_LIST
47 uint8_t *event_log_start;
48 uint8_t *event_log_finish;
49 size_t bl1_event_log_size;
50 struct transfer_list_entry *te;
51 int rc;
52
53 event_log_start = transfer_list_event_log_extend(
54 secure_tl, PLAT_ARM_EVENT_LOG_MAX_SIZE);
55
56 /*
57 * Retrieve the extend event log entry from the transfer list, the API above
58 * returns a cursor position rather than the base address - we need both to
59 * init the library.
60 */
61 te = transfer_list_find(secure_tl, TL_TAG_TPM_EVLOG);
62
63 event_log_base =
64 transfer_list_entry_data(te) + EVENT_LOG_RESERVED_BYTES;
65 event_log_finish = transfer_list_entry_data(te) + te->data_size;
66
67 bl1_event_log_size = event_log_start - event_log_base;
68
69 rc = event_log_init_and_reg((uint8_t *)event_log_base, event_log_finish,
70 bl1_event_log_size, crypto_mod_tcg_hash);
71 if (rc < 0) {
72 ERROR("Failed to initialize event log (%d).\n", rc);
73 panic();
74 }
75 #endif
76 }
77
plat_mboot_measure_critical_data(unsigned int critical_data_id,const void * base,size_t size)78 int plat_mboot_measure_critical_data(unsigned int critical_data_id,
79 const void *base, size_t size)
80 {
81 /* Nothing */
82 return 0;
83 }
84
bl2_plat_mboot_finish(void)85 void bl2_plat_mboot_finish(void)
86 {
87 #if TRANSFER_LIST
88 /* Event Log filled size */
89 size_t event_log_cur_size;
90
91 event_log_cur_size = event_log_get_cur_size((uint8_t *)event_log_base);
92
93 /*
94 * Re-size the event log for the next stage and update the size to include
95 * the entire event log (i.e., not just what this stage has added.)
96 */
97 event_log_base = transfer_list_event_log_finish(
98 secure_tl, (uintptr_t)event_log_base + event_log_cur_size);
99 if (event_log_base == NULL) {
100 panic();
101 }
102
103 event_log_cur_size = event_log_get_cur_size((uint8_t *)event_log_base);
104 event_log_dump(event_log_base, event_log_cur_size);
105 #endif /* TRANSFER_LIST */
106 }
107