blob: 5f9f9df5be10b872bfc0e8c5cd7fce2becafc0fb [file] [log] [blame]
Achin Gupta4f6ad662013-10-25 09:08:21 +01001/*
Madhukar Pappireddyf4e6ea62020-01-27 15:32:15 -06002 * Copyright (c) 2013-2020, ARM Limited and Contributors. All rights reserved.
Achin Gupta4f6ad662013-10-25 09:08:21 +01003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Achin Gupta4f6ad662013-10-25 09:08:21 +01005 */
6
Dan Handleyed6ff952014-05-14 17:44:19 +01007#include <platform_def.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00008
Masahiro Yamada0b67e562020-03-09 17:39:48 +09009#include <common/bl_common.ld.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000010#include <lib/xlat_tables/xlat_tables_defs.h>
Achin Gupta4f6ad662013-10-25 09:08:21 +010011
12OUTPUT_FORMAT(PLATFORM_LINKER_FORMAT)
13OUTPUT_ARCH(PLATFORM_LINKER_ARCH)
Jeenu Viswambharan2a30a752014-03-11 11:06:45 +000014ENTRY(bl31_entrypoint)
Achin Gupta4f6ad662013-10-25 09:08:21 +010015
16
17MEMORY {
Juan Castillofd8c0772014-09-16 10:40:35 +010018 RAM (rwx): ORIGIN = BL31_BASE, LENGTH = BL31_LIMIT - BL31_BASE
Samuel Holland31a14e12018-10-17 21:40:18 -050019#if SEPARATE_NOBITS_REGION
20 NOBITS (rw!a): ORIGIN = BL31_NOBITS_BASE, LENGTH = BL31_NOBITS_LIMIT - BL31_NOBITS_BASE
21#else
22#define NOBITS RAM
23#endif
Achin Gupta4f6ad662013-10-25 09:08:21 +010024}
25
Caesar Wangd90f43e2016-10-11 09:36:00 +080026#ifdef PLAT_EXTRA_LD_SCRIPT
27#include <plat.ld.S>
28#endif
Achin Gupta4f6ad662013-10-25 09:08:21 +010029
30SECTIONS
31{
Sandrine Bailleux8d69a032013-11-27 09:38:52 +000032 . = BL31_BASE;
Antonio Nino Diaz2ce2b092017-11-15 11:45:35 +000033 ASSERT(. == ALIGN(PAGE_SIZE),
Sandrine Bailleux8d69a032013-11-27 09:38:52 +000034 "BL31_BASE address is not aligned on a page boundary.")
Achin Gupta4f6ad662013-10-25 09:08:21 +010035
Soby Mathew4e28c202018-10-14 08:09:22 +010036 __BL31_START__ = .;
37
Sandrine Bailleuxf91f1442016-07-08 14:37:40 +010038#if SEPARATE_CODE_AND_RODATA
39 .text . : {
40 __TEXT_START__ = .;
41 *bl31_entrypoint.o(.text*)
Samuel Holland23f5e542019-10-20 16:11:25 -050042 *(SORT_BY_ALIGNMENT(.text*))
Sandrine Bailleuxf91f1442016-07-08 14:37:40 +010043 *(.vectors)
Roberto Vargasd93fde32018-04-11 11:53:31 +010044 . = ALIGN(PAGE_SIZE);
Sandrine Bailleuxf91f1442016-07-08 14:37:40 +010045 __TEXT_END__ = .;
46 } >RAM
47
48 .rodata . : {
49 __RODATA_START__ = .;
Samuel Holland23f5e542019-10-20 16:11:25 -050050 *(SORT_BY_ALIGNMENT(.rodata*))
Sandrine Bailleuxf91f1442016-07-08 14:37:40 +010051
52 /* Ensure 8-byte alignment for descriptors and ensure inclusion */
53 . = ALIGN(8);
54 __RT_SVC_DESCS_START__ = .;
55 KEEP(*(rt_svc_descs))
56 __RT_SVC_DESCS_END__ = .;
57
Madhukar Pappireddyae9677b2020-01-27 13:37:51 -060058 . = ALIGN(8);
59 __FCONF_POPULATOR_START__ = .;
60 KEEP(*(.fconf_populator))
61 __FCONF_POPULATOR_END__ = .;
62
Sandrine Bailleuxf91f1442016-07-08 14:37:40 +010063#if ENABLE_PMF
64 /* Ensure 8-byte alignment for descriptors and ensure inclusion */
65 . = ALIGN(8);
66 __PMF_SVC_DESCS_START__ = .;
67 KEEP(*(pmf_svc_descs))
68 __PMF_SVC_DESCS_END__ = .;
69#endif /* ENABLE_PMF */
70
71 /*
72 * Ensure 8-byte alignment for cpu_ops so that its fields are also
73 * aligned. Also ensure cpu_ops inclusion.
74 */
75 . = ALIGN(8);
76 __CPU_OPS_START__ = .;
77 KEEP(*(cpu_ops))
78 __CPU_OPS_END__ = .;
79
Soby Mathew4e28c202018-10-14 08:09:22 +010080 /*
Soby Mathew2b3fc1d2018-12-12 14:33:11 +000081 * Keep the .got section in the RO section as it is patched
Soby Mathew4e28c202018-10-14 08:09:22 +010082 * prior to enabling the MMU and having the .got in RO is better for
Soby Mathew2b3fc1d2018-12-12 14:33:11 +000083 * security. GOT is a table of addresses so ensure 8-byte alignment.
Soby Mathew4e28c202018-10-14 08:09:22 +010084 */
Soby Mathew2b3fc1d2018-12-12 14:33:11 +000085 . = ALIGN(8);
Soby Mathew4e28c202018-10-14 08:09:22 +010086 __GOT_START__ = .;
87 *(.got)
88 __GOT_END__ = .;
89
Jeenu Viswambharane3f22002017-09-22 08:32:10 +010090 /* Place pubsub sections for events */
91 . = ALIGN(8);
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000092#include <lib/el3_runtime/pubsub_events.h>
Jeenu Viswambharane3f22002017-09-22 08:32:10 +010093
Roberto Vargasd93fde32018-04-11 11:53:31 +010094 . = ALIGN(PAGE_SIZE);
Sandrine Bailleuxf91f1442016-07-08 14:37:40 +010095 __RODATA_END__ = .;
96 } >RAM
97#else
Sandrine Bailleux8d69a032013-11-27 09:38:52 +000098 ro . : {
99 __RO_START__ = .;
Andrew Thoelkee01ea342014-03-18 07:13:52 +0000100 *bl31_entrypoint.o(.text*)
Samuel Holland23f5e542019-10-20 16:11:25 -0500101 *(SORT_BY_ALIGNMENT(.text*))
102 *(SORT_BY_ALIGNMENT(.rodata*))
Achin Gupta7421b462014-02-01 18:53:26 +0000103
Andrew Thoelkee01ea342014-03-18 07:13:52 +0000104 /* Ensure 8-byte alignment for descriptors and ensure inclusion */
Achin Gupta7421b462014-02-01 18:53:26 +0000105 . = ALIGN(8);
106 __RT_SVC_DESCS_START__ = .;
Andrew Thoelkee01ea342014-03-18 07:13:52 +0000107 KEEP(*(rt_svc_descs))
Achin Gupta7421b462014-02-01 18:53:26 +0000108 __RT_SVC_DESCS_END__ = .;
109
Madhukar Pappireddyae9677b2020-01-27 13:37:51 -0600110 . = ALIGN(8);
111 __FCONF_POPULATOR_START__ = .;
112 KEEP(*(.fconf_populator))
113 __FCONF_POPULATOR_END__ = .;
114
Yatharth Kochar9518d022016-03-11 14:20:19 +0000115#if ENABLE_PMF
116 /* Ensure 8-byte alignment for descriptors and ensure inclusion */
117 . = ALIGN(8);
118 __PMF_SVC_DESCS_START__ = .;
119 KEEP(*(pmf_svc_descs))
120 __PMF_SVC_DESCS_END__ = .;
121#endif /* ENABLE_PMF */
122
Soby Mathewc704cbc2014-08-14 11:33:56 +0100123 /*
124 * Ensure 8-byte alignment for cpu_ops so that its fields are also
125 * aligned. Also ensure cpu_ops inclusion.
126 */
127 . = ALIGN(8);
128 __CPU_OPS_START__ = .;
129 KEEP(*(cpu_ops))
130 __CPU_OPS_END__ = .;
131
Soby Mathew2b3fc1d2018-12-12 14:33:11 +0000132 /*
133 * Keep the .got section in the RO section as it is patched
134 * prior to enabling the MMU and having the .got in RO is better for
135 * security. GOT is a table of addresses so ensure 8-byte alignment.
136 */
137 . = ALIGN(8);
138 __GOT_START__ = .;
139 *(.got)
140 __GOT_END__ = .;
141
Jeenu Viswambharane3f22002017-09-22 08:32:10 +0100142 /* Place pubsub sections for events */
143 . = ALIGN(8);
Antonio Nino Diaze0f90632018-12-14 00:18:21 +0000144#include <lib/el3_runtime/pubsub_events.h>
Jeenu Viswambharane3f22002017-09-22 08:32:10 +0100145
Achin Guptab739f222014-01-18 16:50:09 +0000146 *(.vectors)
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000147 __RO_END_UNALIGNED__ = .;
148 /*
149 * Memory page(s) mapped to this section will be marked as read-only,
150 * executable. No RW data from the next section must creep in.
151 * Ensure the rest of the current memory page is unused.
152 */
Roberto Vargasd93fde32018-04-11 11:53:31 +0100153 . = ALIGN(PAGE_SIZE);
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000154 __RO_END__ = .;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100155 } >RAM
Sandrine Bailleuxf91f1442016-07-08 14:37:40 +0100156#endif
Achin Gupta4f6ad662013-10-25 09:08:21 +0100157
Soby Mathewc704cbc2014-08-14 11:33:56 +0100158 ASSERT(__CPU_OPS_END__ > __CPU_OPS_START__,
159 "cpu_ops not defined for this platform.")
160
Paul Beesleydb4e25a2019-10-14 15:27:12 +0000161#if SPM_MM
Ard Biesheuvel447d56f2019-01-06 10:07:24 +0100162#ifndef SPM_SHIM_EXCEPTIONS_VMA
163#define SPM_SHIM_EXCEPTIONS_VMA RAM
164#endif
165
Antonio Nino Diazc41f2062017-10-24 10:07:35 +0100166 /*
167 * Exception vectors of the SPM shim layer. They must be aligned to a 2K
168 * address, but we need to place them in a separate page so that we can set
169 * individual permissions to them, so the actual alignment needed is 4K.
170 *
171 * There's no need to include this into the RO section of BL31 because it
172 * doesn't need to be accessed by BL31.
173 */
Antonio Nino Diaz2ce2b092017-11-15 11:45:35 +0000174 spm_shim_exceptions : ALIGN(PAGE_SIZE) {
Antonio Nino Diazc41f2062017-10-24 10:07:35 +0100175 __SPM_SHIM_EXCEPTIONS_START__ = .;
176 *(.spm_shim_exceptions)
Roberto Vargasd93fde32018-04-11 11:53:31 +0100177 . = ALIGN(PAGE_SIZE);
Antonio Nino Diazc41f2062017-10-24 10:07:35 +0100178 __SPM_SHIM_EXCEPTIONS_END__ = .;
Ard Biesheuvel447d56f2019-01-06 10:07:24 +0100179 } >SPM_SHIM_EXCEPTIONS_VMA AT>RAM
180
181 PROVIDE(__SPM_SHIM_EXCEPTIONS_LMA__ = LOADADDR(spm_shim_exceptions));
182 . = LOADADDR(spm_shim_exceptions) + SIZEOF(spm_shim_exceptions);
Antonio Nino Diazc41f2062017-10-24 10:07:35 +0100183#endif
184
Achin Guptae9c4a642015-09-11 16:03:13 +0100185 /*
186 * Define a linker symbol to mark start of the RW memory area for this
187 * image.
188 */
189 __RW_START__ = . ;
190
Douglas Raillard306593d2017-02-24 18:14:15 +0000191 /*
192 * .data must be placed at a lower address than the stacks if the stack
193 * protector is enabled. Alternatively, the .data.stack_protector_canary
194 * section can be placed independently of the main .data section.
195 */
196 .data . : {
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000197 __DATA_START__ = .;
Samuel Holland23f5e542019-10-20 16:11:25 -0500198 *(SORT_BY_ALIGNMENT(.data*))
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000199 __DATA_END__ = .;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100200 } >RAM
201
Soby Mathew4e28c202018-10-14 08:09:22 +0100202 /*
203 * .rela.dyn needs to come after .data for the read-elf utility to parse
Soby Mathew2b3fc1d2018-12-12 14:33:11 +0000204 * this section correctly. Ensure 8-byte alignment so that the fields of
205 * RELA data structure are aligned.
Soby Mathew4e28c202018-10-14 08:09:22 +0100206 */
Soby Mathew2b3fc1d2018-12-12 14:33:11 +0000207 . = ALIGN(8);
Soby Mathew4e28c202018-10-14 08:09:22 +0100208 __RELA_START__ = .;
209 .rela.dyn . : {
210 } >RAM
211 __RELA_END__ = .;
212
Sandrine Bailleuxe2e0c652014-06-16 16:12:27 +0100213#ifdef BL31_PROGBITS_LIMIT
Juan Castillo7d199412015-12-14 09:35:25 +0000214 ASSERT(. <= BL31_PROGBITS_LIMIT, "BL31 progbits has exceeded its limit.")
Sandrine Bailleuxe2e0c652014-06-16 16:12:27 +0100215#endif
216
Samuel Holland31a14e12018-10-17 21:40:18 -0500217#if SEPARATE_NOBITS_REGION
218 /*
219 * Define a linker symbol to mark end of the RW memory area for this
220 * image.
221 */
Madhukar Pappireddyf4e6ea62020-01-27 15:32:15 -0600222 . = ALIGN(PAGE_SIZE);
Samuel Holland31a14e12018-10-17 21:40:18 -0500223 __RW_END__ = .;
224 __BL31_END__ = .;
225
226 ASSERT(. <= BL31_LIMIT, "BL31 image has exceeded its limit.")
227
228 . = BL31_NOBITS_BASE;
229 ASSERT(. == ALIGN(PAGE_SIZE),
230 "BL31 NOBITS base address is not aligned on a page boundary.")
231
232 __NOBITS_START__ = .;
233#endif
234
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000235 stacks (NOLOAD) : {
236 __STACKS_START__ = .;
237 *(tzfw_normal_stacks)
238 __STACKS_END__ = .;
Samuel Holland31a14e12018-10-17 21:40:18 -0500239 } >NOBITS
Achin Gupta4f6ad662013-10-25 09:08:21 +0100240
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000241 /*
242 * The .bss section gets initialised to 0 at runtime.
Douglas Raillard21362a92016-12-02 13:51:54 +0000243 * Its base address should be 16-byte aligned for better performance of the
244 * zero-initialization code.
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000245 */
Andrew Thoelkee466c9f2015-09-10 11:39:36 +0100246 .bss (NOLOAD) : ALIGN(16) {
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000247 __BSS_START__ = .;
Samuel Holland23f5e542019-10-20 16:11:25 -0500248 *(SORT_BY_ALIGNMENT(.bss*))
Achin Gupta4f6ad662013-10-25 09:08:21 +0100249 *(COMMON)
Andrew Thoelkee466c9f2015-09-10 11:39:36 +0100250#if !USE_COHERENT_MEM
251 /*
252 * Bakery locks are stored in normal .bss memory
253 *
254 * Each lock's data is spread across multiple cache lines, one per CPU,
255 * but multiple locks can share the same cache line.
256 * The compiler will allocate enough memory for one CPU's bakery locks,
257 * the remaining cache lines are allocated by the linker script
258 */
259 . = ALIGN(CACHE_WRITEBACK_GRANULE);
260 __BAKERY_LOCK_START__ = .;
Varun Wadekar77c382c2019-01-30 08:26:20 -0800261 __PERCPU_BAKERY_LOCK_START__ = .;
Andrew Thoelkee466c9f2015-09-10 11:39:36 +0100262 *(bakery_lock)
263 . = ALIGN(CACHE_WRITEBACK_GRANULE);
Varun Wadekar77c382c2019-01-30 08:26:20 -0800264 __PERCPU_BAKERY_LOCK_END__ = .;
265 __PERCPU_BAKERY_LOCK_SIZE__ = ABSOLUTE(__PERCPU_BAKERY_LOCK_END__ - __PERCPU_BAKERY_LOCK_START__);
Andrew Thoelkee466c9f2015-09-10 11:39:36 +0100266 . = . + (__PERCPU_BAKERY_LOCK_SIZE__ * (PLATFORM_CORE_COUNT - 1));
267 __BAKERY_LOCK_END__ = .;
Roberto Vargas00996942017-11-13 13:41:58 +0000268
269 /*
270 * If BL31 doesn't use any bakery lock then __PERCPU_BAKERY_LOCK_SIZE__
271 * will be zero. For this reason, the only two valid values for
272 * __PERCPU_BAKERY_LOCK_SIZE__ are 0 or the platform defined value
273 * PLAT_PERCPU_BAKERY_LOCK_SIZE.
274 */
Andrew Thoelkee466c9f2015-09-10 11:39:36 +0100275#ifdef PLAT_PERCPU_BAKERY_LOCK_SIZE
Roberto Vargas00996942017-11-13 13:41:58 +0000276 ASSERT((__PERCPU_BAKERY_LOCK_SIZE__ == 0) || (__PERCPU_BAKERY_LOCK_SIZE__ == PLAT_PERCPU_BAKERY_LOCK_SIZE),
Andrew Thoelkee466c9f2015-09-10 11:39:36 +0100277 "PLAT_PERCPU_BAKERY_LOCK_SIZE does not match bakery lock requirements");
278#endif
279#endif
Yatharth Kochar9518d022016-03-11 14:20:19 +0000280
281#if ENABLE_PMF
282 /*
283 * Time-stamps are stored in normal .bss memory
284 *
285 * The compiler will allocate enough memory for one CPU's time-stamps,
Paul Beesley1fbc97b2019-01-11 18:26:51 +0000286 * the remaining memory for other CPUs is allocated by the
Yatharth Kochar9518d022016-03-11 14:20:19 +0000287 * linker script
288 */
289 . = ALIGN(CACHE_WRITEBACK_GRANULE);
290 __PMF_TIMESTAMP_START__ = .;
291 KEEP(*(pmf_timestamp_array))
292 . = ALIGN(CACHE_WRITEBACK_GRANULE);
293 __PMF_PERCPU_TIMESTAMP_END__ = .;
294 __PERCPU_TIMESTAMP_SIZE__ = ABSOLUTE(. - __PMF_TIMESTAMP_START__);
295 . = . + (__PERCPU_TIMESTAMP_SIZE__ * (PLATFORM_CORE_COUNT - 1));
296 __PMF_TIMESTAMP_END__ = .;
297#endif /* ENABLE_PMF */
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000298 __BSS_END__ = .;
Samuel Holland31a14e12018-10-17 21:40:18 -0500299 } >NOBITS
Achin Gupta4f6ad662013-10-25 09:08:21 +0100300
Masahiro Yamada0b67e562020-03-09 17:39:48 +0900301 XLAT_TABLE_SECTION >NOBITS
Achin Guptaa0cd9892014-02-09 13:30:38 +0000302
Soby Mathew2ae20432015-01-08 18:02:44 +0000303#if USE_COHERENT_MEM
Achin Guptaa0cd9892014-02-09 13:30:38 +0000304 /*
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000305 * The base address of the coherent memory section must be page-aligned (4K)
306 * to guarantee that the coherent data are stored on their own pages and
307 * are not mixed with normal data. This is required to set up the correct
308 * memory attributes for the coherent data page tables.
309 */
Antonio Nino Diaz2ce2b092017-11-15 11:45:35 +0000310 coherent_ram (NOLOAD) : ALIGN(PAGE_SIZE) {
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000311 __COHERENT_RAM_START__ = .;
Andrew Thoelkee466c9f2015-09-10 11:39:36 +0100312 /*
313 * Bakery locks are stored in coherent memory
314 *
315 * Each lock's data is contiguous and fully allocated by the compiler
316 */
317 *(bakery_lock)
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000318 *(tzfw_coherent_mem)
319 __COHERENT_RAM_END_UNALIGNED__ = .;
320 /*
321 * Memory page(s) mapped to this section will be marked
322 * as device memory. No other unexpected data must creep in.
323 * Ensure the rest of the current memory page is unused.
324 */
Roberto Vargasd93fde32018-04-11 11:53:31 +0100325 . = ALIGN(PAGE_SIZE);
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000326 __COHERENT_RAM_END__ = .;
Samuel Holland31a14e12018-10-17 21:40:18 -0500327 } >NOBITS
Soby Mathew2ae20432015-01-08 18:02:44 +0000328#endif
Achin Gupta4f6ad662013-10-25 09:08:21 +0100329
Samuel Holland31a14e12018-10-17 21:40:18 -0500330#if SEPARATE_NOBITS_REGION
331 /*
332 * Define a linker symbol to mark end of the NOBITS memory area for this
333 * image.
334 */
335 __NOBITS_END__ = .;
336
337 ASSERT(. <= BL31_NOBITS_LIMIT, "BL31 NOBITS region has exceeded its limit.")
338#else
Achin Guptae9c4a642015-09-11 16:03:13 +0100339 /*
340 * Define a linker symbol to mark end of the RW memory area for this
341 * image.
342 */
343 __RW_END__ = .;
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000344 __BL31_END__ = .;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100345
Masahiro Yamadad3e7baa2020-01-17 13:44:50 +0900346 /DISCARD/ : {
347 *(.dynsym .dynstr .hash .gnu.hash)
348 }
349
Juan Castillo7d199412015-12-14 09:35:25 +0000350 ASSERT(. <= BL31_LIMIT, "BL31 image has exceeded its limit.")
Samuel Holland31a14e12018-10-17 21:40:18 -0500351#endif
Achin Gupta4f6ad662013-10-25 09:08:21 +0100352}