blob: 3c27443694f1461a45406b7929d78385f34cdf3c [file] [log] [blame]
Roberto Vargase0e99462017-10-30 14:43:43 +00001/*
Masahiro Yamada0b67e562020-03-09 17:39:48 +09002 * Copyright (c) 2017-2020, ARM Limited and Contributors. All rights reserved.
Roberto Vargase0e99462017-10-30 14:43:43 +00003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
Masahiro Yamada0b67e562020-03-09 17:39:48 +09007#include <common/bl_common.ld.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00008#include <lib/xlat_tables/xlat_tables_defs.h>
Roberto Vargase0e99462017-10-30 14:43:43 +00009
10OUTPUT_FORMAT(PLATFORM_LINKER_FORMAT)
11OUTPUT_ARCH(PLATFORM_LINKER_ARCH)
12ENTRY(bl2_entrypoint)
13
14MEMORY {
Jiafei Pan43a7bf42018-03-21 07:20:09 +000015#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 Vargase0e99462017-10-30 14:43:43 +000019 RAM (rwx): ORIGIN = BL2_BASE, LENGTH = BL2_LIMIT - BL2_BASE
Jiafei Pan43a7bf42018-03-21 07:20:09 +000020#endif
Roberto Vargase0e99462017-10-30 14:43:43 +000021}
22
Masahiro Yamada5289b672019-06-14 17:49:17 +090023#if !BL2_IN_XIP_MEM
24#define ROM RAM
25#endif
Roberto Vargase0e99462017-10-30 14:43:43 +000026
27SECTIONS
28{
Jiafei Pan43a7bf42018-03-21 07:20:09 +000029#if BL2_IN_XIP_MEM
30 . = BL2_RO_BASE;
31 ASSERT(. == ALIGN(PAGE_SIZE),
32 "BL2_RO_BASE address is not aligned on a page boundary.")
33#else
Roberto Vargase0e99462017-10-30 14:43:43 +000034 . = BL2_BASE;
35 ASSERT(. == ALIGN(PAGE_SIZE),
36 "BL2_BASE address is not aligned on a page boundary.")
Jiafei Pan43a7bf42018-03-21 07:20:09 +000037#endif
Roberto Vargase0e99462017-10-30 14:43:43 +000038
39#if SEPARATE_CODE_AND_RODATA
40 .text . : {
41 __TEXT_START__ = .;
Roberto Vargas51abc342017-11-17 10:51:54 +000042 __TEXT_RESIDENT_START__ = .;
43 *bl2_el3_entrypoint.o(.text*)
44 *(.text.asm.*)
45 __TEXT_RESIDENT_END__ = .;
Samuel Holland23f5e542019-10-20 16:11:25 -050046 *(SORT_BY_ALIGNMENT(.text*))
Roberto Vargase0e99462017-10-30 14:43:43 +000047 *(.vectors)
Roberto Vargasd93fde32018-04-11 11:53:31 +010048 . = ALIGN(PAGE_SIZE);
Roberto Vargase0e99462017-10-30 14:43:43 +000049 __TEXT_END__ = .;
Jiafei Pan43a7bf42018-03-21 07:20:09 +000050 } >ROM
Roberto Vargase0e99462017-10-30 14:43:43 +000051
52 .rodata . : {
53 __RODATA_START__ = .;
Samuel Holland23f5e542019-10-20 16:11:25 -050054 *(SORT_BY_ALIGNMENT(.rodata*))
Roberto Vargase0e99462017-10-30 14:43:43 +000055
Masahiro Yamada583f8dd2020-03-26 10:57:12 +090056 RODATA_COMMON
Masahiro Yamada65d699d2020-01-17 13:45:02 +090057
Roberto Vargasd93fde32018-04-11 11:53:31 +010058 . = ALIGN(PAGE_SIZE);
Roberto Vargase0e99462017-10-30 14:43:43 +000059 __RODATA_END__ = .;
Jiafei Pan43a7bf42018-03-21 07:20:09 +000060 } >ROM
Roberto Vargas51abc342017-11-17 10:51:54 +000061
62 ASSERT(__TEXT_RESIDENT_END__ - __TEXT_RESIDENT_START__ <= PAGE_SIZE,
63 "Resident part of BL2 has exceeded its limit.")
Roberto Vargase0e99462017-10-30 14:43:43 +000064#else
65 ro . : {
66 __RO_START__ = .;
Roberto Vargas51abc342017-11-17 10:51:54 +000067 __TEXT_RESIDENT_START__ = .;
68 *bl2_el3_entrypoint.o(.text*)
69 *(.text.asm.*)
70 __TEXT_RESIDENT_END__ = .;
Samuel Holland23f5e542019-10-20 16:11:25 -050071 *(SORT_BY_ALIGNMENT(.text*))
72 *(SORT_BY_ALIGNMENT(.rodata*))
Roberto Vargase0e99462017-10-30 14:43:43 +000073
Masahiro Yamada583f8dd2020-03-26 10:57:12 +090074 RODATA_COMMON
Masahiro Yamada65d699d2020-01-17 13:45:02 +090075
Roberto Vargase0e99462017-10-30 14:43:43 +000076 *(.vectors)
77 __RO_END_UNALIGNED__ = .;
78 /*
79 * Memory page(s) mapped to this section will be marked as
80 * read-only, executable. No RW data from the next section must
81 * creep in. Ensure the rest of the current memory page is unused.
82 */
Roberto Vargasd93fde32018-04-11 11:53:31 +010083 . = ALIGN(PAGE_SIZE);
Roberto Vargase0e99462017-10-30 14:43:43 +000084
85 __RO_END__ = .;
Jiafei Pan43a7bf42018-03-21 07:20:09 +000086 } >ROM
Jiafei Pan43a7bf42018-03-21 07:20:09 +000087#endif
Roberto Vargase0e99462017-10-30 14:43:43 +000088
89 ASSERT(__CPU_OPS_END__ > __CPU_OPS_START__,
90 "cpu_ops not defined for this platform.")
91
Jiafei Pan43a7bf42018-03-21 07:20:09 +000092#if BL2_IN_XIP_MEM
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
97
Roberto Vargase0e99462017-10-30 14:43:43 +000098 /*
99 * Define a linker symbol to mark start of the RW memory area for this
100 * image.
101 */
102 __RW_START__ = . ;
103
104 /*
105 * .data must be placed at a lower address than the stacks if the stack
106 * protector is enabled. Alternatively, the .data.stack_protector_canary
107 * section can be placed independently of the main .data section.
108 */
109 .data . : {
Jiafei Pan43a7bf42018-03-21 07:20:09 +0000110 __DATA_RAM_START__ = .;
Samuel Holland23f5e542019-10-20 16:11:25 -0500111 *(SORT_BY_ALIGNMENT(.data*))
Jiafei Pan43a7bf42018-03-21 07:20:09 +0000112 __DATA_RAM_END__ = .;
Jiafei Pan43a7bf42018-03-21 07:20:09 +0000113 } >RAM AT>ROM
Roberto Vargase0e99462017-10-30 14:43:43 +0000114
Masahiro Yamada65d699d2020-01-17 13:45:02 +0900115 /*
116 * .rela.dyn needs to come after .data for the read-elf utility to parse
117 * this section correctly. Ensure 8-byte alignment so that the fields of
118 * RELA data structure are aligned.
119 */
120 . = ALIGN(8);
121 __RELA_START__ = .;
122 .rela.dyn . : {
123 } >RAM
124 __RELA_END__ = .;
125
Roberto Vargase0e99462017-10-30 14:43:43 +0000126 stacks (NOLOAD) : {
127 __STACKS_START__ = .;
128 *(tzfw_normal_stacks)
129 __STACKS_END__ = .;
130 } >RAM
131
132 /*
133 * The .bss section gets initialised to 0 at runtime.
134 * Its base address should be 16-byte aligned for better performance of the
135 * zero-initialization code.
136 */
137 .bss : ALIGN(16) {
138 __BSS_START__ = .;
139 *(SORT_BY_ALIGNMENT(.bss*))
140 *(COMMON)
141 __BSS_END__ = .;
142 } >RAM
143
Masahiro Yamada0b67e562020-03-09 17:39:48 +0900144 XLAT_TABLE_SECTION >RAM
Roberto Vargase0e99462017-10-30 14:43:43 +0000145
146#if USE_COHERENT_MEM
147 /*
148 * The base address of the coherent memory section must be page-aligned (4K)
149 * to guarantee that the coherent data are stored on their own pages and
150 * are not mixed with normal data. This is required to set up the correct
151 * memory attributes for the coherent data page tables.
152 */
153 coherent_ram (NOLOAD) : ALIGN(PAGE_SIZE) {
154 __COHERENT_RAM_START__ = .;
155 *(tzfw_coherent_mem)
156 __COHERENT_RAM_END_UNALIGNED__ = .;
157 /*
158 * Memory page(s) mapped to this section will be marked
159 * as device memory. No other unexpected data must creep in.
160 * Ensure the rest of the current memory page is unused.
161 */
Roberto Vargasd93fde32018-04-11 11:53:31 +0100162 . = ALIGN(PAGE_SIZE);
Roberto Vargase0e99462017-10-30 14:43:43 +0000163 __COHERENT_RAM_END__ = .;
164 } >RAM
165#endif
166
167 /*
168 * Define a linker symbol to mark end of the RW memory area for this
169 * image.
170 */
171 __RW_END__ = .;
172 __BL2_END__ = .;
173
Masahiro Yamada65d699d2020-01-17 13:45:02 +0900174 /DISCARD/ : {
175 *(.dynsym .dynstr .hash .gnu.hash)
176 }
177
Jiafei Pan43a7bf42018-03-21 07:20:09 +0000178#if BL2_IN_XIP_MEM
179 __BL2_RAM_START__ = ADDR(.data);
180 __BL2_RAM_END__ = .;
181
182 __DATA_ROM_START__ = LOADADDR(.data);
183 __DATA_SIZE__ = SIZEOF(.data);
184
185 /*
186 * The .data section is the last PROGBITS section so its end marks the end
187 * of BL2's RO content in XIP memory..
188 */
189 __BL2_ROM_END__ = __DATA_ROM_START__ + __DATA_SIZE__;
190 ASSERT(__BL2_ROM_END__ <= BL2_RO_LIMIT,
191 "BL2's RO content has exceeded its limit.")
192#endif
Roberto Vargase0e99462017-10-30 14:43:43 +0000193 __BSS_SIZE__ = SIZEOF(.bss);
194
Jiafei Pan43a7bf42018-03-21 07:20:09 +0000195
Roberto Vargase0e99462017-10-30 14:43:43 +0000196#if USE_COHERENT_MEM
197 __COHERENT_RAM_UNALIGNED_SIZE__ =
198 __COHERENT_RAM_END_UNALIGNED__ - __COHERENT_RAM_START__;
199#endif
200
Jiafei Pan43a7bf42018-03-21 07:20:09 +0000201#if BL2_IN_XIP_MEM
202 ASSERT(. <= BL2_RW_LIMIT, "BL2's RW content has exceeded its limit.")
203#else
Roberto Vargase0e99462017-10-30 14:43:43 +0000204 ASSERT(. <= BL2_LIMIT, "BL2 image has exceeded its limit.")
Jiafei Pan43a7bf42018-03-21 07:20:09 +0000205#endif
Roberto Vargase0e99462017-10-30 14:43:43 +0000206}