blob: fce9eb266d4b15f595a36b46f86065a15f6c1ebd [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
9#include <lib/xlat_tables/xlat_tables_defs.h>
Achin Gupta4f6ad662013-10-25 09:08:21 +010010
11OUTPUT_FORMAT(PLATFORM_LINKER_FORMAT)
12OUTPUT_ARCH(PLATFORM_LINKER_ARCH)
Jeenu Viswambharan2a30a752014-03-11 11:06:45 +000013ENTRY(bl31_entrypoint)
Achin Gupta4f6ad662013-10-25 09:08:21 +010014
15
16MEMORY {
Juan Castillofd8c0772014-09-16 10:40:35 +010017 RAM (rwx): ORIGIN = BL31_BASE, LENGTH = BL31_LIMIT - BL31_BASE
Samuel Holland31a14e12018-10-17 21:40:18 -050018#if SEPARATE_NOBITS_REGION
19 NOBITS (rw!a): ORIGIN = BL31_NOBITS_BASE, LENGTH = BL31_NOBITS_LIMIT - BL31_NOBITS_BASE
20#else
21#define NOBITS RAM
22#endif
Achin Gupta4f6ad662013-10-25 09:08:21 +010023}
24
Caesar Wangd90f43e2016-10-11 09:36:00 +080025#ifdef PLAT_EXTRA_LD_SCRIPT
26#include <plat.ld.S>
27#endif
Achin Gupta4f6ad662013-10-25 09:08:21 +010028
29SECTIONS
30{
Sandrine Bailleux8d69a032013-11-27 09:38:52 +000031 . = BL31_BASE;
Antonio Nino Diaz2ce2b092017-11-15 11:45:35 +000032 ASSERT(. == ALIGN(PAGE_SIZE),
Sandrine Bailleux8d69a032013-11-27 09:38:52 +000033 "BL31_BASE address is not aligned on a page boundary.")
Achin Gupta4f6ad662013-10-25 09:08:21 +010034
Soby Mathew4e28c202018-10-14 08:09:22 +010035 __BL31_START__ = .;
36
Sandrine Bailleuxf91f1442016-07-08 14:37:40 +010037#if SEPARATE_CODE_AND_RODATA
38 .text . : {
39 __TEXT_START__ = .;
40 *bl31_entrypoint.o(.text*)
Samuel Holland23f5e542019-10-20 16:11:25 -050041 *(SORT_BY_ALIGNMENT(.text*))
Sandrine Bailleuxf91f1442016-07-08 14:37:40 +010042 *(.vectors)
Roberto Vargasd93fde32018-04-11 11:53:31 +010043 . = ALIGN(PAGE_SIZE);
Sandrine Bailleuxf91f1442016-07-08 14:37:40 +010044 __TEXT_END__ = .;
45 } >RAM
46
47 .rodata . : {
48 __RODATA_START__ = .;
Samuel Holland23f5e542019-10-20 16:11:25 -050049 *(SORT_BY_ALIGNMENT(.rodata*))
Sandrine Bailleuxf91f1442016-07-08 14:37:40 +010050
51 /* Ensure 8-byte alignment for descriptors and ensure inclusion */
52 . = ALIGN(8);
53 __RT_SVC_DESCS_START__ = .;
54 KEEP(*(rt_svc_descs))
55 __RT_SVC_DESCS_END__ = .;
56
Madhukar Pappireddyae9677b2020-01-27 13:37:51 -060057 . = ALIGN(8);
58 __FCONF_POPULATOR_START__ = .;
59 KEEP(*(.fconf_populator))
60 __FCONF_POPULATOR_END__ = .;
61
Sandrine Bailleuxf91f1442016-07-08 14:37:40 +010062#if ENABLE_PMF
63 /* Ensure 8-byte alignment for descriptors and ensure inclusion */
64 . = ALIGN(8);
65 __PMF_SVC_DESCS_START__ = .;
66 KEEP(*(pmf_svc_descs))
67 __PMF_SVC_DESCS_END__ = .;
68#endif /* ENABLE_PMF */
69
70 /*
71 * Ensure 8-byte alignment for cpu_ops so that its fields are also
72 * aligned. Also ensure cpu_ops inclusion.
73 */
74 . = ALIGN(8);
75 __CPU_OPS_START__ = .;
76 KEEP(*(cpu_ops))
77 __CPU_OPS_END__ = .;
78
Soby Mathew4e28c202018-10-14 08:09:22 +010079 /*
Soby Mathew2b3fc1d2018-12-12 14:33:11 +000080 * Keep the .got section in the RO section as it is patched
Soby Mathew4e28c202018-10-14 08:09:22 +010081 * prior to enabling the MMU and having the .got in RO is better for
Soby Mathew2b3fc1d2018-12-12 14:33:11 +000082 * security. GOT is a table of addresses so ensure 8-byte alignment.
Soby Mathew4e28c202018-10-14 08:09:22 +010083 */
Soby Mathew2b3fc1d2018-12-12 14:33:11 +000084 . = ALIGN(8);
Soby Mathew4e28c202018-10-14 08:09:22 +010085 __GOT_START__ = .;
86 *(.got)
87 __GOT_END__ = .;
88
Jeenu Viswambharane3f22002017-09-22 08:32:10 +010089 /* Place pubsub sections for events */
90 . = ALIGN(8);
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000091#include <lib/el3_runtime/pubsub_events.h>
Jeenu Viswambharane3f22002017-09-22 08:32:10 +010092
Roberto Vargasd93fde32018-04-11 11:53:31 +010093 . = ALIGN(PAGE_SIZE);
Sandrine Bailleuxf91f1442016-07-08 14:37:40 +010094 __RODATA_END__ = .;
95 } >RAM
96#else
Sandrine Bailleux8d69a032013-11-27 09:38:52 +000097 ro . : {
98 __RO_START__ = .;
Andrew Thoelkee01ea342014-03-18 07:13:52 +000099 *bl31_entrypoint.o(.text*)
Samuel Holland23f5e542019-10-20 16:11:25 -0500100 *(SORT_BY_ALIGNMENT(.text*))
101 *(SORT_BY_ALIGNMENT(.rodata*))
Achin Gupta7421b462014-02-01 18:53:26 +0000102
Andrew Thoelkee01ea342014-03-18 07:13:52 +0000103 /* Ensure 8-byte alignment for descriptors and ensure inclusion */
Achin Gupta7421b462014-02-01 18:53:26 +0000104 . = ALIGN(8);
105 __RT_SVC_DESCS_START__ = .;
Andrew Thoelkee01ea342014-03-18 07:13:52 +0000106 KEEP(*(rt_svc_descs))
Achin Gupta7421b462014-02-01 18:53:26 +0000107 __RT_SVC_DESCS_END__ = .;
108
Madhukar Pappireddyae9677b2020-01-27 13:37:51 -0600109 . = ALIGN(8);
110 __FCONF_POPULATOR_START__ = .;
111 KEEP(*(.fconf_populator))
112 __FCONF_POPULATOR_END__ = .;
113
Yatharth Kochar9518d022016-03-11 14:20:19 +0000114#if ENABLE_PMF
115 /* Ensure 8-byte alignment for descriptors and ensure inclusion */
116 . = ALIGN(8);
117 __PMF_SVC_DESCS_START__ = .;
118 KEEP(*(pmf_svc_descs))
119 __PMF_SVC_DESCS_END__ = .;
120#endif /* ENABLE_PMF */
121
Soby Mathewc704cbc2014-08-14 11:33:56 +0100122 /*
123 * Ensure 8-byte alignment for cpu_ops so that its fields are also
124 * aligned. Also ensure cpu_ops inclusion.
125 */
126 . = ALIGN(8);
127 __CPU_OPS_START__ = .;
128 KEEP(*(cpu_ops))
129 __CPU_OPS_END__ = .;
130
Soby Mathew2b3fc1d2018-12-12 14:33:11 +0000131 /*
132 * Keep the .got section in the RO section as it is patched
133 * prior to enabling the MMU and having the .got in RO is better for
134 * security. GOT is a table of addresses so ensure 8-byte alignment.
135 */
136 . = ALIGN(8);
137 __GOT_START__ = .;
138 *(.got)
139 __GOT_END__ = .;
140
Jeenu Viswambharane3f22002017-09-22 08:32:10 +0100141 /* Place pubsub sections for events */
142 . = ALIGN(8);
Antonio Nino Diaze0f90632018-12-14 00:18:21 +0000143#include <lib/el3_runtime/pubsub_events.h>
Jeenu Viswambharane3f22002017-09-22 08:32:10 +0100144
Achin Guptab739f222014-01-18 16:50:09 +0000145 *(.vectors)
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000146 __RO_END_UNALIGNED__ = .;
147 /*
148 * Memory page(s) mapped to this section will be marked as read-only,
149 * executable. No RW data from the next section must creep in.
150 * Ensure the rest of the current memory page is unused.
151 */
Roberto Vargasd93fde32018-04-11 11:53:31 +0100152 . = ALIGN(PAGE_SIZE);
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000153 __RO_END__ = .;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100154 } >RAM
Sandrine Bailleuxf91f1442016-07-08 14:37:40 +0100155#endif
Achin Gupta4f6ad662013-10-25 09:08:21 +0100156
Soby Mathewc704cbc2014-08-14 11:33:56 +0100157 ASSERT(__CPU_OPS_END__ > __CPU_OPS_START__,
158 "cpu_ops not defined for this platform.")
159
Paul Beesleydb4e25a2019-10-14 15:27:12 +0000160#if SPM_MM
Ard Biesheuvel447d56f2019-01-06 10:07:24 +0100161#ifndef SPM_SHIM_EXCEPTIONS_VMA
162#define SPM_SHIM_EXCEPTIONS_VMA RAM
163#endif
164
Antonio Nino Diazc41f2062017-10-24 10:07:35 +0100165 /*
166 * Exception vectors of the SPM shim layer. They must be aligned to a 2K
167 * address, but we need to place them in a separate page so that we can set
168 * individual permissions to them, so the actual alignment needed is 4K.
169 *
170 * There's no need to include this into the RO section of BL31 because it
171 * doesn't need to be accessed by BL31.
172 */
Antonio Nino Diaz2ce2b092017-11-15 11:45:35 +0000173 spm_shim_exceptions : ALIGN(PAGE_SIZE) {
Antonio Nino Diazc41f2062017-10-24 10:07:35 +0100174 __SPM_SHIM_EXCEPTIONS_START__ = .;
175 *(.spm_shim_exceptions)
Roberto Vargasd93fde32018-04-11 11:53:31 +0100176 . = ALIGN(PAGE_SIZE);
Antonio Nino Diazc41f2062017-10-24 10:07:35 +0100177 __SPM_SHIM_EXCEPTIONS_END__ = .;
Ard Biesheuvel447d56f2019-01-06 10:07:24 +0100178 } >SPM_SHIM_EXCEPTIONS_VMA AT>RAM
179
180 PROVIDE(__SPM_SHIM_EXCEPTIONS_LMA__ = LOADADDR(spm_shim_exceptions));
181 . = LOADADDR(spm_shim_exceptions) + SIZEOF(spm_shim_exceptions);
Antonio Nino Diazc41f2062017-10-24 10:07:35 +0100182#endif
183
Achin Guptae9c4a642015-09-11 16:03:13 +0100184 /*
185 * Define a linker symbol to mark start of the RW memory area for this
186 * image.
187 */
188 __RW_START__ = . ;
189
Douglas Raillard306593d2017-02-24 18:14:15 +0000190 /*
191 * .data must be placed at a lower address than the stacks if the stack
192 * protector is enabled. Alternatively, the .data.stack_protector_canary
193 * section can be placed independently of the main .data section.
194 */
195 .data . : {
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000196 __DATA_START__ = .;
Samuel Holland23f5e542019-10-20 16:11:25 -0500197 *(SORT_BY_ALIGNMENT(.data*))
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000198 __DATA_END__ = .;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100199 } >RAM
200
Soby Mathew4e28c202018-10-14 08:09:22 +0100201 /*
202 * .rela.dyn needs to come after .data for the read-elf utility to parse
Soby Mathew2b3fc1d2018-12-12 14:33:11 +0000203 * this section correctly. Ensure 8-byte alignment so that the fields of
204 * RELA data structure are aligned.
Soby Mathew4e28c202018-10-14 08:09:22 +0100205 */
Soby Mathew2b3fc1d2018-12-12 14:33:11 +0000206 . = ALIGN(8);
Soby Mathew4e28c202018-10-14 08:09:22 +0100207 __RELA_START__ = .;
208 .rela.dyn . : {
209 } >RAM
210 __RELA_END__ = .;
211
Sandrine Bailleuxe2e0c652014-06-16 16:12:27 +0100212#ifdef BL31_PROGBITS_LIMIT
Juan Castillo7d199412015-12-14 09:35:25 +0000213 ASSERT(. <= BL31_PROGBITS_LIMIT, "BL31 progbits has exceeded its limit.")
Sandrine Bailleuxe2e0c652014-06-16 16:12:27 +0100214#endif
215
Samuel Holland31a14e12018-10-17 21:40:18 -0500216#if SEPARATE_NOBITS_REGION
217 /*
218 * Define a linker symbol to mark end of the RW memory area for this
219 * image.
220 */
Madhukar Pappireddyf4e6ea62020-01-27 15:32:15 -0600221 . = ALIGN(PAGE_SIZE);
Samuel Holland31a14e12018-10-17 21:40:18 -0500222 __RW_END__ = .;
223 __BL31_END__ = .;
224
225 ASSERT(. <= BL31_LIMIT, "BL31 image has exceeded its limit.")
226
227 . = BL31_NOBITS_BASE;
228 ASSERT(. == ALIGN(PAGE_SIZE),
229 "BL31 NOBITS base address is not aligned on a page boundary.")
230
231 __NOBITS_START__ = .;
232#endif
233
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000234 stacks (NOLOAD) : {
235 __STACKS_START__ = .;
236 *(tzfw_normal_stacks)
237 __STACKS_END__ = .;
Samuel Holland31a14e12018-10-17 21:40:18 -0500238 } >NOBITS
Achin Gupta4f6ad662013-10-25 09:08:21 +0100239
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000240 /*
241 * The .bss section gets initialised to 0 at runtime.
Douglas Raillard21362a92016-12-02 13:51:54 +0000242 * Its base address should be 16-byte aligned for better performance of the
243 * zero-initialization code.
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000244 */
Andrew Thoelkee466c9f2015-09-10 11:39:36 +0100245 .bss (NOLOAD) : ALIGN(16) {
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000246 __BSS_START__ = .;
Samuel Holland23f5e542019-10-20 16:11:25 -0500247 *(SORT_BY_ALIGNMENT(.bss*))
Achin Gupta4f6ad662013-10-25 09:08:21 +0100248 *(COMMON)
Andrew Thoelkee466c9f2015-09-10 11:39:36 +0100249#if !USE_COHERENT_MEM
250 /*
251 * Bakery locks are stored in normal .bss memory
252 *
253 * Each lock's data is spread across multiple cache lines, one per CPU,
254 * but multiple locks can share the same cache line.
255 * The compiler will allocate enough memory for one CPU's bakery locks,
256 * the remaining cache lines are allocated by the linker script
257 */
258 . = ALIGN(CACHE_WRITEBACK_GRANULE);
259 __BAKERY_LOCK_START__ = .;
Varun Wadekar77c382c2019-01-30 08:26:20 -0800260 __PERCPU_BAKERY_LOCK_START__ = .;
Andrew Thoelkee466c9f2015-09-10 11:39:36 +0100261 *(bakery_lock)
262 . = ALIGN(CACHE_WRITEBACK_GRANULE);
Varun Wadekar77c382c2019-01-30 08:26:20 -0800263 __PERCPU_BAKERY_LOCK_END__ = .;
264 __PERCPU_BAKERY_LOCK_SIZE__ = ABSOLUTE(__PERCPU_BAKERY_LOCK_END__ - __PERCPU_BAKERY_LOCK_START__);
Andrew Thoelkee466c9f2015-09-10 11:39:36 +0100265 . = . + (__PERCPU_BAKERY_LOCK_SIZE__ * (PLATFORM_CORE_COUNT - 1));
266 __BAKERY_LOCK_END__ = .;
Roberto Vargas00996942017-11-13 13:41:58 +0000267
268 /*
269 * If BL31 doesn't use any bakery lock then __PERCPU_BAKERY_LOCK_SIZE__
270 * will be zero. For this reason, the only two valid values for
271 * __PERCPU_BAKERY_LOCK_SIZE__ are 0 or the platform defined value
272 * PLAT_PERCPU_BAKERY_LOCK_SIZE.
273 */
Andrew Thoelkee466c9f2015-09-10 11:39:36 +0100274#ifdef PLAT_PERCPU_BAKERY_LOCK_SIZE
Roberto Vargas00996942017-11-13 13:41:58 +0000275 ASSERT((__PERCPU_BAKERY_LOCK_SIZE__ == 0) || (__PERCPU_BAKERY_LOCK_SIZE__ == PLAT_PERCPU_BAKERY_LOCK_SIZE),
Andrew Thoelkee466c9f2015-09-10 11:39:36 +0100276 "PLAT_PERCPU_BAKERY_LOCK_SIZE does not match bakery lock requirements");
277#endif
278#endif
Yatharth Kochar9518d022016-03-11 14:20:19 +0000279
280#if ENABLE_PMF
281 /*
282 * Time-stamps are stored in normal .bss memory
283 *
284 * The compiler will allocate enough memory for one CPU's time-stamps,
Paul Beesley1fbc97b2019-01-11 18:26:51 +0000285 * the remaining memory for other CPUs is allocated by the
Yatharth Kochar9518d022016-03-11 14:20:19 +0000286 * linker script
287 */
288 . = ALIGN(CACHE_WRITEBACK_GRANULE);
289 __PMF_TIMESTAMP_START__ = .;
290 KEEP(*(pmf_timestamp_array))
291 . = ALIGN(CACHE_WRITEBACK_GRANULE);
292 __PMF_PERCPU_TIMESTAMP_END__ = .;
293 __PERCPU_TIMESTAMP_SIZE__ = ABSOLUTE(. - __PMF_TIMESTAMP_START__);
294 . = . + (__PERCPU_TIMESTAMP_SIZE__ * (PLATFORM_CORE_COUNT - 1));
295 __PMF_TIMESTAMP_END__ = .;
296#endif /* ENABLE_PMF */
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000297 __BSS_END__ = .;
Samuel Holland31a14e12018-10-17 21:40:18 -0500298 } >NOBITS
Achin Gupta4f6ad662013-10-25 09:08:21 +0100299
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000300 /*
Jeenu Viswambharan97cc9ee2014-02-24 15:20:28 +0000301 * The xlat_table section is for full, aligned page tables (4K).
Achin Guptaa0cd9892014-02-09 13:30:38 +0000302 * Removing them from .bss avoids forcing 4K alignment on
Antonio Nino Diaz7c2a3ca2018-02-23 15:07:54 +0000303 * the .bss section. The tables are initialized to zero by the translation
304 * tables library.
Achin Guptaa0cd9892014-02-09 13:30:38 +0000305 */
306 xlat_table (NOLOAD) : {
307 *(xlat_table)
Samuel Holland31a14e12018-10-17 21:40:18 -0500308 } >NOBITS
Achin Guptaa0cd9892014-02-09 13:30:38 +0000309
Soby Mathew2ae20432015-01-08 18:02:44 +0000310#if USE_COHERENT_MEM
Achin Guptaa0cd9892014-02-09 13:30:38 +0000311 /*
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000312 * The base address of the coherent memory section must be page-aligned (4K)
313 * to guarantee that the coherent data are stored on their own pages and
314 * are not mixed with normal data. This is required to set up the correct
315 * memory attributes for the coherent data page tables.
316 */
Antonio Nino Diaz2ce2b092017-11-15 11:45:35 +0000317 coherent_ram (NOLOAD) : ALIGN(PAGE_SIZE) {
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000318 __COHERENT_RAM_START__ = .;
Andrew Thoelkee466c9f2015-09-10 11:39:36 +0100319 /*
320 * Bakery locks are stored in coherent memory
321 *
322 * Each lock's data is contiguous and fully allocated by the compiler
323 */
324 *(bakery_lock)
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000325 *(tzfw_coherent_mem)
326 __COHERENT_RAM_END_UNALIGNED__ = .;
327 /*
328 * Memory page(s) mapped to this section will be marked
329 * as device memory. No other unexpected data must creep in.
330 * Ensure the rest of the current memory page is unused.
331 */
Roberto Vargasd93fde32018-04-11 11:53:31 +0100332 . = ALIGN(PAGE_SIZE);
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000333 __COHERENT_RAM_END__ = .;
Samuel Holland31a14e12018-10-17 21:40:18 -0500334 } >NOBITS
Soby Mathew2ae20432015-01-08 18:02:44 +0000335#endif
Achin Gupta4f6ad662013-10-25 09:08:21 +0100336
Samuel Holland31a14e12018-10-17 21:40:18 -0500337#if SEPARATE_NOBITS_REGION
338 /*
339 * Define a linker symbol to mark end of the NOBITS memory area for this
340 * image.
341 */
342 __NOBITS_END__ = .;
343
344 ASSERT(. <= BL31_NOBITS_LIMIT, "BL31 NOBITS region has exceeded its limit.")
345#else
Achin Guptae9c4a642015-09-11 16:03:13 +0100346 /*
347 * Define a linker symbol to mark end of the RW memory area for this
348 * image.
349 */
350 __RW_END__ = .;
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000351 __BL31_END__ = .;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100352
Masahiro Yamadad3e7baa2020-01-17 13:44:50 +0900353 /DISCARD/ : {
354 *(.dynsym .dynstr .hash .gnu.hash)
355 }
356
Juan Castillo7d199412015-12-14 09:35:25 +0000357 ASSERT(. <= BL31_LIMIT, "BL31 image has exceeded its limit.")
Samuel Holland31a14e12018-10-17 21:40:18 -0500358#endif
Achin Gupta4f6ad662013-10-25 09:08:21 +0100359}