blob: 122bb23b14d42147aac85b9cae7a88a85626e414 [file] [log] [blame]
Ruchika Gupta5c172532022-04-08 13:14:44 +05301/*
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 <stdint.h>
9
10#include <drivers/measured_boot/event_log/event_log.h>
11#include <plat/common/common_def.h>
Manish V Badarkhe95197b52022-11-18 20:43:07 +000012#include <plat/common/platform.h>
Ruchika Gupta5c172532022-04-08 13:14:44 +053013#include <tools_share/tbbr_oid.h>
14
15#include "../common/qemu_private.h"
16
17/* Event Log data */
18static uint8_t event_log[PLAT_EVENT_LOG_MAX_SIZE];
19static uint64_t event_log_base;
20
Manish V Badarkhe95197b52022-11-18 20:43:07 +000021/* QEMU table with platform specific image IDs, names and PCRs */
22static const event_log_metadata_t qemu_event_log_metadata[] = {
Ruchika Gupta5c172532022-04-08 13:14:44 +053023 { BL31_IMAGE_ID, EVLOG_BL31_STRING, PCR_0 },
24 { BL32_IMAGE_ID, EVLOG_BL32_STRING, PCR_0 },
25 { BL32_EXTRA1_IMAGE_ID, EVLOG_BL32_EXTRA1_STRING, PCR_0 },
26 { BL32_EXTRA2_IMAGE_ID, EVLOG_BL32_EXTRA2_STRING, PCR_0 },
27 { BL33_IMAGE_ID, EVLOG_BL33_STRING, PCR_0 },
28 { HW_CONFIG_ID, EVLOG_HW_CONFIG_STRING, PCR_0 },
29 { NT_FW_CONFIG_ID, EVLOG_NT_FW_CONFIG_STRING, PCR_0 },
30 { SCP_BL2_IMAGE_ID, EVLOG_SCP_BL2_STRING, PCR_0 },
31 { SOC_FW_CONFIG_ID, EVLOG_SOC_FW_CONFIG_STRING, PCR_0 },
32 { TOS_FW_CONFIG_ID, EVLOG_TOS_FW_CONFIG_STRING, PCR_0 },
33
34 { EVLOG_INVALID_ID, NULL, (unsigned int)(-1) } /* Terminator */
35};
36
37void bl2_plat_mboot_init(void)
38{
39 /*
40 * Here we assume that BL1/ROM code doesn't have the driver
41 * to measure the BL2 code which is a common case for
42 * already existing platforms
43 */
44 event_log_init(event_log, event_log + sizeof(event_log));
45 event_log_write_header();
46
47 /*
48 * TBD - Add code to do self measurement of BL2 code and add an
49 * event for BL2 measurement
50 */
51
52 event_log_base = (uintptr_t)event_log;
53}
54
55void bl2_plat_mboot_finish(void)
56{
57 int rc;
58
59 /* Event Log address in Non-Secure memory */
60 uintptr_t ns_log_addr;
61
62 /* Event Log filled size */
63 size_t event_log_cur_size;
64
65 event_log_cur_size = event_log_get_cur_size((uint8_t *)event_log_base);
66
67 rc = qemu_set_nt_fw_info(
68#ifdef SPD_opteed
69 (uintptr_t)event_log_base,
70#endif
71 event_log_cur_size, &ns_log_addr);
72 if (rc != 0) {
73 ERROR("%s(): Unable to update %s_FW_CONFIG\n",
74 __func__, "NT");
75 /*
76 * It is a fatal error because on QEMU secure world software
77 * assumes that a valid event log exists and will use it to
78 * record the measurements into the fTPM or sw-tpm.
79 * Note: In QEMU platform, OP-TEE uses nt_fw_config to get the
80 * secure Event Log buffer address.
81 */
82 panic();
83 }
84
85 /* Copy Event Log to Non-secure memory */
86 (void)memcpy((void *)ns_log_addr, (const void *)event_log_base,
87 event_log_cur_size);
88
89 /* Ensure that the Event Log is visible in Non-secure memory */
90 flush_dcache_range(ns_log_addr, event_log_cur_size);
91
92#if defined(SPD_tspd) || defined(SPD_spmd)
93 /* Set Event Log data in TOS_FW_CONFIG */
94 rc = qemu_set_tos_fw_info((uintptr_t)event_log_base,
95 event_log_cur_size);
96 if (rc != 0) {
97 ERROR("%s(): Unable to update %s_FW_CONFIG\n",
98 __func__, "TOS");
99 panic();
100 }
101#endif /* defined(SPD_tspd) || defined(SPD_spmd) */
102
103 dump_event_log((uint8_t *)event_log_base, event_log_cur_size);
104}
Manish V Badarkhe95197b52022-11-18 20:43:07 +0000105
106int plat_mboot_measure_image(unsigned int image_id, image_info_t *image_data)
107{
108 /* Calculate image hash and record data in Event Log */
109 int err = event_log_measure_and_record(image_data->image_base,
110 image_data->image_size,
111 image_id,
112 qemu_event_log_metadata);
113 if (err != 0) {
114 ERROR("%s%s image id %u (%i)\n",
115 "Failed to ", "record", image_id, err);
116 return err;
117 }
118
119 return 0;
120}