blob: 43d0ed440d8101883045a95e39d4b5c9035a61f7 [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 Diaz2ce2b092017-11-15 11:45:35 +00008#include <xlat_tables_defs.h>
Achin Gupta4f6ad662013-10-25 09:08:21 +01009
10OUTPUT_FORMAT(PLATFORM_LINKER_FORMAT)
11OUTPUT_ARCH(PLATFORM_LINKER_ARCH)
Jeenu Viswambharan2a30a752014-03-11 11:06:45 +000012ENTRY(bl31_entrypoint)
Achin Gupta4f6ad662013-10-25 09:08:21 +010013
14
15MEMORY {
Juan Castillofd8c0772014-09-16 10:40:35 +010016 RAM (rwx): ORIGIN = BL31_BASE, LENGTH = BL31_LIMIT - BL31_BASE
Achin Gupta4f6ad662013-10-25 09:08:21 +010017}
18
Caesar Wangd90f43e2016-10-11 09:36:00 +080019#ifdef PLAT_EXTRA_LD_SCRIPT
20#include <plat.ld.S>
21#endif
Achin Gupta4f6ad662013-10-25 09:08:21 +010022
23SECTIONS
24{
Sandrine Bailleux8d69a032013-11-27 09:38:52 +000025 . = BL31_BASE;
Antonio Nino Diaz2ce2b092017-11-15 11:45:35 +000026 ASSERT(. == ALIGN(PAGE_SIZE),
Sandrine Bailleux8d69a032013-11-27 09:38:52 +000027 "BL31_BASE address is not aligned on a page boundary.")
Achin Gupta4f6ad662013-10-25 09:08:21 +010028
Soby Mathew4e28c202018-10-14 08:09:22 +010029 __BL31_START__ = .;
30
Sandrine Bailleuxf91f1442016-07-08 14:37:40 +010031#if SEPARATE_CODE_AND_RODATA
32 .text . : {
33 __TEXT_START__ = .;
34 *bl31_entrypoint.o(.text*)
35 *(.text*)
36 *(.vectors)
Roberto Vargasd93fde32018-04-11 11:53:31 +010037 . = ALIGN(PAGE_SIZE);
Sandrine Bailleuxf91f1442016-07-08 14:37:40 +010038 __TEXT_END__ = .;
39 } >RAM
40
41 .rodata . : {
42 __RODATA_START__ = .;
43 *(.rodata*)
44
45 /* Ensure 8-byte alignment for descriptors and ensure inclusion */
46 . = ALIGN(8);
47 __RT_SVC_DESCS_START__ = .;
48 KEEP(*(rt_svc_descs))
49 __RT_SVC_DESCS_END__ = .;
50
51#if ENABLE_PMF
52 /* Ensure 8-byte alignment for descriptors and ensure inclusion */
53 . = ALIGN(8);
54 __PMF_SVC_DESCS_START__ = .;
55 KEEP(*(pmf_svc_descs))
56 __PMF_SVC_DESCS_END__ = .;
57#endif /* ENABLE_PMF */
58
59 /*
60 * Ensure 8-byte alignment for cpu_ops so that its fields are also
61 * aligned. Also ensure cpu_ops inclusion.
62 */
63 . = ALIGN(8);
64 __CPU_OPS_START__ = .;
65 KEEP(*(cpu_ops))
66 __CPU_OPS_END__ = .;
67
Soby Mathew4e28c202018-10-14 08:09:22 +010068 /*
69 * Keep the .got section in the RO section as the it is patched
70 * prior to enabling the MMU and having the .got in RO is better for
71 * security.
72 */
73 . = ALIGN(16);
74 __GOT_START__ = .;
75 *(.got)
76 __GOT_END__ = .;
77
Jeenu Viswambharane3f22002017-09-22 08:32:10 +010078 /* Place pubsub sections for events */
79 . = ALIGN(8);
80#include <pubsub_events.h>
81
Roberto Vargasd93fde32018-04-11 11:53:31 +010082 . = ALIGN(PAGE_SIZE);
Sandrine Bailleuxf91f1442016-07-08 14:37:40 +010083 __RODATA_END__ = .;
84 } >RAM
85#else
Sandrine Bailleux8d69a032013-11-27 09:38:52 +000086 ro . : {
87 __RO_START__ = .;
Andrew Thoelkee01ea342014-03-18 07:13:52 +000088 *bl31_entrypoint.o(.text*)
89 *(.text*)
Sandrine Bailleux8d69a032013-11-27 09:38:52 +000090 *(.rodata*)
Achin Gupta7421b462014-02-01 18:53:26 +000091
Andrew Thoelkee01ea342014-03-18 07:13:52 +000092 /* Ensure 8-byte alignment for descriptors and ensure inclusion */
Achin Gupta7421b462014-02-01 18:53:26 +000093 . = ALIGN(8);
94 __RT_SVC_DESCS_START__ = .;
Andrew Thoelkee01ea342014-03-18 07:13:52 +000095 KEEP(*(rt_svc_descs))
Achin Gupta7421b462014-02-01 18:53:26 +000096 __RT_SVC_DESCS_END__ = .;
97
Yatharth Kochar9518d022016-03-11 14:20:19 +000098#if ENABLE_PMF
99 /* Ensure 8-byte alignment for descriptors and ensure inclusion */
100 . = ALIGN(8);
101 __PMF_SVC_DESCS_START__ = .;
102 KEEP(*(pmf_svc_descs))
103 __PMF_SVC_DESCS_END__ = .;
104#endif /* ENABLE_PMF */
105
Soby Mathewc704cbc2014-08-14 11:33:56 +0100106 /*
107 * Ensure 8-byte alignment for cpu_ops so that its fields are also
108 * aligned. Also ensure cpu_ops inclusion.
109 */
110 . = ALIGN(8);
111 __CPU_OPS_START__ = .;
112 KEEP(*(cpu_ops))
113 __CPU_OPS_END__ = .;
114
Jeenu Viswambharane3f22002017-09-22 08:32:10 +0100115 /* Place pubsub sections for events */
116 . = ALIGN(8);
117#include <pubsub_events.h>
118
Achin Guptab739f222014-01-18 16:50:09 +0000119 *(.vectors)
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000120 __RO_END_UNALIGNED__ = .;
121 /*
122 * Memory page(s) mapped to this section will be marked as read-only,
123 * executable. No RW data from the next section must creep in.
124 * Ensure the rest of the current memory page is unused.
125 */
Roberto Vargasd93fde32018-04-11 11:53:31 +0100126 . = ALIGN(PAGE_SIZE);
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000127 __RO_END__ = .;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100128 } >RAM
Sandrine Bailleuxf91f1442016-07-08 14:37:40 +0100129#endif
Achin Gupta4f6ad662013-10-25 09:08:21 +0100130
Soby Mathewc704cbc2014-08-14 11:33:56 +0100131 ASSERT(__CPU_OPS_END__ > __CPU_OPS_START__,
132 "cpu_ops not defined for this platform.")
133
Antonio Nino Diazc41f2062017-10-24 10:07:35 +0100134#if ENABLE_SPM
135 /*
136 * Exception vectors of the SPM shim layer. They must be aligned to a 2K
137 * address, but we need to place them in a separate page so that we can set
138 * individual permissions to them, so the actual alignment needed is 4K.
139 *
140 * There's no need to include this into the RO section of BL31 because it
141 * doesn't need to be accessed by BL31.
142 */
Antonio Nino Diaz2ce2b092017-11-15 11:45:35 +0000143 spm_shim_exceptions : ALIGN(PAGE_SIZE) {
Antonio Nino Diazc41f2062017-10-24 10:07:35 +0100144 __SPM_SHIM_EXCEPTIONS_START__ = .;
145 *(.spm_shim_exceptions)
Roberto Vargasd93fde32018-04-11 11:53:31 +0100146 . = ALIGN(PAGE_SIZE);
Antonio Nino Diazc41f2062017-10-24 10:07:35 +0100147 __SPM_SHIM_EXCEPTIONS_END__ = .;
148 } >RAM
149#endif
150
Achin Guptae9c4a642015-09-11 16:03:13 +0100151 /*
152 * Define a linker symbol to mark start of the RW memory area for this
153 * image.
154 */
155 __RW_START__ = . ;
156
Douglas Raillard306593d2017-02-24 18:14:15 +0000157 /*
158 * .data must be placed at a lower address than the stacks if the stack
159 * protector is enabled. Alternatively, the .data.stack_protector_canary
160 * section can be placed independently of the main .data section.
161 */
162 .data . : {
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000163 __DATA_START__ = .;
Andrew Thoelkee01ea342014-03-18 07:13:52 +0000164 *(.data*)
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000165 __DATA_END__ = .;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100166 } >RAM
167
Soby Mathew4e28c202018-10-14 08:09:22 +0100168 . = ALIGN(16);
169 /*
170 * .rela.dyn needs to come after .data for the read-elf utility to parse
171 * this section correctly.
172 */
173 __RELA_START__ = .;
174 .rela.dyn . : {
175 } >RAM
176 __RELA_END__ = .;
177
Sandrine Bailleuxe2e0c652014-06-16 16:12:27 +0100178#ifdef BL31_PROGBITS_LIMIT
Juan Castillo7d199412015-12-14 09:35:25 +0000179 ASSERT(. <= BL31_PROGBITS_LIMIT, "BL31 progbits has exceeded its limit.")
Sandrine Bailleuxe2e0c652014-06-16 16:12:27 +0100180#endif
181
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000182 stacks (NOLOAD) : {
183 __STACKS_START__ = .;
184 *(tzfw_normal_stacks)
185 __STACKS_END__ = .;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100186 } >RAM
187
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000188 /*
189 * The .bss section gets initialised to 0 at runtime.
Douglas Raillard21362a92016-12-02 13:51:54 +0000190 * Its base address should be 16-byte aligned for better performance of the
191 * zero-initialization code.
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000192 */
Andrew Thoelkee466c9f2015-09-10 11:39:36 +0100193 .bss (NOLOAD) : ALIGN(16) {
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000194 __BSS_START__ = .;
Andrew Thoelkee01ea342014-03-18 07:13:52 +0000195 *(.bss*)
Achin Gupta4f6ad662013-10-25 09:08:21 +0100196 *(COMMON)
Andrew Thoelkee466c9f2015-09-10 11:39:36 +0100197#if !USE_COHERENT_MEM
198 /*
199 * Bakery locks are stored in normal .bss memory
200 *
201 * Each lock's data is spread across multiple cache lines, one per CPU,
202 * but multiple locks can share the same cache line.
203 * The compiler will allocate enough memory for one CPU's bakery locks,
204 * the remaining cache lines are allocated by the linker script
205 */
206 . = ALIGN(CACHE_WRITEBACK_GRANULE);
207 __BAKERY_LOCK_START__ = .;
208 *(bakery_lock)
209 . = ALIGN(CACHE_WRITEBACK_GRANULE);
Vikram Kanigiri405fafe2015-09-24 15:45:43 +0100210 __PERCPU_BAKERY_LOCK_SIZE__ = ABSOLUTE(. - __BAKERY_LOCK_START__);
Andrew Thoelkee466c9f2015-09-10 11:39:36 +0100211 . = . + (__PERCPU_BAKERY_LOCK_SIZE__ * (PLATFORM_CORE_COUNT - 1));
212 __BAKERY_LOCK_END__ = .;
Roberto Vargas00996942017-11-13 13:41:58 +0000213
214 /*
215 * If BL31 doesn't use any bakery lock then __PERCPU_BAKERY_LOCK_SIZE__
216 * will be zero. For this reason, the only two valid values for
217 * __PERCPU_BAKERY_LOCK_SIZE__ are 0 or the platform defined value
218 * PLAT_PERCPU_BAKERY_LOCK_SIZE.
219 */
Andrew Thoelkee466c9f2015-09-10 11:39:36 +0100220#ifdef PLAT_PERCPU_BAKERY_LOCK_SIZE
Roberto Vargas00996942017-11-13 13:41:58 +0000221 ASSERT((__PERCPU_BAKERY_LOCK_SIZE__ == 0) || (__PERCPU_BAKERY_LOCK_SIZE__ == PLAT_PERCPU_BAKERY_LOCK_SIZE),
Andrew Thoelkee466c9f2015-09-10 11:39:36 +0100222 "PLAT_PERCPU_BAKERY_LOCK_SIZE does not match bakery lock requirements");
223#endif
224#endif
Yatharth Kochar9518d022016-03-11 14:20:19 +0000225
226#if ENABLE_PMF
227 /*
228 * Time-stamps are stored in normal .bss memory
229 *
230 * The compiler will allocate enough memory for one CPU's time-stamps,
231 * the remaining memory for other CPU's is allocated by the
232 * linker script
233 */
234 . = ALIGN(CACHE_WRITEBACK_GRANULE);
235 __PMF_TIMESTAMP_START__ = .;
236 KEEP(*(pmf_timestamp_array))
237 . = ALIGN(CACHE_WRITEBACK_GRANULE);
238 __PMF_PERCPU_TIMESTAMP_END__ = .;
239 __PERCPU_TIMESTAMP_SIZE__ = ABSOLUTE(. - __PMF_TIMESTAMP_START__);
240 . = . + (__PERCPU_TIMESTAMP_SIZE__ * (PLATFORM_CORE_COUNT - 1));
241 __PMF_TIMESTAMP_END__ = .;
242#endif /* ENABLE_PMF */
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000243 __BSS_END__ = .;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100244 } >RAM
245
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000246 /*
Jeenu Viswambharan97cc9ee2014-02-24 15:20:28 +0000247 * The xlat_table section is for full, aligned page tables (4K).
Achin Guptaa0cd9892014-02-09 13:30:38 +0000248 * Removing them from .bss avoids forcing 4K alignment on
Antonio Nino Diaz7c2a3ca2018-02-23 15:07:54 +0000249 * the .bss section. The tables are initialized to zero by the translation
250 * tables library.
Achin Guptaa0cd9892014-02-09 13:30:38 +0000251 */
252 xlat_table (NOLOAD) : {
253 *(xlat_table)
254 } >RAM
255
Soby Mathew2ae20432015-01-08 18:02:44 +0000256#if USE_COHERENT_MEM
Achin Guptaa0cd9892014-02-09 13:30:38 +0000257 /*
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000258 * The base address of the coherent memory section must be page-aligned (4K)
259 * to guarantee that the coherent data are stored on their own pages and
260 * are not mixed with normal data. This is required to set up the correct
261 * memory attributes for the coherent data page tables.
262 */
Antonio Nino Diaz2ce2b092017-11-15 11:45:35 +0000263 coherent_ram (NOLOAD) : ALIGN(PAGE_SIZE) {
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000264 __COHERENT_RAM_START__ = .;
Andrew Thoelkee466c9f2015-09-10 11:39:36 +0100265 /*
266 * Bakery locks are stored in coherent memory
267 *
268 * Each lock's data is contiguous and fully allocated by the compiler
269 */
270 *(bakery_lock)
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000271 *(tzfw_coherent_mem)
272 __COHERENT_RAM_END_UNALIGNED__ = .;
273 /*
274 * Memory page(s) mapped to this section will be marked
275 * as device memory. No other unexpected data must creep in.
276 * Ensure the rest of the current memory page is unused.
277 */
Roberto Vargasd93fde32018-04-11 11:53:31 +0100278 . = ALIGN(PAGE_SIZE);
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000279 __COHERENT_RAM_END__ = .;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100280 } >RAM
Soby Mathew2ae20432015-01-08 18:02:44 +0000281#endif
Achin Gupta4f6ad662013-10-25 09:08:21 +0100282
Achin Guptae9c4a642015-09-11 16:03:13 +0100283 /*
284 * Define a linker symbol to mark end of the RW memory area for this
285 * image.
286 */
287 __RW_END__ = .;
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000288 __BL31_END__ = .;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100289
Juan Castillo7d199412015-12-14 09:35:25 +0000290 ASSERT(. <= BL31_LIMIT, "BL31 image has exceeded its limit.")
Achin Gupta4f6ad662013-10-25 09:08:21 +0100291}