fvp_r_io_storage.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * Copyright (c) 2021, 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 BL33_IMAGE_NAME "bl33.bin"
  16. #if TRUSTED_BOARD_BOOT
  17. #define TRUSTED_KEY_CERT_NAME "trusted_key.crt"
  18. #define NT_FW_KEY_CERT_NAME "nt_fw_key.crt"
  19. #define NT_FW_CONTENT_CERT_NAME "nt_fw_content.crt"
  20. #endif /* TRUSTED_BOARD_BOOT */
  21. /* IO devices */
  22. static const io_dev_connector_t *sh_dev_con;
  23. static uintptr_t sh_dev_handle;
  24. static const io_file_spec_t sh_file_spec[] = {
  25. [BL33_IMAGE_ID] = {
  26. .path = BL33_IMAGE_NAME,
  27. .mode = FOPEN_MODE_RB
  28. },
  29. #if TRUSTED_BOARD_BOOT
  30. [TRUSTED_KEY_CERT_ID] = {
  31. .path = TRUSTED_KEY_CERT_NAME,
  32. .mode = FOPEN_MODE_RB
  33. },
  34. [NON_TRUSTED_FW_KEY_CERT_ID] = {
  35. .path = NT_FW_KEY_CERT_NAME,
  36. .mode = FOPEN_MODE_RB
  37. },
  38. [NON_TRUSTED_FW_CONTENT_CERT_ID] = {
  39. .path = NT_FW_CONTENT_CERT_NAME,
  40. .mode = FOPEN_MODE_RB
  41. },
  42. #endif /* TRUSTED_BOARD_BOOT */
  43. };
  44. static int open_semihosting(const uintptr_t spec)
  45. {
  46. int result;
  47. uintptr_t local_image_handle;
  48. /* See if the file exists on semi-hosting.*/
  49. result = io_dev_init(sh_dev_handle, (uintptr_t)NULL);
  50. if (result == 0) {
  51. result = io_open(sh_dev_handle, spec, &local_image_handle);
  52. if (result == 0) {
  53. VERBOSE("Using Semi-hosting IO\n");
  54. io_close(local_image_handle);
  55. }
  56. }
  57. return result;
  58. }
  59. void plat_arm_io_setup(void)
  60. {
  61. int io_result;
  62. io_result = arm_io_setup();
  63. if (io_result < 0) {
  64. panic();
  65. }
  66. /* Register the additional IO devices on this platform */
  67. io_result = register_io_dev_sh(&sh_dev_con);
  68. if (io_result < 0) {
  69. panic();
  70. }
  71. /* Open connections to devices and cache the handles */
  72. io_result = io_dev_open(sh_dev_con, (uintptr_t)NULL, &sh_dev_handle);
  73. if (io_result < 0) {
  74. panic();
  75. }
  76. }
  77. /*
  78. * FVP_R provides semihosting as an alternative to load images
  79. */
  80. int plat_arm_get_alt_image_source(unsigned int image_id, uintptr_t *dev_handle,
  81. uintptr_t *image_spec)
  82. {
  83. int result = open_semihosting((const uintptr_t)&sh_file_spec[image_id]);
  84. if (result == 0) {
  85. *dev_handle = sh_dev_handle;
  86. *image_spec = (uintptr_t)&sh_file_spec[image_id];
  87. }
  88. return result;
  89. }