xref: /rk3399_ARM-atf/plat/arm/board/fvp/fvp_bl1_measured_boot.c (revision 06f3c7058c42a9f1a9f7df75ea2de71a000855e8)
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 #include <drivers/measured_boot/event_log/event_log.h>
10 #include <drivers/measured_boot/metadata.h>
11 #include <tools_share/zero_oid.h>
12 
13 #include <plat/arm/common/plat_arm.h>
14 
15 /* Event Log data */
16 #if TRANSFER_LIST
17 static uint8_t *event_log;
18 #else
19 static uint8_t event_log[PLAT_ARM_EVENT_LOG_MAX_SIZE];
20 #endif
21 
22 /* FVP table with platform specific image IDs, names and PCRs */
23 const event_log_metadata_t fvp_event_log_metadata[] = {
24 	{ FW_CONFIG_ID, MBOOT_FW_CONFIG_STRING, PCR_0 },
25 	{ TB_FW_CONFIG_ID, MBOOT_TB_FW_CONFIG_STRING, PCR_0 },
26 	{ BL2_IMAGE_ID, MBOOT_BL2_IMAGE_STRING, PCR_0 },
27 
28 	{ EVLOG_INVALID_ID, NULL, (unsigned int)(-1) } /* Terminator */
29 };
30 
31 void bl1_plat_mboot_init(void)
32 {
33 	size_t event_log_max_size;
34 	int rc;
35 
36 #if TRANSFER_LIST
37 	event_log = transfer_list_event_log_extend(
38 		secure_tl, PLAT_ARM_EVENT_LOG_MAX_SIZE,
39 		&event_log_max_size);
40 	assert(event_log != NULL);
41 #else
42 	event_log_max_size = sizeof(event_log);
43 #endif
44 
45 	rc = event_log_init(event_log, event_log + event_log_max_size);
46 	if (rc < 0) {
47 		ERROR("Failed to initialize event log (%d).\n", rc);
48 		panic();
49 	}
50 
51 	rc = event_log_write_header();
52 	if (rc < 0) {
53 		ERROR("Failed to write event log header (%d).\n", rc);
54 		panic();
55 	}
56 }
57 
58 void bl1_plat_mboot_finish(void)
59 {
60 	size_t event_log_cur_size = event_log_get_cur_size(event_log);
61 
62 #if TRANSFER_LIST
63 	uint8_t *rc = transfer_list_event_log_finish(
64 		secure_tl, (uintptr_t)event_log + event_log_cur_size);
65 
66 	if (rc != NULL) {
67 		return;
68 	}
69 #else
70 	int rc = arm_set_tb_fw_info((uintptr_t)event_log, event_log_cur_size,
71 				PLAT_ARM_EVENT_LOG_MAX_SIZE);
72 	if (rc == 0) {
73 		return;
74 	}
75 #endif
76 
77 	/*
78 	 * Panic if we fail to set up the event log for the next stage. This is a fatal
79 	 * error because, on the FVP platform, BL2 software assumes that a valid
80 	 * Event Log buffer exists and will use the same Event Log buffer to append image
81 	 * measurements.
82 	 */
83 	panic();
84 }
85