blob: aa457faf4f4022aa854f3993160016c26b8d953e [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 {
Jiafei Pan43a7bf42018-03-21 07:20:09 +000034#if BL2_IN_XIP_MEM
35 . = BL2_RO_BASE;
Chris Kay4b7660a2022-09-29 14:36:53 +010036
Jiafei Pan43a7bf42018-03-21 07:20:09 +000037 ASSERT(. == ALIGN(PAGE_SIZE),
Chris Kay4b7660a2022-09-29 14:36:53 +010038 "BL2_RO_BASE address is not aligned on a page boundary.")
39#else /* BL2_IN_XIP_MEM */
Roberto Vargase0e99462017-10-30 14:43:43 +000040 . = BL2_BASE;
Chris Kay4b7660a2022-09-29 14:36:53 +010041
Roberto Vargase0e99462017-10-30 14:43:43 +000042 ASSERT(. == ALIGN(PAGE_SIZE),
Chris Kay4b7660a2022-09-29 14:36:53 +010043 "BL2_BASE address is not aligned on a page boundary.")
44#endif /* BL2_IN_XIP_MEM */
Roberto Vargase0e99462017-10-30 14:43:43 +000045
46#if SEPARATE_CODE_AND_RODATA
47 .text . : {
48 __TEXT_START__ = .;
Chris Kay4b7660a2022-09-29 14:36:53 +010049 __TEXT_RESIDENT_START__ = .;
50
51 *bl2_el3_entrypoint.o(.text*)
52 *(.text.asm.*)
53
54 __TEXT_RESIDENT_END__ = .;
55
Samuel Holland23f5e542019-10-20 16:11:25 -050056 *(SORT_BY_ALIGNMENT(.text*))
Roberto Vargase0e99462017-10-30 14:43:43 +000057 *(.vectors)
Chris Kay4b7660a2022-09-29 14:36:53 +010058
Roberto Vargasd93fde32018-04-11 11:53:31 +010059 . = ALIGN(PAGE_SIZE);
Chris Kay4b7660a2022-09-29 14:36:53 +010060
Roberto Vargase0e99462017-10-30 14:43:43 +000061 __TEXT_END__ = .;
Chris Kay4b7660a2022-09-29 14:36:53 +010062 } >ROM
Roberto Vargase0e99462017-10-30 14:43:43 +000063
64 .rodata . : {
65 __RODATA_START__ = .;
Chris Kay4b7660a2022-09-29 14:36:53 +010066
Samuel Holland23f5e542019-10-20 16:11:25 -050067 *(SORT_BY_ALIGNMENT(.rodata*))
Roberto Vargase0e99462017-10-30 14:43:43 +000068
Chris Kay4b7660a2022-09-29 14:36:53 +010069 RODATA_COMMON
Masahiro Yamada65d699d2020-01-17 13:45:02 +090070
Roberto Vargasd93fde32018-04-11 11:53:31 +010071 . = ALIGN(PAGE_SIZE);
Chris Kay4b7660a2022-09-29 14:36:53 +010072
Roberto Vargase0e99462017-10-30 14:43:43 +000073 __RODATA_END__ = .;
Jiafei Pan43a7bf42018-03-21 07:20:09 +000074 } >ROM
Roberto Vargas51abc342017-11-17 10:51:54 +000075
76 ASSERT(__TEXT_RESIDENT_END__ - __TEXT_RESIDENT_START__ <= PAGE_SIZE,
Chris Kay4b7660a2022-09-29 14:36:53 +010077 "Resident part of BL2 has exceeded its limit.")
78#else /* SEPARATE_CODE_AND_RODATA */
Chris Kay33bfc5e2023-02-14 11:30:04 +000079 .ro . : {
Roberto Vargase0e99462017-10-30 14:43:43 +000080 __RO_START__ = .;
Chris Kay4b7660a2022-09-29 14:36:53 +010081 __TEXT_RESIDENT_START__ = .;
82
83 *bl2_el3_entrypoint.o(.text*)
84 *(.text.asm.*)
85
86 __TEXT_RESIDENT_END__ = .;
87
Samuel Holland23f5e542019-10-20 16:11:25 -050088 *(SORT_BY_ALIGNMENT(.text*))
89 *(SORT_BY_ALIGNMENT(.rodata*))
Roberto Vargase0e99462017-10-30 14:43:43 +000090
Chris Kay4b7660a2022-09-29 14:36:53 +010091 RODATA_COMMON
Masahiro Yamada65d699d2020-01-17 13:45:02 +090092
Roberto Vargase0e99462017-10-30 14:43:43 +000093 *(.vectors)
Chris Kay4b7660a2022-09-29 14:36:53 +010094
Roberto Vargase0e99462017-10-30 14:43:43 +000095 __RO_END_UNALIGNED__ = .;
Chris Kay4b7660a2022-09-29 14:36:53 +010096
Roberto Vargase0e99462017-10-30 14:43:43 +000097 /*
Chris Kay4b7660a2022-09-29 14:36:53 +010098 * Memory page(s) mapped to this section will be marked as read-only,
99 * executable. No RW data from the next section must creep in. Ensure
100 * that the rest of the current memory page is unused.
Roberto Vargase0e99462017-10-30 14:43:43 +0000101 */
Roberto Vargasd93fde32018-04-11 11:53:31 +0100102 . = ALIGN(PAGE_SIZE);
Roberto Vargase0e99462017-10-30 14:43:43 +0000103
104 __RO_END__ = .;
Jiafei Pan43a7bf42018-03-21 07:20:09 +0000105 } >ROM
Chris Kay4b7660a2022-09-29 14:36:53 +0100106#endif /* SEPARATE_CODE_AND_RODATA */
Roberto Vargase0e99462017-10-30 14:43:43 +0000107
108 ASSERT(__CPU_OPS_END__ > __CPU_OPS_START__,
Chris Kay4b7660a2022-09-29 14:36:53 +0100109 "cpu_ops not defined for this platform.")
Roberto Vargase0e99462017-10-30 14:43:43 +0000110
Jiafei Pan43a7bf42018-03-21 07:20:09 +0000111#if BL2_IN_XIP_MEM
112 . = BL2_RW_BASE;
Chris Kay4b7660a2022-09-29 14:36:53 +0100113
Jiafei Pan43a7bf42018-03-21 07:20:09 +0000114 ASSERT(BL2_RW_BASE == ALIGN(PAGE_SIZE),
115 "BL2_RW_BASE address is not aligned on a page boundary.")
Chris Kay4b7660a2022-09-29 14:36:53 +0100116#endif /* BL2_IN_XIP_MEM */
Jiafei Pan43a7bf42018-03-21 07:20:09 +0000117
Chris Kay4b7660a2022-09-29 14:36:53 +0100118 __RW_START__ = .;
Roberto Vargase0e99462017-10-30 14:43:43 +0000119
Masahiro Yamadac5864d82020-04-22 10:50:12 +0900120 DATA_SECTION >RAM AT>ROM
Chris Kay4b7660a2022-09-29 14:36:53 +0100121
Masahiro Yamadac5864d82020-04-22 10:50:12 +0900122 __DATA_RAM_START__ = __DATA_START__;
123 __DATA_RAM_END__ = __DATA_END__;
Roberto Vargase0e99462017-10-30 14:43:43 +0000124
Masahiro Yamada85fa00e2020-04-22 11:27:55 +0900125 RELA_SECTION >RAM
Chris Kay4b7660a2022-09-29 14:36:53 +0100126
Jiafei Pan0824b452022-02-24 10:47:33 +0800127#if SEPARATE_BL2_NOLOAD_REGION
128 SAVED_ADDR = .;
Chris Kay4b7660a2022-09-29 14:36:53 +0100129
Jiafei Pan0824b452022-02-24 10:47:33 +0800130 . = BL2_NOLOAD_START;
Chris Kay4b7660a2022-09-29 14:36:53 +0100131
Jiafei Pan0824b452022-02-24 10:47:33 +0800132 __BL2_NOLOAD_START__ = .;
Chris Kay4b7660a2022-09-29 14:36:53 +0100133#endif /* SEPARATE_BL2_NOLOAD_REGION */
134
Jiafei Pan0824b452022-02-24 10:47:33 +0800135 STACK_SECTION >RAM_NOLOAD
136 BSS_SECTION >RAM_NOLOAD
137 XLAT_TABLE_SECTION >RAM_NOLOAD
Chris Kay4b7660a2022-09-29 14:36:53 +0100138
Jiafei Pan0824b452022-02-24 10:47:33 +0800139#if SEPARATE_BL2_NOLOAD_REGION
140 __BL2_NOLOAD_END__ = .;
Chris Kay4b7660a2022-09-29 14:36:53 +0100141
Jiafei Pan0824b452022-02-24 10:47:33 +0800142 . = SAVED_ADDR;
Chris Kay4b7660a2022-09-29 14:36:53 +0100143#endif /* SEPARATE_BL2_NOLOAD_REGION */
Roberto Vargase0e99462017-10-30 14:43:43 +0000144
145#if USE_COHERENT_MEM
146 /*
Chris Kay4b7660a2022-09-29 14:36:53 +0100147 * The base address of the coherent memory section must be page-aligned to
148 * guarantee that the coherent data are stored on their own pages and are
149 * not mixed with normal data. This is required to set up the correct
Roberto Vargase0e99462017-10-30 14:43:43 +0000150 * memory attributes for the coherent data page tables.
151 */
Chris Kay33bfc5e2023-02-14 11:30:04 +0000152 .coherent_ram (NOLOAD) : ALIGN(PAGE_SIZE) {
Roberto Vargase0e99462017-10-30 14:43:43 +0000153 __COHERENT_RAM_START__ = .;
Chris Kay4b7660a2022-09-29 14:36:53 +0100154
Chris Kay33bfc5e2023-02-14 11:30:04 +0000155 *(.tzfw_coherent_mem)
Chris Kay4b7660a2022-09-29 14:36:53 +0100156
Roberto Vargase0e99462017-10-30 14:43:43 +0000157 __COHERENT_RAM_END_UNALIGNED__ = .;
Chris Kay4b7660a2022-09-29 14:36:53 +0100158
Roberto Vargase0e99462017-10-30 14:43:43 +0000159 /*
Chris Kay4b7660a2022-09-29 14:36:53 +0100160 * Memory page(s) mapped to this section will be marked as device
161 * memory. No other unexpected data must creep in. Ensure the rest of
162 * the current memory page is unused.
Roberto Vargase0e99462017-10-30 14:43:43 +0000163 */
Roberto Vargasd93fde32018-04-11 11:53:31 +0100164 . = ALIGN(PAGE_SIZE);
Chris Kay4b7660a2022-09-29 14:36:53 +0100165
Roberto Vargase0e99462017-10-30 14:43:43 +0000166 __COHERENT_RAM_END__ = .;
167 } >RAM
Chris Kay4b7660a2022-09-29 14:36:53 +0100168#endif /* USE_COHERENT_MEM */
Roberto Vargase0e99462017-10-30 14:43:43 +0000169
Roberto Vargase0e99462017-10-30 14:43:43 +0000170 __RW_END__ = .;
171 __BL2_END__ = .;
172
Masahiro Yamada65d699d2020-01-17 13:45:02 +0900173 /DISCARD/ : {
174 *(.dynsym .dynstr .hash .gnu.hash)
175 }
176
Jiafei Pan43a7bf42018-03-21 07:20:09 +0000177#if BL2_IN_XIP_MEM
178 __BL2_RAM_START__ = ADDR(.data);
179 __BL2_RAM_END__ = .;
180
181 __DATA_ROM_START__ = LOADADDR(.data);
182 __DATA_SIZE__ = SIZEOF(.data);
183
184 /*
185 * The .data section is the last PROGBITS section so its end marks the end
Chris Kay4b7660a2022-09-29 14:36:53 +0100186 * of BL2's RO content in XIP memory.
Jiafei Pan43a7bf42018-03-21 07:20:09 +0000187 */
188 __BL2_ROM_END__ = __DATA_ROM_START__ + __DATA_SIZE__;
Chris Kay4b7660a2022-09-29 14:36:53 +0100189
Jiafei Pan43a7bf42018-03-21 07:20:09 +0000190 ASSERT(__BL2_ROM_END__ <= BL2_RO_LIMIT,
191 "BL2's RO content has exceeded its limit.")
Chris Kay4b7660a2022-09-29 14:36:53 +0100192#endif /* BL2_IN_XIP_MEM */
Roberto Vargase0e99462017-10-30 14:43:43 +0000193
Chris Kay4b7660a2022-09-29 14:36:53 +0100194 __BSS_SIZE__ = SIZEOF(.bss);
Jiafei Pan43a7bf42018-03-21 07:20:09 +0000195
Roberto Vargase0e99462017-10-30 14:43:43 +0000196#if USE_COHERENT_MEM
197 __COHERENT_RAM_UNALIGNED_SIZE__ =
198 __COHERENT_RAM_END_UNALIGNED__ - __COHERENT_RAM_START__;
Chris Kay4b7660a2022-09-29 14:36:53 +0100199#endif /* USE_COHERENT_MEM */
Roberto Vargase0e99462017-10-30 14:43:43 +0000200
Jiafei Pan43a7bf42018-03-21 07:20:09 +0000201#if BL2_IN_XIP_MEM
202 ASSERT(. <= BL2_RW_LIMIT, "BL2's RW content has exceeded its limit.")
Chris Kay4b7660a2022-09-29 14:36:53 +0100203#else /* BL2_IN_XIP_MEM */
Roberto Vargase0e99462017-10-30 14:43:43 +0000204 ASSERT(. <= BL2_LIMIT, "BL2 image has exceeded its limit.")
Chris Kay4b7660a2022-09-29 14:36:53 +0100205#endif /* BL2_IN_XIP_MEM */
Roberto Vargase0e99462017-10-30 14:43:43 +0000206}