fvp_r_bl1_setup.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. /*
  2. * Copyright (c) 2021-2024, Arm Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. /* Use the xlat_tables_v2 data structures: */
  7. #define XLAT_TABLES_LIB_V2 1
  8. #include <assert.h>
  9. #include <bl1/bl1.h>
  10. #include <common/tbbr/tbbr_img_def.h>
  11. #include <drivers/arm/sp805.h>
  12. #include <lib/fconf/fconf.h>
  13. #include <lib/fconf/fconf_dyn_cfg_getter.h>
  14. #include <lib/xlat_mpu/xlat_mpu.h>
  15. #include "fvp_r_private.h"
  16. #include <plat/arm/common/arm_config.h>
  17. #include <plat/arm/common/arm_def.h>
  18. #include <plat/arm/common/plat_arm.h>
  19. #include <plat/common/platform.h>
  20. #include <platform_def.h>
  21. #define MAP_BL1_TOTAL MAP_REGION_FLAT( \
  22. bl1_tzram_layout.total_base, \
  23. bl1_tzram_layout.total_size, \
  24. MT_MEMORY | MT_RW | MT_SECURE)
  25. /*
  26. * If SEPARATE_CODE_AND_RODATA=1 we define a region for each section
  27. * otherwise one region is defined containing both
  28. */
  29. #if SEPARATE_CODE_AND_RODATA
  30. #define MAP_BL1_RO MAP_REGION_FLAT( \
  31. BL_CODE_BASE, \
  32. BL1_CODE_END - BL_CODE_BASE, \
  33. MT_CODE | MT_SECURE), \
  34. MAP_REGION_FLAT( \
  35. BL1_RO_DATA_BASE, \
  36. BL1_RO_DATA_END \
  37. - BL_RO_DATA_BASE, \
  38. MT_RO_DATA | MT_SECURE)
  39. #else
  40. #define MAP_BL1_RO MAP_REGION_FLAT( \
  41. BL_CODE_BASE, \
  42. BL1_CODE_END - BL_CODE_BASE, \
  43. MT_CODE | MT_SECURE)
  44. #endif
  45. /* Data structure which holds the extents of the trusted SRAM for BL1*/
  46. static meminfo_t bl1_tzram_layout;
  47. struct meminfo *bl1_plat_sec_mem_layout(void)
  48. {
  49. return &bl1_tzram_layout;
  50. }
  51. void arm_bl1_early_platform_setup(void)
  52. {
  53. #if !ARM_DISABLE_TRUSTED_WDOG
  54. /* Enable watchdog */
  55. plat_arm_secure_wdt_start();
  56. #endif
  57. /* Initialize the console to provide early debug support */
  58. arm_console_boot_init();
  59. /* Allow BL1 to see the whole Trusted RAM */
  60. bl1_tzram_layout.total_base = ARM_BL_RAM_BASE;
  61. bl1_tzram_layout.total_size = ARM_BL_RAM_SIZE;
  62. }
  63. /* Boolean variable to hold condition whether firmware update needed or not */
  64. static bool is_fwu_needed;
  65. /*******************************************************************************
  66. * Perform any BL1 specific platform actions.
  67. ******************************************************************************/
  68. void bl1_early_platform_setup(void)
  69. {
  70. arm_bl1_early_platform_setup();
  71. /* Initialize the platform config for future decision making */
  72. fvp_config_setup();
  73. /*
  74. * Initialize Interconnect for this cluster during cold boot.
  75. * No need for locks as no other CPU is active.
  76. */
  77. fvp_interconnect_init();
  78. /*
  79. * Enable coherency in Interconnect for the primary CPU's cluster.
  80. */
  81. fvp_interconnect_enable();
  82. }
  83. void arm_bl1_plat_arch_setup(void)
  84. {
  85. const mmap_region_t bl_regions[] = {
  86. MAP_BL1_TOTAL,
  87. MAP_BL1_RO,
  88. #if USE_ROMLIB
  89. ARM_MAP_ROMLIB_CODE,
  90. ARM_MAP_ROMLIB_DATA,
  91. #endif
  92. /* DRAM1_region: */
  93. MAP_REGION_FLAT(
  94. PLAT_ARM_DRAM1_BASE,
  95. PLAT_ARM_DRAM1_SIZE,
  96. MT_MEMORY | MT_SECURE | MT_EXECUTE
  97. | MT_RW | MT_NON_CACHEABLE),
  98. /* NULL terminator: */
  99. {0}
  100. };
  101. setup_page_tables(bl_regions, plat_arm_get_mmap());
  102. enable_mpu_el2(0);
  103. arm_setup_romlib();
  104. }
  105. void plat_arm_secure_wdt_start(void)
  106. {
  107. sp805_start(ARM_SP805_TWDG_BASE, ARM_TWDG_LOAD_VAL);
  108. }
  109. void plat_arm_secure_wdt_stop(void)
  110. {
  111. sp805_stop(ARM_SP805_TWDG_BASE);
  112. }
  113. /*
  114. * Perform the platform specific architecture setup shared between
  115. * ARM standard platforms.
  116. */
  117. void arm_bl1_platform_setup(void)
  118. {
  119. uint32_t fw_config_max_size;
  120. /* Initialise the IO layer and register platform IO devices */
  121. plat_arm_io_setup();
  122. /* Check if we need FWU before further processing */
  123. is_fwu_needed = plat_arm_bl1_fwu_needed();
  124. if (is_fwu_needed) {
  125. ERROR("Skip platform setup as FWU detected\n");
  126. return;
  127. }
  128. /* Set global DTB info for fixed fw_config information */
  129. fw_config_max_size = ARM_FW_CONFIG_LIMIT - ARM_FW_CONFIG_BASE;
  130. set_config_info(ARM_FW_CONFIG_BASE, ~0UL, fw_config_max_size,
  131. FW_CONFIG_ID);
  132. assert(bl1_plat_get_image_desc(BL33_IMAGE_ID) != NULL);
  133. /*
  134. * Allow access to the System counter timer module and program
  135. * counter frequency for non secure images during FWU
  136. */
  137. #ifdef ARM_SYS_TIMCTL_BASE
  138. arm_configure_sys_timer();
  139. #endif
  140. #if (ARM_ARCH_MAJOR > 7) || defined(ARMV7_SUPPORTS_GENERIC_TIMER)
  141. write_cntfrq_el0(plat_get_syscnt_freq2());
  142. #endif
  143. }
  144. void bl1_platform_setup(void)
  145. {
  146. arm_bl1_platform_setup();
  147. /* Initialize System level generic or SP804 timer */
  148. fvp_timer_init();
  149. }
  150. __dead2 void bl1_plat_fwu_done(void *client_cookie, void *reserved)
  151. {
  152. /* Setup the watchdog to reset the system as soon as possible */
  153. sp805_refresh(ARM_SP805_TWDG_BASE, 1U);
  154. while (true) {
  155. wfi();
  156. }
  157. }
  158. unsigned int bl1_plat_get_next_image_id(void)
  159. {
  160. return is_fwu_needed ? NS_BL1U_IMAGE_ID : BL33_IMAGE_ID;
  161. }
  162. /*
  163. * Returns BL33 image details.
  164. */
  165. struct image_desc *bl1_plat_get_image_desc(unsigned int image_id)
  166. {
  167. static image_desc_t bl33_img_desc = BL33_IMAGE_DESC;
  168. return &bl33_img_desc;
  169. }
  170. /*
  171. * This function populates the default arguments to BL33.
  172. * The BL33 memory layout structure is allocated and the
  173. * calculated layout is populated in arg1 to BL33.
  174. */
  175. int bl1_plat_handle_post_image_load(unsigned int image_id)
  176. {
  177. meminfo_t *bl33_secram_layout;
  178. meminfo_t *bl1_secram_layout;
  179. image_desc_t *image_desc;
  180. entry_point_info_t *ep_info;
  181. if (image_id != BL33_IMAGE_ID) {
  182. return 0;
  183. }
  184. /* Get the image descriptor */
  185. image_desc = bl1_plat_get_image_desc(BL33_IMAGE_ID);
  186. assert(image_desc != NULL);
  187. /* Get the entry point info */
  188. ep_info = &image_desc->ep_info;
  189. /* Find out how much free trusted ram remains after BL1 load */
  190. bl1_secram_layout = bl1_plat_sec_mem_layout();
  191. /*
  192. * Create a new layout of memory for BL33 as seen by BL1 i.e.
  193. * tell it the amount of total and free memory available.
  194. * This layout is created at the first free address visible
  195. * to BL33. BL33 will read the memory layout before using its
  196. * memory for other purposes.
  197. */
  198. bl33_secram_layout = (meminfo_t *) bl1_secram_layout->total_base;
  199. bl1_plat_calc_bl2_layout(bl1_secram_layout, bl33_secram_layout);
  200. ep_info->args.arg1 = (uintptr_t)bl33_secram_layout;
  201. VERBOSE("BL1: BL3 memory layout address = %p\n",
  202. (void *) bl33_secram_layout);
  203. return 0;
  204. }