blob: 5925e0ca0ce16ab03abefabd53f4e8337f52b30f [file] [log] [blame]
Achin Gupta4f6ad662013-10-25 09:08:21 +01001/*
Antonio Nino Diaz7c2a3ca2018-02-23 15:07:54 +00002 * Copyright (c) 2013-2018, 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
Achin Gupta4f6ad662013-10-25 09:08:21 +010018}
19
Caesar Wangd90f43e2016-10-11 09:36:00 +080020#ifdef PLAT_EXTRA_LD_SCRIPT
21#include <plat.ld.S>
22#endif
Achin Gupta4f6ad662013-10-25 09:08:21 +010023
24SECTIONS
25{
Sandrine Bailleux8d69a032013-11-27 09:38:52 +000026 . = BL31_BASE;
Antonio Nino Diaz2ce2b092017-11-15 11:45:35 +000027 ASSERT(. == ALIGN(PAGE_SIZE),
Sandrine Bailleux8d69a032013-11-27 09:38:52 +000028 "BL31_BASE address is not aligned on a page boundary.")
Achin Gupta4f6ad662013-10-25 09:08:21 +010029
Soby Mathew4e28c202018-10-14 08:09:22 +010030 __BL31_START__ = .;
31
Sandrine Bailleuxf91f1442016-07-08 14:37:40 +010032#if SEPARATE_CODE_AND_RODATA
33 .text . : {
34 __TEXT_START__ = .;
35 *bl31_entrypoint.o(.text*)
36 *(.text*)
37 *(.vectors)
Roberto Vargasd93fde32018-04-11 11:53:31 +010038 . = ALIGN(PAGE_SIZE);
Sandrine Bailleuxf91f1442016-07-08 14:37:40 +010039 __TEXT_END__ = .;
40 } >RAM
41
42 .rodata . : {
43 __RODATA_START__ = .;
44 *(.rodata*)
45
46 /* Ensure 8-byte alignment for descriptors and ensure inclusion */
47 . = ALIGN(8);
48 __RT_SVC_DESCS_START__ = .;
49 KEEP(*(rt_svc_descs))
50 __RT_SVC_DESCS_END__ = .;
51
52#if ENABLE_PMF
53 /* Ensure 8-byte alignment for descriptors and ensure inclusion */
54 . = ALIGN(8);
55 __PMF_SVC_DESCS_START__ = .;
56 KEEP(*(pmf_svc_descs))
57 __PMF_SVC_DESCS_END__ = .;
58#endif /* ENABLE_PMF */
59
60 /*
61 * Ensure 8-byte alignment for cpu_ops so that its fields are also
62 * aligned. Also ensure cpu_ops inclusion.
63 */
64 . = ALIGN(8);
65 __CPU_OPS_START__ = .;
66 KEEP(*(cpu_ops))
67 __CPU_OPS_END__ = .;
68
Soby Mathew4e28c202018-10-14 08:09:22 +010069 /*
Soby Mathew2b3fc1d2018-12-12 14:33:11 +000070 * Keep the .got section in the RO section as it is patched
Soby Mathew4e28c202018-10-14 08:09:22 +010071 * prior to enabling the MMU and having the .got in RO is better for
Soby Mathew2b3fc1d2018-12-12 14:33:11 +000072 * security. GOT is a table of addresses so ensure 8-byte alignment.
Soby Mathew4e28c202018-10-14 08:09:22 +010073 */
Soby Mathew2b3fc1d2018-12-12 14:33:11 +000074 . = ALIGN(8);
Soby Mathew4e28c202018-10-14 08:09:22 +010075 __GOT_START__ = .;
76 *(.got)
77 __GOT_END__ = .;
78
Jeenu Viswambharane3f22002017-09-22 08:32:10 +010079 /* Place pubsub sections for events */
80 . = ALIGN(8);
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000081#include <lib/el3_runtime/pubsub_events.h>
Jeenu Viswambharane3f22002017-09-22 08:32:10 +010082
Roberto Vargasd93fde32018-04-11 11:53:31 +010083 . = ALIGN(PAGE_SIZE);
Sandrine Bailleuxf91f1442016-07-08 14:37:40 +010084 __RODATA_END__ = .;
85 } >RAM
86#else
Sandrine Bailleux8d69a032013-11-27 09:38:52 +000087 ro . : {
88 __RO_START__ = .;
Andrew Thoelkee01ea342014-03-18 07:13:52 +000089 *bl31_entrypoint.o(.text*)
90 *(.text*)
Sandrine Bailleux8d69a032013-11-27 09:38:52 +000091 *(.rodata*)
Achin Gupta7421b462014-02-01 18:53:26 +000092
Andrew Thoelkee01ea342014-03-18 07:13:52 +000093 /* Ensure 8-byte alignment for descriptors and ensure inclusion */
Achin Gupta7421b462014-02-01 18:53:26 +000094 . = ALIGN(8);
95 __RT_SVC_DESCS_START__ = .;
Andrew Thoelkee01ea342014-03-18 07:13:52 +000096 KEEP(*(rt_svc_descs))
Achin Gupta7421b462014-02-01 18:53:26 +000097 __RT_SVC_DESCS_END__ = .;
98
Yatharth Kochar9518d022016-03-11 14:20:19 +000099#if ENABLE_PMF
100 /* Ensure 8-byte alignment for descriptors and ensure inclusion */
101 . = ALIGN(8);
102 __PMF_SVC_DESCS_START__ = .;
103 KEEP(*(pmf_svc_descs))
104 __PMF_SVC_DESCS_END__ = .;
105#endif /* ENABLE_PMF */
106
Soby Mathewc704cbc2014-08-14 11:33:56 +0100107 /*
108 * Ensure 8-byte alignment for cpu_ops so that its fields are also
109 * aligned. Also ensure cpu_ops inclusion.
110 */
111 . = ALIGN(8);
112 __CPU_OPS_START__ = .;
113 KEEP(*(cpu_ops))
114 __CPU_OPS_END__ = .;
115
Soby Mathew2b3fc1d2018-12-12 14:33:11 +0000116 /*
117 * Keep the .got section in the RO section as it is patched
118 * prior to enabling the MMU and having the .got in RO is better for
119 * security. GOT is a table of addresses so ensure 8-byte alignment.
120 */
121 . = ALIGN(8);
122 __GOT_START__ = .;
123 *(.got)
124 __GOT_END__ = .;
125
Jeenu Viswambharane3f22002017-09-22 08:32:10 +0100126 /* Place pubsub sections for events */
127 . = ALIGN(8);
Antonio Nino Diaze0f90632018-12-14 00:18:21 +0000128#include <lib/el3_runtime/pubsub_events.h>
Jeenu Viswambharane3f22002017-09-22 08:32:10 +0100129
Achin Guptab739f222014-01-18 16:50:09 +0000130 *(.vectors)
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000131 __RO_END_UNALIGNED__ = .;
132 /*
133 * Memory page(s) mapped to this section will be marked as read-only,
134 * executable. No RW data from the next section must creep in.
135 * Ensure the rest of the current memory page is unused.
136 */
Roberto Vargasd93fde32018-04-11 11:53:31 +0100137 . = ALIGN(PAGE_SIZE);
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000138 __RO_END__ = .;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100139 } >RAM
Sandrine Bailleuxf91f1442016-07-08 14:37:40 +0100140#endif
Achin Gupta4f6ad662013-10-25 09:08:21 +0100141
Soby Mathewc704cbc2014-08-14 11:33:56 +0100142 ASSERT(__CPU_OPS_END__ > __CPU_OPS_START__,
143 "cpu_ops not defined for this platform.")
144
Antonio Nino Diazc41f2062017-10-24 10:07:35 +0100145#if ENABLE_SPM
146 /*
147 * Exception vectors of the SPM shim layer. They must be aligned to a 2K
148 * address, but we need to place them in a separate page so that we can set
149 * individual permissions to them, so the actual alignment needed is 4K.
150 *
151 * There's no need to include this into the RO section of BL31 because it
152 * doesn't need to be accessed by BL31.
153 */
Antonio Nino Diaz2ce2b092017-11-15 11:45:35 +0000154 spm_shim_exceptions : ALIGN(PAGE_SIZE) {
Antonio Nino Diazc41f2062017-10-24 10:07:35 +0100155 __SPM_SHIM_EXCEPTIONS_START__ = .;
156 *(.spm_shim_exceptions)
Roberto Vargasd93fde32018-04-11 11:53:31 +0100157 . = ALIGN(PAGE_SIZE);
Antonio Nino Diazc41f2062017-10-24 10:07:35 +0100158 __SPM_SHIM_EXCEPTIONS_END__ = .;
159 } >RAM
160#endif
161
Achin Guptae9c4a642015-09-11 16:03:13 +0100162 /*
163 * Define a linker symbol to mark start of the RW memory area for this
164 * image.
165 */
166 __RW_START__ = . ;
167
Douglas Raillard306593d2017-02-24 18:14:15 +0000168 /*
169 * .data must be placed at a lower address than the stacks if the stack
170 * protector is enabled. Alternatively, the .data.stack_protector_canary
171 * section can be placed independently of the main .data section.
172 */
173 .data . : {
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000174 __DATA_START__ = .;
Andrew Thoelkee01ea342014-03-18 07:13:52 +0000175 *(.data*)
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000176 __DATA_END__ = .;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100177 } >RAM
178
Soby Mathew4e28c202018-10-14 08:09:22 +0100179 /*
180 * .rela.dyn needs to come after .data for the read-elf utility to parse
Soby Mathew2b3fc1d2018-12-12 14:33:11 +0000181 * this section correctly. Ensure 8-byte alignment so that the fields of
182 * RELA data structure are aligned.
Soby Mathew4e28c202018-10-14 08:09:22 +0100183 */
Soby Mathew2b3fc1d2018-12-12 14:33:11 +0000184 . = ALIGN(8);
Soby Mathew4e28c202018-10-14 08:09:22 +0100185 __RELA_START__ = .;
186 .rela.dyn . : {
187 } >RAM
188 __RELA_END__ = .;
189
Sandrine Bailleuxe2e0c652014-06-16 16:12:27 +0100190#ifdef BL31_PROGBITS_LIMIT
Juan Castillo7d199412015-12-14 09:35:25 +0000191 ASSERT(. <= BL31_PROGBITS_LIMIT, "BL31 progbits has exceeded its limit.")
Sandrine Bailleuxe2e0c652014-06-16 16:12:27 +0100192#endif
193
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000194 stacks (NOLOAD) : {
195 __STACKS_START__ = .;
196 *(tzfw_normal_stacks)
197 __STACKS_END__ = .;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100198 } >RAM
199
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000200 /*
201 * The .bss section gets initialised to 0 at runtime.
Douglas Raillard21362a92016-12-02 13:51:54 +0000202 * Its base address should be 16-byte aligned for better performance of the
203 * zero-initialization code.
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000204 */
Andrew Thoelkee466c9f2015-09-10 11:39:36 +0100205 .bss (NOLOAD) : ALIGN(16) {
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000206 __BSS_START__ = .;
Andrew Thoelkee01ea342014-03-18 07:13:52 +0000207 *(.bss*)
Achin Gupta4f6ad662013-10-25 09:08:21 +0100208 *(COMMON)
Andrew Thoelkee466c9f2015-09-10 11:39:36 +0100209#if !USE_COHERENT_MEM
210 /*
211 * Bakery locks are stored in normal .bss memory
212 *
213 * Each lock's data is spread across multiple cache lines, one per CPU,
214 * but multiple locks can share the same cache line.
215 * The compiler will allocate enough memory for one CPU's bakery locks,
216 * the remaining cache lines are allocated by the linker script
217 */
218 . = ALIGN(CACHE_WRITEBACK_GRANULE);
219 __BAKERY_LOCK_START__ = .;
220 *(bakery_lock)
221 . = ALIGN(CACHE_WRITEBACK_GRANULE);
Vikram Kanigiri405fafe2015-09-24 15:45:43 +0100222 __PERCPU_BAKERY_LOCK_SIZE__ = ABSOLUTE(. - __BAKERY_LOCK_START__);
Andrew Thoelkee466c9f2015-09-10 11:39:36 +0100223 . = . + (__PERCPU_BAKERY_LOCK_SIZE__ * (PLATFORM_CORE_COUNT - 1));
224 __BAKERY_LOCK_END__ = .;
Roberto Vargas00996942017-11-13 13:41:58 +0000225
226 /*
227 * If BL31 doesn't use any bakery lock then __PERCPU_BAKERY_LOCK_SIZE__
228 * will be zero. For this reason, the only two valid values for
229 * __PERCPU_BAKERY_LOCK_SIZE__ are 0 or the platform defined value
230 * PLAT_PERCPU_BAKERY_LOCK_SIZE.
231 */
Andrew Thoelkee466c9f2015-09-10 11:39:36 +0100232#ifdef PLAT_PERCPU_BAKERY_LOCK_SIZE
Roberto Vargas00996942017-11-13 13:41:58 +0000233 ASSERT((__PERCPU_BAKERY_LOCK_SIZE__ == 0) || (__PERCPU_BAKERY_LOCK_SIZE__ == PLAT_PERCPU_BAKERY_LOCK_SIZE),
Andrew Thoelkee466c9f2015-09-10 11:39:36 +0100234 "PLAT_PERCPU_BAKERY_LOCK_SIZE does not match bakery lock requirements");
235#endif
236#endif
Yatharth Kochar9518d022016-03-11 14:20:19 +0000237
238#if ENABLE_PMF
239 /*
240 * Time-stamps are stored in normal .bss memory
241 *
242 * The compiler will allocate enough memory for one CPU's time-stamps,
243 * the remaining memory for other CPU's is allocated by the
244 * linker script
245 */
246 . = ALIGN(CACHE_WRITEBACK_GRANULE);
247 __PMF_TIMESTAMP_START__ = .;
248 KEEP(*(pmf_timestamp_array))
249 . = ALIGN(CACHE_WRITEBACK_GRANULE);
250 __PMF_PERCPU_TIMESTAMP_END__ = .;
251 __PERCPU_TIMESTAMP_SIZE__ = ABSOLUTE(. - __PMF_TIMESTAMP_START__);
252 . = . + (__PERCPU_TIMESTAMP_SIZE__ * (PLATFORM_CORE_COUNT - 1));
253 __PMF_TIMESTAMP_END__ = .;
254#endif /* ENABLE_PMF */
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000255 __BSS_END__ = .;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100256 } >RAM
257
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000258 /*
Jeenu Viswambharan97cc9ee2014-02-24 15:20:28 +0000259 * The xlat_table section is for full, aligned page tables (4K).
Achin Guptaa0cd9892014-02-09 13:30:38 +0000260 * Removing them from .bss avoids forcing 4K alignment on
Antonio Nino Diaz7c2a3ca2018-02-23 15:07:54 +0000261 * the .bss section. The tables are initialized to zero by the translation
262 * tables library.
Achin Guptaa0cd9892014-02-09 13:30:38 +0000263 */
264 xlat_table (NOLOAD) : {
265 *(xlat_table)
266 } >RAM
267
Soby Mathew2ae20432015-01-08 18:02:44 +0000268#if USE_COHERENT_MEM
Achin Guptaa0cd9892014-02-09 13:30:38 +0000269 /*
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000270 * The base address of the coherent memory section must be page-aligned (4K)
271 * to guarantee that the coherent data are stored on their own pages and
272 * are not mixed with normal data. This is required to set up the correct
273 * memory attributes for the coherent data page tables.
274 */
Antonio Nino Diaz2ce2b092017-11-15 11:45:35 +0000275 coherent_ram (NOLOAD) : ALIGN(PAGE_SIZE) {
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000276 __COHERENT_RAM_START__ = .;
Andrew Thoelkee466c9f2015-09-10 11:39:36 +0100277 /*
278 * Bakery locks are stored in coherent memory
279 *
280 * Each lock's data is contiguous and fully allocated by the compiler
281 */
282 *(bakery_lock)
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000283 *(tzfw_coherent_mem)
284 __COHERENT_RAM_END_UNALIGNED__ = .;
285 /*
286 * Memory page(s) mapped to this section will be marked
287 * as device memory. No other unexpected data must creep in.
288 * Ensure the rest of the current memory page is unused.
289 */
Roberto Vargasd93fde32018-04-11 11:53:31 +0100290 . = ALIGN(PAGE_SIZE);
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000291 __COHERENT_RAM_END__ = .;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100292 } >RAM
Soby Mathew2ae20432015-01-08 18:02:44 +0000293#endif
Achin Gupta4f6ad662013-10-25 09:08:21 +0100294
Achin Guptae9c4a642015-09-11 16:03:13 +0100295 /*
296 * Define a linker symbol to mark end of the RW memory area for this
297 * image.
298 */
299 __RW_END__ = .;
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000300 __BL31_END__ = .;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100301
Juan Castillo7d199412015-12-14 09:35:25 +0000302 ASSERT(. <= BL31_LIMIT, "BL31 image has exceeded its limit.")
Achin Gupta4f6ad662013-10-25 09:08:21 +0100303}