blob: 867dedb999bbb99ed5688bfe5547d5b952290b4e [file] [log] [blame]
Achin Gupta4f6ad662013-10-25 09:08:21 +01001/*
Chris Kay33bfc5e2023-02-14 11:30:04 +00002 * Copyright (c) 2013-2023, 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
Achin Gupta4f6ad662013-10-25 09:08:21 +010014MEMORY {
Juan Castillofd8c0772014-09-16 10:40:35 +010015 RAM (rwx): ORIGIN = BL31_BASE, LENGTH = BL31_LIMIT - BL31_BASE
Chris Kay4b7660a2022-09-29 14:36:53 +010016
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
Chris Kay4b7660a2022-09-29 14:36:53 +010019#else /* SEPARATE_NOBITS_REGION */
20# define NOBITS RAM
21#endif /* SEPARATE_NOBITS_REGION */
Ye Li97267752022-08-26 13:48:31 +080022
23#if SEPARATE_RWDATA_REGION
24 RAM_RW (rw): ORIGIN = BL31_RWDATA_BASE, LENGTH = BL31_RWDATA_LIMIT - BL31_RWDATA_BASE
25#else /* SEPARATE_RWDATA_REGION */
26#define RAM_RW RAM
27#endif /* SEPARATE_RWDATA_REGION */
Achin Gupta4f6ad662013-10-25 09:08:21 +010028}
29
Caesar Wangd90f43e2016-10-11 09:36:00 +080030#ifdef PLAT_EXTRA_LD_SCRIPT
Chris Kay4b7660a2022-09-29 14:36:53 +010031# include <plat.ld.S>
32#endif /* PLAT_EXTRA_LD_SCRIPT */
Achin Gupta4f6ad662013-10-25 09:08:21 +010033
Chris Kay4b7660a2022-09-29 14:36:53 +010034SECTIONS {
Harrison Mutai8d6b7412023-04-19 09:30:15 +010035 RAM_REGION_START = ORIGIN(RAM);
36 RAM_REGION_LENGTH = LENGTH(RAM);
Sandrine Bailleux8d69a032013-11-27 09:38:52 +000037 . = BL31_BASE;
Chris Kay4b7660a2022-09-29 14:36:53 +010038
Antonio Nino Diaz2ce2b092017-11-15 11:45:35 +000039 ASSERT(. == ALIGN(PAGE_SIZE),
Chris Kay4b7660a2022-09-29 14:36:53 +010040 "BL31_BASE address is not aligned on a page boundary.")
Achin Gupta4f6ad662013-10-25 09:08:21 +010041
Soby Mathew4e28c202018-10-14 08:09:22 +010042 __BL31_START__ = .;
43
Sandrine Bailleuxf91f1442016-07-08 14:37:40 +010044#if SEPARATE_CODE_AND_RODATA
45 .text . : {
Andrey Skvortsov08526ad2023-09-05 22:09:25 +030046 ASSERT(. == ALIGN(PAGE_SIZE),
47 ".text is not aligned on a page boundary.");
48
Sandrine Bailleuxf91f1442016-07-08 14:37:40 +010049 __TEXT_START__ = .;
Chris Kay4b7660a2022-09-29 14:36:53 +010050
Sandrine Bailleuxf91f1442016-07-08 14:37:40 +010051 *bl31_entrypoint.o(.text*)
Jimmy Brissoned202072020-08-04 16:18:52 -050052 *(SORT_BY_ALIGNMENT(SORT(.text*)))
Sandrine Bailleuxf91f1442016-07-08 14:37:40 +010053 *(.vectors)
Michal Simek80c530e2023-04-27 14:26:03 +020054 __TEXT_END_UNALIGNED__ = .;
Chris Kay4b7660a2022-09-29 14:36:53 +010055
Roberto Vargasd93fde32018-04-11 11:53:31 +010056 . = ALIGN(PAGE_SIZE);
Chris Kay4b7660a2022-09-29 14:36:53 +010057
Sandrine Bailleuxf91f1442016-07-08 14:37:40 +010058 __TEXT_END__ = .;
59 } >RAM
60
61 .rodata . : {
62 __RODATA_START__ = .;
Chris Kay4b7660a2022-09-29 14:36:53 +010063
Samuel Holland23f5e542019-10-20 16:11:25 -050064 *(SORT_BY_ALIGNMENT(.rodata*))
Sandrine Bailleuxf91f1442016-07-08 14:37:40 +010065
Chris Kay4b7660a2022-09-29 14:36:53 +010066# if PLAT_EXTRA_RODATA_INCLUDES
67# include <plat.ld.rodata.inc>
68# endif /* PLAT_EXTRA_RODATA_INCLUDES */
developer8a3180d2022-08-05 10:04:10 +080069
Chris Kay4b7660a2022-09-29 14:36:53 +010070 RODATA_COMMON
Soby Mathew4e28c202018-10-14 08:09:22 +010071
Jeenu Viswambharane3f22002017-09-22 08:32:10 +010072 . = ALIGN(8);
Chris Kay4b7660a2022-09-29 14:36:53 +010073
74# include <lib/el3_runtime/pubsub_events.h>
Michal Simek80c530e2023-04-27 14:26:03 +020075 __RODATA_END_UNALIGNED__ = .;
Jeenu Viswambharane3f22002017-09-22 08:32:10 +010076
Roberto Vargasd93fde32018-04-11 11:53:31 +010077 . = ALIGN(PAGE_SIZE);
Chris Kay4b7660a2022-09-29 14:36:53 +010078
Sandrine Bailleuxf91f1442016-07-08 14:37:40 +010079 __RODATA_END__ = .;
80 } >RAM
Chris Kay4b7660a2022-09-29 14:36:53 +010081#else /* SEPARATE_CODE_AND_RODATA */
Chris Kay33bfc5e2023-02-14 11:30:04 +000082 .ro . : {
Andrey Skvortsov08526ad2023-09-05 22:09:25 +030083 ASSERT(. == ALIGN(PAGE_SIZE),
84 ".ro is not aligned on a page boundary.");
85
Sandrine Bailleux8d69a032013-11-27 09:38:52 +000086 __RO_START__ = .;
Chris Kay4b7660a2022-09-29 14:36:53 +010087
Andrew Thoelkee01ea342014-03-18 07:13:52 +000088 *bl31_entrypoint.o(.text*)
Samuel Holland23f5e542019-10-20 16:11:25 -050089 *(SORT_BY_ALIGNMENT(.text*))
90 *(SORT_BY_ALIGNMENT(.rodata*))
Achin Gupta7421b462014-02-01 18:53:26 +000091
Chris Kay4b7660a2022-09-29 14:36:53 +010092 RODATA_COMMON
Soby Mathew2b3fc1d2018-12-12 14:33:11 +000093
Jeenu Viswambharane3f22002017-09-22 08:32:10 +010094 . = ALIGN(8);
Chris Kay4b7660a2022-09-29 14:36:53 +010095
96# include <lib/el3_runtime/pubsub_events.h>
Jeenu Viswambharane3f22002017-09-22 08:32:10 +010097
Achin Guptab739f222014-01-18 16:50:09 +000098 *(.vectors)
Chris Kay4b7660a2022-09-29 14:36:53 +010099
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000100 __RO_END_UNALIGNED__ = .;
Chris Kay4b7660a2022-09-29 14:36:53 +0100101
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000102 /*
103 * Memory page(s) mapped to this section will be marked as read-only,
Chris Kay4b7660a2022-09-29 14:36:53 +0100104 * executable. No RW data from the next section must creep in. Ensure
105 * that the rest of the current memory page is unused.
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000106 */
Roberto Vargasd93fde32018-04-11 11:53:31 +0100107 . = ALIGN(PAGE_SIZE);
Chris Kay4b7660a2022-09-29 14:36:53 +0100108
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000109 __RO_END__ = .;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100110 } >RAM
Chris Kay4b7660a2022-09-29 14:36:53 +0100111#endif /* SEPARATE_CODE_AND_RODATA */
Achin Gupta4f6ad662013-10-25 09:08:21 +0100112
Soby Mathewc704cbc2014-08-14 11:33:56 +0100113 ASSERT(__CPU_OPS_END__ > __CPU_OPS_START__,
Chris Kay4b7660a2022-09-29 14:36:53 +0100114 "cpu_ops not defined for this platform.")
Soby Mathewc704cbc2014-08-14 11:33:56 +0100115
Nishant Sharma341b3112023-10-12 10:43:16 +0100116#if SPM_MM || (SPMC_AT_EL3 && SPMC_AT_EL3_SEL0_SP)
Chris Kay4b7660a2022-09-29 14:36:53 +0100117# ifndef SPM_SHIM_EXCEPTIONS_VMA
118# define SPM_SHIM_EXCEPTIONS_VMA RAM
119# endif /* SPM_SHIM_EXCEPTIONS_VMA */
Ard Biesheuvel447d56f2019-01-06 10:07:24 +0100120
Antonio Nino Diazc41f2062017-10-24 10:07:35 +0100121 /*
122 * Exception vectors of the SPM shim layer. They must be aligned to a 2K
Chris Kay4b7660a2022-09-29 14:36:53 +0100123 * address but we need to place them in a separate page so that we can set
124 * individual permissions on them, so the actual alignment needed is the
125 * page size.
Antonio Nino Diazc41f2062017-10-24 10:07:35 +0100126 *
127 * There's no need to include this into the RO section of BL31 because it
128 * doesn't need to be accessed by BL31.
129 */
Chris Kay33bfc5e2023-02-14 11:30:04 +0000130 .spm_shim_exceptions : ALIGN(PAGE_SIZE) {
Antonio Nino Diazc41f2062017-10-24 10:07:35 +0100131 __SPM_SHIM_EXCEPTIONS_START__ = .;
Chris Kay4b7660a2022-09-29 14:36:53 +0100132
Antonio Nino Diazc41f2062017-10-24 10:07:35 +0100133 *(.spm_shim_exceptions)
Chris Kay4b7660a2022-09-29 14:36:53 +0100134
Roberto Vargasd93fde32018-04-11 11:53:31 +0100135 . = ALIGN(PAGE_SIZE);
Chris Kay4b7660a2022-09-29 14:36:53 +0100136
Antonio Nino Diazc41f2062017-10-24 10:07:35 +0100137 __SPM_SHIM_EXCEPTIONS_END__ = .;
Ard Biesheuvel447d56f2019-01-06 10:07:24 +0100138 } >SPM_SHIM_EXCEPTIONS_VMA AT>RAM
139
Chris Kay33bfc5e2023-02-14 11:30:04 +0000140 PROVIDE(__SPM_SHIM_EXCEPTIONS_LMA__ = LOADADDR(.spm_shim_exceptions));
Chris Kay4b7660a2022-09-29 14:36:53 +0100141
Chris Kay33bfc5e2023-02-14 11:30:04 +0000142 . = LOADADDR(.spm_shim_exceptions) + SIZEOF(.spm_shim_exceptions);
Nishant Sharma341b3112023-10-12 10:43:16 +0100143#endif /* SPM_MM || (SPMC_AT_EL3 && SPMC_AT_EL3_SEL0_SP) */
Antonio Nino Diazc41f2062017-10-24 10:07:35 +0100144
Ye Li97267752022-08-26 13:48:31 +0800145#if SEPARATE_RWDATA_REGION
146 . = BL31_RWDATA_BASE;
147 ASSERT(BL31_RWDATA_BASE == ALIGN(PAGE_SIZE),
148 "BL31_RWDATA_BASE address is not aligned on a page boundary.")
149
150 /*
151 * Define a linker symbol to mark the start of the RW memory area for this
152 * image.
153 */
154 __RW_START__ = . ;
155
156 DATA_SECTION >RAM_RW AT>RAM
157 __DATA_RAM_START__ = __DATA_START__;
158 __DATA_RAM_END__ = __DATA_END__;
159 __DATA_ROM_START__ = LOADADDR(.data);
160
161 . = ALIGN(PAGE_SIZE);
162 __RW_END__ = .;
163
164 RELA_SECTION >RAM
165#else /* SEPARATE_RWDATA_REGION */
166 /*
167 * Define a linker symbol to mark the start of the RW memory area for this
168 * image.
169 */
170 __RW_START__ = . ;
Achin Guptae9c4a642015-09-11 16:03:13 +0100171
Masahiro Yamadac5864d82020-04-22 10:50:12 +0900172 DATA_SECTION >RAM
Masahiro Yamada85fa00e2020-04-22 11:27:55 +0900173 RELA_SECTION >RAM
Ye Li97267752022-08-26 13:48:31 +0800174#endif /* SEPARATE_RWDATA_REGION */
Soby Mathew4e28c202018-10-14 08:09:22 +0100175
Sandrine Bailleuxe2e0c652014-06-16 16:12:27 +0100176#ifdef BL31_PROGBITS_LIMIT
Boyan Karatotev3e0e7892023-03-30 14:56:45 +0100177 ASSERT(
178 . <= BL31_PROGBITS_LIMIT,
179 "BL31 progbits has exceeded its limit. Consider disabling some features."
180 )
Chris Kay4b7660a2022-09-29 14:36:53 +0100181#endif /* BL31_PROGBITS_LIMIT */
Sandrine Bailleuxe2e0c652014-06-16 16:12:27 +0100182
Samuel Holland31a14e12018-10-17 21:40:18 -0500183#if SEPARATE_NOBITS_REGION
Madhukar Pappireddyf4e6ea62020-01-27 15:32:15 -0600184 . = ALIGN(PAGE_SIZE);
Chris Kay4b7660a2022-09-29 14:36:53 +0100185
Ye Li97267752022-08-26 13:48:31 +0800186#if !SEPARATE_RWDATA_REGION
Samuel Holland31a14e12018-10-17 21:40:18 -0500187 __RW_END__ = .;
Ye Li97267752022-08-26 13:48:31 +0800188#endif /* SEPARATE_RWDATA_REGION */
Samuel Holland31a14e12018-10-17 21:40:18 -0500189 __BL31_END__ = .;
190
191 ASSERT(. <= BL31_LIMIT, "BL31 image has exceeded its limit.")
192
193 . = BL31_NOBITS_BASE;
Chris Kay4b7660a2022-09-29 14:36:53 +0100194
Samuel Holland31a14e12018-10-17 21:40:18 -0500195 ASSERT(. == ALIGN(PAGE_SIZE),
Chris Kay4b7660a2022-09-29 14:36:53 +0100196 "BL31 NOBITS base address is not aligned on a page boundary.")
Samuel Holland31a14e12018-10-17 21:40:18 -0500197
198 __NOBITS_START__ = .;
Chris Kay4b7660a2022-09-29 14:36:53 +0100199#endif /* SEPARATE_NOBITS_REGION */
Samuel Holland31a14e12018-10-17 21:40:18 -0500200
Masahiro Yamada403990e2020-04-07 13:04:24 +0900201 STACK_SECTION >NOBITS
Masahiro Yamadadd053b62020-03-26 13:16:33 +0900202 BSS_SECTION >NOBITS
Masahiro Yamada0b67e562020-03-09 17:39:48 +0900203 XLAT_TABLE_SECTION >NOBITS
Achin Guptaa0cd9892014-02-09 13:30:38 +0000204
Soby Mathew2ae20432015-01-08 18:02:44 +0000205#if USE_COHERENT_MEM
Achin Guptaa0cd9892014-02-09 13:30:38 +0000206 /*
Chris Kay4b7660a2022-09-29 14:36:53 +0100207 * The base address of the coherent memory section must be page-aligned to
208 * guarantee that the coherent data are stored on their own pages and are
209 * not mixed with normal data. This is required to set up the correct
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000210 * memory attributes for the coherent data page tables.
211 */
Chris Kay33bfc5e2023-02-14 11:30:04 +0000212 .coherent_ram (NOLOAD) : ALIGN(PAGE_SIZE) {
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000213 __COHERENT_RAM_START__ = .;
Chris Kay4b7660a2022-09-29 14:36:53 +0100214
Andrew Thoelkee466c9f2015-09-10 11:39:36 +0100215 /*
Chris Kay4b7660a2022-09-29 14:36:53 +0100216 * Bakery locks are stored in coherent memory. Each lock's data is
217 * contiguous and fully allocated by the compiler.
Andrew Thoelkee466c9f2015-09-10 11:39:36 +0100218 */
Chris Kay33bfc5e2023-02-14 11:30:04 +0000219 *(.bakery_lock)
220 *(.tzfw_coherent_mem)
Chris Kay4b7660a2022-09-29 14:36:53 +0100221
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000222 __COHERENT_RAM_END_UNALIGNED__ = .;
Chris Kay4b7660a2022-09-29 14:36:53 +0100223
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000224 /*
Chris Kay4b7660a2022-09-29 14:36:53 +0100225 * Memory page(s) mapped to this section will be marked as device
226 * memory. No other unexpected data must creep in. Ensure the rest of
227 * the current memory page is unused.
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000228 */
Roberto Vargasd93fde32018-04-11 11:53:31 +0100229 . = ALIGN(PAGE_SIZE);
Chris Kay4b7660a2022-09-29 14:36:53 +0100230
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000231 __COHERENT_RAM_END__ = .;
Samuel Holland31a14e12018-10-17 21:40:18 -0500232 } >NOBITS
Chris Kay4b7660a2022-09-29 14:36:53 +0100233#endif /* USE_COHERENT_MEM */
Achin Gupta4f6ad662013-10-25 09:08:21 +0100234
Samuel Holland31a14e12018-10-17 21:40:18 -0500235#if SEPARATE_NOBITS_REGION
Samuel Holland31a14e12018-10-17 21:40:18 -0500236 __NOBITS_END__ = .;
237
238 ASSERT(. <= BL31_NOBITS_LIMIT, "BL31 NOBITS region has exceeded its limit.")
Chris Kay4b7660a2022-09-29 14:36:53 +0100239#else /* SEPARATE_NOBITS_REGION */
Ye Li97267752022-08-26 13:48:31 +0800240 /*
241 * Define a linker symbol to mark the end of the RW memory area for this
242 * image.
243 */
244#if !SEPARATE_RWDATA_REGION
Achin Guptae9c4a642015-09-11 16:03:13 +0100245 __RW_END__ = .;
Ye Li97267752022-08-26 13:48:31 +0800246#endif /* SEPARATE_RWDATA_REGION */
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000247 __BL31_END__ = .;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100248
Samuel Holland322df2a2022-04-08 22:22:04 -0500249 ASSERT(. <= BL31_LIMIT, "BL31 image has exceeded its limit.")
Chris Kay4b7660a2022-09-29 14:36:53 +0100250#endif /* SEPARATE_NOBITS_REGION */
Harrison Mutai8d6b7412023-04-19 09:30:15 +0100251 RAM_REGION_END = .;
Samuel Holland322df2a2022-04-08 22:22:04 -0500252
Masahiro Yamadad3e7baa2020-01-17 13:44:50 +0900253 /DISCARD/ : {
254 *(.dynsym .dynstr .hash .gnu.hash)
255 }
Achin Gupta4f6ad662013-10-25 09:08:21 +0100256}