bl2_image_load_v2.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * Copyright (c) 2016-2022, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <assert.h>
  7. #include <stdint.h>
  8. #include <arch.h>
  9. #include <arch_helpers.h>
  10. #include "bl2_private.h"
  11. #include <common/bl_common.h>
  12. #include <common/debug.h>
  13. #include <common/desc_image_load.h>
  14. #include <drivers/auth/auth_mod.h>
  15. #include <plat/common/platform.h>
  16. #include <platform_def.h>
  17. /*******************************************************************************
  18. * This function loads SCP_BL2/BL3x images and returns the ep_info for
  19. * the next executable image.
  20. ******************************************************************************/
  21. struct entry_point_info *bl2_load_images(void)
  22. {
  23. bl_params_t *bl2_to_next_bl_params;
  24. bl_load_info_t *bl2_load_info;
  25. const bl_load_info_node_t *bl2_node_info;
  26. int plat_setup_done = 0;
  27. int err;
  28. /*
  29. * Get information about the images to load.
  30. */
  31. bl2_load_info = plat_get_bl_image_load_info();
  32. assert(bl2_load_info != NULL);
  33. assert(bl2_load_info->head != NULL);
  34. assert(bl2_load_info->h.type == PARAM_BL_LOAD_INFO);
  35. assert(bl2_load_info->h.version >= VERSION_2);
  36. bl2_node_info = bl2_load_info->head;
  37. while (bl2_node_info != NULL) {
  38. /*
  39. * Perform platform setup before loading the image,
  40. * if indicated in the image attributes AND if NOT
  41. * already done before.
  42. */
  43. if ((bl2_node_info->image_info->h.attr &
  44. IMAGE_ATTRIB_PLAT_SETUP) != 0U) {
  45. if (plat_setup_done != 0) {
  46. WARN("BL2: Platform setup already done!!\n");
  47. } else {
  48. INFO("BL2: Doing platform setup\n");
  49. bl2_platform_setup();
  50. plat_setup_done = 1;
  51. }
  52. }
  53. err = bl2_plat_handle_pre_image_load(bl2_node_info->image_id);
  54. if (err != 0) {
  55. ERROR("BL2: Failure in pre image load handling (%i)\n", err);
  56. plat_error_handler(err);
  57. }
  58. if ((bl2_node_info->image_info->h.attr &
  59. IMAGE_ATTRIB_SKIP_LOADING) == 0U) {
  60. INFO("BL2: Loading image id %u\n", bl2_node_info->image_id);
  61. err = load_auth_image(bl2_node_info->image_id,
  62. bl2_node_info->image_info);
  63. if (err != 0) {
  64. ERROR("BL2: Failed to load image id %u (%i)\n",
  65. bl2_node_info->image_id, err);
  66. plat_error_handler(err);
  67. }
  68. } else {
  69. INFO("BL2: Skip loading image id %u\n", bl2_node_info->image_id);
  70. }
  71. /* Allow platform to handle image information. */
  72. err = bl2_plat_handle_post_image_load(bl2_node_info->image_id);
  73. if (err != 0) {
  74. ERROR("BL2: Failure in post image load handling (%i)\n", err);
  75. plat_error_handler(err);
  76. }
  77. /* Go to next image */
  78. bl2_node_info = bl2_node_info->next_load_info;
  79. }
  80. /*
  81. * Get information to pass to the next image.
  82. */
  83. bl2_to_next_bl_params = plat_get_next_bl_params();
  84. assert(bl2_to_next_bl_params != NULL);
  85. assert(bl2_to_next_bl_params->head != NULL);
  86. assert(bl2_to_next_bl_params->h.type == PARAM_BL_PARAMS);
  87. assert(bl2_to_next_bl_params->h.version >= VERSION_2);
  88. assert(bl2_to_next_bl_params->head->ep_info != NULL);
  89. /* Populate arg0 for the next BL image if not already provided */
  90. if (bl2_to_next_bl_params->head->ep_info->args.arg0 == (u_register_t)0)
  91. bl2_to_next_bl_params->head->ep_info->args.arg0 =
  92. (u_register_t)bl2_to_next_bl_params;
  93. /* Flush the parameters to be passed to next image */
  94. plat_flush_next_bl_params();
  95. return bl2_to_next_bl_params->head->ep_info;
  96. }