bl2_el3.ld.S 4.94 KB
Newer Older
Roberto Vargas's avatar
Roberto Vargas committed
1
/*
2
 * Copyright (c) 2017-2020, ARM Limited and Contributors. All rights reserved.
Roberto Vargas's avatar
Roberto Vargas committed
3
4
5
6
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

7
#include <common/bl_common.ld.h>
8
#include <lib/xlat_tables/xlat_tables_defs.h>
Roberto Vargas's avatar
Roberto Vargas committed
9
10
11
12
13
14

OUTPUT_FORMAT(PLATFORM_LINKER_FORMAT)
OUTPUT_ARCH(PLATFORM_LINKER_ARCH)
ENTRY(bl2_entrypoint)

MEMORY {
Jiafei Pan's avatar
Jiafei Pan committed
15
16
17
18
#if BL2_IN_XIP_MEM
    ROM (rx): ORIGIN = BL2_RO_BASE, LENGTH = BL2_RO_LIMIT - BL2_RO_BASE
    RAM (rwx): ORIGIN = BL2_RW_BASE, LENGTH = BL2_RW_LIMIT - BL2_RW_BASE
#else
Roberto Vargas's avatar
Roberto Vargas committed
19
    RAM (rwx): ORIGIN = BL2_BASE, LENGTH = BL2_LIMIT - BL2_BASE
Jiafei Pan's avatar
Jiafei Pan committed
20
#endif
Roberto Vargas's avatar
Roberto Vargas committed
21
22
}

23
24
25
#if !BL2_IN_XIP_MEM
#define ROM RAM
#endif
Roberto Vargas's avatar
Roberto Vargas committed
26
27
28

SECTIONS
{
Jiafei Pan's avatar
Jiafei Pan committed
29
30
31
32
33
#if BL2_IN_XIP_MEM
    . = BL2_RO_BASE;
    ASSERT(. == ALIGN(PAGE_SIZE),
           "BL2_RO_BASE address is not aligned on a page boundary.")
#else
Roberto Vargas's avatar
Roberto Vargas committed
34
35
36
    . = BL2_BASE;
    ASSERT(. == ALIGN(PAGE_SIZE),
           "BL2_BASE address is not aligned on a page boundary.")
Jiafei Pan's avatar
Jiafei Pan committed
37
#endif
Roberto Vargas's avatar
Roberto Vargas committed
38
39
40
41

#if SEPARATE_CODE_AND_RODATA
    .text . : {
        __TEXT_START__ = .;
42
43
44
45
	__TEXT_RESIDENT_START__ = .;
	*bl2_el3_entrypoint.o(.text*)
	*(.text.asm.*)
	__TEXT_RESIDENT_END__ = .;
46
        *(SORT_BY_ALIGNMENT(.text*))
Roberto Vargas's avatar
Roberto Vargas committed
47
        *(.vectors)
48
        . = ALIGN(PAGE_SIZE);
Roberto Vargas's avatar
Roberto Vargas committed
49
        __TEXT_END__ = .;
Jiafei Pan's avatar
Jiafei Pan committed
50
     } >ROM
Roberto Vargas's avatar
Roberto Vargas committed
51
52
53

    .rodata . : {
        __RODATA_START__ = .;
54
        *(SORT_BY_ALIGNMENT(.rodata*))
Roberto Vargas's avatar
Roberto Vargas committed
55

56
	RODATA_COMMON
Masahiro Yamada's avatar
Masahiro Yamada committed
57

58
        . = ALIGN(PAGE_SIZE);
Roberto Vargas's avatar
Roberto Vargas committed
59
        __RODATA_END__ = .;
Jiafei Pan's avatar
Jiafei Pan committed
60
    } >ROM
61
62
63

    ASSERT(__TEXT_RESIDENT_END__ - __TEXT_RESIDENT_START__ <= PAGE_SIZE,
          "Resident part of BL2 has exceeded its limit.")
Roberto Vargas's avatar
Roberto Vargas committed
64
65
66
#else
    ro . : {
        __RO_START__ = .;
67
68
69
70
	__TEXT_RESIDENT_START__ = .;
	*bl2_el3_entrypoint.o(.text*)
	*(.text.asm.*)
	__TEXT_RESIDENT_END__ = .;
71
72
        *(SORT_BY_ALIGNMENT(.text*))
        *(SORT_BY_ALIGNMENT(.rodata*))
Roberto Vargas's avatar
Roberto Vargas committed
73

74
	RODATA_COMMON
Masahiro Yamada's avatar
Masahiro Yamada committed
75

Roberto Vargas's avatar
Roberto Vargas committed
76
77
78
79
80
81
82
        *(.vectors)
        __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.
         */
