1 /* 2 * Copyright (c) 2022-2025, Arm Limited. All rights reserved. 3 * Copyright (c) 2022, Linaro. 4 * 5 * SPDX-License-Identifier: BSD-3-Clause 6 */ 7 8 #include <string.h> 9 10 #include "./include/imx8m_measured_boot.h" 11 #include <drivers/measured_boot/event_log/event_log.h> 12 #include <drivers/measured_boot/metadata.h> 13 #include <plat/arm/common/plat_arm.h> 14 15 /* Event Log data */ 16 static uint8_t event_log[PLAT_IMX_EVENT_LOG_MAX_SIZE]; 17 18 /* FVP table with platform specific image IDs, names and PCRs */ 19 static const event_log_metadata_t imx8m_event_log_metadata[] = { 20 { BL31_IMAGE_ID, MBOOT_BL31_IMAGE_STRING, PCR_0 }, 21 { BL32_IMAGE_ID, MBOOT_BL32_IMAGE_STRING, PCR_0 }, 22 { BL32_EXTRA1_IMAGE_ID, MBOOT_BL32_EXTRA1_IMAGE_STRING, PCR_0 }, 23 { BL32_EXTRA2_IMAGE_ID, MBOOT_BL32_EXTRA2_IMAGE_STRING, PCR_0 }, 24 { BL33_IMAGE_ID, MBOOT_BL33_IMAGE_STRING, PCR_0 }, 25 { EVLOG_INVALID_ID, NULL, (unsigned int)(-1) } /* Terminator */ 26 }; 27 28 int plat_mboot_measure_image(unsigned int image_id, image_info_t *image_data) 29 { 30 /* Calculate image hash and record data in Event Log */ 31 int err = event_log_measure_and_record(image_data->image_base, 32 image_data->image_size, 33 image_id, 34 imx8m_event_log_metadata); 35 if (err != 0) { 36 ERROR("%s%s image id %u (%i)\n", 37 "Failed to ", "record", image_id, err); 38 return err; 39 } 40 41 return 0; 42 } 43 44 void bl2_plat_mboot_init(void) 45 { 46 event_log_init(event_log, event_log + sizeof(event_log)); 47 event_log_write_header(); 48 } 49 50 void bl2_plat_mboot_finish(void) 51 { 52 int rc = 0; 53 54 /* Event Log address in Non-Secure memory */ 55 uintptr_t ns_log_addr; 56 57 /* Event Log filled size */ 58 size_t event_log_cur_size; 59 60 event_log_cur_size = event_log_get_cur_size(event_log); 61 62 rc = imx8m_set_nt_fw_info(event_log_cur_size, &ns_log_addr); 63 if (rc != 0) { 64 ERROR("%s(): Unable to update %s_FW_CONFIG\n", 65 __func__, "NT"); 66 /* 67 * It is a fatal error because on i.MX U-boot assumes that 68 * a valid event log exists and will use it to record the 69 * measurements into the fTPM. 70 */ 71 panic(); 72 } 73 74 /* Copy Event Log to Non-secure memory */ 75 (void)memcpy((void *)ns_log_addr, (const void *)event_log, 76 event_log_cur_size); 77 78 /* Ensure that the Event Log is visible in Non-secure memory */ 79 flush_dcache_range(ns_log_addr, event_log_cur_size); 80 81 event_log_dump((uint8_t *)event_log, event_log_cur_size); 82 } 83 84 int plat_mboot_measure_key(const void *pk_oid, const void *pk_ptr, 85 size_t pk_len) 86 { 87 return 0; 88 } 89