plat_bl1_common.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * Copyright (c) 2015-2024, Arm Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <assert.h>
  7. #include <errno.h>
  8. #include <platform_def.h>
  9. #include <arch_helpers.h>
  10. #include <bl1/bl1.h>
  11. #include <common/bl_common.h>
  12. #include <common/debug.h>
  13. #include <plat/common/platform.h>
  14. /*
  15. * The following platform functions are weakly defined. They
  16. * are default implementations that allow BL1 to compile in
  17. * absence of real definitions. The Platforms may override
  18. * with more complex definitions.
  19. */
  20. #pragma weak bl1_plat_get_next_image_id
  21. #pragma weak bl1_plat_set_ep_info
  22. #pragma weak bl1_plat_get_image_desc
  23. #pragma weak bl1_plat_fwu_done
  24. #pragma weak bl1_plat_handle_pre_image_load
  25. #pragma weak bl1_plat_handle_post_image_load
  26. unsigned int bl1_plat_get_next_image_id(void)
  27. {
  28. /* BL2 load will be done by default. */
  29. return BL2_IMAGE_ID;
  30. }
  31. void bl1_plat_set_ep_info(unsigned int image_id,
  32. struct entry_point_info *ep_info)
  33. {
  34. }
  35. int bl1_plat_handle_pre_image_load(unsigned int image_id)
  36. {
  37. return 0;
  38. }
  39. /*
  40. * Following is the default definition that always
  41. * returns BL2 image details.
  42. */
  43. struct image_desc *bl1_plat_get_image_desc(unsigned int image_id)
  44. {
  45. static image_desc_t bl2_img_desc = BL2_IMAGE_DESC;
  46. return &bl2_img_desc;
  47. }
  48. __dead2 void bl1_plat_fwu_done(void *client_cookie, void *reserved)
  49. {
  50. while (true)
  51. wfi();
  52. }
  53. /*
  54. * The Platforms must override with real definition.
  55. */
  56. #pragma weak bl1_plat_mem_check
  57. int bl1_plat_mem_check(uintptr_t mem_base, unsigned int mem_size,
  58. unsigned int flags)
  59. {
  60. assert(0);
  61. return -ENOMEM;
  62. }
  63. /*
  64. * Default implementation for bl1_plat_handle_post_image_load(). This function
  65. * populates the default arguments to BL2. The BL2 memory layout structure
  66. * is allocated and the calculated layout is populated in arg1 to BL2.
  67. */
  68. int bl1_plat_handle_post_image_load(unsigned int image_id)
  69. {
  70. meminfo_t *bl1_tzram_layout;
  71. image_desc_t *image_desc;
  72. if (image_id != BL2_IMAGE_ID)
  73. return 0;
  74. /* Get the image descriptor */
  75. image_desc = bl1_plat_get_image_desc(BL2_IMAGE_ID);
  76. assert(image_desc != NULL);
  77. /* Find out how much free trusted ram remains after BL1 load */
  78. bl1_tzram_layout = bl1_plat_sec_mem_layout();
  79. /*
  80. * Convey this information to BL2 by storing the layout at the first free
  81. * address visible to BL2.
  82. */
  83. bl1_plat_calc_bl2_layout(bl1_tzram_layout,
  84. (meminfo_t *)bl1_tzram_layout->total_base);
  85. image_desc->ep_info.args.arg1 = (uintptr_t)bl1_tzram_layout->total_base;
  86. VERBOSE("BL1: BL2 memory layout address = %p\n",
  87. (void *)image_desc->ep_info.args.arg1);
  88. return 0;
  89. }
  90. /*******************************************************************************
  91. * Helper utility to calculate the BL2 memory layout taking into consideration
  92. * the BL1 RW data assuming that it is at the top of the memory layout.
  93. ******************************************************************************/
  94. void bl1_plat_calc_bl2_layout(const meminfo_t *bl1_mem_layout,
  95. meminfo_t *bl2_mem_layout)
  96. {
  97. assert(bl1_mem_layout != NULL);
  98. assert(bl2_mem_layout != NULL);
  99. /*
  100. * Remove BL1 RW data from the scope of memory visible to BL2.
  101. * This is assuming BL1 RW data is at the top of bl1_mem_layout.
  102. */
  103. assert(BL1_RW_BASE > bl1_mem_layout->total_base);
  104. bl2_mem_layout->total_base = bl1_mem_layout->total_base;
  105. bl2_mem_layout->total_size = BL1_RW_BASE - bl1_mem_layout->total_base;
  106. flush_dcache_range((uintptr_t)bl2_mem_layout, sizeof(meminfo_t));
  107. }