xref: /rk3399_ARM-atf/bl2/bl2_el3.ld.S (revision 0a0a7a9ac82cb79af91f098cedc69cc67bca3978)
1b1d27b48SRoberto Vargas/*
2665e71b8SMasahiro 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
7665e71b8SMasahiro Yamada#include <common/bl_common.ld.h>
809d40e0eSAntonio Nino Diaz#include <lib/xlat_tables/xlat_tables_defs.h>
9b1d27b48SRoberto Vargas
10b1d27b48SRoberto VargasOUTPUT_FORMAT(PLATFORM_LINKER_FORMAT)
11b1d27b48SRoberto VargasOUTPUT_ARCH(PLATFORM_LINKER_ARCH)
12b1d27b48SRoberto VargasENTRY(bl2_entrypoint)
13b1d27b48SRoberto Vargas
14b1d27b48SRoberto VargasMEMORY {
157d173fc5SJiafei Pan#if BL2_IN_XIP_MEM
167d173fc5SJiafei Pan    ROM (rx): ORIGIN = BL2_RO_BASE, LENGTH = BL2_RO_LIMIT - BL2_RO_BASE
177d173fc5SJiafei Pan    RAM (rwx): ORIGIN = BL2_RW_BASE, LENGTH = BL2_RW_LIMIT - BL2_RW_BASE
187d173fc5SJiafei Pan#else
19b1d27b48SRoberto Vargas    RAM (rwx): ORIGIN = BL2_BASE, LENGTH = BL2_LIMIT - BL2_BASE
207d173fc5SJiafei Pan#endif
21b1d27b48SRoberto Vargas}
22b1d27b48SRoberto Vargas
232f6f00dcSMasahiro Yamada#if !BL2_IN_XIP_MEM
242f6f00dcSMasahiro Yamada#define ROM RAM
252f6f00dcSMasahiro Yamada#endif
26b1d27b48SRoberto Vargas
27b1d27b48SRoberto VargasSECTIONS
28b1d27b48SRoberto Vargas{
297d173fc5SJiafei Pan#if BL2_IN_XIP_MEM
307d173fc5SJiafei Pan    . = BL2_RO_BASE;
317d173fc5SJiafei Pan    ASSERT(. == ALIGN(PAGE_SIZE),
327d173fc5SJiafei Pan           "BL2_RO_BASE address is not aligned on a page boundary.")
337d173fc5SJiafei Pan#else
34b1d27b48SRoberto Vargas    . = BL2_BASE;
35b1d27b48SRoberto Vargas    ASSERT(. == ALIGN(PAGE_SIZE),
36b1d27b48SRoberto Vargas           "BL2_BASE address is not aligned on a page boundary.")
377d173fc5SJiafei Pan#endif
38b1d27b48SRoberto Vargas
39b1d27b48SRoberto Vargas#if SEPARATE_CODE_AND_RODATA
40b1d27b48SRoberto Vargas    .text . : {
41b1d27b48SRoberto Vargas        __TEXT_START__ = .;
42487d3bf2SRoberto Vargas	__TEXT_RESIDENT_START__ = .;
43b1d27b48SRoberto Vargas	*bl2_el3_entrypoint.o(.text*)
44487d3bf2SRoberto Vargas	*(.text.asm.*)
45487d3bf2SRoberto Vargas	__TEXT_RESIDENT_END__ = .;
46ebd6efaeSSamuel Holland        *(SORT_BY_ALIGNMENT(.text*))
47b1d27b48SRoberto Vargas        *(.vectors)
485629b2b1SRoberto Vargas        . = ALIGN(PAGE_SIZE);
49b1d27b48SRoberto Vargas        __TEXT_END__ = .;
507d173fc5SJiafei Pan     } >ROM
51b1d27b48SRoberto Vargas
52b1d27b48SRoberto Vargas    .rodata . : {
53b1d27b48SRoberto Vargas        __RODATA_START__ = .;
54ebd6efaeSSamuel Holland        *(SORT_BY_ALIGNMENT(.rodata*))
55b1d27b48SRoberto Vargas
56*0a0a7a9aSMasahiro Yamada	RODATA_COMMON
5769af7fcfSMasahiro Yamada
585629b2b1SRoberto Vargas        . = ALIGN(PAGE_SIZE);
59b1d27b48SRoberto Vargas        __RODATA_END__ = .;
607d173fc5SJiafei Pan    } >ROM
61487d3bf2SRoberto Vargas
62487d3bf2SRoberto Vargas    ASSERT(__TEXT_RESIDENT_END__ - __TEXT_RESIDENT_START__ <= PAGE_SIZE,
63487d3bf2SRoberto Vargas          "Resident part of BL2 has exceeded its limit.")
64b1d27b48SRoberto Vargas#else
65b1d27b48SRoberto Vargas    ro . : {
66b1d27b48SRoberto Vargas        __RO_START__ = .;
67487d3bf2SRoberto Vargas	__TEXT_RESIDENT_START__ = .;
68b1d27b48SRoberto Vargas	*bl2_el3_entrypoint.o(.text*)
69487d3bf2SRoberto Vargas	*(.text.asm.*)
70487d3bf2SRoberto Vargas	__TEXT_RESIDENT_END__ = .;
71ebd6efaeSSamuel Holland        *(SORT_BY_ALIGNMENT(.text*))
72ebd6efaeSSamuel Holland        *(SORT_BY_ALIGNMENT(.rodata*))
73b1d27b48SRoberto Vargas
74*0a0a7a9aSMasahiro Yamada	RODATA_COMMON
7569af7fcfSMasahiro Yamada
76b1d27b48SRoberto Vargas        *(.vectors)
77b1d27b48SRoberto Vargas        __RO_END_UNALIGNED__ = .;
78b1d27b48SRoberto Vargas        /*
79b1d27b48SRoberto Vargas         * Memory page(s) mapped to this section will be marked as
80b1d27b48SRoberto Vargas         * read-only, executable.  No RW data from the next section must
81b1d27b48SRoberto Vargas         * creep in.  Ensure the rest of the current memory page is unused.
82b1d27b48SRoberto Vargas         */
835629b2b1SRoberto Vargas        . = ALIGN(PAGE_SIZE);
84b1d27b48SRoberto Vargas
85b1d27b48SRoberto Vargas        __RO_END__ = .;
867d173fc5SJiafei Pan    } >ROM
877d173fc5SJiafei Pan#endif
88b1d27b48SRoberto Vargas
89b1d27b48SRoberto Vargas    ASSERT(__CPU_OPS_END__ > __CPU_OPS_START__,
90b1d27b48SRoberto Vargas          "cpu_ops not defined for this platform.")
91b1d27b48SRoberto Vargas
927d173fc5SJiafei Pan#if BL2_IN_XIP_MEM
937d173fc5SJiafei Pan    . = BL2_RW_BASE;
947d173fc5SJiafei Pan    ASSERT(BL2_RW_BASE == ALIGN(PAGE_SIZE),
957d173fc5SJiafei Pan           "BL2_RW_BASE address is not aligned on a page boundary.")
967d173fc5SJiafei Pan#endif
977d173fc5SJiafei Pan
98b1d27b48SRoberto Vargas    /*
99b1d27b48SRoberto Vargas     * Define a linker symbol to mark start of the RW memory area for this
100b1d27b48SRoberto Vargas     * image.
101b1d27b48SRoberto Vargas     */
102b1d27b48SRoberto Vargas    __RW_START__ = . ;
103b1d27b48SRoberto Vargas
104b1d27b48SRoberto Vargas    /*
105b1d27b48SRoberto Vargas     * .data must be placed at a lower address than the stacks if the stack
106b1d27b48SRoberto Vargas     * protector is enabled. Alternatively, the .data.stack_protector_canary
107b1d27b48SRoberto Vargas     * section can be placed independently of the main .data section.
108b1d27b48SRoberto Vargas     */
109b1d27b48SRoberto Vargas    .data . : {
1107d173fc5SJiafei Pan        __DATA_RAM_START__ = .;
111ebd6efaeSSamuel Holland        *(SORT_BY_ALIGNMENT(.data*))
1127d173fc5SJiafei Pan        __DATA_RAM_END__ = .;
1137d173fc5SJiafei Pan    } >RAM AT>ROM
114b1d27b48SRoberto Vargas
11569af7fcfSMasahiro Yamada    /*
11669af7fcfSMasahiro Yamada     * .rela.dyn needs to come after .data for the read-elf utility to parse
11769af7fcfSMasahiro Yamada     * this section correctly. Ensure 8-byte alignment so that the fields of
11869af7fcfSMasahiro Yamada     * RELA data structure are aligned.
11969af7fcfSMasahiro Yamada     */
12069af7fcfSMasahiro Yamada    . = ALIGN(8);
12169af7fcfSMasahiro Yamada    __RELA_START__ = .;
12269af7fcfSMasahiro Yamada    .rela.dyn . : {
12369af7fcfSMasahiro Yamada    } >RAM
12469af7fcfSMasahiro Yamada    __RELA_END__ = .;
12569af7fcfSMasahiro Yamada
126b1d27b48SRoberto Vargas    stacks (NOLOAD) : {
127b1d27b48SRoberto Vargas        __STACKS_START__ = .;
128b1d27b48SRoberto Vargas        *(tzfw_normal_stacks)
129b1d27b48SRoberto Vargas        __STACKS_END__ = .;
130b1d27b48SRoberto Vargas    } >RAM
131b1d27b48SRoberto Vargas
132b1d27b48SRoberto Vargas    /*
133b1d27b48SRoberto Vargas     * The .bss section gets initialised to 0 at runtime.
134b1d27b48SRoberto Vargas     * Its base address should be 16-byte aligned for better performance of the
135b1d27b48SRoberto Vargas     * zero-initialization code.
136b1d27b48SRoberto Vargas     */
137b1d27b48SRoberto Vargas    .bss : ALIGN(16) {
138b1d27b48SRoberto Vargas        __BSS_START__ = .;
139b1d27b48SRoberto Vargas        *(SORT_BY_ALIGNMENT(.bss*))
140b1d27b48SRoberto Vargas        *(COMMON)
141b1d27b48SRoberto Vargas        __BSS_END__ = .;
142b1d27b48SRoberto Vargas    } >RAM
143b1d27b48SRoberto Vargas
144665e71b8SMasahiro Yamada    XLAT_TABLE_SECTION >RAM
145b1d27b48SRoberto Vargas
146b1d27b48SRoberto Vargas#if USE_COHERENT_MEM
147b1d27b48SRoberto Vargas    /*
148b1d27b48SRoberto Vargas     * The base address of the coherent memory section must be page-aligned (4K)
149b1d27b48SRoberto Vargas     * to guarantee that the coherent data are stored on their own pages and
150b1d27b48SRoberto Vargas     * are not mixed with normal data.  This is required to set up the correct
151b1d27b48SRoberto Vargas     * memory attributes for the coherent data page tables.
152b1d27b48SRoberto Vargas     */
153b1d27b48SRoberto Vargas    coherent_ram (NOLOAD) : ALIGN(PAGE_SIZE) {
154b1d27b48SRoberto Vargas        __COHERENT_RAM_START__ = .;
155b1d27b48SRoberto Vargas        *(tzfw_coherent_mem)
156b1d27b48SRoberto Vargas        __COHERENT_RAM_END_UNALIGNED__ = .;
157b1d27b48SRoberto Vargas        /*
158b1d27b48SRoberto Vargas         * Memory page(s) mapped to this section will be marked
159b1d27b48SRoberto Vargas         * as device memory.  No other unexpected data must creep in.
160b1d27b48SRoberto Vargas         * Ensure the rest of the current memory page is unused.
161b1d27b48SRoberto Vargas         */
1625629b2b1SRoberto Vargas        . = ALIGN(PAGE_SIZE);
163b1d27b48SRoberto Vargas        __COHERENT_RAM_END__ = .;
164b1d27b48SRoberto Vargas    } >RAM
165b1d27b48SRoberto Vargas#endif
166b1d27b48SRoberto Vargas
167b1d27b48SRoberto Vargas    /*
168b1d27b48SRoberto Vargas     * Define a linker symbol to mark end of the RW memory area for this
169b1d27b48SRoberto Vargas     * image.
170b1d27b48SRoberto Vargas     */
171b1d27b48SRoberto Vargas    __RW_END__ = .;
172b1d27b48SRoberto Vargas    __BL2_END__ = .;
173b1d27b48SRoberto Vargas
17469af7fcfSMasahiro Yamada    /DISCARD/ : {
17569af7fcfSMasahiro Yamada        *(.dynsym .dynstr .hash .gnu.hash)
17669af7fcfSMasahiro Yamada    }
17769af7fcfSMasahiro Yamada
1787d173fc5SJiafei Pan#if BL2_IN_XIP_MEM
1797d173fc5SJiafei Pan    __BL2_RAM_START__ = ADDR(.data);
1807d173fc5SJiafei Pan    __BL2_RAM_END__ = .;
1817d173fc5SJiafei Pan
1827d173fc5SJiafei Pan    __DATA_ROM_START__ = LOADADDR(.data);
1837d173fc5SJiafei Pan    __DATA_SIZE__ = SIZEOF(.data);
1847d173fc5SJiafei Pan
1857d173fc5SJiafei Pan    /*
1867d173fc5SJiafei Pan     * The .data section is the last PROGBITS section so its end marks the end
1877d173fc5SJiafei Pan     * of BL2's RO content in XIP memory..
1887d173fc5SJiafei Pan     */
1897d173fc5SJiafei Pan    __BL2_ROM_END__ =  __DATA_ROM_START__ + __DATA_SIZE__;
1907d173fc5SJiafei Pan    ASSERT(__BL2_ROM_END__ <= BL2_RO_LIMIT,
1917d173fc5SJiafei Pan           "BL2's RO content has exceeded its limit.")
1927d173fc5SJiafei Pan#endif
193b1d27b48SRoberto Vargas    __BSS_SIZE__ = SIZEOF(.bss);
194b1d27b48SRoberto Vargas
1957d173fc5SJiafei Pan
196b1d27b48SRoberto Vargas#if USE_COHERENT_MEM
197b1d27b48SRoberto Vargas    __COHERENT_RAM_UNALIGNED_SIZE__ =
198b1d27b48SRoberto Vargas        __COHERENT_RAM_END_UNALIGNED__ - __COHERENT_RAM_START__;
199b1d27b48SRoberto Vargas#endif
200b1d27b48SRoberto Vargas
2017d173fc5SJiafei Pan#if BL2_IN_XIP_MEM
2027d173fc5SJiafei Pan    ASSERT(. <= BL2_RW_LIMIT, "BL2's RW content has exceeded its limit.")
2037d173fc5SJiafei Pan#else
204b1d27b48SRoberto Vargas    ASSERT(. <= BL2_LIMIT, "BL2 image has exceeded its limit.")
2057d173fc5SJiafei Pan#endif
206b1d27b48SRoberto Vargas}
207