blob: 4aa5cb0459ddae0bddb4a977f090aa4b728eb7ad [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 . : {
58 __TEXT_START__ = .;
Chris Kay4b7660a2022-09-29 14:36:53 +010059 __TEXT_RESIDENT_START__ = .;
60
61 *bl2_el3_entrypoint.o(.text*)
62 *(.text.asm.*)
63
64 __TEXT_RESIDENT_END__ = .;
65
Samuel Holland23f5e542019-10-20 16:11:25 -050066 *(SORT_BY_ALIGNMENT(.text*))
Roberto Vargase0e99462017-10-30 14:43:43 +000067 *(.vectors)
Michal Simek80c530e2023-04-27 14:26:03 +020068 __TEXT_END_UNALIGNED__ = .;
Chris Kay4b7660a2022-09-29 14:36:53 +010069
Roberto Vargasd93fde32018-04-11 11:53:31 +010070 . = ALIGN(PAGE_SIZE);
Chris Kay4b7660a2022-09-29 14:36:53 +010071
Roberto Vargase0e99462017-10-30 14:43:43 +000072 __TEXT_END__ = .;
Chris Kay4b7660a2022-09-29 14:36:53 +010073 } >ROM
Roberto Vargase0e99462017-10-30 14:43:43 +000074
75 .rodata . : {
76 __RODATA_START__ = .;
Chris Kay4b7660a2022-09-29 14:36:53 +010077
Samuel Holland23f5e542019-10-20 16:11:25 -050078 *(SORT_BY_ALIGNMENT(.rodata*))
Roberto Vargase0e99462017-10-30 14:43:43 +000079
Chris Kay4b7660a2022-09-29 14:36:53 +010080 RODATA_COMMON
Masahiro Yamada65d699d2020-01-17 13:45:02 +090081
Michal Simek80c530e2023-04-27 14:26:03 +020082 __RODATA_END_UNALIGNED__ = .;
Roberto Vargasd93fde32018-04-11 11:53:31 +010083 . = ALIGN(PAGE_SIZE);
Chris Kay4b7660a2022-09-29 14:36:53 +010084
Roberto Vargase0e99462017-10-30 14:43:43 +000085 __RODATA_END__ = .;
Jiafei Pan43a7bf42018-03-21 07:20:09 +000086 } >ROM
Roberto Vargas51abc342017-11-17 10:51:54 +000087
88 ASSERT(__TEXT_RESIDENT_END__ - __TEXT_RESIDENT_START__ <= PAGE_SIZE,
Chris Kay4b7660a2022-09-29 14:36:53 +010089 "Resident part of BL2 has exceeded its limit.")
90#else /* SEPARATE_CODE_AND_RODATA */
Chris Kay33bfc5e2023-02-14 11:30:04 +000091 .ro . : {
Roberto Vargase0e99462017-10-30 14:43:43 +000092 __RO_START__ = .;
Chris Kay4b7660a2022-09-29 14:36:53 +010093 __TEXT_RESIDENT_START__ = .;
94
95 *bl2_el3_entrypoint.o(.text*)
96 *(.text.asm.*)
97
98 __TEXT_RESIDENT_END__ = .;
99
Samuel Holland23f5e542019-10-20 16:11:25 -0500100 *(SORT_BY_ALIGNMENT(.text*))
101 *(SORT_BY_ALIGNMENT(.rodata*))
Roberto Vargase0e99462017-10-30 14:43:43 +0000102
Chris Kay4b7660a2022-09-29 14:36:53 +0100103 RODATA_COMMON
Masahiro Yamada65d699d2020-01-17 13:45:02 +0900104
Roberto Vargase0e99462017-10-30 14:43:43 +0000105 *(.vectors)
Chris Kay4b7660a2022-09-29 14:36:53 +0100106
Roberto Vargase0e99462017-10-30 14:43:43 +0000107 __RO_END_UNALIGNED__ = .;
Chris Kay4b7660a2022-09-29 14:36:53 +0100108
Roberto Vargase0e99462017-10-30 14:43:43 +0000109 /*
Chris Kay4b7660a2022-09-29 14:36:53 +0100110 * Memory page(s) mapped to this section will be marked as read-only,
111 * executable. No RW data from the next section must creep in. Ensure
112 * that the rest of the current memory page is unused.
Roberto Vargase0e99462017-10-30 14:43:43 +0000113 */
Roberto Vargasd93fde32018-04-11 11:53:31 +0100114 . = ALIGN(PAGE_SIZE);
Roberto Vargase0e99462017-10-30 14:43:43 +0000115
116 __RO_END__ = .;
Jiafei Pan43a7bf42018-03-21 07:20:09 +0000117 } >ROM
Chris Kay4b7660a2022-09-29 14:36:53 +0100118#endif /* SEPARATE_CODE_AND_RODATA */
Roberto Vargase0e99462017-10-30 14:43:43 +0000119
120 ASSERT(__CPU_OPS_END__ > __CPU_OPS_START__,
Chris Kay4b7660a2022-09-29 14:36:53 +0100121 "cpu_ops not defined for this platform.")
Roberto Vargase0e99462017-10-30 14:43:43 +0000122
Jiafei Pan43a7bf42018-03-21 07:20:09 +0000123#if BL2_IN_XIP_MEM
Harrison Mutaib6f9a2b2023-04-19 10:08:56 +0100124 ROM_REGION_END = .;
Jiafei Pan43a7bf42018-03-21 07:20:09 +0000125 . = BL2_RW_BASE;
Chris Kay4b7660a2022-09-29 14:36:53 +0100126
Jiafei Pan43a7bf42018-03-21 07:20:09 +0000127 ASSERT(BL2_RW_BASE == ALIGN(PAGE_SIZE),
128 "BL2_RW_BASE address is not aligned on a page boundary.")
Chris Kay4b7660a2022-09-29 14:36:53 +0100129#endif /* BL2_IN_XIP_MEM */
Jiafei Pan43a7bf42018-03-21 07:20:09 +0000130
Chris Kay4b7660a2022-09-29 14:36:53 +0100131 __RW_START__ = .;
Roberto Vargase0e99462017-10-30 14:43:43 +0000132
Masahiro Yamadac5864d82020-04-22 10:50:12 +0900133 DATA_SECTION >RAM AT>ROM
Chris Kay4b7660a2022-09-29 14:36:53 +0100134
Masahiro Yamadac5864d82020-04-22 10:50:12 +0900135 __DATA_RAM_START__ = __DATA_START__;
136 __DATA_RAM_END__ = __DATA_END__;
Roberto Vargase0e99462017-10-30 14:43:43 +0000137
Masahiro Yamada85fa00e2020-04-22 11:27:55 +0900138 RELA_SECTION >RAM
Chris Kay4b7660a2022-09-29 14:36:53 +0100139
Jiafei Pan0824b452022-02-24 10:47:33 +0800140#if SEPARATE_BL2_NOLOAD_REGION
141 SAVED_ADDR = .;
Chris Kay4b7660a2022-09-29 14:36:53 +0100142
Jiafei Pan0824b452022-02-24 10:47:33 +0800143 . = BL2_NOLOAD_START;
Chris Kay4b7660a2022-09-29 14:36:53 +0100144
Jiafei Pan0824b452022-02-24 10:47:33 +0800145 __BL2_NOLOAD_START__ = .;
Chris Kay4b7660a2022-09-29 14:36:53 +0100146#endif /* SEPARATE_BL2_NOLOAD_REGION */
147
Jiafei Pan0824b452022-02-24 10:47:33 +0800148 STACK_SECTION >RAM_NOLOAD
149 BSS_SECTION >RAM_NOLOAD
150 XLAT_TABLE_SECTION >RAM_NOLOAD
Chris Kay4b7660a2022-09-29 14:36:53 +0100151
Jiafei Pan0824b452022-02-24 10:47:33 +0800152#if SEPARATE_BL2_NOLOAD_REGION
153 __BL2_NOLOAD_END__ = .;
Harrison Mutaib6f9a2b2023-04-19 10:08:56 +0100154 RAM_NOLOAD_REGION_END = .;
Chris Kay4b7660a2022-09-29 14:36:53 +0100155
Jiafei Pan0824b452022-02-24 10:47:33 +0800156 . = SAVED_ADDR;
Chris Kay4b7660a2022-09-29 14:36:53 +0100157#endif /* SEPARATE_BL2_NOLOAD_REGION */
Roberto Vargase0e99462017-10-30 14:43:43 +0000158
159#if USE_COHERENT_MEM
160 /*
Chris Kay4b7660a2022-09-29 14:36:53 +0100161 * The base address of the coherent memory section must be page-aligned to
162 * guarantee that the coherent data are stored on their own pages and are
163 * not mixed with normal data. This is required to set up the correct
Roberto Vargase0e99462017-10-30 14:43:43 +0000164 * memory attributes for the coherent data page tables.
165 */
Chris Kay33bfc5e2023-02-14 11:30:04 +0000166 .coherent_ram (NOLOAD) : ALIGN(PAGE_SIZE) {
Roberto Vargase0e99462017-10-30 14:43:43 +0000167 __COHERENT_RAM_START__ = .;
Chris Kay4b7660a2022-09-29 14:36:53 +0100168
Chris Kay33bfc5e2023-02-14 11:30:04 +0000169 *(.tzfw_coherent_mem)
Chris Kay4b7660a2022-09-29 14:36:53 +0100170
Roberto Vargase0e99462017-10-30 14:43:43 +0000171 __COHERENT_RAM_END_UNALIGNED__ = .;
Chris Kay4b7660a2022-09-29 14:36:53 +0100172
Roberto Vargase0e99462017-10-30 14:43:43 +0000173 /*
Chris Kay4b7660a2022-09-29 14:36:53 +0100174 * Memory page(s) mapped to this section will be marked as device
175 * memory. No other unexpected data must creep in. Ensure the rest of
176 * the current memory page is unused.
Roberto Vargase0e99462017-10-30 14:43:43 +0000177 */
Roberto Vargasd93fde32018-04-11 11:53:31 +0100178 . = ALIGN(PAGE_SIZE);
Chris Kay4b7660a2022-09-29 14:36:53 +0100179
Roberto Vargase0e99462017-10-30 14:43:43 +0000180 __COHERENT_RAM_END__ = .;
181 } >RAM
Chris Kay4b7660a2022-09-29 14:36:53 +0100182#endif /* USE_COHERENT_MEM */
Roberto Vargase0e99462017-10-30 14:43:43 +0000183
Roberto Vargase0e99462017-10-30 14:43:43 +0000184 __RW_END__ = .;
185 __BL2_END__ = .;
186
Masahiro Yamada65d699d2020-01-17 13:45:02 +0900187 /DISCARD/ : {
188 *(.dynsym .dynstr .hash .gnu.hash)
189 }
190
Jiafei Pan43a7bf42018-03-21 07:20:09 +0000191#if BL2_IN_XIP_MEM
192 __BL2_RAM_START__ = ADDR(.data);
193 __BL2_RAM_END__ = .;
194
195 __DATA_ROM_START__ = LOADADDR(.data);
196 __DATA_SIZE__ = SIZEOF(.data);
197
198 /*
199 * The .data section is the last PROGBITS section so its end marks the end
Chris Kay4b7660a2022-09-29 14:36:53 +0100200 * of BL2's RO content in XIP memory.
Jiafei Pan43a7bf42018-03-21 07:20:09 +0000201 */
202 __BL2_ROM_END__ = __DATA_ROM_START__ + __DATA_SIZE__;
Chris Kay4b7660a2022-09-29 14:36:53 +0100203
Jiafei Pan43a7bf42018-03-21 07:20:09 +0000204 ASSERT(__BL2_ROM_END__ <= BL2_RO_LIMIT,
205 "BL2's RO content has exceeded its limit.")
Chris Kay4b7660a2022-09-29 14:36:53 +0100206#endif /* BL2_IN_XIP_MEM */
Roberto Vargase0e99462017-10-30 14:43:43 +0000207
Chris Kay4b7660a2022-09-29 14:36:53 +0100208 __BSS_SIZE__ = SIZEOF(.bss);
Jiafei Pan43a7bf42018-03-21 07:20:09 +0000209
Roberto Vargase0e99462017-10-30 14:43:43 +0000210#if USE_COHERENT_MEM
211 __COHERENT_RAM_UNALIGNED_SIZE__ =
212 __COHERENT_RAM_END_UNALIGNED__ - __COHERENT_RAM_START__;
Chris Kay4b7660a2022-09-29 14:36:53 +0100213#endif /* USE_COHERENT_MEM */
Roberto Vargase0e99462017-10-30 14:43:43 +0000214
Harrison Mutaib6f9a2b2023-04-19 10:08:56 +0100215 RAM_REGION_END = .;
Jiafei Pan43a7bf42018-03-21 07:20:09 +0000216#if BL2_IN_XIP_MEM
217 ASSERT(. <= BL2_RW_LIMIT, "BL2's RW content has exceeded its limit.")
Chris Kay4b7660a2022-09-29 14:36:53 +0100218#else /* BL2_IN_XIP_MEM */
Roberto Vargase0e99462017-10-30 14:43:43 +0000219 ASSERT(. <= BL2_LIMIT, "BL2 image has exceeded its limit.")
Chris Kay4b7660a2022-09-29 14:36:53 +0100220#endif /* BL2_IN_XIP_MEM */
Roberto Vargase0e99462017-10-30 14:43:43 +0000221}