Alexei Fedorov | 71d81dc | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2020, Arm Limited. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #ifndef EVENT_LOG_H |
| 8 | #define EVENT_LOG_H |
| 9 | |
| 10 | #include <stdint.h> |
| 11 | |
| 12 | #include <common/debug.h> |
| 13 | #include <drivers/measured_boot/tcg.h> |
| 14 | |
| 15 | /* |
| 16 | * Set Event Log debug level to one of: |
| 17 | * |
| 18 | * LOG_LEVEL_ERROR |
| 19 | * LOG_LEVEL_INFO |
| 20 | * LOG_LEVEL_WARNING |
| 21 | * LOG_LEVEL_VERBOSE |
| 22 | */ |
| 23 | #define EVENT_LOG_LEVEL LOG_LEVEL_INFO |
| 24 | |
| 25 | #if EVENT_LOG_LEVEL == LOG_LEVEL_ERROR |
| 26 | #define LOG_EVENT ERROR |
| 27 | #elif EVENT_LOG_LEVEL == LOG_LEVEL_NOTICE |
| 28 | #define LOG_EVENT NOTICE |
| 29 | #elif EVENT_LOG_LEVEL == LOG_LEVEL_WARNING |
| 30 | #define LOG_EVENT WARN |
| 31 | #elif EVENT_LOG_LEVEL == LOG_LEVEL_INFO |
| 32 | #define LOG_EVENT INFO |
| 33 | #elif EVENT_LOG_LEVEL == LOG_LEVEL_VERBOSE |
| 34 | #define LOG_EVENT VERBOSE |
| 35 | #else |
| 36 | #error "Not supported EVENT_LOG_LEVEL" |
| 37 | #endif |
| 38 | |
| 39 | /* Number of hashing algorithms supported */ |
| 40 | #define HASH_ALG_COUNT 1U |
| 41 | |
| 42 | #define INVALID_ID MAX_NUMBER_IDS |
| 43 | |
| 44 | #define MEMBER_SIZE(type, member) sizeof(((type *)0)->member) |
| 45 | |
| 46 | #define BL2_STRING "BL_2" |
| 47 | #define BL31_STRING "BL_31" |
| 48 | #define BL32_STRING "BL_32" |
| 49 | #define BL32_EXTRA1_IMAGE_STRING "BL32_EXTRA1_IMAGE" |
| 50 | #define BL32_EXTRA2_IMAGE_STRING "BL32_EXTRA2_IMAGE" |
| 51 | #define BL33_STRING "BL_33" |
| 52 | #define GPT_IMAGE_STRING "GPT" |
| 53 | #define HW_CONFIG_STRING "HW_CONFIG" |
| 54 | #define NT_FW_CONFIG_STRING "NT_FW_CONFIG" |
| 55 | #define SCP_BL2_IMAGE_STRING "SCP_BL2_IMAGE" |
| 56 | #define SOC_FW_CONFIG_STRING "SOC_FW_CONFIG" |
| 57 | #define STM32_IMAGE_STRING "STM32" |
| 58 | #define TOS_FW_CONFIG_STRING "TOS_FW_CONFIG" |
| 59 | |
| 60 | typedef struct { |
| 61 | unsigned int id; |
| 62 | const char *name; |
| 63 | unsigned int pcr; |
| 64 | } image_data_t; |
| 65 | |
| 66 | typedef struct { |
| 67 | const image_data_t *images_data; |
| 68 | int (*set_nt_fw_info)(uintptr_t config_base, |
| 69 | #ifdef SPD_opteed |
| 70 | uintptr_t log_addr, |
| 71 | #endif |
| 72 | size_t log_size, uintptr_t *ns_log_addr); |
| 73 | int (*set_tos_fw_info)(uintptr_t config_base, uintptr_t log_addr, |
| 74 | size_t log_size); |
| 75 | } measured_boot_data_t; |
| 76 | |
| 77 | #define ID_EVENT_SIZE (sizeof(id_event_headers_t) + \ |
| 78 | (sizeof(id_event_algorithm_size_t) * HASH_ALG_COUNT) + \ |
| 79 | sizeof(id_event_struct_data_t)) |
| 80 | |
| 81 | #define LOC_EVENT_SIZE (sizeof(event2_header_t) + \ |
| 82 | sizeof(tpmt_ha) + TCG_DIGEST_SIZE + \ |
| 83 | sizeof(event2_data_t) + \ |
| 84 | sizeof(startup_locality_event_t)) |
| 85 | |
| 86 | #define LOG_MIN_SIZE (ID_EVENT_SIZE + LOC_EVENT_SIZE) |
| 87 | |
| 88 | #define EVENT2_HDR_SIZE (sizeof(event2_header_t) + \ |
| 89 | sizeof(tpmt_ha) + TCG_DIGEST_SIZE + \ |
| 90 | sizeof(event2_data_t)) |
| 91 | |
| 92 | /* Functions' declarations */ |
| 93 | void event_log_init(void); |
| 94 | int event_log_finalise(uint8_t **log_addr, size_t *log_size); |
| 95 | void dump_event_log(uint8_t *log_addr, size_t log_size); |
| 96 | const measured_boot_data_t *plat_get_measured_boot_data(void); |
| 97 | int tpm_record_measurement(uintptr_t data_base, uint32_t data_size, |
| 98 | uint32_t data_id); |
| 99 | #endif /* EVENT_LOG_H */ |