Roberto Vargas | e0e9946 | 2017-10-30 14:43:43 +0000 | [diff] [blame] | 1 | /* |
Jiafei Pan | 0824b45 | 2022-02-24 10:47:33 +0800 | [diff] [blame] | 2 | * Copyright (c) 2017-2022, ARM Limited and Contributors. All rights reserved. |
Roberto Vargas | e0e9946 | 2017-10-30 14:43:43 +0000 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
Masahiro Yamada | 0b67e56 | 2020-03-09 17:39:48 +0900 | [diff] [blame] | 7 | #include <common/bl_common.ld.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 8 | #include <lib/xlat_tables/xlat_tables_defs.h> |
Roberto Vargas | e0e9946 | 2017-10-30 14:43:43 +0000 | [diff] [blame] | 9 | |
| 10 | OUTPUT_FORMAT(PLATFORM_LINKER_FORMAT) |
| 11 | OUTPUT_ARCH(PLATFORM_LINKER_ARCH) |
| 12 | ENTRY(bl2_entrypoint) |
| 13 | |
| 14 | MEMORY { |
Jiafei Pan | 43a7bf4 | 2018-03-21 07:20:09 +0000 | [diff] [blame] | 15 | #if BL2_IN_XIP_MEM |
| 16 | ROM (rx): ORIGIN = BL2_RO_BASE, LENGTH = BL2_RO_LIMIT - BL2_RO_BASE |
| 17 | RAM (rwx): ORIGIN = BL2_RW_BASE, LENGTH = BL2_RW_LIMIT - BL2_RW_BASE |
| 18 | #else |
Roberto Vargas | e0e9946 | 2017-10-30 14:43:43 +0000 | [diff] [blame] | 19 | RAM (rwx): ORIGIN = BL2_BASE, LENGTH = BL2_LIMIT - BL2_BASE |
Yann Gautier | 4f5d81d | 2022-03-31 14:42:11 +0200 | [diff] [blame] | 20 | #endif |
Jiafei Pan | 0824b45 | 2022-02-24 10:47:33 +0800 | [diff] [blame] | 21 | #if SEPARATE_BL2_NOLOAD_REGION |
| 22 | RAM_NOLOAD (rw!a): ORIGIN = BL2_NOLOAD_START, LENGTH = BL2_NOLOAD_LIMIT - BL2_NOLOAD_START |
| 23 | #else |
| 24 | #define RAM_NOLOAD RAM |
| 25 | #endif |
Roberto Vargas | e0e9946 | 2017-10-30 14:43:43 +0000 | [diff] [blame] | 26 | } |
| 27 | |
Masahiro Yamada | 5289b67 | 2019-06-14 17:49:17 +0900 | [diff] [blame] | 28 | #if !BL2_IN_XIP_MEM |
| 29 | #define ROM RAM |
| 30 | #endif |
Roberto Vargas | e0e9946 | 2017-10-30 14:43:43 +0000 | [diff] [blame] | 31 | |
| 32 | SECTIONS |
| 33 | { |
Jiafei Pan | 43a7bf4 | 2018-03-21 07:20:09 +0000 | [diff] [blame] | 34 | #if BL2_IN_XIP_MEM |
| 35 | . = BL2_RO_BASE; |
| 36 | ASSERT(. == ALIGN(PAGE_SIZE), |
| 37 | "BL2_RO_BASE address is not aligned on a page boundary.") |
| 38 | #else |
Roberto Vargas | e0e9946 | 2017-10-30 14:43:43 +0000 | [diff] [blame] | 39 | . = BL2_BASE; |
| 40 | ASSERT(. == ALIGN(PAGE_SIZE), |
| 41 | "BL2_BASE address is not aligned on a page boundary.") |
Jiafei Pan | 43a7bf4 | 2018-03-21 07:20:09 +0000 | [diff] [blame] | 42 | #endif |
Roberto Vargas | e0e9946 | 2017-10-30 14:43:43 +0000 | [diff] [blame] | 43 | |
| 44 | #if SEPARATE_CODE_AND_RODATA |
| 45 | .text . : { |
| 46 | __TEXT_START__ = .; |
Roberto Vargas | 51abc34 | 2017-11-17 10:51:54 +0000 | [diff] [blame] | 47 | __TEXT_RESIDENT_START__ = .; |
| 48 | *bl2_el3_entrypoint.o(.text*) |
| 49 | *(.text.asm.*) |
| 50 | __TEXT_RESIDENT_END__ = .; |
Samuel Holland | 23f5e54 | 2019-10-20 16:11:25 -0500 | [diff] [blame] | 51 | *(SORT_BY_ALIGNMENT(.text*)) |
Roberto Vargas | e0e9946 | 2017-10-30 14:43:43 +0000 | [diff] [blame] | 52 | *(.vectors) |
Roberto Vargas | d93fde3 | 2018-04-11 11:53:31 +0100 | [diff] [blame] | 53 | . = ALIGN(PAGE_SIZE); |
Roberto Vargas | e0e9946 | 2017-10-30 14:43:43 +0000 | [diff] [blame] | 54 | __TEXT_END__ = .; |
Jiafei Pan | 43a7bf4 | 2018-03-21 07:20:09 +0000 | [diff] [blame] | 55 | } >ROM |
Roberto Vargas | e0e9946 | 2017-10-30 14:43:43 +0000 | [diff] [blame] | 56 | |
| 57 | .rodata . : { |
| 58 | __RODATA_START__ = .; |
Samuel Holland | 23f5e54 | 2019-10-20 16:11:25 -0500 | [diff] [blame] | 59 | *(SORT_BY_ALIGNMENT(.rodata*)) |
Roberto Vargas | e0e9946 | 2017-10-30 14:43:43 +0000 | [diff] [blame] | 60 | |
Masahiro Yamada | 583f8dd | 2020-03-26 10:57:12 +0900 | [diff] [blame] | 61 | RODATA_COMMON |
Masahiro Yamada | 65d699d | 2020-01-17 13:45:02 +0900 | [diff] [blame] | 62 | |
Roberto Vargas | d93fde3 | 2018-04-11 11:53:31 +0100 | [diff] [blame] | 63 | . = ALIGN(PAGE_SIZE); |
Roberto Vargas | e0e9946 | 2017-10-30 14:43:43 +0000 | [diff] [blame] | 64 | __RODATA_END__ = .; |
Jiafei Pan | 43a7bf4 | 2018-03-21 07:20:09 +0000 | [diff] [blame] | 65 | } >ROM |
Roberto Vargas | 51abc34 | 2017-11-17 10:51:54 +0000 | [diff] [blame] | 66 | |
| 67 | ASSERT(__TEXT_RESIDENT_END__ - __TEXT_RESIDENT_START__ <= PAGE_SIZE, |
| 68 | "Resident part of BL2 has exceeded its limit.") |
Roberto Vargas | e0e9946 | 2017-10-30 14:43:43 +0000 | [diff] [blame] | 69 | #else |
| 70 | ro . : { |
| 71 | __RO_START__ = .; |
Roberto Vargas | 51abc34 | 2017-11-17 10:51:54 +0000 | [diff] [blame] | 72 | __TEXT_RESIDENT_START__ = .; |
| 73 | *bl2_el3_entrypoint.o(.text*) |
| 74 | *(.text.asm.*) |
| 75 | __TEXT_RESIDENT_END__ = .; |
Samuel Holland | 23f5e54 | 2019-10-20 16:11:25 -0500 | [diff] [blame] | 76 | *(SORT_BY_ALIGNMENT(.text*)) |
| 77 | *(SORT_BY_ALIGNMENT(.rodata*)) |
Roberto Vargas | e0e9946 | 2017-10-30 14:43:43 +0000 | [diff] [blame] | 78 | |
Masahiro Yamada | 583f8dd | 2020-03-26 10:57:12 +0900 | [diff] [blame] | 79 | RODATA_COMMON |
Masahiro Yamada | 65d699d | 2020-01-17 13:45:02 +0900 | [diff] [blame] | 80 | |
Roberto Vargas | e0e9946 | 2017-10-30 14:43:43 +0000 | [diff] [blame] | 81 | *(.vectors) |
| 82 | __RO_END_UNALIGNED__ = .; |
| 83 | /* |
| 84 | * Memory page(s) mapped to this section will be marked as |
| 85 | * read-only, executable. No RW data from the next section must |
| 86 | * creep in. Ensure the rest of the current memory page is unused. |
| 87 | */ |
Roberto Vargas | d93fde3 | 2018-04-11 11:53:31 +0100 | [diff] [blame] | 88 | . = ALIGN(PAGE_SIZE); |
Roberto Vargas | e0e9946 | 2017-10-30 14:43:43 +0000 | [diff] [blame] | 89 | |
| 90 | __RO_END__ = .; |
Jiafei Pan | 43a7bf4 | 2018-03-21 07:20:09 +0000 | [diff] [blame] | 91 | } >ROM |
Jiafei Pan | 43a7bf4 | 2018-03-21 07:20:09 +0000 | [diff] [blame] | 92 | #endif |
Roberto Vargas | e0e9946 | 2017-10-30 14:43:43 +0000 | [diff] [blame] | 93 | |
| 94 | ASSERT(__CPU_OPS_END__ > __CPU_OPS_START__, |
| 95 | "cpu_ops not defined for this platform.") |
| 96 | |
Jiafei Pan | 43a7bf4 | 2018-03-21 07:20:09 +0000 | [diff] [blame] | 97 | #if BL2_IN_XIP_MEM |
| 98 | . = BL2_RW_BASE; |
| 99 | ASSERT(BL2_RW_BASE == ALIGN(PAGE_SIZE), |
| 100 | "BL2_RW_BASE address is not aligned on a page boundary.") |
| 101 | #endif |
| 102 | |
Roberto Vargas | e0e9946 | 2017-10-30 14:43:43 +0000 | [diff] [blame] | 103 | /* |
| 104 | * Define a linker symbol to mark start of the RW memory area for this |
| 105 | * image. |
| 106 | */ |
| 107 | __RW_START__ = . ; |
| 108 | |
Masahiro Yamada | c5864d8 | 2020-04-22 10:50:12 +0900 | [diff] [blame] | 109 | DATA_SECTION >RAM AT>ROM |
| 110 | __DATA_RAM_START__ = __DATA_START__; |
| 111 | __DATA_RAM_END__ = __DATA_END__; |
Roberto Vargas | e0e9946 | 2017-10-30 14:43:43 +0000 | [diff] [blame] | 112 | |
Masahiro Yamada | 85fa00e | 2020-04-22 11:27:55 +0900 | [diff] [blame] | 113 | RELA_SECTION >RAM |
Jiafei Pan | 0824b45 | 2022-02-24 10:47:33 +0800 | [diff] [blame] | 114 | #if SEPARATE_BL2_NOLOAD_REGION |
| 115 | SAVED_ADDR = .; |
| 116 | . = BL2_NOLOAD_START; |
| 117 | __BL2_NOLOAD_START__ = .; |
| 118 | #endif |
| 119 | STACK_SECTION >RAM_NOLOAD |
| 120 | BSS_SECTION >RAM_NOLOAD |
| 121 | XLAT_TABLE_SECTION >RAM_NOLOAD |
| 122 | #if SEPARATE_BL2_NOLOAD_REGION |
| 123 | __BL2_NOLOAD_END__ = .; |
| 124 | . = SAVED_ADDR; |
| 125 | #endif |
Roberto Vargas | e0e9946 | 2017-10-30 14:43:43 +0000 | [diff] [blame] | 126 | |
| 127 | #if USE_COHERENT_MEM |
| 128 | /* |
| 129 | * The base address of the coherent memory section must be page-aligned (4K) |
| 130 | * to guarantee that the coherent data are stored on their own pages and |
| 131 | * are not mixed with normal data. This is required to set up the correct |
| 132 | * memory attributes for the coherent data page tables. |
| 133 | */ |
| 134 | coherent_ram (NOLOAD) : ALIGN(PAGE_SIZE) { |
| 135 | __COHERENT_RAM_START__ = .; |
| 136 | *(tzfw_coherent_mem) |
| 137 | __COHERENT_RAM_END_UNALIGNED__ = .; |
| 138 | /* |
| 139 | * Memory page(s) mapped to this section will be marked |
| 140 | * as device memory. No other unexpected data must creep in. |
| 141 | * Ensure the rest of the current memory page is unused. |
| 142 | */ |
Roberto Vargas | d93fde3 | 2018-04-11 11:53:31 +0100 | [diff] [blame] | 143 | . = ALIGN(PAGE_SIZE); |
Roberto Vargas | e0e9946 | 2017-10-30 14:43:43 +0000 | [diff] [blame] | 144 | __COHERENT_RAM_END__ = .; |
| 145 | } >RAM |
| 146 | #endif |
| 147 | |
| 148 | /* |
| 149 | * Define a linker symbol to mark end of the RW memory area for this |
| 150 | * image. |
| 151 | */ |
| 152 | __RW_END__ = .; |
| 153 | __BL2_END__ = .; |
| 154 | |
Masahiro Yamada | 65d699d | 2020-01-17 13:45:02 +0900 | [diff] [blame] | 155 | /DISCARD/ : { |
| 156 | *(.dynsym .dynstr .hash .gnu.hash) |
| 157 | } |
| 158 | |
Jiafei Pan | 43a7bf4 | 2018-03-21 07:20:09 +0000 | [diff] [blame] | 159 | #if BL2_IN_XIP_MEM |
| 160 | __BL2_RAM_START__ = ADDR(.data); |
| 161 | __BL2_RAM_END__ = .; |
| 162 | |
| 163 | __DATA_ROM_START__ = LOADADDR(.data); |
| 164 | __DATA_SIZE__ = SIZEOF(.data); |
| 165 | |
| 166 | /* |
| 167 | * The .data section is the last PROGBITS section so its end marks the end |
| 168 | * of BL2's RO content in XIP memory.. |
| 169 | */ |
| 170 | __BL2_ROM_END__ = __DATA_ROM_START__ + __DATA_SIZE__; |
| 171 | ASSERT(__BL2_ROM_END__ <= BL2_RO_LIMIT, |
| 172 | "BL2's RO content has exceeded its limit.") |
| 173 | #endif |
Roberto Vargas | e0e9946 | 2017-10-30 14:43:43 +0000 | [diff] [blame] | 174 | __BSS_SIZE__ = SIZEOF(.bss); |
| 175 | |
Jiafei Pan | 43a7bf4 | 2018-03-21 07:20:09 +0000 | [diff] [blame] | 176 | |
Roberto Vargas | e0e9946 | 2017-10-30 14:43:43 +0000 | [diff] [blame] | 177 | #if USE_COHERENT_MEM |
| 178 | __COHERENT_RAM_UNALIGNED_SIZE__ = |
| 179 | __COHERENT_RAM_END_UNALIGNED__ - __COHERENT_RAM_START__; |
| 180 | #endif |
| 181 | |
Jiafei Pan | 43a7bf4 | 2018-03-21 07:20:09 +0000 | [diff] [blame] | 182 | #if BL2_IN_XIP_MEM |
| 183 | ASSERT(. <= BL2_RW_LIMIT, "BL2's RW content has exceeded its limit.") |
| 184 | #else |
Roberto Vargas | e0e9946 | 2017-10-30 14:43:43 +0000 | [diff] [blame] | 185 | ASSERT(. <= BL2_LIMIT, "BL2 image has exceeded its limit.") |
Jiafei Pan | 43a7bf4 | 2018-03-21 07:20:09 +0000 | [diff] [blame] | 186 | #endif |
Roberto Vargas | e0e9946 | 2017-10-30 14:43:43 +0000 | [diff] [blame] | 187 | } |