xref: /rk3399_ARM-atf/bl2/bl2_el3.ld.S (revision 487d3bf286d73cf5cb9dadb95426b4aed36764ad)
1b1d27b48SRoberto Vargas/*
2b1d27b48SRoberto Vargas * Copyright (c) 2017, 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 {
15b1d27b48SRoberto Vargas    RAM (rwx): ORIGIN = BL2_BASE, LENGTH = BL2_LIMIT - BL2_BASE
16b1d27b48SRoberto Vargas}
17b1d27b48SRoberto Vargas
18b1d27b48SRoberto Vargas
19b1d27b48SRoberto VargasSECTIONS
20b1d27b48SRoberto Vargas{
21b1d27b48SRoberto Vargas    . = BL2_BASE;
22b1d27b48SRoberto Vargas    ASSERT(. == ALIGN(PAGE_SIZE),
23b1d27b48SRoberto Vargas           "BL2_BASE address is not aligned on a page boundary.")
24b1d27b48SRoberto Vargas
25b1d27b48SRoberto Vargas#if SEPARATE_CODE_AND_RODATA
26b1d27b48SRoberto Vargas    .text . : {
27b1d27b48SRoberto Vargas        __TEXT_START__ = .;
28*487d3bf2SRoberto Vargas	__TEXT_RESIDENT_START__ = .;
29b1d27b48SRoberto Vargas	*bl2_el3_entrypoint.o(.text*)
30*487d3bf2SRoberto Vargas	*(.text.asm.*)
31*487d3bf2SRoberto Vargas	__TEXT_RESIDENT_END__ = .;
32b1d27b48SRoberto Vargas        *(.text*)
33b1d27b48SRoberto Vargas        *(.vectors)
34b1d27b48SRoberto Vargas        . = NEXT(PAGE_SIZE);
35b1d27b48SRoberto Vargas        __TEXT_END__ = .;
36b1d27b48SRoberto Vargas     } >RAM
37b1d27b48SRoberto Vargas
38b1d27b48SRoberto Vargas    .rodata . : {
39b1d27b48SRoberto Vargas        __RODATA_START__ = .;
40b1d27b48SRoberto Vargas        *(.rodata*)
41b1d27b48SRoberto Vargas
42b1d27b48SRoberto Vargas        /* Ensure 8-byte alignment for descriptors and ensure inclusion */
43b1d27b48SRoberto Vargas        . = ALIGN(8);
44b1d27b48SRoberto Vargas        __PARSER_LIB_DESCS_START__ = .;
45b1d27b48SRoberto Vargas        KEEP(*(.img_parser_lib_descs))
46b1d27b48SRoberto Vargas        __PARSER_LIB_DESCS_END__ = .;
47b1d27b48SRoberto Vargas
48b1d27b48SRoberto Vargas        /*
49b1d27b48SRoberto Vargas         * Ensure 8-byte alignment for cpu_ops so that its fields are also
50b1d27b48SRoberto Vargas         * aligned. Also ensure cpu_ops inclusion.
51b1d27b48SRoberto Vargas         */
52b1d27b48SRoberto Vargas        . = ALIGN(8);
53b1d27b48SRoberto Vargas        __CPU_OPS_START__ = .;
54b1d27b48SRoberto Vargas        KEEP(*(cpu_ops))
55b1d27b48SRoberto Vargas        __CPU_OPS_END__ = .;
56b1d27b48SRoberto Vargas
57b1d27b48SRoberto Vargas        . = NEXT(PAGE_SIZE);
58b1d27b48SRoberto Vargas        __RODATA_END__ = .;
59b1d27b48SRoberto Vargas    } >RAM
60*487d3bf2SRoberto Vargas
61*487d3bf2SRoberto Vargas    ASSERT(__TEXT_RESIDENT_END__ - __TEXT_RESIDENT_START__ <= PAGE_SIZE,
62*487d3bf2SRoberto Vargas          "Resident part of BL2 has exceeded its limit.")
63b1d27b48SRoberto Vargas#else
64b1d27b48SRoberto Vargas    ro . : {
65b1d27b48SRoberto Vargas        __RO_START__ = .;
66*487d3bf2SRoberto Vargas	__TEXT_RESIDENT_START__ = .;
67b1d27b48SRoberto Vargas	*bl2_el3_entrypoint.o(.text*)
68*487d3bf2SRoberto Vargas	*(.text.asm.*)
69*487d3bf2SRoberto Vargas	__TEXT_RESIDENT_END__ = .;
70b1d27b48SRoberto Vargas        *(.text*)
71b1d27b48SRoberto Vargas        *(.rodata*)
72b1d27b48SRoberto Vargas
73b1d27b48SRoberto Vargas        /*
74b1d27b48SRoberto Vargas         * Ensure 8-byte alignment for cpu_ops so that its fields are also
75b1d27b48SRoberto Vargas         * aligned. Also ensure cpu_ops inclusion.
76b1d27b48SRoberto Vargas         */
77b1d27b48SRoberto Vargas        . = ALIGN(8);
78b1d27b48SRoberto Vargas        __CPU_OPS_START__ = .;
79b1d27b48SRoberto Vargas        KEEP(*(cpu_ops))
80b1d27b48SRoberto Vargas        __CPU_OPS_END__ = .;
81b1d27b48SRoberto Vargas
82b1d27b48SRoberto Vargas        /* Ensure 8-byte alignment for descriptors and ensure inclusion */
83b1d27b48SRoberto Vargas        . = ALIGN(8);
84b1d27b48SRoberto Vargas        __PARSER_LIB_DESCS_START__ = .;
85b1d27b48SRoberto Vargas        KEEP(*(.img_parser_lib_descs))
86b1d27b48SRoberto Vargas        __PARSER_LIB_DESCS_END__ = .;
87b1d27b48SRoberto Vargas
88b1d27b48SRoberto Vargas        *(.vectors)
89b1d27b48SRoberto Vargas        __RO_END_UNALIGNED__ = .;
90b1d27b48SRoberto Vargas        /*
91b1d27b48SRoberto Vargas         * Memory page(s) mapped to this section will be marked as
92b1d27b48SRoberto Vargas         * read-only, executable.  No RW data from the next section must
93b1d27b48SRoberto Vargas         * creep in.  Ensure the rest of the current memory page is unused.
94b1d27b48SRoberto Vargas         */
95b1d27b48SRoberto Vargas        . = NEXT(PAGE_SIZE);
96b1d27b48SRoberto Vargas
97b1d27b48SRoberto Vargas        __RO_END__ = .;
98b1d27b48SRoberto Vargas    } >RAM
99b1d27b48SRoberto Vargas#endif
100b1d27b48SRoberto Vargas
101b1d27b48SRoberto Vargas    ASSERT(__CPU_OPS_END__ > __CPU_OPS_START__,
102b1d27b48SRoberto Vargas          "cpu_ops not defined for this platform.")
103b1d27b48SRoberto Vargas
104b1d27b48SRoberto Vargas    /*
105b1d27b48SRoberto Vargas     * Define a linker symbol to mark start of the RW memory area for this
106b1d27b48SRoberto Vargas     * image.
107b1d27b48SRoberto Vargas     */
108b1d27b48SRoberto Vargas    __RW_START__ = . ;
109b1d27b48SRoberto Vargas
110b1d27b48SRoberto Vargas    /*
111b1d27b48SRoberto Vargas     * .data must be placed at a lower address than the stacks if the stack
112b1d27b48SRoberto Vargas     * protector is enabled. Alternatively, the .data.stack_protector_canary
113b1d27b48SRoberto Vargas     * section can be placed independently of the main .data section.
114b1d27b48SRoberto Vargas     */
115b1d27b48SRoberto Vargas    .data . : {
116b1d27b48SRoberto Vargas        __DATA_START__ = .;
117b1d27b48SRoberto Vargas        *(.data*)
118b1d27b48SRoberto Vargas        __DATA_END__ = .;
119b1d27b48SRoberto Vargas    } >RAM
120b1d27b48SRoberto Vargas
121b1d27b48SRoberto Vargas    stacks (NOLOAD) : {
122b1d27b48SRoberto Vargas        __STACKS_START__ = .;
123b1d27b48SRoberto Vargas        *(tzfw_normal_stacks)
124b1d27b48SRoberto Vargas        __STACKS_END__ = .;
125b1d27b48SRoberto Vargas    } >RAM
126b1d27b48SRoberto Vargas
127b1d27b48SRoberto Vargas    /*
128b1d27b48SRoberto Vargas     * The .bss section gets initialised to 0 at runtime.
129b1d27b48SRoberto Vargas     * Its base address should be 16-byte aligned for better performance of the
130b1d27b48SRoberto Vargas     * zero-initialization code.
131b1d27b48SRoberto Vargas     */
132b1d27b48SRoberto Vargas    .bss : ALIGN(16) {
133b1d27b48SRoberto Vargas        __BSS_START__ = .;
134b1d27b48SRoberto Vargas        *(SORT_BY_ALIGNMENT(.bss*))
135b1d27b48SRoberto Vargas        *(COMMON)
136b1d27b48SRoberto Vargas        __BSS_END__ = .;
137b1d27b48SRoberto Vargas    } >RAM
138b1d27b48SRoberto Vargas
139b1d27b48SRoberto Vargas    /*
140b1d27b48SRoberto Vargas     * The xlat_table section is for full, aligned page tables (4K).
141b1d27b48SRoberto Vargas     * Removing them from .bss avoids forcing 4K alignment on
142b1d27b48SRoberto Vargas     * the .bss section and eliminates the unnecessary zero init
143b1d27b48SRoberto Vargas     */
144b1d27b48SRoberto Vargas    xlat_table (NOLOAD) : {
145b1d27b48SRoberto Vargas        *(xlat_table)
146b1d27b48SRoberto Vargas    } >RAM
147b1d27b48SRoberto Vargas
148b1d27b48SRoberto Vargas#if USE_COHERENT_MEM
149b1d27b48SRoberto Vargas    /*
150b1d27b48SRoberto Vargas     * The base address of the coherent memory section must be page-aligned (4K)
151b1d27b48SRoberto Vargas     * to guarantee that the coherent data are stored on their own pages and
152b1d27b48SRoberto Vargas     * are not mixed with normal data.  This is required to set up the correct
153b1d27b48SRoberto Vargas     * memory attributes for the coherent data page tables.
154b1d27b48SRoberto Vargas     */
155b1d27b48SRoberto Vargas    coherent_ram (NOLOAD) : ALIGN(PAGE_SIZE) {
156b1d27b48SRoberto Vargas        __COHERENT_RAM_START__ = .;
157b1d27b48SRoberto Vargas        *(tzfw_coherent_mem)
158b1d27b48SRoberto Vargas        __COHERENT_RAM_END_UNALIGNED__ = .;
159b1d27b48SRoberto Vargas        /*
160b1d27b48SRoberto Vargas         * Memory page(s) mapped to this section will be marked
161b1d27b48SRoberto Vargas         * as device memory.  No other unexpected data must creep in.
162b1d27b48SRoberto Vargas         * Ensure the rest of the current memory page is unused.
163b1d27b48SRoberto Vargas         */
164b1d27b48SRoberto Vargas        . = NEXT(PAGE_SIZE);
165b1d27b48SRoberto Vargas        __COHERENT_RAM_END__ = .;
166b1d27b48SRoberto Vargas    } >RAM
167b1d27b48SRoberto Vargas#endif
168b1d27b48SRoberto Vargas
169b1d27b48SRoberto Vargas    /*
170b1d27b48SRoberto Vargas     * Define a linker symbol to mark end of the RW memory area for this
171b1d27b48SRoberto Vargas     * image.
172b1d27b48SRoberto Vargas     */
173b1d27b48SRoberto Vargas    __RW_END__ = .;
174b1d27b48SRoberto Vargas    __BL2_END__ = .;
175b1d27b48SRoberto Vargas
176b1d27b48SRoberto Vargas    __BSS_SIZE__ = SIZEOF(.bss);
177b1d27b48SRoberto Vargas
178b1d27b48SRoberto Vargas#if USE_COHERENT_MEM
179b1d27b48SRoberto Vargas    __COHERENT_RAM_UNALIGNED_SIZE__ =
180b1d27b48SRoberto Vargas        __COHERENT_RAM_END_UNALIGNED__ - __COHERENT_RAM_START__;
181b1d27b48SRoberto Vargas#endif
182b1d27b48SRoberto Vargas
183b1d27b48SRoberto Vargas    ASSERT(. <= BL2_LIMIT, "BL2 image has exceeded its limit.")
184b1d27b48SRoberto Vargas}
185