Alexei Fedorov | 71d81dc | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 1 | /* |
Manish V Badarkhe | 6e83676 | 2022-06-09 22:39:32 +0100 | [diff] [blame] | 2 | * Copyright (c) 2020-2022, 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 | #include <assert.h> |
| 8 | #include <errno.h> |
| 9 | #include <string.h> |
| 10 | #include <arch_helpers.h> |
| 11 | |
| 12 | #include <common/bl_common.h> |
| 13 | #include <common/debug.h> |
| 14 | #include <drivers/auth/crypto_mod.h> |
Sandrine Bailleux | 3c2db6f | 2021-07-07 14:47:08 +0200 | [diff] [blame] | 15 | #include <drivers/measured_boot/event_log/event_log.h> |
Alexei Fedorov | 71d81dc | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 16 | |
Manish V Badarkhe | e112a5a | 2021-10-06 23:41:50 +0100 | [diff] [blame] | 17 | #if TPM_ALG_ID == TPM_ALG_SHA512 |
| 18 | #define CRYPTO_MD_ID CRYPTO_MD_SHA512 |
| 19 | #elif TPM_ALG_ID == TPM_ALG_SHA384 |
| 20 | #define CRYPTO_MD_ID CRYPTO_MD_SHA384 |
| 21 | #elif TPM_ALG_ID == TPM_ALG_SHA256 |
| 22 | #define CRYPTO_MD_ID CRYPTO_MD_SHA256 |
| 23 | #else |
| 24 | # error Invalid TPM algorithm. |
| 25 | #endif /* TPM_ALG_ID */ |
| 26 | |
Manish V Badarkhe | 7ca9d65 | 2021-09-14 22:41:46 +0100 | [diff] [blame] | 27 | /* Running Event Log Pointer */ |
| 28 | static uint8_t *log_ptr; |
Alexei Fedorov | 71d81dc | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 29 | |
Manish V Badarkhe | 7ca9d65 | 2021-09-14 22:41:46 +0100 | [diff] [blame] | 30 | /* Pointer to the first byte past end of the Event Log buffer */ |
| 31 | static uintptr_t log_end; |
Alexei Fedorov | 71d81dc | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 32 | |
Alexei Fedorov | 71d81dc | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 33 | /* TCG_EfiSpecIdEvent */ |
| 34 | static const id_event_headers_t id_event_header = { |
| 35 | .header = { |
| 36 | .pcr_index = PCR_0, |
| 37 | .event_type = EV_NO_ACTION, |
| 38 | .digest = {0}, |
| 39 | .event_size = (uint32_t)(sizeof(id_event_struct_t) + |
| 40 | (sizeof(id_event_algorithm_size_t) * |
| 41 | HASH_ALG_COUNT)) |
| 42 | }, |
| 43 | |
| 44 | .struct_header = { |
| 45 | .signature = TCG_ID_EVENT_SIGNATURE_03, |
| 46 | .platform_class = PLATFORM_CLASS_CLIENT, |
| 47 | .spec_version_minor = TCG_SPEC_VERSION_MINOR_TPM2, |
| 48 | .spec_version_major = TCG_SPEC_VERSION_MAJOR_TPM2, |
| 49 | .spec_errata = TCG_SPEC_ERRATA_TPM2, |
| 50 | .uintn_size = (uint8_t)(sizeof(unsigned int) / |
| 51 | sizeof(uint32_t)), |
| 52 | .number_of_algorithms = HASH_ALG_COUNT |
| 53 | } |
| 54 | }; |
| 55 | |
| 56 | static const event2_header_t locality_event_header = { |
Sandrine Bailleux | be76143 | 2021-06-23 10:40:08 +0200 | [diff] [blame] | 57 | /* |
| 58 | * All EV_NO_ACTION events SHALL set |
| 59 | * TCG_PCR_EVENT2.pcrIndex = 0, unless otherwise specified |
| 60 | */ |
| 61 | .pcr_index = PCR_0, |
Alexei Fedorov | 71d81dc | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 62 | |
Sandrine Bailleux | be76143 | 2021-06-23 10:40:08 +0200 | [diff] [blame] | 63 | /* |
| 64 | * All EV_NO_ACTION events SHALL set |
| 65 | * TCG_PCR_EVENT2.eventType = 03h |
| 66 | */ |
| 67 | .event_type = EV_NO_ACTION, |
Alexei Fedorov | 71d81dc | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 68 | |
Sandrine Bailleux | be76143 | 2021-06-23 10:40:08 +0200 | [diff] [blame] | 69 | /* |
| 70 | * All EV_NO_ACTION events SHALL set TCG_PCR_EVENT2.digests to all |
| 71 | * 0x00's for each allocated Hash algorithm |
| 72 | */ |
| 73 | .digests = { |
| 74 | .count = HASH_ALG_COUNT |
| 75 | } |
Alexei Fedorov | 71d81dc | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 76 | }; |
| 77 | |
Alexei Fedorov | 71d81dc | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 78 | /* |
Sandrine Bailleux | 36af1c8 | 2021-06-17 15:44:40 +0200 | [diff] [blame] | 79 | * Record a measurement as a TCG_PCR_EVENT2 event |
Alexei Fedorov | 71d81dc | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 80 | * |
Manish V Badarkhe | 7ca9d65 | 2021-09-14 22:41:46 +0100 | [diff] [blame] | 81 | * @param[in] hash Pointer to hash data of TCG_DIGEST_SIZE bytes |
Manish V Badarkhe | 5a9eaa7 | 2022-06-15 15:06:43 +0100 | [diff] [blame] | 82 | * @param[in] event_type Type of Event, Various Event Types are |
| 83 | * mentioned in tcg.h header |
Manish V Badarkhe | 7ca9d65 | 2021-09-14 22:41:46 +0100 | [diff] [blame] | 84 | * @param[in] metadata_ptr Pointer to event_log_metadata_t structure |
Sandrine Bailleux | 9ebe81e | 2021-06-23 15:43:02 +0200 | [diff] [blame] | 85 | * |
| 86 | * There must be room for storing this new event into the event log buffer. |
Alexei Fedorov | 71d81dc | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 87 | */ |
Manish V Badarkhe | 5a9eaa7 | 2022-06-15 15:06:43 +0100 | [diff] [blame] | 88 | void event_log_record(const uint8_t *hash, uint32_t event_type, |
| 89 | const event_log_metadata_t *metadata_ptr) |
Alexei Fedorov | 71d81dc | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 90 | { |
| 91 | void *ptr = log_ptr; |
Manish V Badarkhe | 5a9eaa7 | 2022-06-15 15:06:43 +0100 | [diff] [blame] | 92 | uint32_t name_len = 0U; |
Alexei Fedorov | 71d81dc | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 93 | |
Sandrine Bailleux | 898c099 | 2021-06-17 16:10:40 +0200 | [diff] [blame] | 94 | assert(hash != NULL); |
Manish V Badarkhe | 7ca9d65 | 2021-09-14 22:41:46 +0100 | [diff] [blame] | 95 | assert(metadata_ptr != NULL); |
Manish V Badarkhe | 5a9eaa7 | 2022-06-15 15:06:43 +0100 | [diff] [blame] | 96 | /* event_log_buf_init() must have been called prior to this. */ |
Manish V Badarkhe | 7ca9d65 | 2021-09-14 22:41:46 +0100 | [diff] [blame] | 97 | assert(log_ptr != NULL); |
Alexei Fedorov | 71d81dc | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 98 | |
Manish V Badarkhe | 5a9eaa7 | 2022-06-15 15:06:43 +0100 | [diff] [blame] | 99 | if (metadata_ptr->name != NULL) { |
| 100 | name_len = (uint32_t)strlen(metadata_ptr->name) + 1U; |
| 101 | } |
Alexei Fedorov | 71d81dc | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 102 | |
| 103 | /* Check for space in Event Log buffer */ |
Manish V Badarkhe | 7ca9d65 | 2021-09-14 22:41:46 +0100 | [diff] [blame] | 104 | assert(((uintptr_t)ptr + (uint32_t)EVENT2_HDR_SIZE + name_len) < |
| 105 | log_end); |
Alexei Fedorov | 71d81dc | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 106 | |
| 107 | /* |
| 108 | * As per TCG specifications, firmware components that are measured |
| 109 | * into PCR[0] must be logged in the event log using the event type |
| 110 | * EV_POST_CODE. |
| 111 | */ |
| 112 | /* TCG_PCR_EVENT2.PCRIndex */ |
Manish V Badarkhe | 7ca9d65 | 2021-09-14 22:41:46 +0100 | [diff] [blame] | 113 | ((event2_header_t *)ptr)->pcr_index = metadata_ptr->pcr; |
Alexei Fedorov | 71d81dc | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 114 | |
| 115 | /* TCG_PCR_EVENT2.EventType */ |
Manish V Badarkhe | 5a9eaa7 | 2022-06-15 15:06:43 +0100 | [diff] [blame] | 116 | ((event2_header_t *)ptr)->event_type = event_type; |
Alexei Fedorov | 71d81dc | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 117 | |
| 118 | /* TCG_PCR_EVENT2.Digests.Count */ |
| 119 | ptr = (uint8_t *)ptr + offsetof(event2_header_t, digests); |
| 120 | ((tpml_digest_values *)ptr)->count = HASH_ALG_COUNT; |
| 121 | |
| 122 | /* TCG_PCR_EVENT2.Digests[] */ |
Alexei Fedorov | f52e6a1 | 2020-09-28 14:47:54 +0100 | [diff] [blame] | 123 | ptr = (uint8_t *)((uintptr_t)ptr + |
| 124 | offsetof(tpml_digest_values, digests)); |
Alexei Fedorov | 71d81dc | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 125 | |
| 126 | /* TCG_PCR_EVENT2.Digests[].AlgorithmId */ |
| 127 | ((tpmt_ha *)ptr)->algorithm_id = TPM_ALG_ID; |
| 128 | |
| 129 | /* TCG_PCR_EVENT2.Digests[].Digest[] */ |
Alexei Fedorov | f52e6a1 | 2020-09-28 14:47:54 +0100 | [diff] [blame] | 130 | ptr = (uint8_t *)((uintptr_t)ptr + offsetof(tpmt_ha, digest)); |
Alexei Fedorov | 71d81dc | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 131 | |
Sandrine Bailleux | 898c099 | 2021-06-17 16:10:40 +0200 | [diff] [blame] | 132 | /* Copy digest */ |
| 133 | (void)memcpy(ptr, (const void *)hash, TCG_DIGEST_SIZE); |
Alexei Fedorov | 71d81dc | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 134 | |
| 135 | /* TCG_PCR_EVENT2.EventSize */ |
Alexei Fedorov | f52e6a1 | 2020-09-28 14:47:54 +0100 | [diff] [blame] | 136 | ptr = (uint8_t *)((uintptr_t)ptr + TCG_DIGEST_SIZE); |
Alexei Fedorov | 71d81dc | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 137 | ((event2_data_t *)ptr)->event_size = name_len; |
| 138 | |
| 139 | /* Copy event data to TCG_PCR_EVENT2.Event */ |
Manish V Badarkhe | 5a9eaa7 | 2022-06-15 15:06:43 +0100 | [diff] [blame] | 140 | if (metadata_ptr->name != NULL) { |
| 141 | (void)memcpy((void *)(((event2_data_t *)ptr)->event), |
| 142 | (const void *)metadata_ptr->name, name_len); |
| 143 | } |
Alexei Fedorov | 71d81dc | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 144 | |
| 145 | /* End of event data */ |
Alexei Fedorov | f52e6a1 | 2020-09-28 14:47:54 +0100 | [diff] [blame] | 146 | log_ptr = (uint8_t *)((uintptr_t)ptr + |
| 147 | offsetof(event2_data_t, event) + name_len); |
Alexei Fedorov | 71d81dc | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 148 | } |
| 149 | |
Manish V Badarkhe | 5a9eaa7 | 2022-06-15 15:06:43 +0100 | [diff] [blame] | 150 | void event_log_buf_init(uint8_t *event_log_start, uint8_t *event_log_finish) |
| 151 | { |
| 152 | assert(event_log_start != NULL); |
| 153 | assert(event_log_finish > event_log_start); |
| 154 | |
| 155 | log_ptr = event_log_start; |
| 156 | log_end = (uintptr_t)event_log_finish; |
| 157 | } |
| 158 | |
Alexei Fedorov | 71d81dc | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 159 | /* |
Manish V Badarkhe | 7ca9d65 | 2021-09-14 22:41:46 +0100 | [diff] [blame] | 160 | * Initialise Event Log global variables, used during the recording |
| 161 | * of various payload measurements into the Event Log buffer |
Alexei Fedorov | 71d81dc | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 162 | * |
Manish V Badarkhe | 7ca9d65 | 2021-09-14 22:41:46 +0100 | [diff] [blame] | 163 | * @param[in] event_log_start Base address of Event Log buffer |
| 164 | * @param[in] event_log_finish End address of Event Log buffer, |
| 165 | * it is a first byte past end of the |
| 166 | * buffer |
| 167 | */ |
| 168 | void event_log_init(uint8_t *event_log_start, uint8_t *event_log_finish) |
| 169 | { |
Manish V Badarkhe | 5a9eaa7 | 2022-06-15 15:06:43 +0100 | [diff] [blame] | 170 | event_log_buf_init(event_log_start, event_log_finish); |
Manish V Badarkhe | 7ca9d65 | 2021-09-14 22:41:46 +0100 | [diff] [blame] | 171 | } |
| 172 | |
Manish V Badarkhe | 5a9eaa7 | 2022-06-15 15:06:43 +0100 | [diff] [blame] | 173 | void event_log_write_specid_event(void) |
Alexei Fedorov | 71d81dc | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 174 | { |
Manish V Badarkhe | 7ca9d65 | 2021-09-14 22:41:46 +0100 | [diff] [blame] | 175 | void *ptr = log_ptr; |
Alexei Fedorov | 71d81dc | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 176 | |
Manish V Badarkhe | 5a9eaa7 | 2022-06-15 15:06:43 +0100 | [diff] [blame] | 177 | /* event_log_buf_init() must have been called prior to this. */ |
Manish V Badarkhe | 7ca9d65 | 2021-09-14 22:41:46 +0100 | [diff] [blame] | 178 | assert(log_ptr != NULL); |
Manish V Badarkhe | 5a9eaa7 | 2022-06-15 15:06:43 +0100 | [diff] [blame] | 179 | assert(((uintptr_t)log_ptr + ID_EVENT_SIZE) < log_end); |
Alexei Fedorov | 71d81dc | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 180 | |
| 181 | /* |
| 182 | * Add Specification ID Event first |
| 183 | * |
| 184 | * Copy TCG_EfiSpecIDEventStruct structure header |
| 185 | */ |
| 186 | (void)memcpy(ptr, (const void *)&id_event_header, |
| 187 | sizeof(id_event_header)); |
Alexei Fedorov | f52e6a1 | 2020-09-28 14:47:54 +0100 | [diff] [blame] | 188 | ptr = (uint8_t *)((uintptr_t)ptr + sizeof(id_event_header)); |
Alexei Fedorov | 71d81dc | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 189 | |
| 190 | /* TCG_EfiSpecIdEventAlgorithmSize structure */ |
| 191 | ((id_event_algorithm_size_t *)ptr)->algorithm_id = TPM_ALG_ID; |
| 192 | ((id_event_algorithm_size_t *)ptr)->digest_size = TCG_DIGEST_SIZE; |
Alexei Fedorov | f52e6a1 | 2020-09-28 14:47:54 +0100 | [diff] [blame] | 193 | ptr = (uint8_t *)((uintptr_t)ptr + sizeof(id_event_algorithm_size_t)); |
Alexei Fedorov | 71d81dc | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 194 | |
| 195 | /* |
| 196 | * TCG_EfiSpecIDEventStruct.vendorInfoSize |
| 197 | * No vendor data |
| 198 | */ |
| 199 | ((id_event_struct_data_t *)ptr)->vendor_info_size = 0; |
Manish V Badarkhe | 5a9eaa7 | 2022-06-15 15:06:43 +0100 | [diff] [blame] | 200 | log_ptr = (uint8_t *)((uintptr_t)ptr + |
Alexei Fedorov | f52e6a1 | 2020-09-28 14:47:54 +0100 | [diff] [blame] | 201 | offsetof(id_event_struct_data_t, vendor_info)); |
Manish V Badarkhe | 5a9eaa7 | 2022-06-15 15:06:43 +0100 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | /* |
| 205 | * Initialises Event Log by writing Specification ID and |
| 206 | * Startup Locality events |
| 207 | */ |
| 208 | void event_log_write_header(void) |
| 209 | { |
| 210 | const char locality_signature[] = TCG_STARTUP_LOCALITY_SIGNATURE; |
| 211 | void *ptr; |
| 212 | |
| 213 | event_log_write_specid_event(); |
| 214 | |
| 215 | ptr = log_ptr; |
| 216 | assert(((uintptr_t)log_ptr + LOC_EVENT_SIZE) < log_end); |
Alexei Fedorov | 71d81dc | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 217 | |
| 218 | /* |
| 219 | * The Startup Locality event should be placed in the log before |
| 220 | * any event which extends PCR[0]. |
| 221 | * |
| 222 | * Ref. TCG PC Client Platform Firmware Profile 9.4.5.3 |
| 223 | */ |
| 224 | |
| 225 | /* Copy Startup Locality Event Header */ |
| 226 | (void)memcpy(ptr, (const void *)&locality_event_header, |
| 227 | sizeof(locality_event_header)); |
Alexei Fedorov | f52e6a1 | 2020-09-28 14:47:54 +0100 | [diff] [blame] | 228 | ptr = (uint8_t *)((uintptr_t)ptr + sizeof(locality_event_header)); |
Alexei Fedorov | 71d81dc | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 229 | |
| 230 | /* TCG_PCR_EVENT2.Digests[].AlgorithmId */ |
| 231 | ((tpmt_ha *)ptr)->algorithm_id = TPM_ALG_ID; |
| 232 | |
| 233 | /* TCG_PCR_EVENT2.Digests[].Digest[] */ |
Manish V Badarkhe | 6e83676 | 2022-06-09 22:39:32 +0100 | [diff] [blame] | 234 | (void)memset(&((tpmt_ha *)ptr)->digest, 0, TCG_DIGEST_SIZE); |
Alexei Fedorov | f52e6a1 | 2020-09-28 14:47:54 +0100 | [diff] [blame] | 235 | ptr = (uint8_t *)((uintptr_t)ptr + |
| 236 | offsetof(tpmt_ha, digest) + TCG_DIGEST_SIZE); |
Alexei Fedorov | 71d81dc | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 237 | |
| 238 | /* TCG_PCR_EVENT2.EventSize */ |
| 239 | ((event2_data_t *)ptr)->event_size = |
| 240 | (uint32_t)sizeof(startup_locality_event_t); |
Alexei Fedorov | f52e6a1 | 2020-09-28 14:47:54 +0100 | [diff] [blame] | 241 | ptr = (uint8_t *)((uintptr_t)ptr + offsetof(event2_data_t, event)); |
Alexei Fedorov | 71d81dc | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 242 | |
| 243 | /* TCG_EfiStartupLocalityEvent.Signature */ |
| 244 | (void)memcpy(ptr, (const void *)locality_signature, |
| 245 | sizeof(TCG_STARTUP_LOCALITY_SIGNATURE)); |
| 246 | |
| 247 | /* |
| 248 | * TCG_EfiStartupLocalityEvent.StartupLocality = 0: |
| 249 | * the platform's boot firmware |
| 250 | */ |
| 251 | ((startup_locality_event_t *)ptr)->startup_locality = 0U; |
Manish V Badarkhe | 7ca9d65 | 2021-09-14 22:41:46 +0100 | [diff] [blame] | 252 | log_ptr = (uint8_t *)((uintptr_t)ptr + sizeof(startup_locality_event_t)); |
Alexei Fedorov | 71d81dc | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 253 | } |
| 254 | |
Manish V Badarkhe | 5a9eaa7 | 2022-06-15 15:06:43 +0100 | [diff] [blame] | 255 | int event_log_measure(uintptr_t data_base, uint32_t data_size, |
| 256 | unsigned char hash_data[CRYPTO_MD_MAX_SIZE]) |
| 257 | { |
| 258 | /* Calculate hash */ |
| 259 | return crypto_mod_calc_hash(CRYPTO_MD_ID, |
| 260 | (void *)data_base, data_size, hash_data); |
| 261 | } |
| 262 | |
Alexei Fedorov | 71d81dc | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 263 | /* |
| 264 | * Calculate and write hash of image, configuration data, etc. |
| 265 | * to Event Log. |
| 266 | * |
| 267 | * @param[in] data_base Address of data |
| 268 | * @param[in] data_size Size of data |
| 269 | * @param[in] data_id Data ID |
Manish V Badarkhe | ad44e8b | 2022-11-18 18:30:08 +0000 | [diff] [blame] | 270 | * @param[in] metadata_ptr Event Log metadata |
Alexei Fedorov | 71d81dc | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 271 | * @return: |
| 272 | * 0 = success |
| 273 | * < 0 = error |
| 274 | */ |
Sandrine Bailleux | 4e9af17 | 2021-07-01 14:13:09 +0200 | [diff] [blame] | 275 | int event_log_measure_and_record(uintptr_t data_base, uint32_t data_size, |
Manish V Badarkhe | ad44e8b | 2022-11-18 18:30:08 +0000 | [diff] [blame] | 276 | uint32_t data_id, |
| 277 | const event_log_metadata_t *metadata_ptr) |
Alexei Fedorov | 71d81dc | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 278 | { |
Manish V Badarkhe | e112a5a | 2021-10-06 23:41:50 +0100 | [diff] [blame] | 279 | unsigned char hash_data[CRYPTO_MD_MAX_SIZE]; |
Alexei Fedorov | 71d81dc | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 280 | int rc; |
Manish V Badarkhe | ad44e8b | 2022-11-18 18:30:08 +0000 | [diff] [blame] | 281 | |
| 282 | assert(metadata_ptr != NULL); |
Alexei Fedorov | 71d81dc | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 283 | |
Sandrine Bailleux | 74b8e17 | 2021-06-23 15:44:18 +0200 | [diff] [blame] | 284 | /* Get the metadata associated with this image. */ |
Manish V Badarkhe | 67009c3 | 2021-10-31 14:47:49 +0000 | [diff] [blame] | 285 | while ((metadata_ptr->id != EVLOG_INVALID_ID) && |
Manish V Badarkhe | 7ca9d65 | 2021-09-14 22:41:46 +0100 | [diff] [blame] | 286 | (metadata_ptr->id != data_id)) { |
| 287 | metadata_ptr++; |
Alexei Fedorov | 71d81dc | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 288 | } |
Manish V Badarkhe | 67009c3 | 2021-10-31 14:47:49 +0000 | [diff] [blame] | 289 | assert(metadata_ptr->id != EVLOG_INVALID_ID); |
Alexei Fedorov | 71d81dc | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 290 | |
Manish V Badarkhe | 5a9eaa7 | 2022-06-15 15:06:43 +0100 | [diff] [blame] | 291 | /* Measure the payload with algorithm selected by EventLog driver */ |
| 292 | rc = event_log_measure(data_base, data_size, hash_data); |
Alexei Fedorov | 71d81dc | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 293 | if (rc != 0) { |
| 294 | return rc; |
| 295 | } |
| 296 | |
Manish V Badarkhe | 5a9eaa7 | 2022-06-15 15:06:43 +0100 | [diff] [blame] | 297 | event_log_record(hash_data, EV_POST_CODE, metadata_ptr); |
Sandrine Bailleux | 36af1c8 | 2021-06-17 15:44:40 +0200 | [diff] [blame] | 298 | |
Sandrine Bailleux | 9ebe81e | 2021-06-23 15:43:02 +0200 | [diff] [blame] | 299 | return 0; |
Alexei Fedorov | 71d81dc | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | /* |
Manish V Badarkhe | 7ca9d65 | 2021-09-14 22:41:46 +0100 | [diff] [blame] | 303 | * Get current Event Log buffer size i.e. used space of Event Log buffer |
Alexei Fedorov | 71d81dc | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 304 | * |
Manish V Badarkhe | 7ca9d65 | 2021-09-14 22:41:46 +0100 | [diff] [blame] | 305 | * @param[in] event_log_start Base Pointer to Event Log buffer |
| 306 | * |
| 307 | * @return: current Size of Event Log buffer |
Alexei Fedorov | 71d81dc | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 308 | */ |
Manish V Badarkhe | 7ca9d65 | 2021-09-14 22:41:46 +0100 | [diff] [blame] | 309 | size_t event_log_get_cur_size(uint8_t *event_log_start) |
Alexei Fedorov | 71d81dc | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 310 | { |
Manish V Badarkhe | 7ca9d65 | 2021-09-14 22:41:46 +0100 | [diff] [blame] | 311 | assert(event_log_start != NULL); |
| 312 | assert(log_ptr >= event_log_start); |
Alexei Fedorov | 71d81dc | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 313 | |
Manish V Badarkhe | 7ca9d65 | 2021-09-14 22:41:46 +0100 | [diff] [blame] | 314 | return (size_t)((uintptr_t)log_ptr - (uintptr_t)event_log_start); |
Alexei Fedorov | 71d81dc | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 315 | } |