bl2_el3.ld.S 5.5 KB

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