blob: e9ea2d8734f18aa6c5af8a333ec185acaa3fbe79 [file] [log] [blame]
Ying-Chun Liu (PaulLiu)ac6d8622021-10-06 09:27:00 +08001/*
2 * Copyright (c) 2022, 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 <plat/arm/common/plat_arm.h>
13
14/* Event Log data */
15static uint8_t event_log[PLAT_IMX_EVENT_LOG_MAX_SIZE];
16
17/* FVP table with platform specific image IDs, names and PCRs */
18static const event_log_metadata_t imx8m_event_log_metadata[] = {
19 { BL31_IMAGE_ID, EVLOG_BL31_STRING, PCR_0 },
20 { BL32_IMAGE_ID, EVLOG_BL32_STRING, PCR_0 },
21 { BL32_EXTRA1_IMAGE_ID, EVLOG_BL32_EXTRA1_STRING, PCR_0 },
22 { BL32_EXTRA2_IMAGE_ID, EVLOG_BL32_EXTRA2_STRING, PCR_0 },
23 { BL33_IMAGE_ID, EVLOG_BL33_STRING, PCR_0 },
24 { EVLOG_INVALID_ID, NULL, (unsigned int)(-1) } /* Terminator */
25};
26
Ying-Chun Liu (PaulLiu)ac6d8622021-10-06 09:27:00 +080027int plat_mboot_measure_image(unsigned int image_id, image_info_t *image_data)
28{
29 /* Calculate image hash and record data in Event Log */
30 int err = event_log_measure_and_record(image_data->image_base,
31 image_data->image_size,
Manish V Badarkhecbbe28e2022-11-18 20:42:44 +000032 image_id,
33 imx8m_event_log_metadata);
Ying-Chun Liu (PaulLiu)ac6d8622021-10-06 09:27:00 +080034 if (err != 0) {
35 ERROR("%s%s image id %u (%i)\n",
36 "Failed to ", "record", image_id, err);
37 return err;
38 }
39
40 return 0;
41}
42
43void bl2_plat_mboot_init(void)
44{
45 event_log_init(event_log, event_log + sizeof(event_log));
46 event_log_write_header();
47}
48
49void bl2_plat_mboot_finish(void)
50{
51 int rc = 0;
52
53 /* Event Log address in Non-Secure memory */
54 uintptr_t ns_log_addr;
55
56 /* Event Log filled size */
57 size_t event_log_cur_size;
58
59 event_log_cur_size = event_log_get_cur_size(event_log);
60
61 rc = imx8m_set_nt_fw_info(event_log_cur_size, &ns_log_addr);
62 if (rc != 0) {
63 ERROR("%s(): Unable to update %s_FW_CONFIG\n",
64 __func__, "NT");
65 /*
66 * It is a fatal error because on i.MX U-boot assumes that
67 * a valid event log exists and will use it to record the
68 * measurements into the fTPM.
69 */
70 panic();
71 }
72
73 /* Copy Event Log to Non-secure memory */
74 (void)memcpy((void *)ns_log_addr, (const void *)event_log,
75 event_log_cur_size);
76
77 /* Ensure that the Event Log is visible in Non-secure memory */
78 flush_dcache_range(ns_log_addr, event_log_cur_size);
79
80 dump_event_log((uint8_t *)event_log, event_log_cur_size);
81}