blob: 9ff774b6252813602bec13220841259fd9cd1215 [file] [log] [blame]
Achin Gupta4f6ad662013-10-25 09:08:21 +01001/*
Douglas Raillard21362a92016-12-02 13:51:54 +00002 * Copyright (c) 2013-2017, 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>
Achin Gupta4f6ad662013-10-25 09:08:21 +01008
9OUTPUT_FORMAT(PLATFORM_LINKER_FORMAT)
10OUTPUT_ARCH(PLATFORM_LINKER_ARCH)
Jeenu Viswambharan2a30a752014-03-11 11:06:45 +000011ENTRY(bl31_entrypoint)
Achin Gupta4f6ad662013-10-25 09:08:21 +010012
13
14MEMORY {
Juan Castillofd8c0772014-09-16 10:40:35 +010015 RAM (rwx): ORIGIN = BL31_BASE, LENGTH = BL31_LIMIT - BL31_BASE
Achin Gupta4f6ad662013-10-25 09:08:21 +010016}
17
Caesar Wangd90f43e2016-10-11 09:36:00 +080018#ifdef PLAT_EXTRA_LD_SCRIPT
19#include <plat.ld.S>
20#endif
Achin Gupta4f6ad662013-10-25 09:08:21 +010021
22SECTIONS
23{
Sandrine Bailleux8d69a032013-11-27 09:38:52 +000024 . = BL31_BASE;
25 ASSERT(. == ALIGN(4096),
26 "BL31_BASE address is not aligned on a page boundary.")
Achin Gupta4f6ad662013-10-25 09:08:21 +010027
Sandrine Bailleuxf91f1442016-07-08 14:37:40 +010028#if SEPARATE_CODE_AND_RODATA
29 .text . : {
30 __TEXT_START__ = .;
31 *bl31_entrypoint.o(.text*)
32 *(.text*)
33 *(.vectors)
34 . = NEXT(4096);
35 __TEXT_END__ = .;
36 } >RAM
37
38 .rodata . : {
39 __RODATA_START__ = .;
40 *(.rodata*)
41
42 /* Ensure 8-byte alignment for descriptors and ensure inclusion */
43 . = ALIGN(8);
44 __RT_SVC_DESCS_START__ = .;
45 KEEP(*(rt_svc_descs))
46 __RT_SVC_DESCS_END__ = .;
47
48#if ENABLE_PMF
49 /* Ensure 8-byte alignment for descriptors and ensure inclusion */
50 . = ALIGN(8);
51 __PMF_SVC_DESCS_START__ = .;
52 KEEP(*(pmf_svc_descs))
53 __PMF_SVC_DESCS_END__ = .;
54#endif /* ENABLE_PMF */
55
56 /*
57 * Ensure 8-byte alignment for cpu_ops so that its fields are also
58 * aligned. Also ensure cpu_ops inclusion.
59 */
60 . = ALIGN(8);
61 __CPU_OPS_START__ = .;
62 KEEP(*(cpu_ops))
63 __CPU_OPS_END__ = .;
64
Jeenu Viswambharane3f22002017-09-22 08:32:10 +010065 /* Place pubsub sections for events */
66 . = ALIGN(8);
67#include <pubsub_events.h>
68
Sandrine Bailleuxf91f1442016-07-08 14:37:40 +010069 . = NEXT(4096);
70 __RODATA_END__ = .;
71 } >RAM
72#else
Sandrine Bailleux8d69a032013-11-27 09:38:52 +000073 ro . : {
74 __RO_START__ = .;
Andrew Thoelkee01ea342014-03-18 07:13:52 +000075 *bl31_entrypoint.o(.text*)
76 *(.text*)
Sandrine Bailleux8d69a032013-11-27 09:38:52 +000077 *(.rodata*)
Achin Gupta7421b462014-02-01 18:53:26 +000078
Andrew Thoelkee01ea342014-03-18 07:13:52 +000079 /* Ensure 8-byte alignment for descriptors and ensure inclusion */
Achin Gupta7421b462014-02-01 18:53:26 +000080 . = ALIGN(8);
81 __RT_SVC_DESCS_START__ = .;
Andrew Thoelkee01ea342014-03-18 07:13:52 +000082 KEEP(*(rt_svc_descs))
Achin Gupta7421b462014-02-01 18:53:26 +000083 __RT_SVC_DESCS_END__ = .;
84
Yatharth Kochar9518d022016-03-11 14:20:19 +000085#if ENABLE_PMF
86 /* Ensure 8-byte alignment for descriptors and ensure inclusion */
87 . = ALIGN(8);
88 __PMF_SVC_DESCS_START__ = .;
89 KEEP(*(pmf_svc_descs))
90 __PMF_SVC_DESCS_END__ = .;
91#endif /* ENABLE_PMF */
92
Soby Mathewc704cbc2014-08-14 11:33:56 +010093 /*
94 * Ensure 8-byte alignment for cpu_ops so that its fields are also
95 * aligned. Also ensure cpu_ops inclusion.
96 */
97 . = ALIGN(8);
98 __CPU_OPS_START__ = .;
99 KEEP(*(cpu_ops))
100 __CPU_OPS_END__ = .;
101
Jeenu Viswambharane3f22002017-09-22 08:32:10 +0100102 /* Place pubsub sections for events */
103 . = ALIGN(8);
104#include <pubsub_events.h>
105
Achin Guptab739f222014-01-18 16:50:09 +0000106 *(.vectors)
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000107 __RO_END_UNALIGNED__ = .;
108 /*
109 * Memory page(s) mapped to this section will be marked as read-only,
110 * executable. No RW data from the next section must creep in.
111 * Ensure the rest of the current memory page is unused.
112 */
113 . = NEXT(4096);
114 __RO_END__ = .;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100115 } >RAM
Sandrine Bailleuxf91f1442016-07-08 14:37:40 +0100116#endif
Achin Gupta4f6ad662013-10-25 09:08:21 +0100117
Soby Mathewc704cbc2014-08-14 11:33:56 +0100118 ASSERT(__CPU_OPS_END__ > __CPU_OPS_START__,
119 "cpu_ops not defined for this platform.")
120
Achin Guptae9c4a642015-09-11 16:03:13 +0100121 /*
122 * Define a linker symbol to mark start of the RW memory area for this
123 * image.
124 */
125 __RW_START__ = . ;
126
Douglas Raillard306593d2017-02-24 18:14:15 +0000127 /*
128 * .data must be placed at a lower address than the stacks if the stack
129 * protector is enabled. Alternatively, the .data.stack_protector_canary
130 * section can be placed independently of the main .data section.
131 */
132 .data . : {
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000133 __DATA_START__ = .;
Andrew Thoelkee01ea342014-03-18 07:13:52 +0000134 *(.data*)
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000135 __DATA_END__ = .;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100136 } >RAM
137
Sandrine Bailleuxe2e0c652014-06-16 16:12:27 +0100138#ifdef BL31_PROGBITS_LIMIT
Juan Castillo7d199412015-12-14 09:35:25 +0000139 ASSERT(. <= BL31_PROGBITS_LIMIT, "BL31 progbits has exceeded its limit.")
Sandrine Bailleuxe2e0c652014-06-16 16:12:27 +0100140#endif
141
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000142 stacks (NOLOAD) : {
143 __STACKS_START__ = .;
144 *(tzfw_normal_stacks)
145 __STACKS_END__ = .;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100146 } >RAM
147
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000148 /*
149 * The .bss section gets initialised to 0 at runtime.
Douglas Raillard21362a92016-12-02 13:51:54 +0000150 * Its base address should be 16-byte aligned for better performance of the
151 * zero-initialization code.
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000152 */
Andrew Thoelkee466c9f2015-09-10 11:39:36 +0100153 .bss (NOLOAD) : ALIGN(16) {
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000154 __BSS_START__ = .;
Andrew Thoelkee01ea342014-03-18 07:13:52 +0000155 *(.bss*)
Achin Gupta4f6ad662013-10-25 09:08:21 +0100156 *(COMMON)
Andrew Thoelkee466c9f2015-09-10 11:39:36 +0100157#if !USE_COHERENT_MEM
158 /*
159 * Bakery locks are stored in normal .bss memory
160 *
161 * Each lock's data is spread across multiple cache lines, one per CPU,
162 * but multiple locks can share the same cache line.
163 * The compiler will allocate enough memory for one CPU's bakery locks,
164 * the remaining cache lines are allocated by the linker script
165 */
166 . = ALIGN(CACHE_WRITEBACK_GRANULE);
167 __BAKERY_LOCK_START__ = .;
168 *(bakery_lock)
169 . = ALIGN(CACHE_WRITEBACK_GRANULE);
Vikram Kanigiri405fafe2015-09-24 15:45:43 +0100170 __PERCPU_BAKERY_LOCK_SIZE__ = ABSOLUTE(. - __BAKERY_LOCK_START__);
Andrew Thoelkee466c9f2015-09-10 11:39:36 +0100171 . = . + (__PERCPU_BAKERY_LOCK_SIZE__ * (PLATFORM_CORE_COUNT - 1));
172 __BAKERY_LOCK_END__ = .;
173#ifdef PLAT_PERCPU_BAKERY_LOCK_SIZE
174 ASSERT(__PERCPU_BAKERY_LOCK_SIZE__ == PLAT_PERCPU_BAKERY_LOCK_SIZE,
175 "PLAT_PERCPU_BAKERY_LOCK_SIZE does not match bakery lock requirements");
176#endif
177#endif
Yatharth Kochar9518d022016-03-11 14:20:19 +0000178
179#if ENABLE_PMF
180 /*
181 * Time-stamps are stored in normal .bss memory
182 *
183 * The compiler will allocate enough memory for one CPU's time-stamps,
184 * the remaining memory for other CPU's is allocated by the
185 * linker script
186 */
187 . = ALIGN(CACHE_WRITEBACK_GRANULE);
188 __PMF_TIMESTAMP_START__ = .;
189 KEEP(*(pmf_timestamp_array))
190 . = ALIGN(CACHE_WRITEBACK_GRANULE);
191 __PMF_PERCPU_TIMESTAMP_END__ = .;
192 __PERCPU_TIMESTAMP_SIZE__ = ABSOLUTE(. - __PMF_TIMESTAMP_START__);
193 . = . + (__PERCPU_TIMESTAMP_SIZE__ * (PLATFORM_CORE_COUNT - 1));
194 __PMF_TIMESTAMP_END__ = .;
195#endif /* ENABLE_PMF */
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000196 __BSS_END__ = .;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100197 } >RAM
198
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000199 /*
Jeenu Viswambharan97cc9ee2014-02-24 15:20:28 +0000200 * The xlat_table section is for full, aligned page tables (4K).
Achin Guptaa0cd9892014-02-09 13:30:38 +0000201 * Removing them from .bss avoids forcing 4K alignment on
202 * the .bss section and eliminates the unecessary zero init
203 */
204 xlat_table (NOLOAD) : {
205 *(xlat_table)
206 } >RAM
207
Soby Mathew2ae20432015-01-08 18:02:44 +0000208#if USE_COHERENT_MEM
Achin Guptaa0cd9892014-02-09 13:30:38 +0000209 /*
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000210 * The base address of the coherent memory section must be page-aligned (4K)
211 * to guarantee that the coherent data are stored on their own pages and
212 * are not mixed with normal data. This is required to set up the correct
213 * memory attributes for the coherent data page tables.
214 */
215 coherent_ram (NOLOAD) : ALIGN(4096) {
216 __COHERENT_RAM_START__ = .;
Andrew Thoelkee466c9f2015-09-10 11:39:36 +0100217 /*
218 * Bakery locks are stored in coherent memory
219 *
220 * Each lock's data is contiguous and fully allocated by the compiler
221 */
222 *(bakery_lock)
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000223 *(tzfw_coherent_mem)
224 __COHERENT_RAM_END_UNALIGNED__ = .;
225 /*
226 * Memory page(s) mapped to this section will be marked
227 * as device memory. No other unexpected data must creep in.
228 * Ensure the rest of the current memory page is unused.
229 */
230 . = NEXT(4096);
231 __COHERENT_RAM_END__ = .;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100232 } >RAM
Soby Mathew2ae20432015-01-08 18:02:44 +0000233#endif
Achin Gupta4f6ad662013-10-25 09:08:21 +0100234
Achin Guptae9c4a642015-09-11 16:03:13 +0100235 /*
236 * Define a linker symbol to mark end of the RW memory area for this
237 * image.
238 */
239 __RW_END__ = .;
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000240 __BL31_END__ = .;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100241
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000242 __BSS_SIZE__ = SIZEOF(.bss);
Soby Mathew2ae20432015-01-08 18:02:44 +0000243#if USE_COHERENT_MEM
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000244 __COHERENT_RAM_UNALIGNED_SIZE__ =
245 __COHERENT_RAM_END_UNALIGNED__ - __COHERENT_RAM_START__;
Soby Mathew2ae20432015-01-08 18:02:44 +0000246#endif
Achin Gupta4f6ad662013-10-25 09:08:21 +0100247
Juan Castillo7d199412015-12-14 09:35:25 +0000248 ASSERT(. <= BL31_LIMIT, "BL31 image has exceeded its limit.")
Achin Gupta4f6ad662013-10-25 09:08:21 +0100249}