bl1.ld.S 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*
  2. * Copyright (c) 2013-2023, Arm Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. /*
  7. * The .data section gets copied from ROM to RAM at runtime. Its LMA should be
  8. * 16-byte aligned to allow efficient copying of 16-bytes aligned regions in it.
  9. * Its VMA must be page-aligned as it marks the first read/write page.
  10. */
  11. #define DATA_ALIGN 16
  12. #include <common/bl_common.ld.h>
  13. #include <lib/xlat_tables/xlat_tables_defs.h>
  14. OUTPUT_FORMAT(PLATFORM_LINKER_FORMAT)
  15. OUTPUT_ARCH(PLATFORM_LINKER_ARCH)
  16. ENTRY(bl1_entrypoint)
  17. MEMORY {
  18. ROM (rx): ORIGIN = BL1_RO_BASE, LENGTH = BL1_RO_LIMIT - BL1_RO_BASE
  19. RAM (rwx): ORIGIN = BL1_RW_BASE, LENGTH = BL1_RW_LIMIT - BL1_RW_BASE
  20. }
  21. SECTIONS {
  22. ROM_REGION_START = ORIGIN(ROM);
  23. ROM_REGION_LENGTH = LENGTH(ROM);
  24. RAM_REGION_START = ORIGIN(RAM);
  25. RAM_REGION_LENGTH = LENGTH(RAM);
  26. . = BL1_RO_BASE;
  27. ASSERT(. == ALIGN(PAGE_SIZE),
  28. "BL1_RO_BASE address is not aligned on a page boundary.")
  29. #if SEPARATE_CODE_AND_RODATA
  30. .text . : {
  31. ASSERT(. == ALIGN(PAGE_SIZE),
  32. ".text address is not aligned on a page boundary.");
  33. __TEXT_START__ = .;
  34. *bl1_entrypoint.o(.text*)
  35. *(SORT_BY_ALIGNMENT(.text*))
  36. *(.vectors)
  37. __TEXT_END_UNALIGNED__ = .;
  38. . = ALIGN(PAGE_SIZE);
  39. __TEXT_END__ = .;
  40. } >ROM
  41. /* .ARM.extab and .ARM.exidx are only added because Clang needs them */
  42. .ARM.extab . : {
  43. *(.ARM.extab* .gnu.linkonce.armextab.*)
  44. } >ROM
  45. .ARM.exidx . : {
  46. *(.ARM.exidx* .gnu.linkonce.armexidx.*)
  47. } >ROM
  48. .rodata . : {
  49. __RODATA_START__ = .;
  50. *(SORT_BY_ALIGNMENT(.rodata*))
  51. RODATA_COMMON
  52. /*
  53. * No need to pad out the .rodata section to a page boundary. Next is
  54. * the .data section, which can mapped in ROM with the same memory
  55. * attributes as the .rodata section.
  56. *
  57. * Pad out to 16 bytes though as .data section needs to be 16-byte
  58. * aligned and lld does not align the LMA to the alignment specified
  59. * on the .data section.
  60. */
  61. __RODATA_END_UNALIGNED__ = .;
  62. __RODATA_END__ = .;
  63. . = ALIGN(16);
  64. } >ROM
  65. #else /* SEPARATE_CODE_AND_RODATA */
  66. .ro . : {
  67. ASSERT(. == ALIGN(PAGE_SIZE),
  68. ".ro address is not aligned on a page boundary.");
  69. __RO_START__ = .;
  70. *bl1_entrypoint.o(.text*)
  71. *(SORT_BY_ALIGNMENT(.text*))
  72. *(SORT_BY_ALIGNMENT(.rodata*))
  73. RODATA_COMMON
  74. *(.vectors)
  75. __RO_END__ = .;
  76. /*
  77. * Pad out to 16 bytes as the .data section needs to be 16-byte aligned
  78. * and lld does not align the LMA to the alignment specified on the
  79. * .data section.
  80. */
  81. . = ALIGN(16);
  82. } >ROM
  83. #endif /* SEPARATE_CODE_AND_RODATA */
  84. ASSERT(__CPU_OPS_END__ > __CPU_OPS_START__,
  85. "cpu_ops not defined for this platform.")
  86. ROM_REGION_END = .;
  87. . = BL1_RW_BASE;
  88. ASSERT(BL1_RW_BASE == ALIGN(PAGE_SIZE),
  89. "BL1_RW_BASE address is not aligned on a page boundary.")
  90. DATA_SECTION >RAM AT>ROM
  91. __DATA_RAM_START__ = __DATA_START__;
  92. __DATA_RAM_END__ = __DATA_END__;
  93. STACK_SECTION >RAM
  94. BSS_SECTION >RAM
  95. XLAT_TABLE_SECTION >RAM
  96. #if USE_COHERENT_MEM
  97. /*
  98. * The base address of the coherent memory section must be page-aligned to
  99. * guarantee that the coherent data are stored on their own pages and are
  100. * not mixed with normal data. This is required to set up the correct memory
  101. * attributes for the coherent data page tables.
  102. */
  103. .coherent_ram (NOLOAD) : ALIGN(PAGE_SIZE) {
  104. __COHERENT_RAM_START__ = .;
  105. *(.tzfw_coherent_mem)
  106. __COHERENT_RAM_END_UNALIGNED__ = .;
  107. /*
  108. * Memory page(s) mapped to this section will be marked as device
  109. * memory. No other unexpected data must creep in. Ensure the rest of
  110. * the current memory page is unused.
  111. */
  112. . = ALIGN(PAGE_SIZE);
  113. __COHERENT_RAM_END__ = .;
  114. } >RAM
  115. #endif /* USE_COHERENT_MEM */
  116. __BL1_RAM_START__ = ADDR(.data);
  117. __BL1_RAM_END__ = .;
  118. __DATA_ROM_START__ = LOADADDR(.data);
  119. __DATA_SIZE__ = SIZEOF(.data);
  120. /*
  121. * The .data section is the last PROGBITS section so its end marks the end
  122. * of BL1's actual content in Trusted ROM.
  123. */
  124. __BL1_ROM_END__ = __DATA_ROM_START__ + __DATA_SIZE__;
  125. ASSERT(__BL1_ROM_END__ <= BL1_RO_LIMIT,
  126. "BL1's ROM content has exceeded its limit.")
  127. __BSS_SIZE__ = SIZEOF(.bss);
  128. #if USE_COHERENT_MEM
  129. __COHERENT_RAM_UNALIGNED_SIZE__ =
  130. __COHERENT_RAM_END_UNALIGNED__ - __COHERENT_RAM_START__;
  131. #endif /* USE_COHERENT_MEM */
  132. ASSERT(. <= BL1_RW_LIMIT, "BL1's RW section has exceeded its limit.")
  133. RAM_REGION_END = .;
  134. }