Alexei Fedorov | 71d81dc | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 1 | /* |
Sandrine Bailleux | 4e9af17 | 2021-07-01 14:13:09 +0200 | [diff] [blame] | 2 | * Copyright (c) 2020-2021, Arm Limited. All rights reserved. |
Alexei Fedorov | 71d81dc | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 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> |
Manish V Badarkhe | 7ca9d65 | 2021-09-14 22:41:46 +0100 | [diff] [blame] | 13 | #include <common/tbbr/tbbr_img_def.h> |
Sandrine Bailleux | 3c2db6f | 2021-07-07 14:47:08 +0200 | [diff] [blame] | 14 | #include <drivers/measured_boot/event_log/tcg.h> |
Alexei Fedorov | 71d81dc | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 15 | |
| 16 | /* |
| 17 | * Set Event Log debug level to one of: |
| 18 | * |
| 19 | * LOG_LEVEL_ERROR |
| 20 | * LOG_LEVEL_INFO |
| 21 | * LOG_LEVEL_WARNING |
| 22 | * LOG_LEVEL_VERBOSE |
| 23 | */ |
Alexei Fedorov | 71d81dc | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 24 | #if EVENT_LOG_LEVEL == LOG_LEVEL_ERROR |
| 25 | #define LOG_EVENT ERROR |
| 26 | #elif EVENT_LOG_LEVEL == LOG_LEVEL_NOTICE |
| 27 | #define LOG_EVENT NOTICE |
| 28 | #elif EVENT_LOG_LEVEL == LOG_LEVEL_WARNING |
| 29 | #define LOG_EVENT WARN |
| 30 | #elif EVENT_LOG_LEVEL == LOG_LEVEL_INFO |
| 31 | #define LOG_EVENT INFO |
| 32 | #elif EVENT_LOG_LEVEL == LOG_LEVEL_VERBOSE |
| 33 | #define LOG_EVENT VERBOSE |
| 34 | #else |
| 35 | #error "Not supported EVENT_LOG_LEVEL" |
| 36 | #endif |
| 37 | |
| 38 | /* Number of hashing algorithms supported */ |
| 39 | #define HASH_ALG_COUNT 1U |
| 40 | |
| 41 | #define INVALID_ID MAX_NUMBER_IDS |
| 42 | |
| 43 | #define MEMBER_SIZE(type, member) sizeof(((type *)0)->member) |
| 44 | |
Manish V Badarkhe | 72e0369 | 2021-09-08 20:04:24 +0100 | [diff] [blame] | 45 | /* |
| 46 | * Each event log entry has some metadata (i.e. a string) that identifies |
| 47 | * what is measured.These macros define these strings. |
| 48 | * Note that these strings follow the standardization recommendations |
| 49 | * defined in the Arm Server Base Security Guide (a.k.a. SBSG, Arm DEN 0086), |
| 50 | * where applicable. They should not be changed in the code. |
| 51 | * Where the SBSG does not make recommendations, we are free to choose any |
| 52 | * naming convention. |
| 53 | * The key thing is to choose meaningful strings so that when the TPM event |
| 54 | * log is used in attestation, the different components can be identified. |
| 55 | */ |
| 56 | #define EVLOG_BL2_STRING "BL_2" |
| 57 | #define EVLOG_BL31_STRING "SECURE_RT_EL3" |
| 58 | #if defined(SPD_opteed) |
| 59 | #define EVLOG_BL32_STRING "SECURE_RT_EL1_OPTEE" |
| 60 | #elif defined(SPD_tspd) |
| 61 | #define EVLOG_BL32_STRING "SECURE_RT_EL1_TSPD" |
| 62 | #elif defined(SPD_tlkd) |
| 63 | #define EVLOG_BL32_STRING "SECURE_RT_EL1_TLKD" |
| 64 | #elif defined(SPD_trusty) |
| 65 | #define EVLOG_BL32_STRING "SECURE_RT_EL1_TRUSTY" |
| 66 | #else |
| 67 | #define EVLOG_BL32_STRING "SECURE_RT_EL1_UNKNOWN" |
| 68 | #endif |
| 69 | #define EVLOG_BL32_EXTRA1_STRING "SECURE_RT_EL1_OPTEE_EXTRA1" |
| 70 | #define EVLOG_BL32_EXTRA2_STRING "SECURE_RT_EL1_OPTEE_EXTRA2" |
| 71 | #define EVLOG_BL33_STRING "BL_33" |
| 72 | #define EVLOG_FW_CONFIG_STRING "FW_CONFIG" |
| 73 | #define EVLOG_HW_CONFIG_STRING "HW_CONFIG" |
| 74 | #define EVLOG_NT_FW_CONFIG_STRING "NT_FW_CONFIG" |
| 75 | #define EVLOG_SCP_BL2_STRING "SYS_CTRL_2" |
| 76 | #define EVLOG_SOC_FW_CONFIG_STRING "SOC_FW_CONFIG" |
| 77 | #define EVLOG_STM32_STRING "STM32" |
| 78 | #define EVLOG_TB_FW_CONFIG_STRING "TB_FW_CONFIG" |
| 79 | #define EVLOG_TOS_FW_CONFIG_STRING "TOS_FW_CONFIG" |
Alexei Fedorov | 71d81dc | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 80 | |
| 81 | typedef struct { |
| 82 | unsigned int id; |
| 83 | const char *name; |
| 84 | unsigned int pcr; |
Manish V Badarkhe | 7ca9d65 | 2021-09-14 22:41:46 +0100 | [diff] [blame] | 85 | } event_log_metadata_t; |
Alexei Fedorov | 71d81dc | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 86 | |
| 87 | #define ID_EVENT_SIZE (sizeof(id_event_headers_t) + \ |
| 88 | (sizeof(id_event_algorithm_size_t) * HASH_ALG_COUNT) + \ |
| 89 | sizeof(id_event_struct_data_t)) |
| 90 | |
| 91 | #define LOC_EVENT_SIZE (sizeof(event2_header_t) + \ |
| 92 | sizeof(tpmt_ha) + TCG_DIGEST_SIZE + \ |
| 93 | sizeof(event2_data_t) + \ |
| 94 | sizeof(startup_locality_event_t)) |
| 95 | |
| 96 | #define LOG_MIN_SIZE (ID_EVENT_SIZE + LOC_EVENT_SIZE) |
| 97 | |
| 98 | #define EVENT2_HDR_SIZE (sizeof(event2_header_t) + \ |
| 99 | sizeof(tpmt_ha) + TCG_DIGEST_SIZE + \ |
| 100 | sizeof(event2_data_t)) |
| 101 | |
| 102 | /* Functions' declarations */ |
Manish V Badarkhe | 7ca9d65 | 2021-09-14 22:41:46 +0100 | [diff] [blame] | 103 | void event_log_init(uint8_t *event_log_start, uint8_t *event_log_finish); |
| 104 | void event_log_write_header(void); |
Alexei Fedorov | 71d81dc | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 105 | void dump_event_log(uint8_t *log_addr, size_t log_size); |
Manish V Badarkhe | 7ca9d65 | 2021-09-14 22:41:46 +0100 | [diff] [blame] | 106 | const event_log_metadata_t *plat_event_log_get_metadata(void); |
Sandrine Bailleux | 4e9af17 | 2021-07-01 14:13:09 +0200 | [diff] [blame] | 107 | int event_log_measure_and_record(uintptr_t data_base, uint32_t data_size, |
| 108 | uint32_t data_id); |
Manish V Badarkhe | 7ca9d65 | 2021-09-14 22:41:46 +0100 | [diff] [blame] | 109 | size_t event_log_get_cur_size(uint8_t *event_log_start); |
Sandrine Bailleux | 898c099 | 2021-06-17 16:10:40 +0200 | [diff] [blame] | 110 | |
Alexei Fedorov | 71d81dc | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 111 | #endif /* EVENT_LOG_H */ |