Abhi Singh | c4c9e2b | 2024-11-06 11:11:11 -0600 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2025, Arm Limited. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <assert.h> |
| 8 | #include <stdarg.h> |
| 9 | #include <stdint.h> |
| 10 | |
| 11 | #include "./include/rpi3_measured_boot.h" |
| 12 | |
| 13 | #include <drivers/auth/crypto_mod.h> |
| 14 | #include <drivers/measured_boot/event_log/event_log.h> |
| 15 | #include <drivers/measured_boot/metadata.h> |
| 16 | #include <plat/common/common_def.h> |
| 17 | #include <plat/common/platform.h> |
| 18 | #include <platform_def.h> |
| 19 | #include <tools_share/tbbr_oid.h> |
| 20 | |
| 21 | /* RPI3 table with platform specific image IDs, names and PCRs */ |
| 22 | const event_log_metadata_t rpi3_event_log_metadata[] = { |
| 23 | { BL31_IMAGE_ID, MBOOT_BL31_IMAGE_STRING, PCR_0 }, |
| 24 | { BL33_IMAGE_ID, MBOOT_BL33_IMAGE_STRING, PCR_0 }, |
| 25 | { NT_FW_CONFIG_ID, MBOOT_NT_FW_CONFIG_STRING, PCR_0 }, |
| 26 | |
| 27 | { EVLOG_INVALID_ID, NULL, (unsigned int)(-1) } /* Terminator */ |
| 28 | }; |
| 29 | |
| 30 | static uint8_t *event_log_start; |
| 31 | static size_t event_log_size; |
| 32 | |
| 33 | void bl2_plat_mboot_init(void) |
| 34 | { |
| 35 | uint8_t *bl2_event_log_start; |
| 36 | uint8_t *bl2_event_log_finish; |
| 37 | |
| 38 | rpi3_mboot_fetch_eventlog_info(&event_log_start, &event_log_size); |
| 39 | bl2_event_log_start = event_log_start + event_log_size; |
| 40 | bl2_event_log_finish = event_log_start + PLAT_ARM_EVENT_LOG_MAX_SIZE; |
| 41 | event_log_init(bl2_event_log_start, bl2_event_log_finish); |
| 42 | } |
| 43 | |
| 44 | void bl2_plat_mboot_finish(void) |
| 45 | { |
| 46 | /* Event Log filled size */ |
| 47 | size_t event_log_cur_size; |
| 48 | |
| 49 | event_log_cur_size = event_log_get_cur_size((uint8_t *)event_log_start); |
| 50 | |
| 51 | /* Dump Event Log for user view */ |
| 52 | dump_event_log((uint8_t *)event_log_start, event_log_cur_size); |
| 53 | } |
| 54 | |
| 55 | int plat_mboot_measure_image(unsigned int image_id, image_info_t *image_data) |
| 56 | { |
| 57 | int rc = 0; |
| 58 | |
| 59 | unsigned char hash_data[CRYPTO_MD_MAX_SIZE]; |
| 60 | const event_log_metadata_t *metadata_ptr = rpi3_event_log_metadata; |
| 61 | |
| 62 | /* Measure the payload with algorithm selected by EventLog driver */ |
| 63 | rc = event_log_measure(image_data->image_base, image_data->image_size, hash_data); |
| 64 | if (rc != 0) { |
| 65 | return rc; |
| 66 | } |
| 67 | |
| 68 | while ((metadata_ptr->id != EVLOG_INVALID_ID) && |
| 69 | (metadata_ptr->id != image_id)) { |
| 70 | metadata_ptr++; |
| 71 | } |
| 72 | assert(metadata_ptr->id != EVLOG_INVALID_ID); |
| 73 | |
| 74 | event_log_record(hash_data, EV_POST_CODE, metadata_ptr); |
| 75 | |
| 76 | return rc; |
| 77 | } |