bl31.ld.S 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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. }
  19. #ifdef PLAT_EXTRA_LD_SCRIPT
  20. # include <plat.ld.S>
  21. #endif /* PLAT_EXTRA_LD_SCRIPT */
  22. SECTIONS {
  23. RAM_REGION_START = ORIGIN(RAM);
  24. RAM_REGION_LENGTH = LENGTH(RAM);
  25. . = BL31_BASE;
  26. ASSERT(. == ALIGN(PAGE_SIZE),
  27. "BL31_BASE address is not aligned on a page boundary.")
  28. __BL31_START__ = .;
  29. #if SEPARATE_CODE_AND_RODATA
  30. .text . : {
  31. ASSERT(. == ALIGN(PAGE_SIZE),
  32. ".text is not aligned on a page boundary.");
  33. __TEXT_START__ = .;
  34. *bl31_entrypoint.o(.text*)
  35. *(SORT_BY_ALIGNMENT(SORT(.text*)))
  36. *(.vectors)
  37. __TEXT_END_UNALIGNED__ = .;
  38. . = ALIGN(PAGE_SIZE);
  39. __TEXT_END__ = .;
  40. } >RAM
  41. .rodata . : {
  42. __RODATA_START__ = .;
  43. *(SORT_BY_ALIGNMENT(.rodata*))
  44. # if PLAT_EXTRA_RODATA_INCLUDES
  45. # include <plat.ld.rodata.inc>
  46. # endif /* PLAT_EXTRA_RODATA_INCLUDES */
  47. RODATA_COMMON
  48. . = ALIGN(8);
  49. # include <lib/el3_runtime/pubsub_events.h>
  50. __RODATA_END_UNALIGNED__ = .;
  51. . = ALIGN(PAGE_SIZE);
  52. __RODATA_END__ = .;
  53. } >RAM
  54. #else /* SEPARATE_CODE_AND_RODATA */
  55. .ro . : {
  56. ASSERT(. == ALIGN(PAGE_SIZE),
  57. ".ro is not aligned on a page boundary.");
  58. __RO_START__ = .;
  59. *bl31_entrypoint.o(.text*)
  60. *(SORT_BY_ALIGNMENT(.text*))
  61. *(SORT_BY_ALIGNMENT(.rodata*))
  62. RODATA_COMMON
  63. . = ALIGN(8);
  64. # include <lib/el3_runtime/pubsub_events.h>
  65. *(.vectors)
  66. __RO_END_UNALIGNED__ = .;
  67. /*
  68. * Memory page(s) mapped to this section will be marked as read-only,
  69. * executable. No RW data from the next section must creep in. Ensure
  70. * that the rest of the current memory page is unused.
  71. */
  72. . = ALIGN(PAGE_SIZE);
  73. __RO_END__ = .;
  74. } >RAM
  75. #endif /* SEPARATE_CODE_AND_RODATA */
  76. ASSERT(__CPU_OPS_END__ > __CPU_OPS_START__,
  77. "cpu_ops not defined for this platform.")
  78. #if SPM_MM || (SPMC_AT_EL3 && SPMC_AT_EL3_SEL0_SP)
  79. # ifndef SPM_SHIM_EXCEPTIONS_VMA
  80. # define SPM_SHIM_EXCEPTIONS_VMA RAM
  81. # endif /* SPM_SHIM_EXCEPTIONS_VMA */
  82. /*
  83. * Exception vectors of the SPM shim layer. They must be aligned to a 2K
  84. * address but we need to place them in a separate page so that we can set
  85. * individual permissions on them, so the actual alignment needed is the
  86. * page size.
  87. *
  88. * There's no need to include this into the RO section of BL31 because it
  89. * doesn't need to be accessed by BL31.
  90. */
  91. .spm_shim_exceptions : ALIGN(PAGE_SIZE) {
  92. __SPM_SHIM_EXCEPTIONS_START__ = .;
  93. *(.spm_shim_exceptions)
  94. . = ALIGN(PAGE_SIZE);
  95. __SPM_SHIM_EXCEPTIONS_END__ = .;
  96. } >SPM_SHIM_EXCEPTIONS_VMA AT>RAM
  97. PROVIDE(__SPM_SHIM_EXCEPTIONS_LMA__ = LOADADDR(.spm_shim_exceptions));
  98. . = LOADADDR(.spm_shim_exceptions) + SIZEOF(.spm_shim_exceptions);
  99. #endif /* SPM_MM || (SPMC_AT_EL3 && SPMC_AT_EL3_SEL0_SP) */
  100. __RW_START__ = .;
  101. DATA_SECTION >RAM
  102. RELA_SECTION >RAM
  103. #ifdef BL31_PROGBITS_LIMIT
  104. ASSERT(
  105. . <= BL31_PROGBITS_LIMIT,
  106. "BL31 progbits has exceeded its limit. Consider disabling some features."
  107. )
  108. #endif /* BL31_PROGBITS_LIMIT */
  109. #if SEPARATE_NOBITS_REGION
  110. . = ALIGN(PAGE_SIZE);
  111. __RW_END__ = .;
  112. __BL31_END__ = .;
  113. ASSERT(. <= BL31_LIMIT, "BL31 image has exceeded its limit.")
  114. . = BL31_NOBITS_BASE;
  115. ASSERT(. == ALIGN(PAGE_SIZE),
  116. "BL31 NOBITS base address is not aligned on a page boundary.")
  117. __NOBITS_START__ = .;
  118. #endif /* SEPARATE_NOBITS_REGION */
  119. STACK_SECTION >NOBITS
  120. BSS_SECTION >NOBITS
  121. XLAT_TABLE_SECTION >NOBITS
  122. #if USE_COHERENT_MEM
  123. /*
  124. * The base address of the coherent memory section must be page-aligned to
  125. * guarantee that the coherent data are stored on their own pages and are
  126. * not mixed with normal data. This is required to set up the correct
  127. * memory attributes for the coherent data page tables.
  128. */
  129. .coherent_ram (NOLOAD) : ALIGN(PAGE_SIZE) {
  130. __COHERENT_RAM_START__ = .;
  131. /*
  132. * Bakery locks are stored in coherent memory. Each lock's data is
  133. * contiguous and fully allocated by the compiler.
  134. */
  135. *(.bakery_lock)
  136. *(.tzfw_coherent_mem)
  137. __COHERENT_RAM_END_UNALIGNED__ = .;
  138. /*
  139. * Memory page(s) mapped to this section will be marked as device
  140. * memory. No other unexpected data must creep in. Ensure the rest of
  141. * the current memory page is unused.
  142. */
  143. . = ALIGN(PAGE_SIZE);
  144. __COHERENT_RAM_END__ = .;
  145. } >NOBITS
  146. #endif /* USE_COHERENT_MEM */
  147. #if SEPARATE_NOBITS_REGION
  148. __NOBITS_END__ = .;
  149. ASSERT(. <= BL31_NOBITS_LIMIT, "BL31 NOBITS region has exceeded its limit.")
  150. #else /* SEPARATE_NOBITS_REGION */
  151. __RW_END__ = .;
  152. __BL31_END__ = .;
  153. ASSERT(. <= BL31_LIMIT, "BL31 image has exceeded its limit.")
  154. #endif /* SEPARATE_NOBITS_REGION */
  155. RAM_REGION_END = .;
  156. /DISCARD/ : {
  157. *(.dynsym .dynstr .hash .gnu.hash)
  158. }
  159. }