blob: 5da631c073e7d54b9a65c0c17f4438111ea3698f [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)
Chris Kay4b7660a2022-09-29 14:36:53 +010068
Roberto Vargasd93fde32018-04-11 11:53:31 +010069 . = ALIGN(PAGE_SIZE);
Chris Kay4b7660a2022-09-29 14:36:53 +010070
Roberto Vargase0e99462017-10-30 14:43:43 +000071 __TEXT_END__ = .;
Chris Kay4b7660a2022-09-29 14:36:53 +010072 } >ROM
Roberto Vargase0e99462017-10-30 14:43:43 +000073
74 .rodata . : {
75 __RODATA_START__ = .;
Chris Kay4b7660a2022-09-29 14:36:53 +010076
Samuel Holland23f5e542019-10-20 16:11:25 -050077 *(SORT_BY_ALIGNMENT(.rodata*))
Roberto Vargase0e99462017-10-30 14:43:43 +000078
Chris Kay4b7660a2022-09-29 14:36:53 +010079 RODATA_COMMON
Masahiro Yamada65d699d2020-01-17 13:45:02 +090080
Roberto Vargasd93fde32018-04-11 11:53:31 +010081 . = ALIGN(PAGE_SIZE);
Chris Kay4b7660a2022-09-29 14:36:53 +010082
Roberto Vargase0e99462017-10-30 14:43:43 +000083 __RODATA_END__ = .;
Jiafei Pan43a7bf42018-03-21 07:20:09 +000084 } >ROM
Roberto Vargas51abc342017-11-17 10:51:54 +000085
86 ASSERT(__TEXT_RESIDENT_END__ - __TEXT_RESIDENT_START__ <= PAGE_SIZE,
Chris Kay4b7660a2022-09-29 14:36:53 +010087 "Resident part of BL2 has exceeded its limit.")
88#else /* SEPARATE_CODE_AND_RODATA */
Chris Kay33bfc5e2023-02-14 11:30:04 +000089 .ro . : {
Roberto Vargase0e99462017-10-30 14:43:43 +000090 __RO_START__ = .;
Chris Kay4b7660a2022-09-29 14:36:53 +010091 __TEXT_RESIDENT_START__ = .;
92
93 *bl2_el3_entrypoint.o(.text*)
94 *(.text.asm.*)
95
96 __TEXT_RESIDENT_END__ = .;
97
Samuel Holland23f5e542019-10-20 16:11:25 -050098 *(SORT_BY_ALIGNMENT(.text*))
99 *(SORT_BY_ALIGNMENT(.rodata*))
Roberto Vargase0e99462017-10-30 14:43:43 +0000100
Chris Kay4b7660a2022-09-29 14:36:53 +0100101 RODATA_COMMON
Masahiro Yamada65d699d2020-01-17 13:45:02 +0900102
Roberto Vargase0e99462017-10-30 14:43:43 +0000103 *(.vectors)
Chris Kay4b7660a2022-09-29 14:36:53 +0100104
Roberto Vargase0e99462017-10-30 14:43:43 +0000105 __RO_END_UNALIGNED__ = .;
Chris Kay4b7660a2022-09-29 14:36:53 +0100106
Roberto Vargase0e99462017-10-30 14:43:43 +0000107 /*
Chris Kay4b7660a2022-09-29 14:36:53 +0100108 * Memory page(s) mapped to this section will be marked as read-only,
109 * executable. No RW data from the next section must creep in. Ensure
110 * that the rest of the current memory page is unused.
Roberto Vargase0e99462017-10-30 14:43:43 +0000111 */
Roberto Vargasd93fde32018-04-11 11:53:31 +0100112 . = ALIGN(PAGE_SIZE);
Roberto Vargase0e99462017-10-30 14:43:43 +0000113
114 __RO_END__ = .;
Jiafei Pan43a7bf42018-03-21 07:20:09 +0000115 } >ROM
Chris Kay4b7660a2022-09-29 14:36:53 +0100116#endif /* SEPARATE_CODE_AND_RODATA */
Roberto Vargase0e99462017-10-30 14:43:43 +0000117
118 ASSERT(__CPU_OPS_END__ > __CPU_OPS_START__,
Chris Kay4b7660a2022-09-29 14:36:53 +0100119 "cpu_ops not defined for this platform.")
Roberto Vargase0e99462017-10-30 14:43:43 +0000120
Jiafei Pan43a7bf42018-03-21 07:20:09 +0000121#if BL2_IN_XIP_MEM
Harrison Mutaib6f9a2b2023-04-19 10:08:56 +0100122 ROM_REGION_END = .;
Jiafei Pan43a7bf42018-03-21 07:20:09 +0000123 . = BL2_RW_BASE;
Chris Kay4b7660a2022-09-29 14:36:53 +0100124
Jiafei Pan43a7bf42018-03-21 07:20:09 +0000125 ASSERT(BL2_RW_BASE == ALIGN(PAGE_SIZE),
126 "BL2_RW_BASE address is not aligned on a page boundary.")
Chris Kay4b7660a2022-09-29 14:36:53 +0100127#endif /* BL2_IN_XIP_MEM */
Jiafei Pan43a7bf42018-03-21 07:20:09 +0000128
Chris Kay4b7660a2022-09-29 14:36:53 +0100129 __RW_START__ = .;
Roberto Vargase0e99462017-10-30 14:43:43 +0000130
Masahiro Yamadac5864d82020-04-22 10:50:12 +0900131 DATA_SECTION >RAM AT>ROM
Chris Kay4b7660a2022-09-29 14:36:53 +0100132
Masahiro Yamadac5864d82020-04-22 10:50:12 +0900133 __DATA_RAM_START__ = __DATA_START__;
134 __DATA_RAM_END__ = __DATA_END__;
Roberto Vargase0e99462017-10-30 14:43:43 +0000135
Masahiro Yamada85fa00e2020-04-22 11:27:55 +0900136 RELA_SECTION >RAM
Chris Kay4b7660a2022-09-29 14:36:53 +0100137
Jiafei Pan0824b452022-02-24 10:47:33 +0800138#if SEPARATE_BL2_NOLOAD_REGION
139 SAVED_ADDR = .;
Chris Kay4b7660a2022-09-29 14:36:53 +0100140
Jiafei Pan0824b452022-02-24 10:47:33 +0800141 . = BL2_NOLOAD_START;
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#endif /* SEPARATE_BL2_NOLOAD_REGION */
145
Jiafei Pan0824b452022-02-24 10:47:33 +0800146 STACK_SECTION >RAM_NOLOAD
147 BSS_SECTION >RAM_NOLOAD
148 XLAT_TABLE_SECTION >RAM_NOLOAD
Chris Kay4b7660a2022-09-29 14:36:53 +0100149
Jiafei Pan0824b452022-02-24 10:47:33 +0800150#if SEPARATE_BL2_NOLOAD_REGION
151 __BL2_NOLOAD_END__ = .;
Harrison Mutaib6f9a2b2023-04-19 10:08:56 +0100152 RAM_NOLOAD_REGION_END = .;
Chris Kay4b7660a2022-09-29 14:36:53 +0100153
Jiafei Pan0824b452022-02-24 10:47:33 +0800154 . = SAVED_ADDR;
Chris Kay4b7660a2022-09-29 14:36:53 +0100155#endif /* SEPARATE_BL2_NOLOAD_REGION */
Roberto Vargase0e99462017-10-30 14:43:43 +0000156
157#if USE_COHERENT_MEM
158 /*
Chris Kay4b7660a2022-09-29 14:36:53 +0100159 * The base address of the coherent memory section must be page-aligned to
160 * guarantee that the coherent data are stored on their own pages and are
161 * not mixed with normal data. This is required to set up the correct
Roberto Vargase0e99462017-10-30 14:43:43 +0000162 * memory attributes for the coherent data page tables.
163 */
Chris Kay33bfc5e2023-02-14 11:30:04 +0000164 .coherent_ram (NOLOAD) : ALIGN(PAGE_SIZE) {
Roberto Vargase0e99462017-10-30 14:43:43 +0000165 __COHERENT_RAM_START__ = .;
Chris Kay4b7660a2022-09-29 14:36:53 +0100166
Chris Kay33bfc5e2023-02-14 11:30:04 +0000167 *(.tzfw_coherent_mem)
Chris Kay4b7660a2022-09-29 14:36:53 +0100168
Roberto Vargase0e99462017-10-30 14:43:43 +0000169 __COHERENT_RAM_END_UNALIGNED__ = .;
Chris Kay4b7660a2022-09-29 14:36:53 +0100170
Roberto Vargase0e99462017-10-30 14:43:43 +0000171 /*
Chris Kay4b7660a2022-09-29 14:36:53 +0100172 * Memory page(s) mapped to this section will be marked as device
173 * memory. No other unexpected data must creep in. Ensure the rest of
174 * the current memory page is unused.
Roberto Vargase0e99462017-10-30 14:43:43 +0000175 */
Roberto Vargasd93fde32018-04-11 11:53:31 +0100176 . = ALIGN(PAGE_SIZE);
Chris Kay4b7660a2022-09-29 14:36:53 +0100177
Roberto Vargase0e99462017-10-30 14:43:43 +0000178 __COHERENT_RAM_END__ = .;
179 } >RAM
Chris Kay4b7660a2022-09-29 14:36:53 +0100180#endif /* USE_COHERENT_MEM */
Roberto Vargase0e99462017-10-30 14:43:43 +0000181
Roberto Vargase0e99462017-10-30 14:43:43 +0000182 __RW_END__ = .;
183 __BL2_END__ = .;
184
Masahiro Yamada65d699d2020-01-17 13:45:02 +0900185 /DISCARD/ : {
186 *(.dynsym .dynstr .hash .gnu.hash)
187 }
188
Jiafei Pan43a7bf42018-03-21 07:20:09 +0000189#if BL2_IN_XIP_MEM
190 __BL2_RAM_START__ = ADDR(.data);
191 __BL2_RAM_END__ = .;
192
193 __DATA_ROM_START__ = LOADADDR(.data);
194 __DATA_SIZE__ = SIZEOF(.data);
195
196 /*
197 * The .data section is the last PROGBITS section so its end marks the end
Chris Kay4b7660a2022-09-29 14:36:53 +0100198 * of BL2's RO content in XIP memory.
Jiafei Pan43a7bf42018-03-21 07:20:09 +0000199 */
200 __BL2_ROM_END__ = __DATA_ROM_START__ + __DATA_SIZE__;
Chris Kay4b7660a2022-09-29 14:36:53 +0100201
Jiafei Pan43a7bf42018-03-21 07:20:09 +0000202 ASSERT(__BL2_ROM_END__ <= BL2_RO_LIMIT,
203 "BL2's RO content has exceeded its limit.")
Chris Kay4b7660a2022-09-29 14:36:53 +0100204#endif /* BL2_IN_XIP_MEM */
Roberto Vargase0e99462017-10-30 14:43:43 +0000205
Chris Kay4b7660a2022-09-29 14:36:53 +0100206 __BSS_SIZE__ = SIZEOF(.bss);
Jiafei Pan43a7bf42018-03-21 07:20:09 +0000207
Roberto Vargase0e99462017-10-30 14:43:43 +0000208#if USE_COHERENT_MEM
209 __COHERENT_RAM_UNALIGNED_SIZE__ =
210 __COHERENT_RAM_END_UNALIGNED__ - __COHERENT_RAM_START__;
Chris Kay4b7660a2022-09-29 14:36:53 +0100211#endif /* USE_COHERENT_MEM */
Roberto Vargase0e99462017-10-30 14:43:43 +0000212
Harrison Mutaib6f9a2b2023-04-19 10:08:56 +0100213 RAM_REGION_END = .;
Jiafei Pan43a7bf42018-03-21 07:20:09 +0000214#if BL2_IN_XIP_MEM
215 ASSERT(. <= BL2_RW_LIMIT, "BL2's RW content has exceeded its limit.")
Chris Kay4b7660a2022-09-29 14:36:53 +0100216#else /* BL2_IN_XIP_MEM */
Roberto Vargase0e99462017-10-30 14:43:43 +0000217 ASSERT(. <= BL2_LIMIT, "BL2 image has exceeded its limit.")
Chris Kay4b7660a2022-09-29 14:36:53 +0100218#endif /* BL2_IN_XIP_MEM */
Roberto Vargase0e99462017-10-30 14:43:43 +0000219}