bl31.ld.S 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. /*
  2. * Copyright (c) 2013-2023, Arm Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <common/bl_common.ld.h>
  7. #include <lib/xlat_tables/xlat_tables_defs.h>
  8. OUTPUT_FORMAT(PLATFORM_LINKER_FORMAT)
  9. OUTPUT_ARCH(PLATFORM_LINKER_ARCH)
  10. ENTRY(bl31_entrypoint)
  11. MEMORY {
  12. RAM (rwx): ORIGIN = BL31_BASE, LENGTH = BL31_LIMIT - BL31_BASE
  13. #if SEPARATE_NOBITS_REGION
  14. NOBITS (rw!a): ORIGIN = BL31_NOBITS_BASE, LENGTH = BL31_NOBITS_LIMIT - BL31_NOBITS_BASE
  15. #else /* SEPARATE_NOBITS_REGION */
  16. # define NOBITS RAM
  17. #endif /* SEPARATE_NOBITS_REGION */
  18. #if SEPARATE_RWDATA_REGION
  19. RAM_RW (rw): ORIGIN = BL31_RWDATA_BASE, LENGTH = BL31_RWDATA_LIMIT - BL31_RWDATA_BASE
  20. #else /* SEPARATE_RWDATA_REGION */
  21. #define RAM_RW RAM
  22. #endif /* SEPARATE_RWDATA_REGION */
  23. }
  24. #ifdef PLAT_EXTRA_LD_SCRIPT
  25. # include <plat.ld.S>
  26. #endif /* PLAT_EXTRA_LD_SCRIPT */
  27. SECTIONS {
  28. RAM_REGION_START = ORIGIN(RAM);
  29. RAM_REGION_LENGTH = LENGTH(RAM);
  30. . = BL31_BASE;
  31. ASSERT(. == ALIGN(PAGE_SIZE),
  32. "BL31_BASE address is not aligned on a page boundary.")
  33. __BL31_START__ = .;
  34. #if SEPARATE_CODE_AND_RODATA
  35. .text . : {
  36. ASSERT(. == ALIGN(PAGE_SIZE),
  37. ".text is not aligned on a page boundary.");
  38. __TEXT_START__ = .;
  39. *bl31_entrypoint.o(.text*)
  40. *(SORT_BY_ALIGNMENT(SORT(.text*)))
  41. *(.vectors)
  42. __TEXT_END_UNALIGNED__ = .;
  43. . = ALIGN(PAGE_SIZE);
  44. __TEXT_END__ = .;
  45. } >RAM
  46. .rodata . : {
  47. __RODATA_START__ = .;
  48. *(SORT_BY_ALIGNMENT(.rodata*))
  49. # if PLAT_EXTRA_RODATA_INCLUDES
  50. # include <plat.ld.rodata.inc>
  51. # endif /* PLAT_EXTRA_RODATA_INCLUDES */
  52. RODATA_COMMON
  53. . = ALIGN(8);
  54. # include <lib/el3_runtime/pubsub_events.h>
  55. __RODATA_END_UNALIGNED__ = .;
  56. . = ALIGN(PAGE_SIZE);
  57. __RODATA_END__ = .;
  58. } >RAM
  59. #else /* SEPARATE_CODE_AND_RODATA */
  60. .ro . : {
  61. ASSERT(. == ALIGN(PAGE_SIZE),
  62. ".ro is not aligned on a page boundary.");
  63. __RO_START__ = .;
  64. *bl31_entrypoint.o(.text*)
  65. *(SORT_BY_ALIGNMENT(.text*))
  66. *(SORT_BY_ALIGNMENT(.rodata*))
  67. RODATA_COMMON
  68. . = ALIGN(8);
  69. # include <lib/el3_runtime/pubsub_events.h>
  70. *(.vectors)
  71. __RO_END_UNALIGNED__ = .;
  72. /*
  73. * Memory page(s) mapped to this section will be marked as read-only,
  74. * executable. No RW data from the next section must creep in. Ensure
  75. * that the rest of the current memory page is unused.
  76. */
  77. . = ALIGN(PAGE_SIZE);
  78. __RO_END__ = .;
  79. } >RAM
  80. #endif /* SEPARATE_CODE_AND_RODATA */
  81. ASSERT(__CPU_OPS_END__ > __CPU_OPS_START__,
  82. "cpu_ops not defined for this platform.")
  83. #if SPM_MM || (SPMC_AT_EL3 && SPMC_AT_EL3_SEL0_SP)
  84. # ifndef SPM_SHIM_EXCEPTIONS_VMA
  85. # define SPM_SHIM_EXCEPTIONS_VMA RAM
  86. # endif /* SPM_SHIM_EXCEPTIONS_VMA */
  87. /*
  88. * Exception vectors of the SPM shim layer. They must be aligned to a 2K
  89. * address but we need to place them in a separate page so that we can set
  90. * individual permissions on them, so the actual alignment needed is the
  91. * page size.
  92. *
  93. * There's no need to include this into the RO section of BL31 because it
  94. * doesn't need to be accessed by BL31.
  95. */
  96. .spm_shim_exceptions : ALIGN(PAGE_SIZE) {
  97. __SPM_SHIM_EXCEPTIONS_START__ = .;
  98. *(.spm_shim_exceptions)
  99. . = ALIGN(PAGE_SIZE);
  100. __SPM_SHIM_EXCEPTIONS_END__ = .;
  101. } >SPM_SHIM_EXCEPTIONS_VMA AT>RAM
  102. PROVIDE(__SPM_SHIM_EXCEPTIONS_LMA__ = LOADADDR(.spm_shim_exceptions));
  103. . = LOADADDR(.spm_shim_exceptions) + SIZEOF(.spm_shim_exceptions);
  104. #endif /* SPM_MM || (SPMC_AT_EL3 && SPMC_AT_EL3_SEL0_SP) */
  105. #if SEPARATE_RWDATA_REGION
  106. . = BL31_RWDATA_BASE;
  107. ASSERT(BL31_RWDATA_BASE == ALIGN(PAGE_SIZE),
  108. "BL31_RWDATA_BASE address is not aligned on a page boundary.")
  109. /*
  110. * Define a linker symbol to mark the start of the RW memory area for this
  111. * image.
  112. */
  113. __RW_START__ = . ;
  114. DATA_SECTION >RAM_RW AT>RAM
  115. __DATA_RAM_START__ = __DATA_START__;
  116. __DATA_RAM_END__ = __DATA_END__;
  117. __DATA_ROM_START__ = LOADADDR(.data);
  118. . = ALIGN(PAGE_SIZE);
  119. __RW_END__ = .;
  120. RELA_SECTION >RAM
  121. #else /* SEPARATE_RWDATA_REGION */
  122. /*
  123. * Define a linker symbol to mark the start of the RW memory area for this
  124. * image.
  125. */
  126. __RW_START__ = . ;
  127. DATA_SECTION >RAM
  128. RELA_SECTION >RAM
  129. #endif /* SEPARATE_RWDATA_REGION */
  130. #ifdef BL31_PROGBITS_LIMIT
  131. ASSERT(
  132. . <= BL31_PROGBITS_LIMIT,
  133. "BL31 progbits has exceeded its limit. Consider disabling some features."
  134. )
  135. #endif /* BL31_PROGBITS_LIMIT */
  136. #if SEPARATE_NOBITS_REGION
  137. . = ALIGN(PAGE_SIZE);
  138. #if !SEPARATE_RWDATA_REGION
  139. __RW_END__ = .;
  140. #endif /* SEPARATE_RWDATA_REGION */
  141. __BL31_END__ = .;
  142. ASSERT(. <= BL31_LIMIT, "BL31 image has exceeded its limit.")
  143. . = BL31_NOBITS_BASE;
  144. ASSERT(. == ALIGN(PAGE_SIZE),
  145. "BL31 NOBITS base address is not aligned on a page boundary.")
  146. __NOBITS_START__ = .;
  147. #endif /* SEPARATE_NOBITS_REGION */
  148. STACK_SECTION >NOBITS
  149. BSS_SECTION >NOBITS
  150. XLAT_TABLE_SECTION >NOBITS
  151. #if USE_COHERENT_MEM
  152. /*
  153. * The base address of the coherent memory section must be page-aligned to
  154. * guarantee that the coherent data are stored on their own pages and are
  155. * not mixed with normal data. This is required to set up the correct
  156. * memory attributes for the coherent data page tables.
  157. */
  158. .coherent_ram (NOLOAD) : ALIGN(PAGE_SIZE) {
  159. __COHERENT_RAM_START__ = .;
  160. /*
  161. * Bakery locks are stored in coherent memory. Each lock's data is
  162. * contiguous and fully allocated by the compiler.
  163. */
  164. *(.bakery_lock)
  165. *(.tzfw_coherent_mem)
  166. __COHERENT_RAM_END_UNALIGNED__ = .;
  167. /*
  168. * Memory page(s) mapped to this section will be marked as device
  169. * memory. No other unexpected data must creep in. Ensure the rest of
  170. * the current memory page is unused.
  171. */
  172. . = ALIGN(PAGE_SIZE);
  173. __COHERENT_RAM_END__ = .;
  174. } >NOBITS
  175. #endif /* USE_COHERENT_MEM */
  176. #if SEPARATE_NOBITS_REGION
  177. __NOBITS_END__ = .;
  178. ASSERT(. <= BL31_NOBITS_LIMIT, "BL31 NOBITS region has exceeded its limit.")
  179. #else /* SEPARATE_NOBITS_REGION */
  180. /*
  181. * Define a linker symbol to mark the end of the RW memory area for this
  182. * image.
  183. */
  184. #if !SEPARATE_RWDATA_REGION
  185. __RW_END__ = .;
  186. #endif /* SEPARATE_RWDATA_REGION */
  187. __BL31_END__ = .;
  188. ASSERT(. <= BL31_LIMIT, "BL31 image has exceeded its limit.")
  189. #endif /* SEPARATE_NOBITS_REGION */
  190. RAM_REGION_END = .;
  191. /DISCARD/ : {
  192. *(.dynsym .dynstr .hash .gnu.hash)
  193. }
  194. }