xref: /rk3399_ARM-atf/plat/arm/board/juno/juno_bl1_measured_boot.c (revision b73aa414e4ab919c3a57373235072f3401364d80)
11c199c54SYeoreum Yun /*
21c199c54SYeoreum Yun  * Copyright (c) 2025, Arm Limited. All rights reserved.
31c199c54SYeoreum Yun  *
41c199c54SYeoreum Yun  * SPDX-License-Identifier: BSD-3-Clause
51c199c54SYeoreum Yun  */
61c199c54SYeoreum Yun 
71c199c54SYeoreum Yun #include <stdint.h>
81c199c54SYeoreum Yun 
9*b67e9846SHarrison Mutai #if TRANSFER_LIST
10*b67e9846SHarrison Mutai #include <tpm_event_log.h>
11*b67e9846SHarrison Mutai #endif
121c199c54SYeoreum Yun #include <plat/arm/common/plat_arm.h>
13*b67e9846SHarrison Mutai 
14*b67e9846SHarrison Mutai #include <drivers/auth/crypto_mod.h>
15*b67e9846SHarrison Mutai #include <drivers/measured_boot/metadata.h>
16*b67e9846SHarrison Mutai #include <event_measure.h>
17*b67e9846SHarrison Mutai #include <event_print.h>
181c199c54SYeoreum Yun #include <tools_share/zero_oid.h>
191c199c54SYeoreum Yun 
20*b67e9846SHarrison Mutai static const struct event_log_hash_info crypto_hash_info = {
21*b67e9846SHarrison Mutai 	.func = crypto_mod_calc_hash,
22*b67e9846SHarrison Mutai 	.ids = (const uint32_t[]){ CRYPTO_MD_ID },
23*b67e9846SHarrison Mutai 	.count = 1U,
24*b67e9846SHarrison Mutai };
25*b67e9846SHarrison Mutai 
261c199c54SYeoreum Yun /* Event Log data */
271c199c54SYeoreum Yun static uint8_t *event_log;
281c199c54SYeoreum Yun 
291c199c54SYeoreum Yun /* Juno table with platform specific image IDs, names and PCRs */
301c199c54SYeoreum Yun const event_log_metadata_t juno_event_log_metadata[] = {
311c199c54SYeoreum Yun 	{ FW_CONFIG_ID, MBOOT_FW_CONFIG_STRING, PCR_0 },
321c199c54SYeoreum Yun 	{ TB_FW_CONFIG_ID, MBOOT_TB_FW_CONFIG_STRING, PCR_0 },
331c199c54SYeoreum Yun 	{ BL2_IMAGE_ID, MBOOT_BL2_IMAGE_STRING, PCR_0 },
341c199c54SYeoreum Yun 	{ EVLOG_INVALID_ID, NULL, (unsigned int)(-1) } /* Terminator */
351c199c54SYeoreum Yun };
361c199c54SYeoreum Yun 
bl1_plat_mboot_init(void)371c199c54SYeoreum Yun void bl1_plat_mboot_init(void)
381c199c54SYeoreum Yun {
391c199c54SYeoreum Yun #if TRANSFER_LIST
40*b67e9846SHarrison Mutai 	size_t event_log_max_size = PLAT_ARM_EVENT_LOG_MAX_SIZE;
411c199c54SYeoreum Yun 	int rc;
421c199c54SYeoreum Yun 
43*b67e9846SHarrison Mutai 	event_log =
44*b67e9846SHarrison Mutai 		transfer_list_event_log_extend(secure_tl, event_log_max_size);
451c199c54SYeoreum Yun 	assert(event_log != NULL);
461c199c54SYeoreum Yun 
47*b67e9846SHarrison Mutai 	rc = event_log_init_and_reg(event_log, event_log + event_log_max_size,
48*b67e9846SHarrison Mutai 				    &crypto_hash_info);
491c199c54SYeoreum Yun 	if (rc < 0) {
501c199c54SYeoreum Yun 		ERROR("Failed to initialize event log (%d).\n", rc);
511c199c54SYeoreum Yun 		panic();
521c199c54SYeoreum Yun 	}
531c199c54SYeoreum Yun 
541c199c54SYeoreum Yun 	rc = event_log_write_header();
551c199c54SYeoreum Yun 	if (rc < 0) {
561c199c54SYeoreum Yun 		ERROR("Failed to write event log header (%d).\n", rc);
571c199c54SYeoreum Yun 		panic();
581c199c54SYeoreum Yun 	}
591c199c54SYeoreum Yun #endif
601c199c54SYeoreum Yun }
611c199c54SYeoreum Yun 
bl1_plat_mboot_finish(void)621c199c54SYeoreum Yun void bl1_plat_mboot_finish(void)
631c199c54SYeoreum Yun {
641c199c54SYeoreum Yun #if TRANSFER_LIST
651c199c54SYeoreum Yun 	uint8_t *rc __unused;
661c199c54SYeoreum Yun 	size_t event_log_cur_size = event_log_get_cur_size(event_log);
671c199c54SYeoreum Yun 
681c199c54SYeoreum Yun 	rc = transfer_list_event_log_finish(
691c199c54SYeoreum Yun 		secure_tl, (uintptr_t)event_log + event_log_cur_size);
701c199c54SYeoreum Yun 
711c199c54SYeoreum Yun 	if (rc != NULL)
721c199c54SYeoreum Yun 		return;
731c199c54SYeoreum Yun 
741c199c54SYeoreum Yun 	/*
751c199c54SYeoreum Yun 	 * Panic if we fail to set up the event log for the next stage.
761c199c54SYeoreum Yun 	 * This is a fatal error because, on the Juno platform,
771c199c54SYeoreum Yun 	 * BL2 software assumes that a valid event Log buffer exists and
781c199c54SYeoreum Yun 	 * will use the same event Log buffer to append image
791c199c54SYeoreum Yun 	 * measurements.
801c199c54SYeoreum Yun 	 */
811c199c54SYeoreum Yun 	panic();
821c199c54SYeoreum Yun #endif
831c199c54SYeoreum Yun }
84