bl2_el3.ld.S 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /*
  2. * Copyright (c) 2017-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(bl2_entrypoint)
  11. MEMORY {
  12. #if BL2_IN_XIP_MEM
  13. ROM (rx): ORIGIN = BL2_RO_BASE, LENGTH = BL2_RO_LIMIT - BL2_RO_BASE
  14. RAM (rwx): ORIGIN = BL2_RW_BASE, LENGTH = BL2_RW_LIMIT - BL2_RW_BASE
  15. #else /* BL2_IN_XIP_MEM */
  16. RAM (rwx): ORIGIN = BL2_BASE, LENGTH = BL2_LIMIT - BL2_BASE
  17. #endif /* BL2_IN_XIP_MEM */
  18. #if SEPARATE_BL2_NOLOAD_REGION
  19. RAM_NOLOAD (rw!a): ORIGIN = BL2_NOLOAD_START, LENGTH = BL2_NOLOAD_LIMIT - BL2_NOLOAD_START
  20. #else /* SEPARATE_BL2_NOLOAD_REGION */
  21. # define RAM_NOLOAD RAM
  22. #endif /* SEPARATE_BL2_NOLOAD_REGION */
  23. }
  24. #if !BL2_IN_XIP_MEM
  25. # define ROM RAM
  26. #endif /* !BL2_IN_XIP_MEM */
  27. SECTIONS {
  28. RAM_REGION_START = ORIGIN(RAM);
  29. RAM_REGION_LENGTH = LENGTH(RAM);
  30. #if BL2_IN_XIP_MEM
  31. ROM_REGION_START = ORIGIN(ROM);
  32. ROM_REGION_LENGTH = LENGTH(ROM);
  33. . = BL2_RO_BASE;
  34. ASSERT(. == ALIGN(PAGE_SIZE),
  35. "BL2_RO_BASE address is not aligned on a page boundary.")
  36. #else /* BL2_IN_XIP_MEM */
  37. . = BL2_BASE;
  38. ASSERT(. == ALIGN(PAGE_SIZE),
  39. "BL2_BASE address is not aligned on a page boundary.")
  40. #endif /* BL2_IN_XIP_MEM */
  41. #if SEPARATE_BL2_NOLOAD_REGION
  42. RAM_NOLOAD_REGION_START = ORIGIN(RAM_NOLOAD);
  43. RAM_NOLOAD_REGION_LENGTH = LENGTH(RAM_NOLOAD);
  44. #endif
  45. #if SEPARATE_CODE_AND_RODATA
  46. .text . : {
  47. ASSERT(. == ALIGN(PAGE_SIZE),
  48. ".text address is not aligned on a page boundary.");
  49. __TEXT_START__ = .;
  50. __TEXT_RESIDENT_START__ = .;
  51. *bl2_el3_entrypoint.o(.text*)
  52. *(.text.asm.*)
  53. __TEXT_RESIDENT_END__ = .;
  54. *(SORT_BY_ALIGNMENT(.text*))
  55. *(.vectors)
  56. __TEXT_END_UNALIGNED__ = .;
  57. . = ALIGN(PAGE_SIZE);
  58. __TEXT_END__ = .;
  59. } >ROM
  60. .rodata . : {
  61. __RODATA_START__ = .;
  62. *(SORT_BY_ALIGNMENT(.rodata*))
  63. RODATA_COMMON
  64. __RODATA_END_UNALIGNED__ = .;
  65. . = ALIGN(PAGE_SIZE);
  66. __RODATA_END__ = .;
  67. } >ROM
  68. ASSERT(__TEXT_RESIDENT_END__ - __TEXT_RESIDENT_START__ <= PAGE_SIZE,
  69. "Resident part of BL2 has exceeded its limit.")
  70. #else /* SEPARATE_CODE_AND_RODATA */
  71. .ro . : {
  72. ASSERT(. == ALIGN(PAGE_SIZE),
  73. ".ro address is not aligned on a page boundary.");
  74. __RO_START__ = .;
  75. __TEXT_RESIDENT_START__ = .;
  76. *bl2_el3_entrypoint.o(.text*)
  77. *(.text.asm.*)
  78. __TEXT_RESIDENT_END__ = .;
  79. *(SORT_BY_ALIGNMENT(.text*))
  80. *(SORT_BY_ALIGNMENT(.rodata*))
  81. RODATA_COMMON
  82. *(.vectors)
  83. __RO_END_UNALIGNED__ = .;
  84. /*
  85. * Memory page(s) mapped to this section will be marked as read-only,
  86. * executable. No RW data from the next section must creep in. Ensure
  87. * that the rest of the current memory page is unused.
  88. */
  89. . = ALIGN(PAGE_SIZE);
  90. __RO_END__ = .;
  91. } >ROM
  92. #endif /* SEPARATE_CODE_AND_RODATA */
  93. ASSERT(__CPU_OPS_END__ > __CPU_OPS_START__,
  94. "cpu_ops not defined for this platform.")
  95. #if BL2_IN_XIP_MEM
  96. ROM_REGION_END = .;
  97. . = BL2_RW_BASE;
  98. ASSERT(BL2_RW_BASE == ALIGN(PAGE_SIZE),
  99. "BL2_RW_BASE address is not aligned on a page boundary.")
  100. #endif /* BL2_IN_XIP_MEM */
  101. __RW_START__ = .;
  102. DATA_SECTION >RAM AT>ROM
  103. __DATA_RAM_START__ = __DATA_START__;
  104. __DATA_RAM_END__ = __DATA_END__;
  105. RELA_SECTION >RAM
  106. #if SEPARATE_BL2_NOLOAD_REGION
  107. SAVED_ADDR = .;
  108. . = BL2_NOLOAD_START;
  109. __BL2_NOLOAD_START__ = .;
  110. #endif /* SEPARATE_BL2_NOLOAD_REGION */
  111. STACK_SECTION >RAM_NOLOAD
  112. BSS_SECTION >RAM_NOLOAD
  113. XLAT_TABLE_SECTION >RAM_NOLOAD
  114. #if SEPARATE_BL2_NOLOAD_REGION
  115. __BL2_NOLOAD_END__ = .;
  116. RAM_NOLOAD_REGION_END = .;
  117. . = SAVED_ADDR;
  118. #endif /* SEPARATE_BL2_NOLOAD_REGION */
  119. #if USE_COHERENT_MEM
  120. /*
  121. * The base address of the coherent memory section must be page-aligned to
  122. * guarantee that the coherent data are stored on their own pages and are
  123. * not mixed with normal data. This is required to set up the correct
  124. * memory attributes for the coherent data page tables.
  125. */
  126. .coherent_ram (NOLOAD) : ALIGN(PAGE_SIZE) {
  127. __COHERENT_RAM_START__ = .;
  128. *(.tzfw_coherent_mem)
  129. __COHERENT_RAM_END_UNALIGNED__ = .;
  130. /*
  131. * Memory page(s) mapped to this section will be marked as device
  132. * memory. No other unexpected data must creep in. Ensure the rest of
  133. * the current memory page is unused.
  134. */
  135. . = ALIGN(PAGE_SIZE);
  136. __COHERENT_RAM_END__ = .;
  137. } >RAM
  138. #endif /* USE_COHERENT_MEM */
  139. __RW_END__ = .;
  140. __BL2_END__ = .;
  141. /DISCARD/ : {
  142. *(.dynsym .dynstr .hash .gnu.hash)
  143. }
  144. #if BL2_IN_XIP_MEM
  145. __BL2_RAM_START__ = ADDR(.data);
  146. __BL2_RAM_END__ = .;
  147. __DATA_ROM_START__ = LOADADDR(.data);
  148. __DATA_SIZE__ = SIZEOF(.data);
  149. /*
  150. * The .data section is the last PROGBITS section so its end marks the end
  151. * of BL2's RO content in XIP memory.
  152. */
  153. __BL2_ROM_END__ = __DATA_ROM_START__ + __DATA_SIZE__;
  154. ASSERT(__BL2_ROM_END__ <= BL2_RO_LIMIT,
  155. "BL2's RO content has exceeded its limit.")
  156. #endif /* BL2_IN_XIP_MEM */
  157. __BSS_SIZE__ = SIZEOF(.bss);
  158. #if USE_COHERENT_MEM
  159. __COHERENT_RAM_UNALIGNED_SIZE__ =
  160. __COHERENT_RAM_END_UNALIGNED__ - __COHERENT_RAM_START__;
  161. #endif /* USE_COHERENT_MEM */
  162. RAM_REGION_END = .;
  163. #if BL2_IN_XIP_MEM
  164. ASSERT(. <= BL2_RW_LIMIT, "BL2's RW content has exceeded its limit.")
  165. #else /* BL2_IN_XIP_MEM */
  166. ASSERT(. <= BL2_LIMIT, "BL2 image has exceeded its limit.")
  167. #endif /* BL2_IN_XIP_MEM */
  168. }