Alexei Fedorov | 61369a2 | 2020-07-13 14:59:02 +0100 | [diff] [blame] | 1 | /* |
Manish V Badarkhe | 5797b80 | 2021-08-06 09:26:20 +0100 | [diff] [blame] | 2 | * Copyright (c) 2020-2021, Arm Limited. All rights reserved. |
Alexei Fedorov | 61369a2 | 2020-07-13 14:59:02 +0100 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
Manish V Badarkhe | 57b669f | 2021-09-20 09:06:02 +0100 | [diff] [blame] | 7 | #include <assert.h> |
Manish V Badarkhe | 5797b80 | 2021-08-06 09:26:20 +0100 | [diff] [blame] | 8 | #include <stdint.h> |
| 9 | |
Manish V Badarkhe | 57b669f | 2021-09-20 09:06:02 +0100 | [diff] [blame] | 10 | #include <common/desc_image_load.h> |
Sandrine Bailleux | 3c2db6f | 2021-07-07 14:47:08 +0200 | [diff] [blame] | 11 | #include <drivers/measured_boot/event_log/event_log.h> |
Manish V Badarkhe | 57b669f | 2021-09-20 09:06:02 +0100 | [diff] [blame] | 12 | |
Alexei Fedorov | 61369a2 | 2020-07-13 14:59:02 +0100 | [diff] [blame] | 13 | #include <plat/arm/common/plat_arm.h> |
Sandrine Bailleux | 898c099 | 2021-06-17 16:10:40 +0200 | [diff] [blame^] | 14 | #include <plat/common/platform.h> |
Alexei Fedorov | 61369a2 | 2020-07-13 14:59:02 +0100 | [diff] [blame] | 15 | |
| 16 | /* FVP table with platform specific image IDs, names and PCRs */ |
| 17 | static 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 Fedorov | 61369a2 | 2020-07-13 14:59:02 +0100 | [diff] [blame] | 24 | { 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 Fedorov | 61369a2 | 2020-07-13 14:59:02 +0100 | [diff] [blame] | 28 | { TOS_FW_CONFIG_ID, TOS_FW_CONFIG_STRING, PCR_0 }, |
| 29 | { INVALID_ID, NULL, (unsigned int)(-1) } /* Terminator */ |
| 30 | }; |
| 31 | |
| 32 | static 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 | */ |
| 41 | const measured_boot_data_t *plat_get_measured_boot_data(void) |
| 42 | { |
| 43 | return &fvp_measured_boot_data; |
| 44 | } |
Manish V Badarkhe | 5797b80 | 2021-08-06 09:26:20 +0100 | [diff] [blame] | 45 | |
| 46 | void bl2_plat_mboot_init(void) |
| 47 | { |
Sandrine Bailleux | 898c099 | 2021-06-17 16:10:40 +0200 | [diff] [blame^] | 48 | uint8_t bl2_hash[TCG_DIGEST_SIZE]; |
| 49 | |
Manish V Badarkhe | 5797b80 | 2021-08-06 09:26:20 +0100 | [diff] [blame] | 50 | event_log_init(); |
Sandrine Bailleux | 898c099 | 2021-06-17 16:10:40 +0200 | [diff] [blame^] | 51 | |
| 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 Badarkhe | 5797b80 | 2021-08-06 09:26:20 +0100 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | void 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 Badarkhe | 57b669f | 2021-09-20 09:06:02 +0100 | [diff] [blame] | 78 | |
| 79 | int 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 | } |