imx8m_measured_boot.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * Copyright (c) 2022-2024, Arm Limited. All rights reserved.
  3. * Copyright (c) 2022, Linaro.
  4. *
  5. * SPDX-License-Identifier: BSD-3-Clause
  6. */
  7. #include <string.h>
  8. #include "./include/imx8m_measured_boot.h"
  9. #include <drivers/measured_boot/event_log/event_log.h>
  10. #include <drivers/measured_boot/metadata.h>
  11. #include <plat/arm/common/plat_arm.h>
  12. /* Event Log data */
  13. static uint8_t event_log[PLAT_IMX_EVENT_LOG_MAX_SIZE];
  14. /* FVP table with platform specific image IDs, names and PCRs */
  15. static const event_log_metadata_t imx8m_event_log_metadata[] = {
  16. { BL31_IMAGE_ID, MBOOT_BL31_IMAGE_STRING, PCR_0 },
  17. { BL32_IMAGE_ID, MBOOT_BL32_IMAGE_STRING, PCR_0 },
  18. { BL32_EXTRA1_IMAGE_ID, MBOOT_BL32_EXTRA1_IMAGE_STRING, PCR_0 },
  19. { BL32_EXTRA2_IMAGE_ID, MBOOT_BL32_EXTRA2_IMAGE_STRING, PCR_0 },
  20. { BL33_IMAGE_ID, MBOOT_BL33_IMAGE_STRING, PCR_0 },
  21. { EVLOG_INVALID_ID, NULL, (unsigned int)(-1) } /* Terminator */
  22. };
  23. int plat_mboot_measure_image(unsigned int image_id, image_info_t *image_data)
  24. {
  25. /* Calculate image hash and record data in Event Log */
  26. int err = event_log_measure_and_record(image_data->image_base,
  27. image_data->image_size,
  28. image_id,
  29. imx8m_event_log_metadata);
  30. if (err != 0) {
  31. ERROR("%s%s image id %u (%i)\n",
  32. "Failed to ", "record", image_id, err);
  33. return err;
  34. }
  35. return 0;
  36. }
  37. void bl2_plat_mboot_init(void)
  38. {
  39. event_log_init(event_log, event_log + sizeof(event_log));
  40. event_log_write_header();
  41. }
  42. void bl2_plat_mboot_finish(void)
  43. {
  44. int rc = 0;
  45. /* Event Log address in Non-Secure memory */
  46. uintptr_t ns_log_addr;
  47. /* Event Log filled size */
  48. size_t event_log_cur_size;
  49. event_log_cur_size = event_log_get_cur_size(event_log);
  50. rc = imx8m_set_nt_fw_info(event_log_cur_size, &ns_log_addr);
  51. if (rc != 0) {
  52. ERROR("%s(): Unable to update %s_FW_CONFIG\n",
  53. __func__, "NT");
  54. /*
  55. * It is a fatal error because on i.MX U-boot assumes that
  56. * a valid event log exists and will use it to record the
  57. * measurements into the fTPM.
  58. */
  59. panic();
  60. }
  61. /* Copy Event Log to Non-secure memory */
  62. (void)memcpy((void *)ns_log_addr, (const void *)event_log,
  63. event_log_cur_size);
  64. /* Ensure that the Event Log is visible in Non-secure memory */
  65. flush_dcache_range(ns_log_addr, event_log_cur_size);
  66. dump_event_log((uint8_t *)event_log, event_log_cur_size);
  67. }
  68. int plat_mboot_measure_key(const void *pk_oid, const void *pk_ptr,
  69. size_t pk_len)
  70. {
  71. return 0;
  72. }