blob: 811f41e1415ceb1cdf81a169680c8ae490463128 [file] [log] [blame]
Roberto Vargase0e99462017-10-30 14:43:43 +00001/*
Chris Kay33bfc5e2023-02-14 11:30:04 +00002 * Copyright (c) 2017-2023, Arm Limited and Contributors. All rights reserved.
Roberto Vargase0e99462017-10-30 14:43:43 +00003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
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>
Roberto Vargase0e99462017-10-30 14:43:43 +00009
10OUTPUT_FORMAT(PLATFORM_LINKER_FORMAT)
11OUTPUT_ARCH(PLATFORM_LINKER_ARCH)
12ENTRY(bl2_entrypoint)
13
14MEMORY {
Jiafei Pan43a7bf42018-03-21 07:20:09 +000015#if BL2_IN_XIP_MEM
16 ROM (rx): ORIGIN = BL2_RO_BASE, LENGTH = BL2_RO_LIMIT - BL2_RO_BASE
17 RAM (rwx): ORIGIN = BL2_RW_BASE, LENGTH = BL2_RW_LIMIT - BL2_RW_BASE
Chris Kay4b7660a2022-09-29 14:36:53 +010018#else /* BL2_IN_XIP_MEM */
Roberto Vargase0e99462017-10-30 14:43:43 +000019 RAM (rwx): ORIGIN = BL2_BASE, LENGTH = BL2_LIMIT - BL2_BASE
Chris Kay4b7660a2022-09-29 14:36:53 +010020#endif /* BL2_IN_XIP_MEM */
21
Jiafei Pan0824b452022-02-24 10:47:33 +080022#if SEPARATE_BL2_NOLOAD_REGION
23 RAM_NOLOAD (rw!a): ORIGIN = BL2_NOLOAD_START, LENGTH = BL2_NOLOAD_LIMIT - BL2_NOLOAD_START
Chris Kay4b7660a2022-09-29 14:36:53 +010024#else /* SEPARATE_BL2_NOLOAD_REGION */
25# define RAM_NOLOAD RAM
26#endif /* SEPARATE_BL2_NOLOAD_REGION */
Roberto Vargase0e99462017-10-30 14:43:43 +000027}
28
Masahiro Yamada5289b672019-06-14 17:49:17 +090029#if !BL2_IN_XIP_MEM
Chris Kay4b7660a2022-09-29 14:36:53 +010030# define ROM RAM
31#endif /* !BL2_IN_XIP_MEM */
Roberto Vargase0e99462017-10-30 14:43:43 +000032
Chris Kay4b7660a2022-09-29 14:36:53 +010033SECTIONS {
Harrison Mutaib6f9a2b2023-04-19 10:08:56 +010034 RAM_REGION_START = ORIGIN(RAM);
35 RAM_REGION_LENGTH = LENGTH(RAM);
Jiafei Pan43a7bf42018-03-21 07:20:09 +000036#if BL2_IN_XIP_MEM
Harrison Mutaib6f9a2b2023-04-19 10:08:56 +010037 ROM_REGION_START = ORIGIN(ROM);
38 ROM_REGION_LENGTH = LENGTH(ROM);
39
Jiafei Pan43a7bf42018-03-21 07:20:09 +000040 . = BL2_RO_BASE;
Chris Kay4b7660a2022-09-29 14:36:53 +010041
Jiafei Pan43a7bf42018-03-21 07:20:09 +000042 ASSERT(. == ALIGN(PAGE_SIZE),
Chris Kay4b7660a2022-09-29 14:36:53 +010043 "BL2_RO_BASE address is not aligned on a page boundary.")
44#else /* BL2_IN_XIP_MEM */
Roberto Vargase0e99462017-10-30 14:43:43 +000045 . = BL2_BASE;
Chris Kay4b7660a2022-09-29 14:36:53 +010046
Roberto Vargase0e99462017-10-30 14:43:43 +000047 ASSERT(. == ALIGN(PAGE_SIZE),
Chris Kay4b7660a2022-09-29 14:36:53 +010048 "BL2_BASE address is not aligned on a page boundary.")
49#endif /* BL2_IN_XIP_MEM */
Roberto Vargase0e99462017-10-30 14:43:43 +000050
Harrison Mutaib6f9a2b2023-04-19 10:08:56 +010051#if SEPARATE_BL2_NOLOAD_REGION
52 RAM_NOLOAD_REGION_START = ORIGIN(RAM_NOLOAD);
53 RAM_NOLOAD_REGION_LENGTH = LENGTH(RAM_NOLOAD);
54#endif
55
Roberto Vargase0e99462017-10-30 14:43:43 +000056#if SEPARATE_CODE_AND_RODATA
57 .text . : {
Andrey Skvortsov08526ad2023-09-05 22:09:25 +030058 ASSERT(. == ALIGN(PAGE_SIZE),
59 ".text address is not aligned on a page boundary.");
60
Roberto Vargase0e99462017-10-30 14:43:43 +000061 __TEXT_START__ = .;
Chris Kay4b7660a2022-09-29 14:36:53 +010062 __TEXT_RESIDENT_START__ = .;
63
64 *bl2_el3_entrypoint.o(.text*)
65 *(.text.asm.*)
66
67 __TEXT_RESIDENT_END__ = .;
68
Samuel Holland23f5e542019-10-20 16:11:25 -050069 *(SORT_BY_ALIGNMENT(.text*))
Roberto Vargase0e99462017-10-30 14:43:43 +000070 *(.vectors)
Michal Simek80c530e2023-04-27 14:26:03 +020071 __TEXT_END_UNALIGNED__ = .;
Chris Kay4b7660a2022-09-29 14:36:53 +010072
Roberto Vargasd93fde32018-04-11 11:53:31 +010073 . = ALIGN(PAGE_SIZE);
Chris Kay4b7660a2022-09-29 14:36:53 +010074
Roberto Vargase0e99462017-10-30 14:43:43 +000075 __TEXT_END__ = .;
Chris Kay4b7660a2022-09-29 14:36:53 +010076 } >ROM
Roberto Vargase0e99462017-10-30 14:43:43 +000077
78 .rodata . : {
79 __RODATA_START__ = .;
Chris Kay4b7660a2022-09-29 14:36:53 +010080
Samuel Holland23f5e542019-10-20 16:11:25 -050081 *(SORT_BY_ALIGNMENT(.rodata*))
Roberto Vargase0e99462017-10-30 14:43:43 +000082
Chris Kay4b7660a2022-09-29 14:36:53 +010083 RODATA_COMMON
Masahiro Yamada65d699d2020-01-17 13:45:02 +090084
Michal Simek80c530e2023-04-27 14:26:03 +020085 __RODATA_END_UNALIGNED__ = .;
Roberto Vargasd93fde32018-04-11 11:53:31 +010086 . = ALIGN(PAGE_SIZE);
Chris Kay4b7660a2022-09-29 14:36:53 +010087
Roberto Vargase0e99462017-10-30 14:43:43 +000088 __RODATA_END__ = .;
Jiafei Pan43a7bf42018-03-21 07:20:09 +000089 } >ROM
Roberto Vargas51abc342017-11-17 10:51:54 +000090
91 ASSERT(__TEXT_RESIDENT_END__ - __TEXT_RESIDENT_START__ <= PAGE_SIZE,
Chris Kay4b7660a2022-09-29 14:36:53 +010092 "Resident part of BL2 has exceeded its limit.")
93#else /* SEPARATE_CODE_AND_RODATA */
Chris Kay33bfc5e2023-02-14 11:30:04 +000094 .ro . : {
Andrey Skvortsov08526ad2023-09-05 22:09:25 +030095 ASSERT(. == ALIGN(PAGE_SIZE),
96 ".ro address is not aligned on a page boundary.");
97
Roberto Vargase0e99462017-10-30 14:43:43 +000098 __RO_START__ = .;
Chris Kay4b7660a2022-09-29 14:36:53 +010099 __TEXT_RESIDENT_START__ = .;
100
101 *bl2_el3_entrypoint.o(.text*)
102 *(.text.asm.*)
103
104 __TEXT_RESIDENT_END__ = .;
105
Samuel Holland23f5e542019-10-20 16:11:25 -0500106 *(SORT_BY_ALIGNMENT(.text*))
107 *(SORT_BY_ALIGNMENT(.rodata*))
Roberto Vargase0e99462017-10-30 14:43:43 +0000108
Chris Kay4b7660a2022-09-29 14:36:53 +0100109 RODATA_COMMON
Masahiro Yamada65d699d2020-01-17 13:45:02 +0900110
Roberto Vargase0e99462017-10-30 14:43:43 +0000111 *(.vectors)
Chris Kay4b7660a2022-09-29 14:36:53 +0100112
Roberto Vargase0e99462017-10-30 14:43:43 +0000113 __RO_END_UNALIGNED__ = .;
Chris Kay4b7660a2022-09-29 14:36:53 +0100114
Roberto Vargase0e99462017-10-30 14:43:43 +0000115 /*
Chris Kay4b7660a2022-09-29 14:36:53 +0100116 * Memory page(s) mapped to this section will be marked as read-only,
117 * executable. No RW data from the next section must creep in. Ensure
118 * that the rest of the current memory page is unused.
Roberto Vargase0e99462017-10-30 14:43:43 +0000119 */
Roberto Vargasd93fde32018-04-11 11:53:31 +0100120 . = ALIGN(PAGE_SIZE);
Roberto Vargase0e99462017-10-30 14:43:43 +0000121
122 __RO_END__ = .;
Jiafei Pan43a7bf42018-03-21 07:20:09 +0000123 } >ROM
Chris Kay4b7660a2022-09-29 14:36:53 +0100124#endif /* SEPARATE_CODE_AND_RODATA */
Roberto Vargase0e99462017-10-30 14:43:43 +0000125
126 ASSERT(__CPU_OPS_END__ > __CPU_OPS_START__,
Chris Kay4b7660a2022-09-29 14:36:53 +0100127 "cpu_ops not defined for this platform.")
Roberto Vargase0e99462017-10-30 14:43:43 +0000128
Jiafei Pan43a7bf42018-03-21 07:20:09 +0000129#if BL2_IN_XIP_MEM
Harrison Mutaib6f9a2b2023-04-19 10:08:56 +0100130 ROM_REGION_END = .;
Jiafei Pan43a7bf42018-03-21 07:20:09 +0000131 . = BL2_RW_BASE;
Chris Kay4b7660a2022-09-29 14:36:53 +0100132
Jiafei Pan43a7bf42018-03-21 07:20:09 +0000133 ASSERT(BL2_RW_BASE == ALIGN(PAGE_SIZE),
134 "BL2_RW_BASE address is not aligned on a page boundary.")
Chris Kay4b7660a2022-09-29 14:36:53 +0100135#endif /* BL2_IN_XIP_MEM */
Jiafei Pan43a7bf42018-03-21 07:20:09 +0000136
Chris Kay4b7660a2022-09-29 14:36:53 +0100137 __RW_START__ = .;
Roberto Vargase0e99462017-10-30 14:43:43 +0000138
Masahiro Yamadac5864d82020-04-22 10:50:12 +0900139 DATA_SECTION >RAM AT>ROM
Chris Kay4b7660a2022-09-29 14:36:53 +0100140
Masahiro Yamadac5864d82020-04-22 10:50:12 +0900141 __DATA_RAM_START__ = __DATA_START__;
142 __DATA_RAM_END__ = __DATA_END__;
Roberto Vargase0e99462017-10-30 14:43:43 +0000143
Masahiro Yamada85fa00e2020-04-22 11:27:55 +0900144 RELA_SECTION >RAM
Chris Kay4b7660a2022-09-29 14:36:53 +0100145
Jiafei Pan0824b452022-02-24 10:47:33 +0800146#if SEPARATE_BL2_NOLOAD_REGION
147 SAVED_ADDR = .;
Chris Kay4b7660a2022-09-29 14:36:53 +0100148
Jiafei Pan0824b452022-02-24 10:47:33 +0800149 . = BL2_NOLOAD_START;
Chris Kay4b7660a2022-09-29 14:36:53 +0100150
Jiafei Pan0824b452022-02-24 10:47:33 +0800151 __BL2_NOLOAD_START__ = .;
Chris Kay4b7660a2022-09-29 14:36:53 +0100152#endif /* SEPARATE_BL2_NOLOAD_REGION */
153
Jiafei Pan0824b452022-02-24 10:47:33 +0800154 STACK_SECTION >RAM_NOLOAD
155 BSS_SECTION >RAM_NOLOAD
156 XLAT_TABLE_SECTION >RAM_NOLOAD
Chris Kay4b7660a2022-09-29 14:36:53 +0100157
Jiafei Pan0824b452022-02-24 10:47:33 +0800158#if SEPARATE_BL2_NOLOAD_REGION
159 __BL2_NOLOAD_END__ = .;
Harrison Mutaib6f9a2b2023-04-19 10:08:56 +0100160 RAM_NOLOAD_REGION_END = .;
Chris Kay4b7660a2022-09-29 14:36:53 +0100161
Jiafei Pan0824b452022-02-24 10:47:33 +0800162 . = SAVED_ADDR;
Chris Kay4b7660a2022-09-29 14:36:53 +0100163#endif /* SEPARATE_BL2_NOLOAD_REGION */
Roberto Vargase0e99462017-10-30 14:43:43 +0000164
165#if USE_COHERENT_MEM
166 /*
Chris Kay4b7660a2022-09-29 14:36:53 +0100167 * The base address of the coherent memory section must be page-aligned to
168 * guarantee that the coherent data are stored on their own pages and are
169 * not mixed with normal data. This is required to set up the correct
Roberto Vargase0e99462017-10-30 14:43:43 +0000170 * memory attributes for the coherent data page tables.
171 */
Chris Kay33bfc5e2023-02-14 11:30:04 +0000172 .coherent_ram (NOLOAD) : ALIGN(PAGE_SIZE) {
Roberto Vargase0e99462017-10-30 14:43:43 +0000173 __COHERENT_RAM_START__ = .;
Chris Kay4b7660a2022-09-29 14:36:53 +0100174
Chris Kay33bfc5e2023-02-14 11:30:04 +0000175 *(.tzfw_coherent_mem)
Chris Kay4b7660a2022-09-29 14:36:53 +0100176
Roberto Vargase0e99462017-10-30 14:43:43 +0000177 __COHERENT_RAM_END_UNALIGNED__ = .;
Chris Kay4b7660a2022-09-29 14:36:53 +0100178
Roberto Vargase0e99462017-10-30 14:43:43 +0000179 /*
Chris Kay4b7660a2022-09-29 14:36:53 +0100180 * Memory page(s) mapped to this section will be marked as device
181 * memory. No other unexpected data must creep in. Ensure the rest of
182 * the current memory page is unused.
Roberto Vargase0e99462017-10-30 14:43:43 +0000183 */
Roberto Vargasd93fde32018-04-11 11:53:31 +0100184 . = ALIGN(PAGE_SIZE);
Chris Kay4b7660a2022-09-29 14:36:53 +0100185
Roberto Vargase0e99462017-10-30 14:43:43 +0000186 __COHERENT_RAM_END__ = .;
187 } >RAM
Chris Kay4b7660a2022-09-29 14:36:53 +0100188#endif /* USE_COHERENT_MEM */
Roberto Vargase0e99462017-10-30 14:43:43 +0000189
Roberto Vargase0e99462017-10-30 14:43:43 +0000190 __RW_END__ = .;
191 __BL2_END__ = .;
192
Masahiro Yamada65d699d2020-01-17 13:45:02 +0900193 /DISCARD/ : {
194 *(.dynsym .dynstr .hash .gnu.hash)
195 }
196
Jiafei Pan43a7bf42018-03-21 07:20:09 +0000197#if BL2_IN_XIP_MEM
198 __BL2_RAM_START__ = ADDR(.data);
199 __BL2_RAM_END__ = .;
200
201 __DATA_ROM_START__ = LOADADDR(.data);
202 __DATA_SIZE__ = SIZEOF(.data);
203
204 /*
205 * The .data section is the last PROGBITS section so its end marks the end
Chris Kay4b7660a2022-09-29 14:36:53 +0100206 * of BL2's RO content in XIP memory.
Jiafei Pan43a7bf42018-03-21 07:20:09 +0000207 */
208 __BL2_ROM_END__ = __DATA_ROM_START__ + __DATA_SIZE__;
Chris Kay4b7660a2022-09-29 14:36:53 +0100209
Jiafei Pan43a7bf42018-03-21 07:20:09 +0000210 ASSERT(__BL2_ROM_END__ <= BL2_RO_LIMIT,
211 "BL2's RO content has exceeded its limit.")
Chris Kay4b7660a2022-09-29 14:36:53 +0100212#endif /* BL2_IN_XIP_MEM */
Roberto Vargase0e99462017-10-30 14:43:43 +0000213
Chris Kay4b7660a2022-09-29 14:36:53 +0100214 __BSS_SIZE__ = SIZEOF(.bss);
Jiafei Pan43a7bf42018-03-21 07:20:09 +0000215
Roberto Vargase0e99462017-10-30 14:43:43 +0000216#if USE_COHERENT_MEM
217 __COHERENT_RAM_UNALIGNED_SIZE__ =
218 __COHERENT_RAM_END_UNALIGNED__ - __COHERENT_RAM_START__;
Chris Kay4b7660a2022-09-29 14:36:53 +0100219#endif /* USE_COHERENT_MEM */
Roberto Vargase0e99462017-10-30 14:43:43 +0000220
Harrison Mutaib6f9a2b2023-04-19 10:08:56 +0100221 RAM_REGION_END = .;
Jiafei Pan43a7bf42018-03-21 07:20:09 +0000222#if BL2_IN_XIP_MEM
223 ASSERT(. <= BL2_RW_LIMIT, "BL2's RW content has exceeded its limit.")
Chris Kay4b7660a2022-09-29 14:36:53 +0100224#else /* BL2_IN_XIP_MEM */
Roberto Vargase0e99462017-10-30 14:43:43 +0000225 ASSERT(. <= BL2_LIMIT, "BL2 image has exceeded its limit.")
Chris Kay4b7660a2022-09-29 14:36:53 +0100226#endif /* BL2_IN_XIP_MEM */
Roberto Vargase0e99462017-10-30 14:43:43 +0000227}