blob: 24885f502405aacef69bdd34bf9c789ea911f409 [file] [log] [blame]
Alexei Fedorov61369a22020-07-13 14:59:02 +01001/*
Manish V Badarkhe5797b802021-08-06 09:26:20 +01002 * Copyright (c) 2020-2021, Arm Limited. All rights reserved.
Alexei Fedorov61369a22020-07-13 14:59:02 +01003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
Manish V Badarkhe57b669f2021-09-20 09:06:02 +01007#include <assert.h>
Manish V Badarkhe5797b802021-08-06 09:26:20 +01008#include <stdint.h>
9
Manish V Badarkhe57b669f2021-09-20 09:06:02 +010010#include <common/desc_image_load.h>
Sandrine Bailleux3c2db6f2021-07-07 14:47:08 +020011#include <drivers/measured_boot/event_log/event_log.h>
Manish V Badarkhe57b669f2021-09-20 09:06:02 +010012
Alexei Fedorov61369a22020-07-13 14:59:02 +010013#include <plat/arm/common/plat_arm.h>
Sandrine Bailleux898c0992021-06-17 16:10:40 +020014#include <plat/common/platform.h>
Alexei Fedorov61369a22020-07-13 14:59:02 +010015
16/* FVP table with platform specific image IDs, names and PCRs */
17static const image_data_t fvp_images_data[] = {
18 { BL2_IMAGE_ID, BL2_STRING, PCR_0 }, /* Reserved for BL2 */
19 { BL31_IMAGE_ID, BL31_STRING, PCR_0 },
20 { BL32_IMAGE_ID, BL32_STRING, PCR_0 },
21 { BL32_EXTRA1_IMAGE_ID, BL32_EXTRA1_IMAGE_STRING, PCR_0 },
22 { BL32_EXTRA2_IMAGE_ID, BL32_EXTRA2_IMAGE_STRING, PCR_0 },
23 { BL33_IMAGE_ID, BL33_STRING, PCR_0 },
Alexei Fedorov61369a22020-07-13 14:59:02 +010024 { HW_CONFIG_ID, HW_CONFIG_STRING, PCR_0 },
25 { NT_FW_CONFIG_ID, NT_FW_CONFIG_STRING, PCR_0 },
26 { SCP_BL2_IMAGE_ID, SCP_BL2_IMAGE_STRING, PCR_0 },
27 { SOC_FW_CONFIG_ID, SOC_FW_CONFIG_STRING, PCR_0 },
Alexei Fedorov61369a22020-07-13 14:59:02 +010028 { TOS_FW_CONFIG_ID, TOS_FW_CONFIG_STRING, PCR_0 },
29 { INVALID_ID, NULL, (unsigned int)(-1) } /* Terminator */
30};
31
32static const measured_boot_data_t fvp_measured_boot_data = {
33 fvp_images_data,
34 arm_set_nt_fw_info,
35 arm_set_tos_fw_info
36};
37
38/*
39 * Function retuns pointer to FVP plat_measured_boot_data_t structure
40 */
41const measured_boot_data_t *plat_get_measured_boot_data(void)
42{
43 return &fvp_measured_boot_data;
44}
Manish V Badarkhe5797b802021-08-06 09:26:20 +010045
46void bl2_plat_mboot_init(void)
47{
Sandrine Bailleux898c0992021-06-17 16:10:40 +020048 uint8_t bl2_hash[TCG_DIGEST_SIZE];
49
Manish V Badarkhe5797b802021-08-06 09:26:20 +010050 event_log_init();
Sandrine Bailleux898c0992021-06-17 16:10:40 +020051
52 /* Get BL2 hash from DTB */
53 /* TODO: Avoid the extra copy of the hash buffer */
54 bl2_plat_get_hash(bl2_hash);
55
56 /* Add BL2 event */
57 event_log_record(bl2_hash, &fvp_images_data[0]);
Manish V Badarkhe5797b802021-08-06 09:26:20 +010058}
59
60void bl2_plat_mboot_finish(void)
61{
62 uint8_t *log_addr;
63 size_t log_size;
64 int rc;
65
66 rc = event_log_finalise(&log_addr, &log_size);
67 if (rc != 0) {
68 /*
69 * It is a fatal error because on FVP secure world software
70 * assumes that a valid event log exists and will use it to
71 * record the measurements into the fTPM
72 */
73 panic();
74 }
75
76 dump_event_log(log_addr, log_size);
77}
Manish V Badarkhe57b669f2021-09-20 09:06:02 +010078
79int plat_mboot_measure_image(unsigned int image_id)
80{
81 const bl_mem_params_node_t *bl_mem_params =
82 get_bl_mem_params_node(image_id);
83
84 assert(bl_mem_params != NULL);
85
86 image_info_t info = bl_mem_params->image_info;
87 int err;
88
89 if ((info.h.attr & IMAGE_ATTRIB_SKIP_LOADING) == 0U) {
90 /* Calculate image hash and record data in Event Log */
91 err = event_log_measure_record(info.image_base,
92 info.image_size, image_id);
93 if (err != 0) {
94 ERROR("%s%s image id %u (%i)\n",
95 "BL2: Failed to ", "record", image_id, err);
96 return err;
97 }
98 }
99
100 return 0;
101}