blob: 1cdf7c94325bccb2b64bd0f15a9b3c87e1a2b5b8 [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
Masahiro Yamada0b67e562020-03-09 17:39:48 +09007#include <common/bl_common.ld.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00008#include <lib/xlat_tables/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
Samuel Holland31a14e12018-10-17 21:40:18 -050017#if SEPARATE_NOBITS_REGION
18 NOBITS (rw!a): ORIGIN = BL31_NOBITS_BASE, LENGTH = BL31_NOBITS_LIMIT - BL31_NOBITS_BASE
19#else
20#define NOBITS RAM
21#endif
Achin Gupta4f6ad662013-10-25 09:08:21 +010022}
23
Caesar Wangd90f43e2016-10-11 09:36:00 +080024#ifdef PLAT_EXTRA_LD_SCRIPT
25#include <plat.ld.S>
26#endif
Achin Gupta4f6ad662013-10-25 09:08:21 +010027
28SECTIONS
29{
Sandrine Bailleux8d69a032013-11-27 09:38:52 +000030 . = BL31_BASE;
Antonio Nino Diaz2ce2b092017-11-15 11:45:35 +000031 ASSERT(. == ALIGN(PAGE_SIZE),
Sandrine Bailleux8d69a032013-11-27 09:38:52 +000032 "BL31_BASE address is not aligned on a page boundary.")
Achin Gupta4f6ad662013-10-25 09:08:21 +010033
Soby Mathew4e28c202018-10-14 08:09:22 +010034 __BL31_START__ = .;
35
Sandrine Bailleuxf91f1442016-07-08 14:37:40 +010036#if SEPARATE_CODE_AND_RODATA
37 .text . : {
38 __TEXT_START__ = .;
39 *bl31_entrypoint.o(.text*)
Samuel Holland23f5e542019-10-20 16:11:25 -050040 *(SORT_BY_ALIGNMENT(.text*))
Sandrine Bailleuxf91f1442016-07-08 14:37:40 +010041 *(.vectors)
Roberto Vargasd93fde32018-04-11 11:53:31 +010042 . = ALIGN(PAGE_SIZE);
Sandrine Bailleuxf91f1442016-07-08 14:37:40 +010043 __TEXT_END__ = .;
44 } >RAM
45
46 .rodata . : {
47 __RODATA_START__ = .;
Samuel Holland23f5e542019-10-20 16:11:25 -050048 *(SORT_BY_ALIGNMENT(.rodata*))
Sandrine Bailleuxf91f1442016-07-08 14:37:40 +010049
Masahiro Yamada583f8dd2020-03-26 10:57:12 +090050 RODATA_COMMON
Soby Mathew4e28c202018-10-14 08:09:22 +010051
Jeenu Viswambharane3f22002017-09-22 08:32:10 +010052 /* Place pubsub sections for events */
53 . = ALIGN(8);
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000054#include <lib/el3_runtime/pubsub_events.h>
Jeenu Viswambharane3f22002017-09-22 08:32:10 +010055
Roberto Vargasd93fde32018-04-11 11:53:31 +010056 . = ALIGN(PAGE_SIZE);
Sandrine Bailleuxf91f1442016-07-08 14:37:40 +010057 __RODATA_END__ = .;
58 } >RAM
59#else
Sandrine Bailleux8d69a032013-11-27 09:38:52 +000060 ro . : {
61 __RO_START__ = .;
Andrew Thoelkee01ea342014-03-18 07:13:52 +000062 *bl31_entrypoint.o(.text*)
Samuel Holland23f5e542019-10-20 16:11:25 -050063 *(SORT_BY_ALIGNMENT(.text*))
64 *(SORT_BY_ALIGNMENT(.rodata*))
Achin Gupta7421b462014-02-01 18:53:26 +000065
Masahiro Yamada583f8dd2020-03-26 10:57:12 +090066 RODATA_COMMON
Soby Mathew2b3fc1d2018-12-12 14:33:11 +000067
Jeenu Viswambharane3f22002017-09-22 08:32:10 +010068 /* Place pubsub sections for events */
69 . = ALIGN(8);
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000070#include <lib/el3_runtime/pubsub_events.h>
Jeenu Viswambharane3f22002017-09-22 08:32:10 +010071
Achin Guptab739f222014-01-18 16:50:09 +000072 *(.vectors)
Sandrine Bailleux8d69a032013-11-27 09:38:52 +000073 __RO_END_UNALIGNED__ = .;
74 /*
75 * Memory page(s) mapped to this section will be marked as read-only,
76 * executable. No RW data from the next section must creep in.
77 * Ensure the rest of the current memory page is unused.
78 */
Roberto Vargasd93fde32018-04-11 11:53:31 +010079 . = ALIGN(PAGE_SIZE);
Sandrine Bailleux8d69a032013-11-27 09:38:52 +000080 __RO_END__ = .;
Achin Gupta4f6ad662013-10-25 09:08:21 +010081 } >RAM
Sandrine Bailleuxf91f1442016-07-08 14:37:40 +010082#endif
Achin Gupta4f6ad662013-10-25 09:08:21 +010083
Soby Mathewc704cbc2014-08-14 11:33:56 +010084 ASSERT(__CPU_OPS_END__ > __CPU_OPS_START__,
85 "cpu_ops not defined for this platform.")
86
Paul Beesleydb4e25a2019-10-14 15:27:12 +000087#if SPM_MM
Ard Biesheuvel447d56f2019-01-06 10:07:24 +010088#ifndef SPM_SHIM_EXCEPTIONS_VMA
89#define SPM_SHIM_EXCEPTIONS_VMA RAM
90#endif
91
Antonio Nino Diazc41f2062017-10-24 10:07:35 +010092 /*
93 * Exception vectors of the SPM shim layer. They must be aligned to a 2K
94 * address, but we need to place them in a separate page so that we can set
95 * individual permissions to them, so the actual alignment needed is 4K.
96 *
97 * There's no need to include this into the RO section of BL31 because it
98 * doesn't need to be accessed by BL31.
99 */
Antonio Nino Diaz2ce2b092017-11-15 11:45:35 +0000100 spm_shim_exceptions : ALIGN(PAGE_SIZE) {
Antonio Nino Diazc41f2062017-10-24 10:07:35 +0100101 __SPM_SHIM_EXCEPTIONS_START__ = .;
102 *(.spm_shim_exceptions)
Roberto Vargasd93fde32018-04-11 11:53:31 +0100103 . = ALIGN(PAGE_SIZE);
Antonio Nino Diazc41f2062017-10-24 10:07:35 +0100104 __SPM_SHIM_EXCEPTIONS_END__ = .;
Ard Biesheuvel447d56f2019-01-06 10:07:24 +0100105 } >SPM_SHIM_EXCEPTIONS_VMA AT>RAM
106
107 PROVIDE(__SPM_SHIM_EXCEPTIONS_LMA__ = LOADADDR(spm_shim_exceptions));
108 . = LOADADDR(spm_shim_exceptions) + SIZEOF(spm_shim_exceptions);
Antonio Nino Diazc41f2062017-10-24 10:07:35 +0100109#endif
110
Achin Guptae9c4a642015-09-11 16:03:13 +0100111 /*
112 * Define a linker symbol to mark start of the RW memory area for this
113 * image.
114 */
115 __RW_START__ = . ;
116
Douglas Raillard306593d2017-02-24 18:14:15 +0000117 /*
118 * .data must be placed at a lower address than the stacks if the stack
119 * protector is enabled. Alternatively, the .data.stack_protector_canary
120 * section can be placed independently of the main .data section.
121 */
122 .data . : {
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000123 __DATA_START__ = .;
Samuel Holland23f5e542019-10-20 16:11:25 -0500124 *(SORT_BY_ALIGNMENT(.data*))
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000125 __DATA_END__ = .;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100126 } >RAM
127
Soby Mathew4e28c202018-10-14 08:09:22 +0100128 /*
129 * .rela.dyn needs to come after .data for the read-elf utility to parse
Soby Mathew2b3fc1d2018-12-12 14:33:11 +0000130 * this section correctly. Ensure 8-byte alignment so that the fields of
131 * RELA data structure are aligned.
Soby Mathew4e28c202018-10-14 08:09:22 +0100132 */
Soby Mathew2b3fc1d2018-12-12 14:33:11 +0000133 . = ALIGN(8);
Soby Mathew4e28c202018-10-14 08:09:22 +0100134 __RELA_START__ = .;
135 .rela.dyn . : {
136 } >RAM
137 __RELA_END__ = .;
138
Sandrine Bailleuxe2e0c652014-06-16 16:12:27 +0100139#ifdef BL31_PROGBITS_LIMIT
Juan Castillo7d199412015-12-14 09:35:25 +0000140 ASSERT(. <= BL31_PROGBITS_LIMIT, "BL31 progbits has exceeded its limit.")
Sandrine Bailleuxe2e0c652014-06-16 16:12:27 +0100141#endif
142
Samuel Holland31a14e12018-10-17 21:40:18 -0500143#if SEPARATE_NOBITS_REGION
144 /*
145 * Define a linker symbol to mark end of the RW memory area for this
146 * image.
147 */
Madhukar Pappireddyf4e6ea62020-01-27 15:32:15 -0600148 . = ALIGN(PAGE_SIZE);
Samuel Holland31a14e12018-10-17 21:40:18 -0500149 __RW_END__ = .;
150 __BL31_END__ = .;
151
152 ASSERT(. <= BL31_LIMIT, "BL31 image has exceeded its limit.")
153
154 . = BL31_NOBITS_BASE;
155 ASSERT(. == ALIGN(PAGE_SIZE),
156 "BL31 NOBITS base address is not aligned on a page boundary.")
157
158 __NOBITS_START__ = .;
159#endif
160
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000161 stacks (NOLOAD) : {
162 __STACKS_START__ = .;
163 *(tzfw_normal_stacks)
164 __STACKS_END__ = .;
Samuel Holland31a14e12018-10-17 21:40:18 -0500165 } >NOBITS
Achin Gupta4f6ad662013-10-25 09:08:21 +0100166
Masahiro Yamadadd053b62020-03-26 13:16:33 +0900167 BSS_SECTION >NOBITS
Masahiro Yamada0b67e562020-03-09 17:39:48 +0900168 XLAT_TABLE_SECTION >NOBITS
Achin Guptaa0cd9892014-02-09 13:30:38 +0000169
Soby Mathew2ae20432015-01-08 18:02:44 +0000170#if USE_COHERENT_MEM
Achin Guptaa0cd9892014-02-09 13:30:38 +0000171 /*
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000172 * The base address of the coherent memory section must be page-aligned (4K)
173 * to guarantee that the coherent data are stored on their own pages and
174 * are not mixed with normal data. This is required to set up the correct
175 * memory attributes for the coherent data page tables.
176 */
Antonio Nino Diaz2ce2b092017-11-15 11:45:35 +0000177 coherent_ram (NOLOAD) : ALIGN(PAGE_SIZE) {
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000178 __COHERENT_RAM_START__ = .;
Andrew Thoelkee466c9f2015-09-10 11:39:36 +0100179 /*
180 * Bakery locks are stored in coherent memory
181 *
182 * Each lock's data is contiguous and fully allocated by the compiler
183 */
184 *(bakery_lock)
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000185 *(tzfw_coherent_mem)
186 __COHERENT_RAM_END_UNALIGNED__ = .;
187 /*
188 * Memory page(s) mapped to this section will be marked
189 * as device memory. No other unexpected data must creep in.
190 * Ensure the rest of the current memory page is unused.
191 */
Roberto Vargasd93fde32018-04-11 11:53:31 +0100192 . = ALIGN(PAGE_SIZE);
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000193 __COHERENT_RAM_END__ = .;
Samuel Holland31a14e12018-10-17 21:40:18 -0500194 } >NOBITS
Soby Mathew2ae20432015-01-08 18:02:44 +0000195#endif
Achin Gupta4f6ad662013-10-25 09:08:21 +0100196
Samuel Holland31a14e12018-10-17 21:40:18 -0500197#if SEPARATE_NOBITS_REGION
198 /*
199 * Define a linker symbol to mark end of the NOBITS memory area for this
200 * image.
201 */
202 __NOBITS_END__ = .;
203
204 ASSERT(. <= BL31_NOBITS_LIMIT, "BL31 NOBITS region has exceeded its limit.")
205#else
Achin Guptae9c4a642015-09-11 16:03:13 +0100206 /*
207 * Define a linker symbol to mark end of the RW memory area for this
208 * image.
209 */
210 __RW_END__ = .;
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000211 __BL31_END__ = .;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100212
Masahiro Yamadad3e7baa2020-01-17 13:44:50 +0900213 /DISCARD/ : {
214 *(.dynsym .dynstr .hash .gnu.hash)
215 }
216
Juan Castillo7d199412015-12-14 09:35:25 +0000217 ASSERT(. <= BL31_LIMIT, "BL31 image has exceeded its limit.")
Samuel Holland31a14e12018-10-17 21:40:18 -0500218#endif
Achin Gupta4f6ad662013-10-25 09:08:21 +0100219}