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
91c199c54SYeoreum Yun #include <common/tbbr/tbbr_img_def.h>
10*b67e9846SHarrison Mutai #if TRANSFER_LIST
11*b67e9846SHarrison Mutai #include <tpm_event_log.h>
12*b67e9846SHarrison Mutai #endif
131c199c54SYeoreum Yun #include <plat/arm/common/plat_arm.h>
141c199c54SYeoreum Yun #include <plat/common/common_def.h>
15*b67e9846SHarrison Mutai
16*b67e9846SHarrison Mutai #include <drivers/auth/crypto_mod.h>
17*b67e9846SHarrison Mutai #include <drivers/measured_boot/metadata.h>
18*b67e9846SHarrison Mutai #include <event_measure.h>
19*b67e9846SHarrison Mutai #include <event_print.h>
201c199c54SYeoreum Yun #if defined(ARM_COT_cca)
211c199c54SYeoreum Yun #include <tools_share/cca_oid.h>
221c199c54SYeoreum Yun #else
231c199c54SYeoreum Yun #include <tools_share/tbbr_oid.h>
241c199c54SYeoreum Yun #endif /* ARM_COT_cca */
251c199c54SYeoreum Yun
261c199c54SYeoreum Yun /* Event Log data */
271c199c54SYeoreum Yun static uint8_t *event_log_base;
281c199c54SYeoreum Yun
29*b67e9846SHarrison Mutai static const struct event_log_hash_info crypto_hash_info = {
30*b67e9846SHarrison Mutai .func = crypto_mod_calc_hash,
31*b67e9846SHarrison Mutai .ids = (const uint32_t[]){ CRYPTO_MD_ID },
32*b67e9846SHarrison Mutai .count = 1U,
33*b67e9846SHarrison Mutai };
34*b67e9846SHarrison Mutai
351c199c54SYeoreum Yun /* table with platform specific image IDs, names and PCRs */
361c199c54SYeoreum Yun const event_log_metadata_t juno_event_log_metadata[] = {
371c199c54SYeoreum Yun { BL31_IMAGE_ID, MBOOT_BL31_IMAGE_STRING, PCR_0 },
381c199c54SYeoreum Yun { BL32_IMAGE_ID, MBOOT_BL32_IMAGE_STRING, PCR_0 },
391c199c54SYeoreum Yun { BL32_EXTRA1_IMAGE_ID, MBOOT_BL32_EXTRA1_IMAGE_STRING, PCR_0 },
401c199c54SYeoreum Yun { BL32_EXTRA2_IMAGE_ID, MBOOT_BL32_EXTRA2_IMAGE_STRING, PCR_0 },
411c199c54SYeoreum Yun { BL33_IMAGE_ID, MBOOT_BL33_IMAGE_STRING, PCR_0 },
421c199c54SYeoreum Yun { HW_CONFIG_ID, MBOOT_HW_CONFIG_STRING, PCR_0 },
431c199c54SYeoreum Yun { NT_FW_CONFIG_ID, MBOOT_NT_FW_CONFIG_STRING, PCR_0 },
441c199c54SYeoreum Yun { SCP_BL2_IMAGE_ID, MBOOT_SCP_BL2_IMAGE_STRING, PCR_0 },
451c199c54SYeoreum Yun { SOC_FW_CONFIG_ID, MBOOT_SOC_FW_CONFIG_STRING, PCR_0 },
461c199c54SYeoreum Yun { TOS_FW_CONFIG_ID, MBOOT_TOS_FW_CONFIG_STRING, PCR_0 },
471c199c54SYeoreum Yun { EVLOG_INVALID_ID, NULL, (unsigned int)(-1) } /* Terminator */
481c199c54SYeoreum Yun };
491c199c54SYeoreum Yun
bl2_plat_mboot_init(void)501c199c54SYeoreum Yun void bl2_plat_mboot_init(void)
511c199c54SYeoreum Yun {
521c199c54SYeoreum Yun #if TRANSFER_LIST
531c199c54SYeoreum Yun uint8_t *event_log_start;
541c199c54SYeoreum Yun uint8_t *event_log_finish;
55*b67e9846SHarrison Mutai int rc;
561c199c54SYeoreum Yun
571c199c54SYeoreum Yun event_log_start = transfer_list_event_log_extend(
58*b67e9846SHarrison Mutai secure_tl, PLAT_ARM_EVENT_LOG_MAX_SIZE);
591c199c54SYeoreum Yun
601c199c54SYeoreum Yun event_log_base = event_log_start;
61*b67e9846SHarrison Mutai event_log_finish = event_log_start + PLAT_ARM_EVENT_LOG_MAX_SIZE;
621c199c54SYeoreum Yun
63*b67e9846SHarrison Mutai rc = event_log_init_and_reg(event_log_start, event_log_finish,
64*b67e9846SHarrison Mutai &crypto_hash_info);
65*b67e9846SHarrison Mutai if (rc < 0) {
66*b67e9846SHarrison Mutai ERROR("Failed to initialize event log (%d).\n", rc);
67*b67e9846SHarrison Mutai panic();
68*b67e9846SHarrison Mutai }
691c199c54SYeoreum Yun #endif
701c199c54SYeoreum Yun }
711c199c54SYeoreum Yun
plat_mboot_measure_critical_data(unsigned int critical_data_id,const void * base,size_t size)721c199c54SYeoreum Yun int plat_mboot_measure_critical_data(unsigned int critical_data_id,
731c199c54SYeoreum Yun const void *base, size_t size)
741c199c54SYeoreum Yun {
751c199c54SYeoreum Yun /* Nothing */
761c199c54SYeoreum Yun return 0;
771c199c54SYeoreum Yun }
781c199c54SYeoreum Yun
bl2_plat_mboot_finish(void)791c199c54SYeoreum Yun void bl2_plat_mboot_finish(void)
801c199c54SYeoreum Yun {
811c199c54SYeoreum Yun #if TRANSFER_LIST
821c199c54SYeoreum Yun /* Event Log filled size */
831c199c54SYeoreum Yun size_t event_log_cur_size;
841c199c54SYeoreum Yun
851c199c54SYeoreum Yun event_log_cur_size = event_log_get_cur_size((uint8_t *)event_log_base);
861c199c54SYeoreum Yun
871c199c54SYeoreum Yun /*
881c199c54SYeoreum Yun * Re-size the event log for the next stage and update the size to include
891c199c54SYeoreum Yun * the entire event log (i.e., not just what this stage has added.)
901c199c54SYeoreum Yun */
911c199c54SYeoreum Yun event_log_base = transfer_list_event_log_finish(
921c199c54SYeoreum Yun secure_tl, (uintptr_t)event_log_base + event_log_cur_size);
931c199c54SYeoreum Yun if (event_log_base == NULL) {
941c199c54SYeoreum Yun panic();
951c199c54SYeoreum Yun }
961c199c54SYeoreum Yun
971c199c54SYeoreum Yun event_log_cur_size = event_log_get_cur_size((uint8_t *)event_log_base);
981c199c54SYeoreum Yun event_log_dump(event_log_base, event_log_cur_size);
991c199c54SYeoreum Yun #endif /* TRANSFER_LIST */
1001c199c54SYeoreum Yun }
101