xref: /rk3399_ARM-atf/bl2/bl2_el3.ld.S (revision 665e71b8ea28162ec7737c1411bca3ea89e5957e)
1b1d27b48SRoberto Vargas/*
2*665e71b8SMasahiro Yamada * Copyright (c) 2017-2020, 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
9*665e71b8SMasahiro Yamada#include <common/bl_common.ld.h>
1009d40e0eSAntonio Nino Diaz#include <lib/xlat_tables/xlat_tables_defs.h>
11b1d27b48SRoberto Vargas
12b1d27b48SRoberto VargasOUTPUT_FORMAT(PLATFORM_LINKER_FORMAT)
13b1d27b48SRoberto VargasOUTPUT_ARCH(PLATFORM_LINKER_ARCH)
14b1d27b48SRoberto VargasENTRY(bl2_entrypoint)
15b1d27b48SRoberto Vargas
16b1d27b48SRoberto VargasMEMORY {
177d173fc5SJiafei Pan#if BL2_IN_XIP_MEM
187d173fc5SJiafei Pan    ROM (rx): ORIGIN = BL2_RO_BASE, LENGTH = BL2_RO_LIMIT - BL2_RO_BASE
197d173fc5SJiafei Pan    RAM (rwx): ORIGIN = BL2_RW_BASE, LENGTH = BL2_RW_LIMIT - BL2_RW_BASE
207d173fc5SJiafei Pan#else
21b1d27b48SRoberto Vargas    RAM (rwx): ORIGIN = BL2_BASE, LENGTH = BL2_LIMIT - BL2_BASE
227d173fc5SJiafei Pan#endif
23b1d27b48SRoberto Vargas}
24b1d27b48SRoberto Vargas
252f6f00dcSMasahiro Yamada#if !BL2_IN_XIP_MEM
262f6f00dcSMasahiro Yamada#define ROM RAM
272f6f00dcSMasahiro Yamada#endif
28b1d27b48SRoberto Vargas
29b1d27b48SRoberto VargasSECTIONS
30b1d27b48SRoberto Vargas{
317d173fc5SJiafei Pan#if BL2_IN_XIP_MEM
327d173fc5SJiafei Pan    . = BL2_RO_BASE;
337d173fc5SJiafei Pan    ASSERT(. == ALIGN(PAGE_SIZE),
347d173fc5SJiafei Pan           "BL2_RO_BASE address is not aligned on a page boundary.")
357d173fc5SJiafei Pan#else
36b1d27b48SRoberto Vargas    . = BL2_BASE;
37b1d27b48SRoberto Vargas    ASSERT(. == ALIGN(PAGE_SIZE),
38b1d27b48SRoberto Vargas           "BL2_BASE address is not aligned on a page boundary.")
397d173fc5SJiafei Pan#endif
40b1d27b48SRoberto Vargas
41b1d27b48SRoberto Vargas#if SEPARATE_CODE_AND_RODATA
42b1d27b48SRoberto Vargas    .text . : {
43b1d27b48SRoberto Vargas        __TEXT_START__ = .;
44487d3bf2SRoberto Vargas	__TEXT_RESIDENT_START__ = .;
45b1d27b48SRoberto Vargas	*bl2_el3_entrypoint.o(.text*)
46487d3bf2SRoberto Vargas	*(.text.asm.*)
47487d3bf2SRoberto Vargas	__TEXT_RESIDENT_END__ = .;
48ebd6efaeSSamuel Holland        *(SORT_BY_ALIGNMENT(.text*))
49b1d27b48SRoberto Vargas        *(.vectors)
505629b2b1SRoberto Vargas        . = ALIGN(PAGE_SIZE);
51b1d27b48SRoberto Vargas        __TEXT_END__ = .;
527d173fc5SJiafei Pan     } >ROM
53b1d27b48SRoberto Vargas
54b1d27b48SRoberto Vargas    .rodata . : {
55b1d27b48SRoberto Vargas        __RODATA_START__ = .;
56ebd6efaeSSamuel Holland        *(SORT_BY_ALIGNMENT(.rodata*))
57b1d27b48SRoberto Vargas
58b1d27b48SRoberto Vargas        /* Ensure 8-byte alignment for descriptors and ensure inclusion */
59b1d27b48SRoberto Vargas        . = ALIGN(8);
60b1d27b48SRoberto Vargas        __PARSER_LIB_DESCS_START__ = .;
61b1d27b48SRoberto Vargas        KEEP(*(.img_parser_lib_descs))
62b1d27b48SRoberto Vargas        __PARSER_LIB_DESCS_END__ = .;
63b1d27b48SRoberto Vargas
64b1d27b48SRoberto Vargas        /*
65b1d27b48SRoberto Vargas         * Ensure 8-byte alignment for cpu_ops so that its fields are also
66b1d27b48SRoberto Vargas         * aligned. Also ensure cpu_ops inclusion.
67b1d27b48SRoberto Vargas         */
68b1d27b48SRoberto Vargas        . = ALIGN(8);
69b1d27b48SRoberto Vargas        __CPU_OPS_START__ = .;
70b1d27b48SRoberto Vargas        KEEP(*(cpu_ops))
71b1d27b48SRoberto Vargas        __CPU_OPS_END__ = .;
72b1d27b48SRoberto Vargas
7369af7fcfSMasahiro Yamada        /*
7469af7fcfSMasahiro Yamada         * Keep the .got section in the RO section as it is patched
7569af7fcfSMasahiro Yamada         * prior to enabling the MMU and having the .got in RO is better for
7669af7fcfSMasahiro Yamada         * security. GOT is a table of addresses so ensure 8-byte alignment.
7769af7fcfSMasahiro Yamada         */
7869af7fcfSMasahiro Yamada        . = ALIGN(8);
7969af7fcfSMasahiro Yamada        __GOT_START__ = .;
8069af7fcfSMasahiro Yamada        *(.got)
8169af7fcfSMasahiro Yamada        __GOT_END__ = .;
8269af7fcfSMasahiro Yamada
835629b2b1SRoberto Vargas        . = ALIGN(PAGE_SIZE);
84b1d27b48SRoberto Vargas        __RODATA_END__ = .;
857d173fc5SJiafei Pan    } >ROM
86487d3bf2SRoberto Vargas
87487d3bf2SRoberto Vargas    ASSERT(__TEXT_RESIDENT_END__ - __TEXT_RESIDENT_START__ <= PAGE_SIZE,
88487d3bf2SRoberto Vargas          "Resident part of BL2 has exceeded its limit.")
89b1d27b48SRoberto Vargas#else
90b1d27b48SRoberto Vargas    ro . : {
91b1d27b48SRoberto Vargas        __RO_START__ = .;
92487d3bf2SRoberto Vargas	__TEXT_RESIDENT_START__ = .;
93b1d27b48SRoberto Vargas	*bl2_el3_entrypoint.o(.text*)
94487d3bf2SRoberto Vargas	*(.text.asm.*)
95487d3bf2SRoberto Vargas	__TEXT_RESIDENT_END__ = .;
96ebd6efaeSSamuel Holland        *(SORT_BY_ALIGNMENT(.text*))
97ebd6efaeSSamuel Holland        *(SORT_BY_ALIGNMENT(.rodata*))
98b1d27b48SRoberto Vargas
99b1d27b48SRoberto Vargas        /*
100b1d27b48SRoberto Vargas         * Ensure 8-byte alignment for cpu_ops so that its fields are also
101b1d27b48SRoberto Vargas         * aligned. Also ensure cpu_ops inclusion.
102b1d27b48SRoberto Vargas         */
103b1d27b48SRoberto Vargas        . = ALIGN(8);
104b1d27b48SRoberto Vargas        __CPU_OPS_START__ = .;
105b1d27b48SRoberto Vargas        KEEP(*(cpu_ops))
106b1d27b48SRoberto Vargas        __CPU_OPS_END__ = .;
107b1d27b48SRoberto Vargas
108b1d27b48SRoberto Vargas        /* Ensure 8-byte alignment for descriptors and ensure inclusion */
109b1d27b48SRoberto Vargas        . = ALIGN(8);
110b1d27b48SRoberto Vargas        __PARSER_LIB_DESCS_START__ = .;
111b1d27b48SRoberto Vargas        KEEP(*(.img_parser_lib_descs))
112b1d27b48SRoberto Vargas        __PARSER_LIB_DESCS_END__ = .;
113b1d27b48SRoberto Vargas
11469af7fcfSMasahiro Yamada        /*
11569af7fcfSMasahiro Yamada         * Keep the .got section in the RO section as it is patched
11669af7fcfSMasahiro Yamada         * prior to enabling the MMU and having the .got in RO is better for
11769af7fcfSMasahiro Yamada         * security. GOT is a table of addresses so ensure 8-byte alignment.
11869af7fcfSMasahiro Yamada         */
11969af7fcfSMasahiro Yamada        . = ALIGN(8);
12069af7fcfSMasahiro Yamada        __GOT_START__ = .;
12169af7fcfSMasahiro Yamada        *(.got)
12269af7fcfSMasahiro Yamada        __GOT_END__ = .;
12369af7fcfSMasahiro Yamada
124b1d27b48SRoberto Vargas        *(.vectors)
125b1d27b48SRoberto Vargas        __RO_END_UNALIGNED__ = .;
126b1d27b48SRoberto Vargas        /*
127b1d27b48SRoberto Vargas         * Memory page(s) mapped to this section will be marked as
128b1d27b48SRoberto Vargas         * read-only, executable.  No RW data from the next section must
129b1d27b48SRoberto Vargas         * creep in.  Ensure the rest of the current memory page is unused.
130b1d27b48SRoberto Vargas         */
1315629b2b1SRoberto Vargas        . = ALIGN(PAGE_SIZE);
132b1d27b48SRoberto Vargas
133b1d27b48SRoberto Vargas        __RO_END__ = .;
1347d173fc5SJiafei Pan    } >ROM
1357d173fc5SJiafei Pan#endif
136b1d27b48SRoberto Vargas
137b1d27b48SRoberto Vargas    ASSERT(__CPU_OPS_END__ > __CPU_OPS_START__,
138b1d27b48SRoberto Vargas          "cpu_ops not defined for this platform.")
139b1d27b48SRoberto Vargas
1407d173fc5SJiafei Pan#if BL2_IN_XIP_MEM
1417d173fc5SJiafei Pan    . = BL2_RW_BASE;
1427d173fc5SJiafei Pan    ASSERT(BL2_RW_BASE == ALIGN(PAGE_SIZE),
1437d173fc5SJiafei Pan           "BL2_RW_BASE address is not aligned on a page boundary.")
1447d173fc5SJiafei Pan#endif
1457d173fc5SJiafei Pan
146b1d27b48SRoberto Vargas    /*
147b1d27b48SRoberto Vargas     * Define a linker symbol to mark start of the RW memory area for this
148b1d27b48SRoberto Vargas     * image.
149b1d27b48SRoberto Vargas     */
150b1d27b48SRoberto Vargas    __RW_START__ = . ;
151b1d27b48SRoberto Vargas
152b1d27b48SRoberto Vargas    /*
153b1d27b48SRoberto Vargas     * .data must be placed at a lower address than the stacks if the stack
154b1d27b48SRoberto Vargas     * protector is enabled. Alternatively, the .data.stack_protector_canary
155b1d27b48SRoberto Vargas     * section can be placed independently of the main .data section.
156b1d27b48SRoberto Vargas     */
157b1d27b48SRoberto Vargas    .data . : {
1587d173fc5SJiafei Pan        __DATA_RAM_START__ = .;
159ebd6efaeSSamuel Holland        *(SORT_BY_ALIGNMENT(.data*))
1607d173fc5SJiafei Pan        __DATA_RAM_END__ = .;
1617d173fc5SJiafei Pan    } >RAM AT>ROM
162b1d27b48SRoberto Vargas
16369af7fcfSMasahiro Yamada    /*
16469af7fcfSMasahiro Yamada     * .rela.dyn needs to come after .data for the read-elf utility to parse
16569af7fcfSMasahiro Yamada     * this section correctly. Ensure 8-byte alignment so that the fields of
16669af7fcfSMasahiro Yamada     * RELA data structure are aligned.
16769af7fcfSMasahiro Yamada     */
16869af7fcfSMasahiro Yamada    . = ALIGN(8);
16969af7fcfSMasahiro Yamada    __RELA_START__ = .;
17069af7fcfSMasahiro Yamada    .rela.dyn . : {
17169af7fcfSMasahiro Yamada    } >RAM
17269af7fcfSMasahiro Yamada    __RELA_END__ = .;
17369af7fcfSMasahiro Yamada
174b1d27b48SRoberto Vargas    stacks (NOLOAD) : {
175b1d27b48SRoberto Vargas        __STACKS_START__ = .;
176b1d27b48SRoberto Vargas        *(tzfw_normal_stacks)
177b1d27b48SRoberto Vargas        __STACKS_END__ = .;
178b1d27b48SRoberto Vargas    } >RAM
179b1d27b48SRoberto Vargas
180b1d27b48SRoberto Vargas    /*
181b1d27b48SRoberto Vargas     * The .bss section gets initialised to 0 at runtime.
182b1d27b48SRoberto Vargas     * Its base address should be 16-byte aligned for better performance of the
183b1d27b48SRoberto Vargas     * zero-initialization code.
184b1d27b48SRoberto Vargas     */
185b1d27b48SRoberto Vargas    .bss : ALIGN(16) {
186b1d27b48SRoberto Vargas        __BSS_START__ = .;
187b1d27b48SRoberto Vargas        *(SORT_BY_ALIGNMENT(.bss*))
188b1d27b48SRoberto Vargas        *(COMMON)
189b1d27b48SRoberto Vargas        __BSS_END__ = .;
190b1d27b48SRoberto Vargas    } >RAM
191b1d27b48SRoberto Vargas
192*665e71b8SMasahiro Yamada    XLAT_TABLE_SECTION >RAM
193b1d27b48SRoberto Vargas
194b1d27b48SRoberto Vargas#if USE_COHERENT_MEM
195b1d27b48SRoberto Vargas    /*
196b1d27b48SRoberto Vargas     * The base address of the coherent memory section must be page-aligned (4K)
197b1d27b48SRoberto Vargas     * to guarantee that the coherent data are stored on their own pages and
198b1d27b48SRoberto Vargas     * are not mixed with normal data.  This is required to set up the correct
199b1d27b48SRoberto Vargas     * memory attributes for the coherent data page tables.
200b1d27b48SRoberto Vargas     */
201b1d27b48SRoberto Vargas    coherent_ram (NOLOAD) : ALIGN(PAGE_SIZE) {
202b1d27b48SRoberto Vargas        __COHERENT_RAM_START__ = .;
203b1d27b48SRoberto Vargas        *(tzfw_coherent_mem)
204b1d27b48SRoberto Vargas        __COHERENT_RAM_END_UNALIGNED__ = .;
205b1d27b48SRoberto Vargas        /*
206b1d27b48SRoberto Vargas         * Memory page(s) mapped to this section will be marked
207b1d27b48SRoberto Vargas         * as device memory.  No other unexpected data must creep in.
208b1d27b48SRoberto Vargas         * Ensure the rest of the current memory page is unused.
209b1d27b48SRoberto Vargas         */
2105629b2b1SRoberto Vargas        . = ALIGN(PAGE_SIZE);
211b1d27b48SRoberto Vargas        __COHERENT_RAM_END__ = .;
212b1d27b48SRoberto Vargas    } >RAM
213b1d27b48SRoberto Vargas#endif
214b1d27b48SRoberto Vargas
215b1d27b48SRoberto Vargas    /*
216b1d27b48SRoberto Vargas     * Define a linker symbol to mark end of the RW memory area for this
217b1d27b48SRoberto Vargas     * image.
218b1d27b48SRoberto Vargas     */
219b1d27b48SRoberto Vargas    __RW_END__ = .;
220b1d27b48SRoberto Vargas    __BL2_END__ = .;
221b1d27b48SRoberto Vargas
22269af7fcfSMasahiro Yamada    /DISCARD/ : {
22369af7fcfSMasahiro Yamada        *(.dynsym .dynstr .hash .gnu.hash)
22469af7fcfSMasahiro Yamada    }
22569af7fcfSMasahiro Yamada
2267d173fc5SJiafei Pan#if BL2_IN_XIP_MEM
2277d173fc5SJiafei Pan    __BL2_RAM_START__ = ADDR(.data);
2287d173fc5SJiafei Pan    __BL2_RAM_END__ = .;
2297d173fc5SJiafei Pan
2307d173fc5SJiafei Pan    __DATA_ROM_START__ = LOADADDR(.data);
2317d173fc5SJiafei Pan    __DATA_SIZE__ = SIZEOF(.data);
2327d173fc5SJiafei Pan
2337d173fc5SJiafei Pan    /*
2347d173fc5SJiafei Pan     * The .data section is the last PROGBITS section so its end marks the end
2357d173fc5SJiafei Pan     * of BL2's RO content in XIP memory..
2367d173fc5SJiafei Pan     */
2377d173fc5SJiafei Pan    __BL2_ROM_END__ =  __DATA_ROM_START__ + __DATA_SIZE__;
2387d173fc5SJiafei Pan    ASSERT(__BL2_ROM_END__ <= BL2_RO_LIMIT,
2397d173fc5SJiafei Pan           "BL2's RO content has exceeded its limit.")
2407d173fc5SJiafei Pan#endif
241b1d27b48SRoberto Vargas    __BSS_SIZE__ = SIZEOF(.bss);
242b1d27b48SRoberto Vargas
2437d173fc5SJiafei Pan
244b1d27b48SRoberto Vargas#if USE_COHERENT_MEM
245b1d27b48SRoberto Vargas    __COHERENT_RAM_UNALIGNED_SIZE__ =
246b1d27b48SRoberto Vargas        __COHERENT_RAM_END_UNALIGNED__ - __COHERENT_RAM_START__;
247b1d27b48SRoberto Vargas#endif
248b1d27b48SRoberto Vargas
2497d173fc5SJiafei Pan#if BL2_IN_XIP_MEM
2507d173fc5SJiafei Pan    ASSERT(. <= BL2_RW_LIMIT, "BL2's RW content has exceeded its limit.")
2517d173fc5SJiafei Pan#else
252b1d27b48SRoberto Vargas    ASSERT(. <= BL2_LIMIT, "BL2 image has exceeded its limit.")
2537d173fc5SJiafei Pan#endif
254b1d27b48SRoberto Vargas}
255