83
        . = ALIGN(PAGE_SIZE);
Roberto Vargas's avatar
Roberto Vargas committed
84
85

        __RO_END__ = .;
Jiafei Pan's avatar
Jiafei Pan committed
86
    } >ROM
Roberto Vargas's avatar
Roberto Vargas committed
87
88
89
90
91
#endif

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

Jiafei Pan's avatar
Jiafei Pan committed
92
93
94
95
96
97
#if BL2_IN_XIP_MEM
    . = BL2_RW_BASE;
    ASSERT(BL2_RW_BASE == ALIGN(PAGE_SIZE),
           "BL2_RW_BASE address is not aligned on a page boundary.")
#endif

Roberto Vargas's avatar
Roberto Vargas committed
98
99
100
101
102
103
104
105
106
107
108
109
    /*
     * Define a linker symbol to mark start of the RW memory area for this
     * image.
     */
    __RW_START__ = . ;

    /*
     * .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 . : {
Jiafei Pan's avatar
Jiafei Pan committed
110
        __DATA_RAM_START__ = .;
111
        *(SORT_BY_ALIGNMENT(.data*))
Jiafei Pan's avatar
Jiafei Pan committed
112
113
        __DATA_RAM_END__ = .;
    } >RAM AT>ROM
Roberto Vargas's avatar
Roberto Vargas committed
114

Masahiro Yamada's avatar
Masahiro Yamada committed
115
116
117
118
119
120
121
122
123
124
125
    /*
     * .rela.dyn needs to come after .data for the read-elf utility to parse
     * this section correctly. Ensure 8-byte alignment so that the fields of
     * RELA data structure are aligned.
     */
    . = ALIGN(8);
    __RELA_START__ = .;
    .rela.dyn . : {
    } >RAM
    __RELA_END__ = .;

126
    STACK_SECTION >RAM
127
    BSS_SECTION >RAM
128
    XLAT_TABLE_SECTION >RAM
Roberto Vargas's avatar
Roberto Vargas committed
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145

#if USE_COHERENT_MEM
    /*
     * 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.
     */
    coherent_ram (NOLOAD) : ALIGN(PAGE_SIZE) {
        __COHERENT_RAM_START__ = .;
        *(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.
         */
146
        . = ALIGN(PAGE_SIZE);
Roberto Vargas's avatar
Roberto Vargas committed
147
148
149
150
151
152
153
154
155
156
157
        __COHERENT_RAM_END__ = .;
    } >RAM
#endif

    /*
     * Define a linker symbol to mark end of the RW memory area for this
     * image.
     */
    __RW_END__ = .;
    __BL2_END__ = .;

Masahiro Yamada's avatar
Masahiro Yamada committed
158
159
160
161
    /DISCARD/ : {
        *(.dynsym .dynstr .hash .gnu.hash)
    }

Jiafei Pan's avatar
Jiafei Pan committed
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#if BL2_IN_XIP_MEM
    __BL2_RAM_START__ = ADDR(.data);
    __BL2_RAM_END__ = .;

    __DATA_ROM_START__ = LOADADDR(.data);
    __DATA_SIZE__ = SIZEOF(.data);

    /*
     * The .data section is the last PROGBITS section so its end marks the end
     * of BL2's RO content in XIP memory..
     */
    __BL2_ROM_END__ =  __DATA_ROM_START__ + __DATA_SIZE__;
    ASSERT(__BL2_ROM_END__ <= BL2_RO_LIMIT,
           "BL2's RO content has exceeded its limit.")
#endif
Roberto Vargas's avatar
Roberto Vargas committed
177
178
    __BSS_SIZE__ = SIZEOF(.bss);

Jiafei Pan's avatar
Jiafei Pan committed
179

Roberto Vargas's avatar
Roberto Vargas committed
180
181
182
183
184
#if USE_COHERENT_MEM
    __COHERENT_RAM_UNALIGNED_SIZE__ =
        __COHERENT_RAM_END_UNALIGNED__ - __COHERENT_RAM_START__;
#endif

Jiafei Pan's avatar
Jiafei Pan committed
185
186
187
#if BL2_IN_XIP_MEM
    ASSERT(. <= BL2_RW_LIMIT, "BL2's RW content has exceeded its limit.")
#else
Roberto Vargas's avatar
Roberto Vargas committed
188
    ASSERT(. <= BL2_LIMIT, "BL2 image has exceeded its limit.")
Jiafei Pan's avatar
Jiafei Pan committed
189
#endif
Roberto Vargas's avatar
Roberto Vargas committed
190
}