rpi3_io_storage.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. /*
  2. * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <assert.h>
  7. #include <string.h>
  8. #include <platform_def.h>
  9. #include <common/bl_common.h>
  10. #include <common/debug.h>
  11. #include <drivers/io/io_driver.h>
  12. #include <drivers/io/io_fip.h>
  13. #include <drivers/io/io_memmap.h>
  14. #include <tools_share/firmware_image_package.h>
  15. /* Semihosting filenames */
  16. #define BL2_IMAGE_NAME "bl2.bin"
  17. #define BL31_IMAGE_NAME "bl31.bin"
  18. #define BL32_IMAGE_NAME "bl32.bin"
  19. #define BL33_IMAGE_NAME "bl33.bin"
  20. #if TRUSTED_BOARD_BOOT
  21. #define TRUSTED_BOOT_FW_CERT_NAME "tb_fw.crt"
  22. #define TRUSTED_KEY_CERT_NAME "trusted_key.crt"
  23. #define SOC_FW_KEY_CERT_NAME "soc_fw_key.crt"
  24. #define TOS_FW_KEY_CERT_NAME "tos_fw_key.crt"
  25. #define NT_FW_KEY_CERT_NAME "nt_fw_key.crt"
  26. #define SOC_FW_CONTENT_CERT_NAME "soc_fw_content.crt"
  27. #define TOS_FW_CONTENT_CERT_NAME "tos_fw_content.crt"
  28. #define NT_FW_CONTENT_CERT_NAME "nt_fw_content.crt"
  29. #endif /* TRUSTED_BOARD_BOOT */
  30. /* IO devices */
  31. static const io_dev_connector_t *fip_dev_con;
  32. static uintptr_t fip_dev_handle;
  33. static const io_dev_connector_t *memmap_dev_con;
  34. static uintptr_t memmap_dev_handle;
  35. static const io_block_spec_t fip_block_spec = {
  36. .offset = PLAT_RPI3_FIP_BASE,
  37. .length = PLAT_RPI3_FIP_MAX_SIZE
  38. };
  39. static const io_uuid_spec_t bl2_uuid_spec = {
  40. .uuid = UUID_TRUSTED_BOOT_FIRMWARE_BL2,
  41. };
  42. static const io_uuid_spec_t bl31_uuid_spec = {
  43. .uuid = UUID_EL3_RUNTIME_FIRMWARE_BL31,
  44. };
  45. static const io_uuid_spec_t bl32_uuid_spec = {
  46. .uuid = UUID_SECURE_PAYLOAD_BL32,
  47. };
  48. static const io_uuid_spec_t bl32_extra1_uuid_spec = {
  49. .uuid = UUID_SECURE_PAYLOAD_BL32_EXTRA1,
  50. };
  51. static const io_uuid_spec_t bl32_extra2_uuid_spec = {
  52. .uuid = UUID_SECURE_PAYLOAD_BL32_EXTRA2,
  53. };
  54. static const io_uuid_spec_t bl33_uuid_spec = {
  55. .uuid = UUID_NON_TRUSTED_FIRMWARE_BL33,
  56. };
  57. #if TRUSTED_BOARD_BOOT
  58. static const io_uuid_spec_t tb_fw_cert_uuid_spec = {
  59. .uuid = UUID_TRUSTED_BOOT_FW_CERT,
  60. };
  61. static const io_uuid_spec_t trusted_key_cert_uuid_spec = {
  62. .uuid = UUID_TRUSTED_KEY_CERT,
  63. };
  64. static const io_uuid_spec_t soc_fw_key_cert_uuid_spec = {
  65. .uuid = UUID_SOC_FW_KEY_CERT,
  66. };
  67. static const io_uuid_spec_t tos_fw_key_cert_uuid_spec = {
  68. .uuid = UUID_TRUSTED_OS_FW_KEY_CERT,
  69. };
  70. static const io_uuid_spec_t nt_fw_key_cert_uuid_spec = {
  71. .uuid = UUID_NON_TRUSTED_FW_KEY_CERT,
  72. };
  73. static const io_uuid_spec_t soc_fw_cert_uuid_spec = {
  74. .uuid = UUID_SOC_FW_CONTENT_CERT,
  75. };
  76. static const io_uuid_spec_t tos_fw_cert_uuid_spec = {
  77. .uuid = UUID_TRUSTED_OS_FW_CONTENT_CERT,
  78. };
  79. static const io_uuid_spec_t nt_fw_cert_uuid_spec = {
  80. .uuid = UUID_NON_TRUSTED_FW_CONTENT_CERT,
  81. };
  82. #endif /* TRUSTED_BOARD_BOOT */
  83. static int open_fip(const uintptr_t spec);
  84. static int open_memmap(const uintptr_t spec);
  85. struct plat_io_policy {
  86. uintptr_t *dev_handle;
  87. uintptr_t image_spec;
  88. int (*check)(const uintptr_t spec);
  89. };
  90. /* By default, load images from the FIP */
  91. static const struct plat_io_policy policies[] = {
  92. [FIP_IMAGE_ID] = {
  93. &memmap_dev_handle,
  94. (uintptr_t)&fip_block_spec,
  95. open_memmap
  96. },
  97. [BL2_IMAGE_ID] = {
  98. &fip_dev_handle,
  99. (uintptr_t)&bl2_uuid_spec,
  100. open_fip
  101. },
  102. [BL31_IMAGE_ID] = {
  103. &fip_dev_handle,
  104. (uintptr_t)&bl31_uuid_spec,
  105. open_fip
  106. },
  107. [BL32_IMAGE_ID] = {
  108. &fip_dev_handle,
  109. (uintptr_t)&bl32_uuid_spec,
  110. open_fip
  111. },
  112. [BL32_EXTRA1_IMAGE_ID] = {
  113. &fip_dev_handle,
  114. (uintptr_t)&bl32_extra1_uuid_spec,
  115. open_fip
  116. },
  117. [BL32_EXTRA2_IMAGE_ID] = {
  118. &fip_dev_handle,
  119. (uintptr_t)&bl32_extra2_uuid_spec,
  120. open_fip
  121. },
  122. [BL33_IMAGE_ID] = {
  123. &fip_dev_handle,
  124. (uintptr_t)&bl33_uuid_spec,
  125. open_fip
  126. },
  127. #if TRUSTED_BOARD_BOOT
  128. [TRUSTED_BOOT_FW_CERT_ID] = {
  129. &fip_dev_handle,
  130. (uintptr_t)&tb_fw_cert_uuid_spec,
  131. open_fip
  132. },
  133. [TRUSTED_KEY_CERT_ID] = {
  134. &fip_dev_handle,
  135. (uintptr_t)&trusted_key_cert_uuid_spec,
  136. open_fip
  137. },
  138. [SOC_FW_KEY_CERT_ID] = {
  139. &fip_dev_handle,
  140. (uintptr_t)&soc_fw_key_cert_uuid_spec,
  141. open_fip
  142. },
  143. [TRUSTED_OS_FW_KEY_CERT_ID] = {
  144. &fip_dev_handle,
  145. (uintptr_t)&tos_fw_key_cert_uuid_spec,
  146. open_fip
  147. },
  148. [NON_TRUSTED_FW_KEY_CERT_ID] = {
  149. &fip_dev_handle,
  150. (uintptr_t)&nt_fw_key_cert_uuid_spec,
  151. open_fip
  152. },
  153. [SOC_FW_CONTENT_CERT_ID] = {
  154. &fip_dev_handle,
  155. (uintptr_t)&soc_fw_cert_uuid_spec,
  156. open_fip
  157. },
  158. [TRUSTED_OS_FW_CONTENT_CERT_ID] = {
  159. &fip_dev_handle,
  160. (uintptr_t)&tos_fw_cert_uuid_spec,
  161. open_fip
  162. },
  163. [NON_TRUSTED_FW_CONTENT_CERT_ID] = {
  164. &fip_dev_handle,
  165. (uintptr_t)&nt_fw_cert_uuid_spec,
  166. open_fip
  167. },
  168. #endif /* TRUSTED_BOARD_BOOT */
  169. };
  170. static int open_fip(const uintptr_t spec)
  171. {
  172. int result;
  173. uintptr_t local_image_handle;
  174. /* See if a Firmware Image Package is available */
  175. result = io_dev_init(fip_dev_handle, (uintptr_t)FIP_IMAGE_ID);
  176. if (result == 0) {
  177. result = io_open(fip_dev_handle, spec, &local_image_handle);
  178. if (result == 0) {
  179. VERBOSE("Using FIP\n");
  180. io_close(local_image_handle);
  181. }
  182. }
  183. return result;
  184. }
  185. static int open_memmap(const uintptr_t spec)
  186. {
  187. int result;
  188. uintptr_t local_image_handle;
  189. result = io_dev_init(memmap_dev_handle, (uintptr_t)NULL);
  190. if (result == 0) {
  191. result = io_open(memmap_dev_handle, spec, &local_image_handle);
  192. if (result == 0) {
  193. VERBOSE("Using Memmap\n");
  194. io_close(local_image_handle);
  195. }
  196. }
  197. return result;
  198. }
  199. void plat_rpi3_io_setup(void)
  200. {
  201. int io_result;
  202. io_result = register_io_dev_fip(&fip_dev_con);
  203. assert(io_result == 0);
  204. io_result = register_io_dev_memmap(&memmap_dev_con);
  205. assert(io_result == 0);
  206. /* Open connections to devices and cache the handles */
  207. io_result = io_dev_open(fip_dev_con, (uintptr_t)NULL,
  208. &fip_dev_handle);
  209. assert(io_result == 0);
  210. io_result = io_dev_open(memmap_dev_con, (uintptr_t)NULL,
  211. &memmap_dev_handle);
  212. assert(io_result == 0);
  213. /* Ignore improbable errors in release builds */
  214. (void)io_result;
  215. }
  216. /*
  217. * Return an IO device handle and specification which can be used to access
  218. * an image. Use this to enforce platform load policy
  219. */
  220. int plat_get_image_source(unsigned int image_id, uintptr_t *dev_handle,
  221. uintptr_t *image_spec)
  222. {
  223. int result;
  224. const struct plat_io_policy *policy;
  225. assert(image_id < ARRAY_SIZE(policies));
  226. policy = &policies[image_id];
  227. result = policy->check(policy->image_spec);
  228. if (result == 0) {
  229. *image_spec = policy->image_spec;
  230. *dev_handle = *(policy->dev_handle);
  231. }
  232. return result;
  233. }