xref: /rk3399_ARM-atf/bl2/bl2.ld.S (revision e21a788ee197ec66f6b8552e2274297bf4a095a8)
1/*
2 * Copyright (c) 2013-2020, ARM Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <platform_def.h>
8
9#include <lib/xlat_tables/xlat_tables_defs.h>
10
11OUTPUT_FORMAT(PLATFORM_LINKER_FORMAT)
12OUTPUT_ARCH(PLATFORM_LINKER_ARCH)
13ENTRY(bl2_entrypoint)
14
15MEMORY {
16    RAM (rwx): ORIGIN = BL2_BASE, LENGTH = BL2_LIMIT - BL2_BASE
17}
18
19
20SECTIONS
21{
22    . = BL2_BASE;
23    ASSERT(. == ALIGN(PAGE_SIZE),
24           "BL2_BASE address is not aligned on a page boundary.")
25
26#if SEPARATE_CODE_AND_RODATA
27    .text . : {
28        __TEXT_START__ = .;
29        *bl2_entrypoint.o(.text*)
30        *(SORT_BY_ALIGNMENT(.text*))
31        *(.vectors)
32        . = ALIGN(PAGE_SIZE);
33        __TEXT_END__ = .;
34     } >RAM
35
36     /* .ARM.extab and .ARM.exidx are only added because Clang need them */
37     .ARM.extab . : {
38        *(.ARM.extab* .gnu.linkonce.armextab.*)
39     } >RAM
40
41     .ARM.exidx . : {
42        *(.ARM.exidx* .gnu.linkonce.armexidx.*)
43     } >RAM
44
45    .rodata . : {
46        __RODATA_START__ = .;
47        *(SORT_BY_ALIGNMENT(.rodata*))
48
49       . = ALIGN(8);
50        __FCONF_POPULATOR_START__ = .;
51        KEEP(*(.fconf_populator))
52        __FCONF_POPULATOR_END__ = .;
53
54        /* Ensure 8-byte alignment for descriptors and ensure inclusion */
55        . = ALIGN(8);
56        __PARSER_LIB_DESCS_START__ = .;
57        KEEP(*(.img_parser_lib_descs))
58        __PARSER_LIB_DESCS_END__ = .;
59
60        . = ALIGN(PAGE_SIZE);
61        __RODATA_END__ = .;
62    } >RAM
63#else
64    ro . : {
65        __RO_START__ = .;
66        *bl2_entrypoint.o(.text*)
67        *(SORT_BY_ALIGNMENT(.text*))
68        *(SORT_BY_ALIGNMENT(.rodata*))
69
70	. = ALIGN(8);
71         __FCONF_POPULATOR_START__ = .;
72         KEEP(*(.fconf_populator))
73         __FCONF_POPULATOR_END__ = .;
74
75        /* Ensure 8-byte alignment for descriptors and ensure inclusion */
76        . = ALIGN(8);
77        __PARSER_LIB_DESCS_START__ = .;
78        KEEP(*(.img_parser_lib_descs))
79        __PARSER_LIB_DESCS_END__ = .;
80
81        *(.vectors)
82        __RO_END_UNALIGNED__ = .;
83        /*
84         * Memory page(s) mapped to this section will be marked as
85         * read-only, executable.  No RW data from the next section must
86         * creep in.  Ensure the rest of the current memory page is unused.
87         */
88        . = ALIGN(PAGE_SIZE);
89        __RO_END__ = .;
90    } >RAM
91#endif
92
93    /*
94     * Define a linker symbol to mark start of the RW memory area for this
95     * image.
96     */
97    __RW_START__ = . ;
98
99    /*
100     * .data must be placed at a lower address than the stacks if the stack
101     * protector is enabled. Alternatively, the .data.stack_protector_canary
102     * section can be placed independently of the main .data section.
103     */
104    .data . : {
105        __DATA_START__ = .;
106        *(SORT_BY_ALIGNMENT(.data*))
107        __DATA_END__ = .;
108    } >RAM
109
110    stacks (NOLOAD) : {
111        __STACKS_START__ = .;
112        *(tzfw_normal_stacks)
113        __STACKS_END__ = .;
114    } >RAM
115
116    /*
117     * The .bss section gets initialised to 0 at runtime.
118     * Its base address should be 16-byte aligned for better performance of the
119     * zero-initialization code.
120     */
121    .bss : ALIGN(16) {
122        __BSS_START__ = .;
123        *(SORT_BY_ALIGNMENT(.bss*))
124        *(COMMON)
125        __BSS_END__ = .;
126    } >RAM
127
128    /*
129     * The xlat_table section is for full, aligned page tables (4K).
130     * Removing them from .bss avoids forcing 4K alignment on
131     * the .bss section. The tables are initialized to zero by the translation
132     * tables library.
133     */
134    xlat_table (NOLOAD) : {
135        *(xlat_table)
136    } >RAM
137
138#if USE_COHERENT_MEM
139    /*
140     * The base address of the coherent memory section must be page-aligned (4K)
141     * to guarantee that the coherent data are stored on their own pages and
142     * are not mixed with normal data.  This is required to set up the correct
143     * memory attributes for the coherent data page tables.
144     */
145    coherent_ram (NOLOAD) : ALIGN(PAGE_SIZE) {
146        __COHERENT_RAM_START__ = .;
147        *(tzfw_coherent_mem)
148        __COHERENT_RAM_END_UNALIGNED__ = .;
149        /*
150         * Memory page(s) mapped to this section will be marked
151         * as device memory.  No other unexpected data must creep in.
152         * Ensure the rest of the current memory page is unused.
153         */
154        . = ALIGN(PAGE_SIZE);
155        __COHERENT_RAM_END__ = .;
156    } >RAM
157#endif
158
159    /*
160     * Define a linker symbol to mark end of the RW memory area for this
161     * image.
162     */
163    __RW_END__ = .;
164    __BL2_END__ = .;
165
166    __BSS_SIZE__ = SIZEOF(.bss);
167
168#if USE_COHERENT_MEM
169    __COHERENT_RAM_UNALIGNED_SIZE__ =
170        __COHERENT_RAM_END_UNALIGNED__ - __COHERENT_RAM_START__;
171#endif
172
173    ASSERT(. <= BL2_LIMIT, "BL2 image has exceeded its limit.")
174}
175