arm_image_load.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. * Copyright (c) 2016-2024, Arm Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <assert.h>
  7. #include <common/bl_common.h>
  8. #include <common/desc_image_load.h>
  9. #if defined(SPD_spmd)
  10. #include <plat/arm/common/fconf_arm_sp_getter.h>
  11. #endif
  12. #include <plat/arm/common/plat_arm.h>
  13. #include <plat/common/platform.h>
  14. #pragma weak plat_flush_next_bl_params
  15. #pragma weak plat_get_bl_image_load_info
  16. #pragma weak plat_get_next_bl_params
  17. #if TRANSFER_LIST
  18. static bl_params_t next_bl_params_cpy;
  19. #endif
  20. bl_params_t *next_bl_params_cpy_ptr;
  21. /*******************************************************************************
  22. * This function flushes the data structures so that they are visible
  23. * in memory for the next BL image.
  24. ******************************************************************************/
  25. void plat_flush_next_bl_params(void)
  26. {
  27. assert(next_bl_params_cpy_ptr != NULL);
  28. flush_bl_params_desc_args(bl_mem_params_desc_ptr,
  29. bl_mem_params_desc_num,
  30. next_bl_params_cpy_ptr);
  31. }
  32. #if defined(SPD_spmd) && BL2_ENABLE_SP_LOAD
  33. /*******************************************************************************
  34. * This function appends Secure Partitions to list of loadable images.
  35. ******************************************************************************/
  36. static void plat_add_sp_images_load_info(struct bl_load_info *load_info)
  37. {
  38. bl_load_info_node_t *curr_node = load_info->head;
  39. bl_load_info_node_t *prev_node;
  40. /* Shortcut for empty SP list */
  41. if (sp_mem_params_descs[0].image_id == 0) {
  42. ERROR("No Secure Partition Image available\n");
  43. return;
  44. }
  45. /* Traverse through the bl images list */
  46. do {
  47. curr_node = curr_node->next_load_info;
  48. } while (curr_node->next_load_info != NULL);
  49. prev_node = curr_node;
  50. for (unsigned int index = 0; index < MAX_SP_IDS; index++) {
  51. if (sp_mem_params_descs[index].image_id == 0) {
  52. return;
  53. }
  54. curr_node = &sp_mem_params_descs[index].load_node_mem;
  55. /* Populate the image information */
  56. curr_node->image_id = sp_mem_params_descs[index].image_id;
  57. curr_node->image_info = &sp_mem_params_descs[index].image_info;
  58. prev_node->next_load_info = curr_node;
  59. prev_node = curr_node;
  60. }
  61. INFO("Reached Max number of SPs\n");
  62. }
  63. #endif
  64. /*******************************************************************************
  65. * This function returns the list of loadable images.
  66. ******************************************************************************/
  67. struct bl_load_info *plat_get_bl_image_load_info(void)
  68. {
  69. #if defined(SPD_spmd) && BL2_ENABLE_SP_LOAD
  70. bl_load_info_t *bl_load_info;
  71. bl_load_info = get_bl_load_info_from_mem_params_desc();
  72. plat_add_sp_images_load_info(bl_load_info);
  73. return bl_load_info;
  74. #else
  75. return get_bl_load_info_from_mem_params_desc();
  76. #endif
  77. }
  78. /*******************************************************************************
  79. * ARM helper function to return the list of executable images.Since the default
  80. * descriptors are allocated within BL2 RW memory, this prevents BL31/BL32
  81. * overlay of BL2 memory. Hence this function also copies the descriptors to a
  82. * pre-allocated memory indicated by ARM_BL2_MEM_DESC_BASE.
  83. ******************************************************************************/
  84. struct bl_params *arm_get_next_bl_params(void)
  85. {
  86. bl_mem_params_node_t *bl2_mem_params_descs_cpy __unused;
  87. const bl_params_t *next_bl_params __unused;
  88. #if TRANSFER_LIST
  89. next_bl_params_cpy_ptr = &next_bl_params_cpy;
  90. SET_PARAM_HEAD(next_bl_params_cpy_ptr, PARAM_BL_PARAMS, VERSION_2, 0U);
  91. #else
  92. bl2_mem_params_descs_cpy =
  93. (bl_mem_params_node_t *)ARM_BL2_MEM_DESC_BASE;
  94. next_bl_params_cpy_ptr =
  95. (bl_params_t *)(ARM_BL2_MEM_DESC_BASE +
  96. (bl_mem_params_desc_num * sizeof(bl_mem_params_node_t)));
  97. /*
  98. * Copy the memory descriptors to ARM_BL2_MEM_DESC_BASE area.
  99. */
  100. (void) memcpy(bl2_mem_params_descs_cpy, bl_mem_params_desc_ptr,
  101. (bl_mem_params_desc_num * sizeof(bl_mem_params_node_t)));
  102. /*
  103. * Modify the global 'bl_mem_params_desc_ptr' to point to the
  104. * copied location.
  105. */
  106. bl_mem_params_desc_ptr = bl2_mem_params_descs_cpy;
  107. next_bl_params = get_next_bl_params_from_mem_params_desc();
  108. assert(next_bl_params != NULL);
  109. /*
  110. * Copy 'next_bl_params' to the reserved location after the copied
  111. * memory descriptors.
  112. */
  113. (void) memcpy(next_bl_params_cpy_ptr, next_bl_params,
  114. (sizeof(bl_params_t)));
  115. populate_next_bl_params_config(next_bl_params_cpy_ptr);
  116. #endif /* TRANSFER_LIST */
  117. return next_bl_params_cpy_ptr;
  118. }
  119. /*******************************************************************************
  120. * This function returns the list of executable images
  121. ******************************************************************************/
  122. struct bl_params *plat_get_next_bl_params(void)
  123. {
  124. return arm_get_next_bl_params();
  125. }