fvp_io_storage.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*
  2. * Copyright (c) 2014-2020, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <assert.h>
  7. #include <common/debug.h>
  8. #include <drivers/io/io_driver.h>
  9. #include <drivers/io/io_semihosting.h>
  10. #include <drivers/io/io_storage.h>
  11. #include <lib/semihosting.h>
  12. #include <plat/arm/common/plat_arm.h>
  13. #include <plat/common/common_def.h>
  14. /* Semihosting filenames */
  15. #define BL2_IMAGE_NAME "bl2.bin"
  16. #define BL31_IMAGE_NAME "bl31.bin"
  17. #define BL32_IMAGE_NAME "bl32.bin"
  18. #define BL33_IMAGE_NAME "bl33.bin"
  19. #define TB_FW_CONFIG_NAME "fvp_tb_fw_config.dtb"
  20. #define SOC_FW_CONFIG_NAME "fvp_soc_fw_config.dtb"
  21. #define TOS_FW_CONFIG_NAME "fvp_tsp_fw_config.dtb"
  22. #define NT_FW_CONFIG_NAME "fvp_nt_fw_config.dtb"
  23. #define FW_CONFIG_NAME "fvp_fw_config.dtb"
  24. #define HW_CONFIG_NAME "hw_config.dtb"
  25. #if TRUSTED_BOARD_BOOT
  26. #define TRUSTED_BOOT_FW_CERT_NAME "tb_fw.crt"
  27. #define TRUSTED_KEY_CERT_NAME "trusted_key.crt"
  28. #define SOC_FW_KEY_CERT_NAME "soc_fw_key.crt"
  29. #define TOS_FW_KEY_CERT_NAME "tos_fw_key.crt"
  30. #define NT_FW_KEY_CERT_NAME "nt_fw_key.crt"
  31. #define SOC_FW_CONTENT_CERT_NAME "soc_fw_content.crt"
  32. #define TOS_FW_CONTENT_CERT_NAME "tos_fw_content.crt"
  33. #define NT_FW_CONTENT_CERT_NAME "nt_fw_content.crt"
  34. #endif /* TRUSTED_BOARD_BOOT */
  35. /* IO devices */
  36. static const io_dev_connector_t *sh_dev_con;
  37. static uintptr_t sh_dev_handle;
  38. static const io_file_spec_t sh_file_spec[] = {
  39. [BL2_IMAGE_ID] = {
  40. .path = BL2_IMAGE_NAME,
  41. .mode = FOPEN_MODE_RB
  42. },
  43. [BL31_IMAGE_ID] = {
  44. .path = BL31_IMAGE_NAME,
  45. .mode = FOPEN_MODE_RB
  46. },
  47. [BL32_IMAGE_ID] = {
  48. .path = BL32_IMAGE_NAME,
  49. .mode = FOPEN_MODE_RB
  50. },
  51. [BL33_IMAGE_ID] = {
  52. .path = BL33_IMAGE_NAME,
  53. .mode = FOPEN_MODE_RB
  54. },
  55. [TB_FW_CONFIG_ID] = {
  56. .path = TB_FW_CONFIG_NAME,
  57. .mode = FOPEN_MODE_RB
  58. },
  59. [SOC_FW_CONFIG_ID] = {
  60. .path = SOC_FW_CONFIG_NAME,
  61. .mode = FOPEN_MODE_RB
  62. },
  63. [TOS_FW_CONFIG_ID] = {
  64. .path = TOS_FW_CONFIG_NAME,
  65. .mode = FOPEN_MODE_RB
  66. },
  67. [NT_FW_CONFIG_ID] = {
  68. .path = NT_FW_CONFIG_NAME,
  69. .mode = FOPEN_MODE_RB
  70. },
  71. [FW_CONFIG_ID] = {
  72. .path = FW_CONFIG_NAME,
  73. .mode = FOPEN_MODE_RB
  74. },
  75. [HW_CONFIG_ID] = {
  76. .path = HW_CONFIG_NAME,
  77. .mode = FOPEN_MODE_RB
  78. },
  79. #if TRUSTED_BOARD_BOOT
  80. [TRUSTED_BOOT_FW_CERT_ID] = {
  81. .path = TRUSTED_BOOT_FW_CERT_NAME,
  82. .mode = FOPEN_MODE_RB
  83. },
  84. [TRUSTED_KEY_CERT_ID] = {
  85. .path = TRUSTED_KEY_CERT_NAME,
  86. .mode = FOPEN_MODE_RB
  87. },
  88. [SOC_FW_KEY_CERT_ID] = {
  89. .path = SOC_FW_KEY_CERT_NAME,
  90. .mode = FOPEN_MODE_RB
  91. },
  92. [TRUSTED_OS_FW_KEY_CERT_ID] = {
  93. .path = TOS_FW_KEY_CERT_NAME,
  94. .mode = FOPEN_MODE_RB
  95. },
  96. [NON_TRUSTED_FW_KEY_CERT_ID] = {
  97. .path = NT_FW_KEY_CERT_NAME,
  98. .mode = FOPEN_MODE_RB
  99. },
  100. [SOC_FW_CONTENT_CERT_ID] = {
  101. .path = SOC_FW_CONTENT_CERT_NAME,
  102. .mode = FOPEN_MODE_RB
  103. },
  104. [TRUSTED_OS_FW_CONTENT_CERT_ID] = {
  105. .path = TOS_FW_CONTENT_CERT_NAME,
  106. .mode = FOPEN_MODE_RB
  107. },
  108. [NON_TRUSTED_FW_CONTENT_CERT_ID] = {
  109. .path = NT_FW_CONTENT_CERT_NAME,
  110. .mode = FOPEN_MODE_RB
  111. },
  112. #endif /* TRUSTED_BOARD_BOOT */
  113. };
  114. static int open_semihosting(const uintptr_t spec)
  115. {
  116. int result;
  117. uintptr_t local_image_handle;
  118. /* See if the file exists on semi-hosting.*/
  119. result = io_dev_init(sh_dev_handle, (uintptr_t)NULL);
  120. if (result == 0) {
  121. result = io_open(sh_dev_handle, spec, &local_image_handle);
  122. if (result == 0) {
  123. VERBOSE("Using Semi-hosting IO\n");
  124. io_close(local_image_handle);
  125. }
  126. }
  127. return result;
  128. }
  129. void plat_arm_io_setup(void)
  130. {
  131. int io_result;
  132. io_result = arm_io_setup();
  133. if (io_result < 0) {
  134. panic();
  135. }
  136. /* Register the additional IO devices on this platform */
  137. io_result = register_io_dev_sh(&sh_dev_con);
  138. if (io_result < 0) {
  139. panic();
  140. }
  141. /* Open connections to devices and cache the handles */
  142. io_result = io_dev_open(sh_dev_con, (uintptr_t)NULL, &sh_dev_handle);
  143. if (io_result < 0) {
  144. panic();
  145. }
  146. }
  147. /*
  148. * FVP provides semihosting as an alternative to load images
  149. */
  150. int plat_arm_get_alt_image_source(unsigned int image_id, uintptr_t *dev_handle,
  151. uintptr_t *image_spec)
  152. {
  153. int result = open_semihosting((const uintptr_t)&sh_file_spec[image_id]);
  154. if (result == 0) {
  155. *dev_handle = sh_dev_handle;
  156. *image_spec = (uintptr_t)&sh_file_spec[image_id];
  157. }
  158. return result;
  159. }