xref: /rk3399_ARM-atf/bl2/bl2_el3.ld.S (revision 69af7fcf99bcce85ed218c97df0b76c377b3ed16)
1b1d27b48SRoberto Vargas/*
2ebd6efaeSSamuel Holland * Copyright (c) 2017-2019, ARM Limited and Contributors. All rights reserved.
3b1d27b48SRoberto Vargas *
4b1d27b48SRoberto Vargas * SPDX-License-Identifier: BSD-3-Clause
5b1d27b48SRoberto Vargas */
6b1d27b48SRoberto Vargas
7b1d27b48SRoberto Vargas#include <platform_def.h>
809d40e0eSAntonio Nino Diaz
909d40e0eSAntonio Nino Diaz#include <lib/xlat_tables/xlat_tables_defs.h>
10b1d27b48SRoberto Vargas
11b1d27b48SRoberto VargasOUTPUT_FORMAT(PLATFORM_LINKER_FORMAT)
12b1d27b48SRoberto VargasOUTPUT_ARCH(PLATFORM_LINKER_ARCH)
13b1d27b48SRoberto VargasENTRY(bl2_entrypoint)
14b1d27b48SRoberto Vargas
15b1d27b48SRoberto VargasMEMORY {
167d173fc5SJiafei Pan#if BL2_IN_XIP_MEM
177d173fc5SJiafei Pan    ROM (rx): ORIGIN = BL2_RO_BASE, LENGTH = BL2_RO_LIMIT - BL2_RO_BASE
187d173fc5SJiafei Pan    RAM (rwx): ORIGIN = BL2_RW_BASE, LENGTH = BL2_RW_LIMIT - BL2_RW_BASE
197d173fc5SJiafei Pan#else
20b1d27b48SRoberto Vargas    RAM (rwx): ORIGIN = BL2_BASE, LENGTH = BL2_LIMIT - BL2_BASE
217d173fc5SJiafei Pan#endif
22b1d27b48SRoberto Vargas}
23b1d27b48SRoberto Vargas
242f6f00dcSMasahiro Yamada#if !BL2_IN_XIP_MEM
252f6f00dcSMasahiro Yamada#define ROM RAM
262f6f00dcSMasahiro Yamada#endif
27b1d27b48SRoberto Vargas
28b1d27b48SRoberto VargasSECTIONS
29b1d27b48SRoberto Vargas{
307d173fc5SJiafei Pan#if BL2_IN_XIP_MEM
317d173fc5SJiafei Pan    . = BL2_RO_BASE;
327d173fc5SJiafei Pan    ASSERT(. == ALIGN(PAGE_SIZE),
337d173fc5SJiafei Pan           "BL2_RO_BASE address is not aligned on a page boundary.")
347d173fc5SJiafei Pan#else
35b1d27b48SRoberto Vargas    . = BL2_BASE;
36b1d27b48SRoberto Vargas    ASSERT(. == ALIGN(PAGE_SIZE),
37b1d27b48SRoberto Vargas           "BL2_BASE address is not aligned on a page boundary.")
387d173fc5SJiafei Pan#endif
39b1d27b48SRoberto Vargas
40b1d27b48SRoberto Vargas#if SEPARATE_CODE_AND_RODATA
41b1d27b48SRoberto Vargas    .text . : {
42b1d27b48SRoberto Vargas        __TEXT_START__ = .;
43487d3bf2SRoberto Vargas	__TEXT_RESIDENT_START__ = .;
44b1d27b48SRoberto Vargas	*bl2_el3_entrypoint.o(.text*)
45487d3bf2SRoberto Vargas	*(.text.asm.*)
46487d3bf2SRoberto Vargas	__TEXT_RESIDENT_END__ = .;
47ebd6efaeSSamuel Holland        *(SORT_BY_ALIGNMENT(.text*))
48b1d27b48SRoberto Vargas        *(.vectors)
495629b2b1SRoberto Vargas        . = ALIGN(PAGE_SIZE);
50b1d27b48SRoberto Vargas        __TEXT_END__ = .;
517d173fc5SJiafei Pan     } >ROM
52b1d27b48SRoberto Vargas
53b1d27b48SRoberto Vargas    .rodata . : {
54b1d27b48SRoberto Vargas        __RODATA_START__ = .;
55ebd6efaeSSamuel Holland        *(SORT_BY_ALIGNMENT(.rodata*))
56b1d27b48SRoberto Vargas
57b1d27b48SRoberto Vargas        /* Ensure 8-byte alignment for descriptors and ensure inclusion */
58b1d27b48SRoberto Vargas        . = ALIGN(8);
59b1d27b48SRoberto Vargas        __PARSER_LIB_DESCS_START__ = .;
60b1d27b48SRoberto Vargas        KEEP(*(.img_parser_lib_descs))
61b1d27b48SRoberto Vargas        __PARSER_LIB_DESCS_END__ = .;
62b1d27b48SRoberto Vargas
63b1d27b48SRoberto Vargas        /*
64b1d27b48SRoberto Vargas         * Ensure 8-byte alignment for cpu_ops so that its fields are also
65b1d27b48SRoberto Vargas         * aligned. Also ensure cpu_ops inclusion.
66b1d27b48SRoberto Vargas         */
67b1d27b48SRoberto Vargas        . = ALIGN(8);
68b1d27b48SRoberto Vargas        __CPU_OPS_START__ = .;
69b1d27b48SRoberto Vargas        KEEP(*(cpu_ops))
70b1d27b48SRoberto Vargas        __CPU_OPS_END__ = .;
71b1d27b48SRoberto Vargas
72*69af7fcfSMasahiro Yamada        /*
73*69af7fcfSMasahiro Yamada         * Keep the .got section in the RO section as it is patched
74*69af7fcfSMasahiro Yamada         * prior to enabling the MMU and having the .got in RO is better for
75*69af7fcfSMasahiro Yamada         * security. GOT is a table of addresses so ensure 8-byte alignment.
76*69af7fcfSMasahiro Yamada         */
77*69af7fcfSMasahiro Yamada        . = ALIGN(8);
78*69af7fcfSMasahiro Yamada        __GOT_START__ = .;
79*69af7fcfSMasahiro Yamada        *(.got)
80*69af7fcfSMasahiro Yamada        __GOT_END__ = .;
81*69af7fcfSMasahiro Yamada
825629b2b1SRoberto Vargas        . = ALIGN(PAGE_SIZE);
83b1d27b48SRoberto Vargas        __RODATA_END__ = .;
847d173fc5SJiafei Pan    } >ROM
85487d3bf2SRoberto Vargas
86487d3bf2SRoberto Vargas    ASSERT(__TEXT_RESIDENT_END__ - __TEXT_RESIDENT_START__ <= PAGE_SIZE,
87487d3bf2SRoberto Vargas          "Resident part of BL2 has exceeded its limit.")
88b1d27b48SRoberto Vargas#else
89b1d27b48SRoberto Vargas    ro . : {
90b1d27b48SRoberto Vargas        __RO_START__ = .;
91487d3bf2SRoberto Vargas	__TEXT_RESIDENT_START__ = .;
92b1d27b48SRoberto Vargas	*bl2_el3_entrypoint.o(.text*)
93487d3bf2SRoberto Vargas	*(.text.asm.*)
94487d3bf2SRoberto Vargas	__TEXT_RESIDENT_END__ = .;
95ebd6efaeSSamuel Holland        *(SORT_BY_ALIGNMENT(.text*))
96ebd6efaeSSamuel Holland        *(SORT_BY_ALIGNMENT(.rodata*))
97b1d27b48SRoberto Vargas
98b1d27b48SRoberto Vargas        /*
99b1d27b48SRoberto Vargas         * Ensure 8-byte alignment for cpu_ops so that its fields are also
100b1d27b48SRoberto Vargas         * aligned. Also ensure cpu_ops inclusion.
101b1d27b48SRoberto Vargas         */
102b1d27b48SRoberto Vargas        . = ALIGN(8);
103b1d27b48SRoberto Vargas        __CPU_OPS_START__ = .;
104b1d27b48SRoberto Vargas        KEEP(*(cpu_ops))
105b1d27b48SRoberto Vargas        __CPU_OPS_END__ = .;
106b1d27b48SRoberto Vargas
107b1d27b48SRoberto Vargas        /* Ensure 8-byte alignment for descriptors and ensure inclusion */
108b1d27b48SRoberto Vargas        . = ALIGN(8);
109b1d27b48SRoberto Vargas        __PARSER_LIB_DESCS_START__ = .;
110b1d27b48SRoberto Vargas        KEEP(*(.img_parser_lib_descs))
111b1d27b48SRoberto Vargas        __PARSER_LIB_DESCS_END__ = .;
112b1d27b48SRoberto Vargas
113*69af7fcfSMasahiro Yamada        /*
114*69af7fcfSMasahiro Yamada         * Keep the .got section in the RO section as it is patched
115*69af7fcfSMasahiro Yamada         * prior to enabling the MMU and having the .got in RO is better for
116*69af7fcfSMasahiro Yamada         * security. GOT is a table of addresses so ensure 8-byte alignment.
117*69af7fcfSMasahiro Yamada         */
118*69af7fcfSMasahiro Yamada        . = ALIGN(8);
119*69af7fcfSMasahiro Yamada        __GOT_START__ = .;
120*69af7fcfSMasahiro Yamada        *(.got)
121*69af7fcfSMasahiro Yamada        __GOT_END__ = .;
122*69af7fcfSMasahiro Yamada
123b1d27b48SRoberto Vargas        *(.vectors)
124b1d27b48SRoberto Vargas        __RO_END_UNALIGNED__ = .;
125b1d27b48SRoberto Vargas        /*
126b1d27b48SRoberto Vargas         * Memory page(s) mapped to this section will be marked as
127b1d27b48SRoberto Vargas         * read-only, executable.  No RW data from the next section must
128b1d27b48SRoberto Vargas         * creep in.  Ensure the rest of the current memory page is unused.
129b1d27b48SRoberto Vargas         */
1305629b2b1SRoberto Vargas        . = ALIGN(PAGE_SIZE);
131b1d27b48SRoberto Vargas
132b1d27b48SRoberto Vargas        __RO_END__ = .;
1337d173fc5SJiafei Pan    } >ROM
1347d173fc5SJiafei Pan#endif
135b1d27b48SRoberto Vargas
136b1d27b48SRoberto Vargas    ASSERT(__CPU_OPS_END__ > __CPU_OPS_START__,
137b1d27b48SRoberto Vargas          "cpu_ops not defined for this platform.")
138b1d27b48SRoberto Vargas
1397d173fc5SJiafei Pan#if BL2_IN_XIP_MEM
1407d173fc5SJiafei Pan    . = BL2_RW_BASE;
1417d173fc5SJiafei Pan    ASSERT(BL2_RW_BASE == ALIGN(PAGE_SIZE),
1427d173fc5SJiafei Pan           "BL2_RW_BASE address is not aligned on a page boundary.")
1437d173fc5SJiafei Pan#endif
1447d173fc5SJiafei Pan
145b1d27b48SRoberto Vargas    /*
146b1d27b48SRoberto Vargas     * Define a linker symbol to mark start of the RW memory area for this
147b1d27b48SRoberto Vargas     * image.
148b1d27b48SRoberto Vargas     */
149b1d27b48SRoberto Vargas    __RW_START__ = . ;
150b1d27b48SRoberto Vargas
151b1d27b48SRoberto Vargas    /*
152b1d27b48SRoberto Vargas     * .data must be placed at a lower address than the stacks if the stack
153b1d27b48SRoberto Vargas     * protector is enabled. Alternatively, the .data.stack_protector_canary
154b1d27b48SRoberto Vargas     * section can be placed independently of the main .data section.
155b1d27b48SRoberto Vargas     */
156b1d27b48SRoberto Vargas    .data . : {
1577d173fc5SJiafei Pan        __DATA_RAM_START__ = .;
158ebd6efaeSSamuel Holland        *(SORT_BY_ALIGNMENT(.data*))
1597d173fc5SJiafei Pan        __DATA_RAM_END__ = .;
1607d173fc5SJiafei Pan    } >RAM AT>ROM
161b1d27b48SRoberto Vargas
162*69af7fcfSMasahiro Yamada    /*
163*69af7fcfSMasahiro Yamada     * .rela.dyn needs to come after .data for the read-elf utility to parse
164*69af7fcfSMasahiro Yamada     * this section correctly. Ensure 8-byte alignment so that the fields of
165*69af7fcfSMasahiro Yamada     * RELA data structure are aligned.
166*69af7fcfSMasahiro Yamada     */
167*69af7fcfSMasahiro Yamada    . = ALIGN(8);
168*69af7fcfSMasahiro Yamada    __RELA_START__ = .;
169*69af7fcfSMasahiro Yamada    .rela.dyn . : {
170*69af7fcfSMasahiro Yamada    } >RAM
171*69af7fcfSMasahiro Yamada    __RELA_END__ = .;
172*69af7fcfSMasahiro Yamada
173b1d27b48SRoberto Vargas    stacks (NOLOAD) : {
174b1d27b48SRoberto Vargas        __STACKS_START__ = .;
175b1d27b48SRoberto Vargas        *(tzfw_normal_stacks)
176b1d27b48SRoberto Vargas        __STACKS_END__ = .;
177b1d27b48SRoberto Vargas    } >RAM
178b1d27b48SRoberto Vargas
179b1d27b48SRoberto Vargas    /*
180b1d27b48SRoberto Vargas     * The .bss section gets initialised to 0 at runtime.
181b1d27b48SRoberto Vargas     * Its base address should be 16-byte aligned for better performance of the
182b1d27b48SRoberto Vargas     * zero-initialization code.
183b1d27b48SRoberto Vargas     */
184b1d27b48SRoberto Vargas    .bss : ALIGN(16) {
185b1d27b48SRoberto Vargas        __BSS_START__ = .;
186b1d27b48SRoberto Vargas        *(SORT_BY_ALIGNMENT(.bss*))
187b1d27b48SRoberto Vargas        *(COMMON)
188b1d27b48SRoberto Vargas        __BSS_END__ = .;
189b1d27b48SRoberto Vargas    } >RAM
190b1d27b48SRoberto Vargas
191b1d27b48SRoberto Vargas    /*
192b1d27b48SRoberto Vargas     * The xlat_table section is for full, aligned page tables (4K).
193b1d27b48SRoberto Vargas     * Removing them from .bss avoids forcing 4K alignment on
194883d1b5dSAntonio Nino Diaz     * the .bss section. The tables are initialized to zero by the translation
195883d1b5dSAntonio Nino Diaz     * tables library.
196b1d27b48SRoberto Vargas     */
197b1d27b48SRoberto Vargas    xlat_table (NOLOAD) : {
198b1d27b48SRoberto Vargas        *(xlat_table)
199b1d27b48SRoberto Vargas    } >RAM
200b1d27b48SRoberto Vargas
201b1d27b48SRoberto Vargas#if USE_COHERENT_MEM
202b1d27b48SRoberto Vargas    /*
203b1d27b48SRoberto Vargas     * The base address of the coherent memory section must be page-aligned (4K)
204b1d27b48SRoberto Vargas     * to guarantee that the coherent data are stored on their own pages and
205b1d27b48SRoberto Vargas     * are not mixed with normal data.  This is required to set up the correct
206b1d27b48SRoberto Vargas     * memory attributes for the coherent data page tables.
207b1d27b48SRoberto Vargas     */
208b1d27b48SRoberto Vargas    coherent_ram (NOLOAD) : ALIGN(PAGE_SIZE) {
209b1d27b48SRoberto Vargas        __COHERENT_RAM_START__ = .;
210b1d27b48SRoberto Vargas        *(tzfw_coherent_mem)
211b1d27b48SRoberto Vargas        __COHERENT_RAM_END_UNALIGNED__ = .;
212b1d27b48SRoberto Vargas        /*
213b1d27b48SRoberto Vargas         * Memory page(s) mapped to this section will be marked
214b1d27b48SRoberto Vargas         * as device memory.  No other unexpected data must creep in.
215b1d27b48SRoberto Vargas         * Ensure the rest of the current memory page is unused.
216b1d27b48SRoberto Vargas         */
2175629b2b1SRoberto Vargas        . = ALIGN(PAGE_SIZE);
218b1d27b48SRoberto Vargas        __COHERENT_RAM_END__ = .;
219b1d27b48SRoberto Vargas    } >RAM
220b1d27b48SRoberto Vargas#endif
221b1d27b48SRoberto Vargas
222b1d27b48SRoberto Vargas    /*
223b1d27b48SRoberto Vargas     * Define a linker symbol to mark end of the RW memory area for this
224b1d27b48SRoberto Vargas     * image.
225b1d27b48SRoberto Vargas     */
226b1d27b48SRoberto Vargas    __RW_END__ = .;
227b1d27b48SRoberto Vargas    __BL2_END__ = .;
228b1d27b48SRoberto Vargas
229*69af7fcfSMasahiro Yamada    /DISCARD/ : {
230*69af7fcfSMasahiro Yamada        *(.dynsym .dynstr .hash .gnu.hash)
231*69af7fcfSMasahiro Yamada    }
232*69af7fcfSMasahiro Yamada
2337d173fc5SJiafei Pan#if BL2_IN_XIP_MEM
2347d173fc5SJiafei Pan    __BL2_RAM_START__ = ADDR(.data);
2357d173fc5SJiafei Pan    __BL2_RAM_END__ = .;
2367d173fc5SJiafei Pan
2377d173fc5SJiafei Pan    __DATA_ROM_START__ = LOADADDR(.data);
2387d173fc5SJiafei Pan    __DATA_SIZE__ = SIZEOF(.data);
2397d173fc5SJiafei Pan
2407d173fc5SJiafei Pan    /*
2417d173fc5SJiafei Pan     * The .data section is the last PROGBITS section so its end marks the end
2427d173fc5SJiafei Pan     * of BL2's RO content in XIP memory..
2437d173fc5SJiafei Pan     */
2447d173fc5SJiafei Pan    __BL2_ROM_END__ =  __DATA_ROM_START__ + __DATA_SIZE__;
2457d173fc5SJiafei Pan    ASSERT(__BL2_ROM_END__ <= BL2_RO_LIMIT,
2467d173fc5SJiafei Pan           "BL2's RO content has exceeded its limit.")
2477d173fc5SJiafei Pan#endif
248b1d27b48SRoberto Vargas    __BSS_SIZE__ = SIZEOF(.bss);
249b1d27b48SRoberto Vargas
2507d173fc5SJiafei Pan
251b1d27b48SRoberto Vargas#if USE_COHERENT_MEM
252b1d27b48SRoberto Vargas    __COHERENT_RAM_UNALIGNED_SIZE__ =
253b1d27b48SRoberto Vargas        __COHERENT_RAM_END_UNALIGNED__ - __COHERENT_RAM_START__;
254b1d27b48SRoberto Vargas#endif
255b1d27b48SRoberto Vargas
2567d173fc5SJiafei Pan#if BL2_IN_XIP_MEM
2577d173fc5SJiafei Pan    ASSERT(. <= BL2_RW_LIMIT, "BL2's RW content has exceeded its limit.")
2587d173fc5SJiafei Pan#else
259b1d27b48SRoberto Vargas    ASSERT(. <= BL2_LIMIT, "BL2 image has exceeded its limit.")
2607d173fc5SJiafei Pan#endif
261b1d27b48SRoberto Vargas}
262