bl31.ld.S 6.12 KB
Newer Older
1
/*
2
 * Copyright (c) 2013-2020, ARM Limited and Contributors. All rights reserved.
3
 *
dp-arm's avatar
dp-arm committed
4
 * SPDX-License-Identifier: BSD-3-Clause
5
6
 */

7
#include <common/bl_common.ld.h>
8
#include <lib/xlat_tables/xlat_tables_defs.h>
9
10
11

OUTPUT_FORMAT(PLATFORM_LINKER_FORMAT)
OUTPUT_ARCH(PLATFORM_LINKER_ARCH)
12
ENTRY(bl31_entrypoint)
13
14
15


MEMORY {
16
    RAM (rwx): ORIGIN = BL31_BASE, LENGTH = BL31_LIMIT - BL31_BASE
17
18
19
20
21
#if SEPARATE_NOBITS_REGION
    NOBITS (rw!a): ORIGIN = BL31_NOBITS_BASE, LENGTH = BL31_NOBITS_LIMIT - BL31_NOBITS_BASE
#else
#define NOBITS RAM
#endif
22
23
}

24
25
26
#ifdef PLAT_EXTRA_LD_SCRIPT
#include <plat.ld.S>
#endif
27
28
29

SECTIONS
{
30
    . = BL31_BASE;
31
    ASSERT(. == ALIGN(PAGE_SIZE),
32
           "BL31_BASE address is not aligned on a page boundary.")
33

34
35
    __BL31_START__ = .;

36
37
38
39
#if SEPARATE_CODE_AND_RODATA
    .text . : {
        __TEXT_START__ = .;
        *bl31_entrypoint.o(.text*)
40
        *(SORT_BY_ALIGNMENT(.text*))
41
        *(.vectors)
42
        . = ALIGN(PAGE_SIZE);
43
44
45
46
47
        __TEXT_END__ = .;
    } >RAM

    .rodata . : {
        __RODATA_START__ = .;
48
        *(SORT_BY_ALIGNMENT(.rodata*))
49

50
	RODATA_COMMON
51

52
53
        /* Place pubsub sections for events */
        . = ALIGN(8);
54
#include <lib/el3_runtime/pubsub_events.h>
55

56
        . = ALIGN(PAGE_SIZE);
57
58
59
        __RODATA_END__ = .;
    } >RAM
#else
60
61
    ro . : {
        __RO_START__ = .;
Andrew Thoelke's avatar
Andrew Thoelke committed
62
        *bl31_entrypoint.o(.text*)
63
64
        *(SORT_BY_ALIGNMENT(.text*))
        *(SORT_BY_ALIGNMENT(.rodata*))
Achin Gupta's avatar
Achin Gupta committed
65

66
	RODATA_COMMON
67

68
69
        /* Place pubsub sections for events */
        . = ALIGN(8);
70
#include <lib/el3_runtime/pubsub_events.h>
71

Achin Gupta's avatar
Achin Gupta committed
72
        *(.vectors)
73
74
75
76
77
78
        __RO_END_UNALIGNED__ = .;
        /*
         * Memory page(s) mapped to this section will be marked as read-only,
         * executable.  No RW data from the next section must creep in.
         * Ensure the rest of the current memory page is unused.
         */
79
        . = ALIGN(PAGE_SIZE);
80
        __RO_END__ = .;
81
    } >RAM
82
#endif
83

84
85
86
    ASSERT(__CPU_OPS_END__ > __CPU_OPS_START__,
           "cpu_ops not defined for this platform.")

87
#if SPM_MM
88
89
90
91
#ifndef SPM_SHIM_EXCEPTIONS_VMA
#define SPM_SHIM_EXCEPTIONS_VMA         RAM
#endif

92
93
94
95
96
97
98
99
    /*
     * Exception vectors of the SPM shim layer. They must be aligned to a 2K
     * address, but we need to place them in a separate page so that we can set
     * individual permissions to them, so the actual alignment needed is 4K.
     *
     * There's no need to include this into the RO section of BL31 because it
     * doesn't need to be accessed by BL31.
     */
100
    spm_shim_exceptions : ALIGN(PAGE_SIZE) {
101
102
        __SPM_SHIM_EXCEPTIONS_START__ = .;
        *(.spm_shim_exceptions)
103
        . = ALIGN(PAGE_SIZE);
104
        __SPM_SHIM_EXCEPTIONS_END__ = .;
105
106
107
108
    } >SPM_SHIM_EXCEPTIONS_VMA AT>RAM

    PROVIDE(__SPM_SHIM_EXCEPTIONS_LMA__ = LOADADDR(spm_shim_exceptions));
    . = LOADADDR(spm_shim_exceptions) + SIZEOF(spm_shim_exceptions);
109
110
#endif

111
112
113
114
115
116
    /*
     * Define a linker symbol to mark start of the RW memory area for this
     * image.
     */
    __RW_START__ = . ;

117
118
119
120
121
122
    /*
     * .data must be placed at a lower address than the stacks if the stack
     * protector is enabled. Alternatively, the .data.stack_protector_canary
     * section can be placed independently of the main .data section.
     */
   .data . : {
123
        __DATA_START__ = .;
124
        *(SORT_BY_ALIGNMENT(.data*))
125
        __DATA_END__ = .;
126
127
    } >RAM

128
129
    /*
     * .rela.dyn needs to come after .data for the read-elf utility to parse
130
131
     * this section correctly. Ensure 8-byte alignment so that the fields of
     * RELA data structure are aligned.
132
     */
133
    . = ALIGN(8);
134
135
136
137
138
    __RELA_START__ = .;
    .rela.dyn . : {
    } >RAM
    __RELA_END__ = .;

139
#ifdef BL31_PROGBITS_LIMIT
140
    ASSERT(. <= BL31_PROGBITS_LIMIT, "BL31 progbits has exceeded its limit.")
141
142
#endif

143
144
145
146
147
#if SEPARATE_NOBITS_REGION
    /*
     * Define a linker symbol to mark end of the RW memory area for this
     * image.
     */
148
    . = ALIGN(PAGE_SIZE);
149
150
151
152
153
154
155
156
157
158
159
160
    __RW_END__ = .;
    __BL31_END__ = .;

    ASSERT(. <= BL31_LIMIT, "BL31 image has exceeded its limit.")

    . = BL31_NOBITS_BASE;
    ASSERT(. == ALIGN(PAGE_SIZE),
           "BL31 NOBITS base address is not aligned on a page boundary.")

    __NOBITS_START__ = .;
#endif

161
162
163
164
    stacks (NOLOAD) : {
        __STACKS_START__ = .;
        *(tzfw_normal_stacks)
        __STACKS_END__ = .;
165
    } >NOBITS
166

167
168
    /*
     * The .bss section gets initialised to 0 at runtime.
169
170
     * Its base address should be 16-byte aligned for better performance of the
     * zero-initialization code.
171
     */
172
    .bss (NOLOAD) : ALIGN(16) {
173
        __BSS_START__ = .;
174
        *(SORT_BY_ALIGNMENT(.bss*))
175
        *(COMMON)
176
177
	BAKERY_LOCK_NORMAL
	PMF_TIMESTAMP
178
        __BSS_END__ = .;
179
    } >NOBITS
180

181
    XLAT_TABLE_SECTION >NOBITS
182

183
#if USE_COHERENT_MEM
184
185
186
187
188
189
    /*
     * The base address of the coherent memory section must be page-aligned (4K)
     * to guarantee that the coherent data are stored on their own pages and
     * are not mixed with normal data.  This is required to set up the correct
     * memory attributes for the coherent data page tables.
     */
190
    coherent_ram (NOLOAD) : ALIGN(PAGE_SIZE) {
191
        __COHERENT_RAM_START__ = .;
192
193
194
195
196
197
        /*
         * Bakery locks are stored in coherent memory
         *
         * Each lock's data is contiguous and fully allocated by the compiler
         */
        *(bakery_lock)
198
199
200
201
202
203
204
        *(tzfw_coherent_mem)
        __COHERENT_RAM_END_UNALIGNED__ = .;
        /*
         * Memory page(s) mapped to this section will be marked
         * as device memory.  No other unexpected data must creep in.
         * Ensure the rest of the current memory page is unused.
         */
205
        . = ALIGN(PAGE_SIZE);
206
        __COHERENT_RAM_END__ = .;
207
    } >NOBITS
208
#endif
209

210
211
212
213
214
215
216
217
218
#if SEPARATE_NOBITS_REGION
    /*
     * Define a linker symbol to mark end of the NOBITS memory area for this
     * image.
     */
    __NOBITS_END__ = .;

    ASSERT(. <= BL31_NOBITS_LIMIT, "BL31 NOBITS region has exceeded its limit.")
#else
219
220
221
222
223
    /*
     * Define a linker symbol to mark end of the RW memory area for this
     * image.
     */
    __RW_END__ = .;
224
    __BL31_END__ = .;
225

226
227
228
229
    /DISCARD/ : {
        *(.dynsym .dynstr .hash .gnu.hash)
    }

230
    ASSERT(. <= BL31_LIMIT, "BL31 image has exceeded its limit.")
231
#endif
232
}