blob: 0fd38664ce211c7941fd04b33f6a6a31893e0c72 [file] [log] [blame]
developer550bf5e2016-07-11 16:05:23 +08001/*
Masahiro Yamada0b67e562020-03-09 17:39:48 +09002 * Copyright (c) 2016-2020, ARM Limited and Contributors. All rights reserved.
developer550bf5e2016-07-11 16:05:23 +08003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
developer550bf5e2016-07-11 16:05:23 +08005 */
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>
developer550bf5e2016-07-11 16:05:23 +08009#include <platform_def.h>
10
11OUTPUT_FORMAT(PLATFORM_LINKER_FORMAT)
12OUTPUT_ARCH(PLATFORM_LINKER_ARCH)
13ENTRY(bl31_entrypoint)
14
15
16MEMORY {
17 RAM (rwx): ORIGIN = BL31_BASE, LENGTH = BL31_TZRAM_SIZE
18 RAM2 (rwx): ORIGIN = TZRAM2_BASE, LENGTH = TZRAM2_SIZE
19}
20
21
22SECTIONS
23{
24 . = BL31_BASE;
25
26 ASSERT(. == ALIGN(2048),
27 "vector base is not aligned on a 2K boundary.")
28
29 __RO_START__ = .;
30 vector . : {
31 *(.vectors)
32 } >RAM
33
Antonio Nino Diaz2ce2b092017-11-15 11:45:35 +000034 ASSERT(. == ALIGN(PAGE_SIZE),
developer550bf5e2016-07-11 16:05:23 +080035 "BL31_BASE address is not aligned on a page boundary.")
36
37 ro . : {
38 *bl31_entrypoint.o(.text*)
39 *(.text*)
40 *(.rodata*)
41
42 /* Ensure 8-byte alignment for descriptors and ensure inclusion */
43 . = ALIGN(8);
44 __RT_SVC_DESCS_START__ = .;
45 KEEP(*(rt_svc_descs))
46 __RT_SVC_DESCS_END__ = .;
47
48 /*
49 * Ensure 8-byte alignment for cpu_ops so that its fields are also
50 * aligned. Also ensure cpu_ops inclusion.
51 */
52 . = ALIGN(8);
53 __CPU_OPS_START__ = .;
54 KEEP(*(cpu_ops))
55 __CPU_OPS_END__ = .;
56
57 __RO_END_UNALIGNED__ = .;
58 /*
59 * Memory page(s) mapped to this section will be marked as read-only,
60 * executable. No RW data from the next section must creep in.
61 * Ensure the rest of the current memory page is unused.
62 */
Roberto Vargasd93fde32018-04-11 11:53:31 +010063 . = ALIGN(PAGE_SIZE);
developer550bf5e2016-07-11 16:05:23 +080064 __RO_END__ = .;
65 } >RAM
66
67 ASSERT(__CPU_OPS_END__ > __CPU_OPS_START__,
68 "cpu_ops not defined for this platform.")
69
70 /*
71 * Define a linker symbol to mark start of the RW memory area for this
72 * image.
73 */
74 __RW_START__ = . ;
75
Douglas Raillard306593d2017-02-24 18:14:15 +000076 /*
77 * .data must be placed at a lower address than the stacks if the stack
78 * protector is enabled. Alternatively, the .data.stack_protector_canary
79 * section can be placed independently of the main .data section.
80 */
developer550bf5e2016-07-11 16:05:23 +080081 .data . : {
82 __DATA_START__ = .;
83 *(.data*)
84 __DATA_END__ = .;
85 } >RAM
86
87#ifdef BL31_PROGBITS_LIMIT
88 ASSERT(. <= BL31_PROGBITS_LIMIT, "BL3-1 progbits has exceeded its limit.")
89#endif
90
91 stacks (NOLOAD) : {
92 __STACKS_START__ = .;
93 *(tzfw_normal_stacks)
94 __STACKS_END__ = .;
95 } >RAM
96
97 /*
98 * The .bss section gets initialised to 0 at runtime.
Douglas Raillard21362a92016-12-02 13:51:54 +000099 * Its base address should be 16-byte aligned for better performance of the
100 * zero-initialization code.
developer550bf5e2016-07-11 16:05:23 +0800101 */
102 .bss (NOLOAD) : ALIGN(16) {
103 __BSS_START__ = .;
104 *(.bss*)
105 *(COMMON)
106#if !USE_COHERENT_MEM
107 /*
108 * Bakery locks are stored in normal .bss memory
109 *
110 * Each lock's data is spread across multiple cache lines, one per CPU,
111 * but multiple locks can share the same cache line.
112 * The compiler will allocate enough memory for one CPU's bakery locks,
113 * the remaining cache lines are allocated by the linker script
114 */
115 . = ALIGN(CACHE_WRITEBACK_GRANULE);
116 __BAKERY_LOCK_START__ = .;
Varun Wadekar77c382c2019-01-30 08:26:20 -0800117 __PERCPU_BAKERY_LOCK_START__ = .;
developer550bf5e2016-07-11 16:05:23 +0800118 *(bakery_lock)
119 . = ALIGN(CACHE_WRITEBACK_GRANULE);
Varun Wadekar77c382c2019-01-30 08:26:20 -0800120 __PERCPU_BAKERY_LOCK_END__ = .;
121 __PERCPU_BAKERY_LOCK_SIZE__ = ABSOLUTE(__PERCPU_BAKERY_LOCK_END__ - __PERCPU_BAKERY_LOCK_START__);
developer550bf5e2016-07-11 16:05:23 +0800122 . = . + (__PERCPU_BAKERY_LOCK_SIZE__ * (PLATFORM_CORE_COUNT - 1));
123 __BAKERY_LOCK_END__ = .;
124#ifdef PLAT_PERCPU_BAKERY_LOCK_SIZE
125 ASSERT(__PERCPU_BAKERY_LOCK_SIZE__ == PLAT_PERCPU_BAKERY_LOCK_SIZE,
126 "PLAT_PERCPU_BAKERY_LOCK_SIZE does not match bakery lock requirements");
127#endif
128#endif
129 __BSS_END__ = .;
130 __RW_END__ = .;
131 } >RAM
132
133 ASSERT(. <= BL31_LIMIT, "BL3-1 image has exceeded its limit.")
134
Masahiro Yamada0b67e562020-03-09 17:39:48 +0900135 XLAT_TABLE_SECTION >RAM2
developer550bf5e2016-07-11 16:05:23 +0800136
137#if USE_COHERENT_MEM
138 /*
139 * The base address of the coherent memory section must be page-aligned (4K)
140 * to guarantee that the coherent data are stored on their own pages and
141 * are not mixed with normal data. This is required to set up the correct
142 * memory attributes for the coherent data page tables.
143 */
Antonio Nino Diaz2ce2b092017-11-15 11:45:35 +0000144 coherent_ram (NOLOAD) : ALIGN(PAGE_SIZE) {
developer550bf5e2016-07-11 16:05:23 +0800145 __COHERENT_RAM_START__ = .;
146 /*
147 * Bakery locks are stored in coherent memory
148 *
149 * Each lock's data is contiguous and fully allocated by the compiler
150 */
151 *(bakery_lock)
152 *(tzfw_coherent_mem)
153 __COHERENT_RAM_END_UNALIGNED__ = .;
154 /*
155 * Memory page(s) mapped to this section will be marked
156 * as device memory. No other unexpected data must creep in.
157 * Ensure the rest of the current memory page is unused.
158 */
Roberto Vargasd93fde32018-04-11 11:53:31 +0100159 . = ALIGN(PAGE_SIZE);
developer550bf5e2016-07-11 16:05:23 +0800160 __COHERENT_RAM_END__ = .;
161 } >RAM2
162#endif
163
164 /*
165 * Define a linker symbol to mark end of the RW memory area for this
166 * image.
167 */
168 __BL31_END__ = .;
169
170 __BSS_SIZE__ = SIZEOF(.bss);
171#if USE_COHERENT_MEM
172 __COHERENT_RAM_UNALIGNED_SIZE__ =
173 __COHERENT_RAM_END_UNALIGNED__ - __COHERENT_RAM_START__;
174#endif
175
176 ASSERT(. <= TZRAM2_LIMIT, "TZRAM2 image has exceeded its limit.")
177}