stm32mp_fconf_io.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /*
  2. * Copyright (c) 2021-2024, STMicroelectronics - All Rights Reserved
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <assert.h>
  7. #include <common/debug.h>
  8. #include <common/fdt_wrappers.h>
  9. #include <drivers/io/io_storage.h>
  10. #include <drivers/mmc.h>
  11. #include <lib/fconf/fconf.h>
  12. #include <lib/object_pool.h>
  13. #include <libfdt.h>
  14. #include <tools_share/firmware_image_package.h>
  15. #include <platform_def.h>
  16. #include <stm32mp_efi.h>
  17. #include <stm32mp_fconf_getter.h>
  18. #include <stm32mp_io_storage.h>
  19. #if STM32MP_SDMMC || STM32MP_EMMC
  20. static io_block_spec_t gpt_block_spec = {
  21. .offset = 0U,
  22. .length = 34U * MMC_BLOCK_SIZE, /* Size of GPT table */
  23. };
  24. #endif
  25. #if PSA_FWU_SUPPORT
  26. static io_block_spec_t metadata_block_spec = {
  27. .offset = 0, /* To be filled at runtime */
  28. .length = 0, /* To be filled at runtime */
  29. };
  30. #endif /* PSA_FWU_SUPPORT */
  31. /* By default, STM32 platforms load images from the FIP */
  32. struct plat_io_policy policies[MAX_NUMBER_IDS] = {
  33. [FIP_IMAGE_ID] = {
  34. .dev_handle = &storage_dev_handle,
  35. .image_spec = (uintptr_t)&image_block_spec,
  36. .img_type_guid = STM32MP_FIP_GUID,
  37. .check = open_storage
  38. },
  39. #ifndef DECRYPTION_SUPPORT_none
  40. [ENC_IMAGE_ID] = {
  41. .dev_handle = &fip_dev_handle,
  42. .image_spec = (uintptr_t)NULL,
  43. .img_type_guid = NULL_GUID,
  44. .check = open_fip
  45. },
  46. #endif
  47. #if STM32MP_SDMMC || STM32MP_EMMC
  48. [GPT_IMAGE_ID] = {
  49. .dev_handle = &storage_dev_handle,
  50. .image_spec = (uintptr_t)&gpt_block_spec,
  51. .img_type_guid = NULL_GUID,
  52. .check = open_storage
  53. },
  54. #endif
  55. #if PSA_FWU_SUPPORT
  56. [FWU_METADATA_IMAGE_ID] = {
  57. .dev_handle = &storage_dev_handle,
  58. .image_spec = (uintptr_t)&metadata_block_spec,
  59. .img_type_guid = NULL_GUID,
  60. .check = open_storage
  61. },
  62. [BKUP_FWU_METADATA_IMAGE_ID] = {
  63. .dev_handle = &storage_dev_handle,
  64. .image_spec = (uintptr_t)&metadata_block_spec,
  65. .img_type_guid = NULL_GUID,
  66. .check = open_storage
  67. },
  68. #endif /* PSA_FWU_SUPPORT */
  69. };
  70. #define DEFAULT_UUID_NUMBER U(7)
  71. #ifdef __aarch64__
  72. #define BL31_UUID_NUMBER U(2)
  73. #else
  74. #define BL31_UUID_NUMBER U(0)
  75. #endif
  76. #if TRUSTED_BOARD_BOOT
  77. #define TBBR_UUID_NUMBER U(6)
  78. #else
  79. #define TBBR_UUID_NUMBER U(0)
  80. #endif
  81. #if STM32MP_DDR_FIP_IO_STORAGE
  82. #define DDR_FW_UUID_NUMBER U(1)
  83. #else
  84. #define DDR_FW_UUID_NUMBER U(0)
  85. #endif
  86. #define FCONF_ST_IO_UUID_NUMBER (DEFAULT_UUID_NUMBER + \
  87. BL31_UUID_NUMBER + \
  88. TBBR_UUID_NUMBER + \
  89. DDR_FW_UUID_NUMBER)
  90. static io_uuid_spec_t fconf_stm32mp_uuids[FCONF_ST_IO_UUID_NUMBER];
  91. static OBJECT_POOL_ARRAY(fconf_stm32mp_uuids_pool, fconf_stm32mp_uuids);
  92. struct policies_load_info {
  93. unsigned int image_id;
  94. const char *name;
  95. };
  96. /* image id to property name table */
  97. static const struct policies_load_info load_info[FCONF_ST_IO_UUID_NUMBER] = {
  98. #if STM32MP_DDR_FIP_IO_STORAGE
  99. {DDR_FW_ID, "ddr_fw_uuid"},
  100. #endif
  101. {FW_CONFIG_ID, "fw_cfg_uuid"},
  102. #ifdef __aarch64__
  103. {BL31_IMAGE_ID, "bl31_uuid"},
  104. {SOC_FW_CONFIG_ID, "soc_fw_cfg_uuid"},
  105. #endif
  106. {BL32_IMAGE_ID, "bl32_uuid"},
  107. {BL32_EXTRA1_IMAGE_ID, "bl32_extra1_uuid"},
  108. {BL32_EXTRA2_IMAGE_ID, "bl32_extra2_uuid"},
  109. {BL33_IMAGE_ID, "bl33_uuid"},
  110. {HW_CONFIG_ID, "hw_cfg_uuid"},
  111. {TOS_FW_CONFIG_ID, "tos_fw_cfg_uuid"},
  112. #if TRUSTED_BOARD_BOOT
  113. {STM32MP_CONFIG_CERT_ID, "stm32mp_cfg_cert_uuid"},
  114. {TRUSTED_KEY_CERT_ID, "t_key_cert_uuid"},
  115. {TRUSTED_OS_FW_KEY_CERT_ID, "tos_fw_key_cert_uuid"},
  116. {NON_TRUSTED_FW_KEY_CERT_ID, "nt_fw_key_cert_uuid"},
  117. {TRUSTED_OS_FW_CONTENT_CERT_ID, "tos_fw_content_cert_uuid"},
  118. {NON_TRUSTED_FW_CONTENT_CERT_ID, "nt_fw_content_cert_uuid"},
  119. #endif /* TRUSTED_BOARD_BOOT */
  120. };
  121. int fconf_populate_stm32mp_io_policies(uintptr_t config)
  122. {
  123. int node;
  124. unsigned int i;
  125. /* As libfdt uses void *, we can't avoid this cast */
  126. const void *dtb = (void *)config;
  127. /* Assert the node offset point to "st,io-fip-handle" compatible property */
  128. const char *compatible_str = "st,io-fip-handle";
  129. node = fdt_node_offset_by_compatible(dtb, -1, compatible_str);
  130. if (node < 0) {
  131. ERROR("FCONF: Can't find %s compatible in dtb\n", compatible_str);
  132. return node;
  133. }
  134. /* Locate the uuid cells and read the value for all the load info uuid */
  135. for (i = 0U; i < FCONF_ST_IO_UUID_NUMBER; i++) {
  136. union uuid_helper_t uuid_helper;
  137. io_uuid_spec_t *uuid_ptr;
  138. int err;
  139. uuid_ptr = pool_alloc(&fconf_stm32mp_uuids_pool);
  140. err = fdtw_read_uuid(dtb, node, load_info[i].name, 16,
  141. (uint8_t *)&uuid_helper);
  142. if (err < 0) {
  143. WARN("FCONF: Read cell failed for %s\n", load_info[i].name);
  144. return err;
  145. }
  146. VERBOSE("FCONF: stm32mp-io_policies.%s cell found with value = "
  147. "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\n",
  148. load_info[i].name,
  149. uuid_helper.uuid_struct.time_low[0], uuid_helper.uuid_struct.time_low[1],
  150. uuid_helper.uuid_struct.time_low[2], uuid_helper.uuid_struct.time_low[3],
  151. uuid_helper.uuid_struct.time_mid[0], uuid_helper.uuid_struct.time_mid[1],
  152. uuid_helper.uuid_struct.time_hi_and_version[0],
  153. uuid_helper.uuid_struct.time_hi_and_version[1],
  154. uuid_helper.uuid_struct.clock_seq_hi_and_reserved,
  155. uuid_helper.uuid_struct.clock_seq_low,
  156. uuid_helper.uuid_struct.node[0], uuid_helper.uuid_struct.node[1],
  157. uuid_helper.uuid_struct.node[2], uuid_helper.uuid_struct.node[3],
  158. uuid_helper.uuid_struct.node[4], uuid_helper.uuid_struct.node[5]);
  159. uuid_ptr->uuid = uuid_helper.uuid_struct;
  160. policies[load_info[i].image_id].image_spec = (uintptr_t)uuid_ptr;
  161. switch (load_info[i].image_id) {
  162. #if ENCRYPT_BL32 && !defined(DECRYPTION_SUPPORT_none)
  163. case BL32_IMAGE_ID:
  164. case BL32_EXTRA1_IMAGE_ID:
  165. case BL32_EXTRA2_IMAGE_ID:
  166. policies[load_info[i].image_id].dev_handle = &enc_dev_handle;
  167. policies[load_info[i].image_id].check = open_enc_fip;
  168. break;
  169. #endif
  170. default:
  171. policies[load_info[i].image_id].dev_handle = &fip_dev_handle;
  172. policies[load_info[i].image_id].check = open_fip;
  173. break;
  174. }
  175. }
  176. return 0;
  177. }
  178. FCONF_REGISTER_POPULATOR(TB_FW, stm32mp_io, fconf_populate_stm32mp_io_policies);