xref: /rk3399_ARM-atf/plat/arm/board/juno/juno_bl2_measured_boot.c (revision a202529e8ed33bacd10069f4f7df081970f0c752)
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 static const struct event_log_hash_info crypto_hash_info = {
30 	.func = crypto_mod_calc_hash,
31 	.ids = (const uint32_t[]){ CRYPTO_MD_ID },
32 	.count = 1U,
33 };
34 
35 /* table with platform specific image IDs, names and PCRs */
36 const event_log_metadata_t juno_event_log_metadata[] = {
37 	{ BL31_IMAGE_ID, MBOOT_BL31_IMAGE_STRING, PCR_0 },
38 	{ BL32_IMAGE_ID, MBOOT_BL32_IMAGE_STRING, PCR_0 },
39 	{ BL32_EXTRA1_IMAGE_ID, MBOOT_BL32_EXTRA1_IMAGE_STRING, PCR_0 },
40 	{ BL32_EXTRA2_IMAGE_ID, MBOOT_BL32_EXTRA2_IMAGE_STRING, PCR_0 },
41 	{ BL33_IMAGE_ID, MBOOT_BL33_IMAGE_STRING, PCR_0 },
42 	{ HW_CONFIG_ID, MBOOT_HW_CONFIG_STRING, PCR_0 },
43 	{ NT_FW_CONFIG_ID, MBOOT_NT_FW_CONFIG_STRING, PCR_0 },
44 	{ SCP_BL2_IMAGE_ID, MBOOT_SCP_BL2_IMAGE_STRING, PCR_0 },
45 	{ SOC_FW_CONFIG_ID, MBOOT_SOC_FW_CONFIG_STRING, PCR_0 },
46 	{ TOS_FW_CONFIG_ID, MBOOT_TOS_FW_CONFIG_STRING, PCR_0 },
47 	{ EVLOG_INVALID_ID, NULL, (unsigned int)(-1) }	/* Terminator */
48 };
49 
50 void bl2_plat_mboot_init(void)
51 {
52 #if TRANSFER_LIST
53 	uint8_t *event_log_start;
54 	uint8_t *event_log_finish;
55 	int rc;
56 
57 	event_log_start = transfer_list_event_log_extend(
58 		secure_tl, PLAT_ARM_EVENT_LOG_MAX_SIZE);
59 
60 	event_log_base = event_log_start;
61 	event_log_finish = event_log_start + PLAT_ARM_EVENT_LOG_MAX_SIZE;
62 
63 	rc = event_log_init_and_reg(event_log_start, event_log_finish,
64 				    &crypto_hash_info);
65 	if (rc < 0) {
66 		ERROR("Failed to initialize event log (%d).\n", rc);
67 		panic();
68 	}
69 #endif
70 }
71 
72 int plat_mboot_measure_critical_data(unsigned int critical_data_id,
73 				     const void *base, size_t size)
74 {
75 	/* Nothing */
76 	return 0;
77 }
78 
79 void bl2_plat_mboot_finish(void)
80 {
81 #if TRANSFER_LIST
82 	/* Event Log filled size */
83 	size_t event_log_cur_size;
84 
85 	event_log_cur_size = event_log_get_cur_size((uint8_t *)event_log_base);
86 
87 	/*
88 	 * Re-size the event log for the next stage and update the size to include
89 	 * the entire event log (i.e., not just what this stage has added.)
90 	 */
91 	event_log_base = transfer_list_event_log_finish(
92 		secure_tl, (uintptr_t)event_log_base + event_log_cur_size);
93 	if (event_log_base == NULL) {
94 		panic();
95 	}
96 
97 	event_log_cur_size = event_log_get_cur_size((uint8_t *)event_log_base);
98 	event_log_dump(event_log_base, event_log_cur_size);
99 #endif /* TRANSFER_LIST */
100 }
101