xref: /rk3399_ARM-atf/bl2/bl2_el3.ld.S (revision 5629b2b11ccbb422847cae776d5faf9bdc5cb5dd)
1b1d27b48SRoberto Vargas/*
2883d1b5dSAntonio Nino Diaz * Copyright (c) 2017-2018, 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>
8b1d27b48SRoberto Vargas#include <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
23b1d27b48SRoberto Vargas
24b1d27b48SRoberto VargasSECTIONS
25b1d27b48SRoberto Vargas{
267d173fc5SJiafei Pan#if BL2_IN_XIP_MEM
277d173fc5SJiafei Pan    . = BL2_RO_BASE;
287d173fc5SJiafei Pan    ASSERT(. == ALIGN(PAGE_SIZE),
297d173fc5SJiafei Pan           "BL2_RO_BASE address is not aligned on a page boundary.")
307d173fc5SJiafei Pan#else
31b1d27b48SRoberto Vargas    . = BL2_BASE;
32b1d27b48SRoberto Vargas    ASSERT(. == ALIGN(PAGE_SIZE),
33b1d27b48SRoberto Vargas           "BL2_BASE address is not aligned on a page boundary.")
347d173fc5SJiafei Pan#endif
35b1d27b48SRoberto Vargas
36b1d27b48SRoberto Vargas#if SEPARATE_CODE_AND_RODATA
37b1d27b48SRoberto Vargas    .text . : {
38b1d27b48SRoberto Vargas        __TEXT_START__ = .;
39487d3bf2SRoberto Vargas	__TEXT_RESIDENT_START__ = .;
40b1d27b48SRoberto Vargas	*bl2_el3_entrypoint.o(.text*)
41487d3bf2SRoberto Vargas	*(.text.asm.*)
42487d3bf2SRoberto Vargas	__TEXT_RESIDENT_END__ = .;
43b1d27b48SRoberto Vargas        *(.text*)
44b1d27b48SRoberto Vargas        *(.vectors)
45*5629b2b1SRoberto Vargas        . = ALIGN(PAGE_SIZE);
46b1d27b48SRoberto Vargas        __TEXT_END__ = .;
477d173fc5SJiafei Pan#if BL2_IN_XIP_MEM
487d173fc5SJiafei Pan     } >ROM
497d173fc5SJiafei Pan#else
50b1d27b48SRoberto Vargas     } >RAM
517d173fc5SJiafei Pan#endif
52b1d27b48SRoberto Vargas
53b1d27b48SRoberto Vargas    .rodata . : {
54b1d27b48SRoberto Vargas        __RODATA_START__ = .;
55b1d27b48SRoberto Vargas        *(.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*5629b2b1SRoberto Vargas        . = ALIGN(PAGE_SIZE);
73b1d27b48SRoberto Vargas        __RODATA_END__ = .;
747d173fc5SJiafei Pan#if BL2_IN_XIP_MEM
757d173fc5SJiafei Pan    } >ROM
767d173fc5SJiafei Pan#else
77b1d27b48SRoberto Vargas    } >RAM
787d173fc5SJiafei Pan#endif
79487d3bf2SRoberto Vargas
80487d3bf2SRoberto Vargas    ASSERT(__TEXT_RESIDENT_END__ - __TEXT_RESIDENT_START__ <= PAGE_SIZE,
81487d3bf2SRoberto Vargas          "Resident part of BL2 has exceeded its limit.")
82b1d27b48SRoberto Vargas#else
83b1d27b48SRoberto Vargas    ro . : {
84b1d27b48SRoberto Vargas        __RO_START__ = .;
85487d3bf2SRoberto Vargas	__TEXT_RESIDENT_START__ = .;
86b1d27b48SRoberto Vargas	*bl2_el3_entrypoint.o(.text*)
87487d3bf2SRoberto Vargas	*(.text.asm.*)
88487d3bf2SRoberto Vargas	__TEXT_RESIDENT_END__ = .;
89b1d27b48SRoberto Vargas        *(.text*)
90b1d27b48SRoberto Vargas        *(.rodata*)
91b1d27b48SRoberto Vargas
92b1d27b48SRoberto Vargas        /*
93b1d27b48SRoberto Vargas         * Ensure 8-byte alignment for cpu_ops so that its fields are also
94b1d27b48SRoberto Vargas         * aligned. Also ensure cpu_ops inclusion.
95b1d27b48SRoberto Vargas         */
96b1d27b48SRoberto Vargas        . = ALIGN(8);
97b1d27b48SRoberto Vargas        __CPU_OPS_START__ = .;
98b1d27b48SRoberto Vargas        KEEP(*(cpu_ops))
99b1d27b48SRoberto Vargas        __CPU_OPS_END__ = .;
100b1d27b48SRoberto Vargas
101b1d27b48SRoberto Vargas        /* Ensure 8-byte alignment for descriptors and ensure inclusion */
102b1d27b48SRoberto Vargas        . = ALIGN(8);
103b1d27b48SRoberto Vargas        __PARSER_LIB_DESCS_START__ = .;
104b1d27b48SRoberto Vargas        KEEP(*(.img_parser_lib_descs))
105b1d27b48SRoberto Vargas        __PARSER_LIB_DESCS_END__ = .;
106b1d27b48SRoberto Vargas
107b1d27b48SRoberto Vargas        *(.vectors)
108b1d27b48SRoberto Vargas        __RO_END_UNALIGNED__ = .;
109b1d27b48SRoberto Vargas        /*
110b1d27b48SRoberto Vargas         * Memory page(s) mapped to this section will be marked as
111b1d27b48SRoberto Vargas         * read-only, executable.  No RW data from the next section must
112b1d27b48SRoberto Vargas         * creep in.  Ensure the rest of the current memory page is unused.
113b1d27b48SRoberto Vargas         */
114*5629b2b1SRoberto Vargas        . = ALIGN(PAGE_SIZE);
115b1d27b48SRoberto Vargas
116b1d27b48SRoberto Vargas        __RO_END__ = .;
1177d173fc5SJiafei Pan#if BL2_IN_XIP_MEM
1187d173fc5SJiafei Pan    } >ROM
1197d173fc5SJiafei Pan#else
120b1d27b48SRoberto Vargas    } >RAM
121b1d27b48SRoberto Vargas#endif
1227d173fc5SJiafei Pan#endif
123b1d27b48SRoberto Vargas
124b1d27b48SRoberto Vargas    ASSERT(__CPU_OPS_END__ > __CPU_OPS_START__,
125b1d27b48SRoberto Vargas          "cpu_ops not defined for this platform.")
126b1d27b48SRoberto Vargas
1277d173fc5SJiafei Pan#if BL2_IN_XIP_MEM
1287d173fc5SJiafei Pan    . = BL2_RW_BASE;
1297d173fc5SJiafei Pan    ASSERT(BL2_RW_BASE == ALIGN(PAGE_SIZE),
1307d173fc5SJiafei Pan           "BL2_RW_BASE address is not aligned on a page boundary.")
1317d173fc5SJiafei Pan#endif
1327d173fc5SJiafei Pan
133b1d27b48SRoberto Vargas    /*
134b1d27b48SRoberto Vargas     * Define a linker symbol to mark start of the RW memory area for this
135b1d27b48SRoberto Vargas     * image.
136b1d27b48SRoberto Vargas     */
137b1d27b48SRoberto Vargas    __RW_START__ = . ;
138b1d27b48SRoberto Vargas
139b1d27b48SRoberto Vargas    /*
140b1d27b48SRoberto Vargas     * .data must be placed at a lower address than the stacks if the stack
141b1d27b48SRoberto Vargas     * protector is enabled. Alternatively, the .data.stack_protector_canary
142b1d27b48SRoberto Vargas     * section can be placed independently of the main .data section.
143b1d27b48SRoberto Vargas     */
144b1d27b48SRoberto Vargas    .data . : {
1457d173fc5SJiafei Pan        __DATA_RAM_START__ = .;
146b1d27b48SRoberto Vargas        *(.data*)
1477d173fc5SJiafei Pan        __DATA_RAM_END__ = .;
1487d173fc5SJiafei Pan#if BL2_IN_XIP_MEM
1497d173fc5SJiafei Pan    } >RAM AT>ROM
1507d173fc5SJiafei Pan#else
151b1d27b48SRoberto Vargas    } >RAM
1527d173fc5SJiafei Pan#endif
153b1d27b48SRoberto Vargas
154b1d27b48SRoberto Vargas    stacks (NOLOAD) : {
155b1d27b48SRoberto Vargas        __STACKS_START__ = .;
156b1d27b48SRoberto Vargas        *(tzfw_normal_stacks)
157b1d27b48SRoberto Vargas        __STACKS_END__ = .;
158b1d27b48SRoberto Vargas    } >RAM
159b1d27b48SRoberto Vargas
160b1d27b48SRoberto Vargas    /*
161b1d27b48SRoberto Vargas     * The .bss section gets initialised to 0 at runtime.
162b1d27b48SRoberto Vargas     * Its base address should be 16-byte aligned for better performance of the
163b1d27b48SRoberto Vargas     * zero-initialization code.
164b1d27b48SRoberto Vargas     */
165b1d27b48SRoberto Vargas    .bss : ALIGN(16) {
166b1d27b48SRoberto Vargas        __BSS_START__ = .;
167b1d27b48SRoberto Vargas        *(SORT_BY_ALIGNMENT(.bss*))
168b1d27b48SRoberto Vargas        *(COMMON)
169b1d27b48SRoberto Vargas        __BSS_END__ = .;
170b1d27b48SRoberto Vargas    } >RAM
171b1d27b48SRoberto Vargas
172b1d27b48SRoberto Vargas    /*
173b1d27b48SRoberto Vargas     * The xlat_table section is for full, aligned page tables (4K).
174b1d27b48SRoberto Vargas     * Removing them from .bss avoids forcing 4K alignment on
175883d1b5dSAntonio Nino Diaz     * the .bss section. The tables are initialized to zero by the translation
176883d1b5dSAntonio Nino Diaz     * tables library.
177b1d27b48SRoberto Vargas     */
178b1d27b48SRoberto Vargas    xlat_table (NOLOAD) : {
179b1d27b48SRoberto Vargas        *(xlat_table)
180b1d27b48SRoberto Vargas    } >RAM
181b1d27b48SRoberto Vargas
182b1d27b48SRoberto Vargas#if USE_COHERENT_MEM
183b1d27b48SRoberto Vargas    /*
184b1d27b48SRoberto Vargas     * The base address of the coherent memory section must be page-aligned (4K)
185b1d27b48SRoberto Vargas     * to guarantee that the coherent data are stored on their own pages and
186b1d27b48SRoberto Vargas     * are not mixed with normal data.  This is required to set up the correct
187b1d27b48SRoberto Vargas     * memory attributes for the coherent data page tables.
188b1d27b48SRoberto Vargas     */
189b1d27b48SRoberto Vargas    coherent_ram (NOLOAD) : ALIGN(PAGE_SIZE) {
190b1d27b48SRoberto Vargas        __COHERENT_RAM_START__ = .;
191b1d27b48SRoberto Vargas        *(tzfw_coherent_mem)
192b1d27b48SRoberto Vargas        __COHERENT_RAM_END_UNALIGNED__ = .;
193b1d27b48SRoberto Vargas        /*
194b1d27b48SRoberto Vargas         * Memory page(s) mapped to this section will be marked
195b1d27b48SRoberto Vargas         * as device memory.  No other unexpected data must creep in.
196b1d27b48SRoberto Vargas         * Ensure the rest of the current memory page is unused.
197b1d27b48SRoberto Vargas         */
198*5629b2b1SRoberto Vargas        . = ALIGN(PAGE_SIZE);
199b1d27b48SRoberto Vargas        __COHERENT_RAM_END__ = .;
200b1d27b48SRoberto Vargas    } >RAM
201b1d27b48SRoberto Vargas#endif
202b1d27b48SRoberto Vargas
203b1d27b48SRoberto Vargas    /*
204b1d27b48SRoberto Vargas     * Define a linker symbol to mark end of the RW memory area for this
205b1d27b48SRoberto Vargas     * image.
206b1d27b48SRoberto Vargas     */
207b1d27b48SRoberto Vargas    __RW_END__ = .;
208b1d27b48SRoberto Vargas    __BL2_END__ = .;
209b1d27b48SRoberto Vargas
2107d173fc5SJiafei Pan#if BL2_IN_XIP_MEM
2117d173fc5SJiafei Pan    __BL2_RAM_START__ = ADDR(.data);
2127d173fc5SJiafei Pan    __BL2_RAM_END__ = .;
2137d173fc5SJiafei Pan
2147d173fc5SJiafei Pan    __DATA_ROM_START__ = LOADADDR(.data);
2157d173fc5SJiafei Pan    __DATA_SIZE__ = SIZEOF(.data);
2167d173fc5SJiafei Pan
2177d173fc5SJiafei Pan    /*
2187d173fc5SJiafei Pan     * The .data section is the last PROGBITS section so its end marks the end
2197d173fc5SJiafei Pan     * of BL2's RO content in XIP memory..
2207d173fc5SJiafei Pan     */
2217d173fc5SJiafei Pan    __BL2_ROM_END__ =  __DATA_ROM_START__ + __DATA_SIZE__;
2227d173fc5SJiafei Pan    ASSERT(__BL2_ROM_END__ <= BL2_RO_LIMIT,
2237d173fc5SJiafei Pan           "BL2's RO content has exceeded its limit.")
2247d173fc5SJiafei Pan#endif
225b1d27b48SRoberto Vargas    __BSS_SIZE__ = SIZEOF(.bss);
226b1d27b48SRoberto Vargas
2277d173fc5SJiafei Pan
228b1d27b48SRoberto Vargas#if USE_COHERENT_MEM
229b1d27b48SRoberto Vargas    __COHERENT_RAM_UNALIGNED_SIZE__ =
230b1d27b48SRoberto Vargas        __COHERENT_RAM_END_UNALIGNED__ - __COHERENT_RAM_START__;
231b1d27b48SRoberto Vargas#endif
232b1d27b48SRoberto Vargas
2337d173fc5SJiafei Pan#if BL2_IN_XIP_MEM
2347d173fc5SJiafei Pan    ASSERT(. <= BL2_RW_LIMIT, "BL2's RW content has exceeded its limit.")
2357d173fc5SJiafei Pan#else
236b1d27b48SRoberto Vargas    ASSERT(. <= BL2_LIMIT, "BL2 image has exceeded its limit.")
2377d173fc5SJiafei Pan#endif
238b1d27b48SRoberto Vargas}
239