event_log.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Copyright (c) 2020-2024, Arm Limited. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #ifndef EVENT_LOG_H
  7. #define EVENT_LOG_H
  8. #include <stdint.h>
  9. #include <common/debug.h>
  10. #include <common/tbbr/tbbr_img_def.h>
  11. #include <drivers/auth/crypto_mod.h>
  12. #include <drivers/measured_boot/event_log/tcg.h>
  13. /*
  14. * Set Event Log debug level to one of:
  15. *
  16. * LOG_LEVEL_ERROR
  17. * LOG_LEVEL_INFO
  18. * LOG_LEVEL_WARNING
  19. * LOG_LEVEL_VERBOSE
  20. */
  21. #if EVENT_LOG_LEVEL == LOG_LEVEL_ERROR
  22. #define LOG_EVENT ERROR
  23. #elif EVENT_LOG_LEVEL == LOG_LEVEL_NOTICE
  24. #define LOG_EVENT NOTICE
  25. #elif EVENT_LOG_LEVEL == LOG_LEVEL_WARNING
  26. #define LOG_EVENT WARN
  27. #elif EVENT_LOG_LEVEL == LOG_LEVEL_INFO
  28. #define LOG_EVENT INFO
  29. #elif EVENT_LOG_LEVEL == LOG_LEVEL_VERBOSE
  30. #define LOG_EVENT VERBOSE
  31. #else
  32. #error "Not supported EVENT_LOG_LEVEL"
  33. #endif
  34. /* Number of hashing algorithms supported */
  35. #define HASH_ALG_COUNT 1U
  36. #define EVLOG_INVALID_ID UINT32_MAX
  37. #define MEMBER_SIZE(type, member) sizeof(((type *)0)->member)
  38. typedef struct {
  39. unsigned int id;
  40. const char *name;
  41. unsigned int pcr;
  42. } event_log_metadata_t;
  43. #define ID_EVENT_SIZE (sizeof(id_event_headers_t) + \
  44. (sizeof(id_event_algorithm_size_t) * HASH_ALG_COUNT) + \
  45. sizeof(id_event_struct_data_t))
  46. #define LOC_EVENT_SIZE (sizeof(event2_header_t) + \
  47. sizeof(tpmt_ha) + TCG_DIGEST_SIZE + \
  48. sizeof(event2_data_t) + \
  49. sizeof(startup_locality_event_t))
  50. #define LOG_MIN_SIZE (ID_EVENT_SIZE + LOC_EVENT_SIZE)
  51. #define EVENT2_HDR_SIZE (sizeof(event2_header_t) + \
  52. sizeof(tpmt_ha) + TCG_DIGEST_SIZE + \
  53. sizeof(event2_data_t))
  54. /* Functions' declarations */
  55. void event_log_buf_init(uint8_t *event_log_start, uint8_t *event_log_finish);
  56. void event_log_init(uint8_t *event_log_start, uint8_t *event_log_finish);
  57. void event_log_write_specid_event(void);
  58. void event_log_write_header(void);
  59. void dump_event_log(uint8_t *log_addr, size_t log_size);
  60. int event_log_measure(uintptr_t data_base, uint32_t data_size,
  61. unsigned char hash_data[CRYPTO_MD_MAX_SIZE]);
  62. void event_log_record(const uint8_t *hash, uint32_t event_type,
  63. const event_log_metadata_t *metadata_ptr);
  64. int event_log_measure_and_record(uintptr_t data_base, uint32_t data_size,
  65. uint32_t data_id,
  66. const event_log_metadata_t *metadata_ptr);
  67. size_t event_log_get_cur_size(uint8_t *event_log_start);
  68. #endif /* EVENT_LOG_H */