blob: 159be00a863284562b52ecaff39340eeef18d3ce [file] [log] [blame]
Ying-Chun Liu (PaulLiu)ac6d8622021-10-06 09:27:00 +08001/*
Tamas Bancba05612023-06-05 11:10:10 +02002 * Copyright (c) 2022-2024, Arm Limited. All rights reserved.
Ying-Chun Liu (PaulLiu)ac6d8622021-10-06 09:27:00 +08003 * 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>
Tamas Bancba05612023-06-05 11:10:10 +020012#include <drivers/measured_boot/metadata.h>
Ying-Chun Liu (PaulLiu)ac6d8622021-10-06 09:27:00 +080013#include <plat/arm/common/plat_arm.h>
14
15/* Event Log data */
16static uint8_t event_log[PLAT_IMX_EVENT_LOG_MAX_SIZE];
17
18/* FVP table with platform specific image IDs, names and PCRs */
19static const event_log_metadata_t imx8m_event_log_metadata[] = {
Tamas Bancba05612023-06-05 11:10:10 +020020 { 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 },
Ying-Chun Liu (PaulLiu)ac6d8622021-10-06 09:27:00 +080025 { EVLOG_INVALID_ID, NULL, (unsigned int)(-1) } /* Terminator */
26};
27
Ying-Chun Liu (PaulLiu)ac6d8622021-10-06 09:27:00 +080028int 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,
Manish V Badarkhecbbe28e2022-11-18 20:42:44 +000033 image_id,
34 imx8m_event_log_metadata);
Ying-Chun Liu (PaulLiu)ac6d8622021-10-06 09:27:00 +080035 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
44void bl2_plat_mboot_init(void)
45{
46 event_log_init(event_log, event_log + sizeof(event_log));
47 event_log_write_header();
48}
49
50void 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 dump_event_log((uint8_t *)event_log, event_log_cur_size);
82}
Manish V Badarkhee2405a92023-07-12 10:22:39 +010083
84int plat_mboot_measure_key(const void *pk_oid, const void *pk_ptr,
85 size_t pk_len)
86{
87 return 0;
88}