xref: /rk3399_ARM-atf/bl2/bl2_el3.ld.S (revision f90fe02f061b8a203391e566682221396b656c6f)
1b1d27b48SRoberto Vargas/*
296a8ed14SJiafei Pan * Copyright (c) 2017-2022, 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
18*f90fe02fSChris Kay#else /* BL2_IN_XIP_MEM */
19b1d27b48SRoberto Vargas    RAM (rwx): ORIGIN = BL2_BASE, LENGTH = BL2_LIMIT - BL2_BASE
20*f90fe02fSChris Kay#endif /* BL2_IN_XIP_MEM */
21*f90fe02fSChris Kay
2296a8ed14SJiafei Pan#if SEPARATE_BL2_NOLOAD_REGION
2396a8ed14SJiafei Pan    RAM_NOLOAD (rw!a): ORIGIN = BL2_NOLOAD_START, LENGTH = BL2_NOLOAD_LIMIT - BL2_NOLOAD_START
24*f90fe02fSChris Kay#else /* SEPARATE_BL2_NOLOAD_REGION */
2596a8ed14SJiafei Pan#   define RAM_NOLOAD RAM
26*f90fe02fSChris Kay#endif /* SEPARATE_BL2_NOLOAD_REGION */
27b1d27b48SRoberto Vargas}
28b1d27b48SRoberto Vargas
292f6f00dcSMasahiro Yamada#if !BL2_IN_XIP_MEM
302f6f00dcSMasahiro Yamada#   define ROM RAM
31*f90fe02fSChris Kay#endif /* !BL2_IN_XIP_MEM */
32b1d27b48SRoberto Vargas
33*f90fe02fSChris KaySECTIONS {
347d173fc5SJiafei Pan#if BL2_IN_XIP_MEM
357d173fc5SJiafei Pan    . = BL2_RO_BASE;
36*f90fe02fSChris Kay
377d173fc5SJiafei Pan    ASSERT(. == ALIGN(PAGE_SIZE),
387d173fc5SJiafei Pan        "BL2_RO_BASE address is not aligned on a page boundary.")
39*f90fe02fSChris Kay#else /* BL2_IN_XIP_MEM */
40b1d27b48SRoberto Vargas    . = BL2_BASE;
41*f90fe02fSChris Kay
42b1d27b48SRoberto Vargas    ASSERT(. == ALIGN(PAGE_SIZE),
43b1d27b48SRoberto Vargas        "BL2_BASE address is not aligned on a page boundary.")
44*f90fe02fSChris Kay#endif /* BL2_IN_XIP_MEM */
45b1d27b48SRoberto Vargas
46b1d27b48SRoberto Vargas#if SEPARATE_CODE_AND_RODATA
47b1d27b48SRoberto Vargas    .text . : {
48b1d27b48SRoberto Vargas        __TEXT_START__ = .;
49487d3bf2SRoberto Vargas        __TEXT_RESIDENT_START__ = .;
50*f90fe02fSChris Kay
51b1d27b48SRoberto Vargas        *bl2_el3_entrypoint.o(.text*)
52487d3bf2SRoberto Vargas        *(.text.asm.*)
53*f90fe02fSChris Kay
54487d3bf2SRoberto Vargas        __TEXT_RESIDENT_END__ = .;
55*f90fe02fSChris Kay
56ebd6efaeSSamuel Holland        *(SORT_BY_ALIGNMENT(.text*))
57b1d27b48SRoberto Vargas        *(.vectors)
58*f90fe02fSChris Kay
595629b2b1SRoberto Vargas        . = ALIGN(PAGE_SIZE);
60*f90fe02fSChris Kay
61b1d27b48SRoberto Vargas        __TEXT_END__ = .;
627d173fc5SJiafei Pan    } >ROM
63b1d27b48SRoberto Vargas
64b1d27b48SRoberto Vargas    .rodata . : {
65b1d27b48SRoberto Vargas        __RODATA_START__ = .;
66*f90fe02fSChris Kay
67ebd6efaeSSamuel Holland        *(SORT_BY_ALIGNMENT(.rodata*))
68b1d27b48SRoberto Vargas
690a0a7a9aSMasahiro Yamada        RODATA_COMMON
7069af7fcfSMasahiro Yamada
715629b2b1SRoberto Vargas        . = ALIGN(PAGE_SIZE);
72*f90fe02fSChris Kay
73b1d27b48SRoberto Vargas        __RODATA_END__ = .;
747d173fc5SJiafei Pan    } >ROM
75487d3bf2SRoberto Vargas
76487d3bf2SRoberto Vargas    ASSERT(__TEXT_RESIDENT_END__ - __TEXT_RESIDENT_START__ <= PAGE_SIZE,
77487d3bf2SRoberto Vargas        "Resident part of BL2 has exceeded its limit.")
78*f90fe02fSChris Kay#else /* SEPARATE_CODE_AND_RODATA */
79b1d27b48SRoberto Vargas    ro . : {
80b1d27b48SRoberto Vargas        __RO_START__ = .;
81487d3bf2SRoberto Vargas        __TEXT_RESIDENT_START__ = .;
82*f90fe02fSChris Kay
83b1d27b48SRoberto Vargas        *bl2_el3_entrypoint.o(.text*)
84487d3bf2SRoberto Vargas        *(.text.asm.*)
85*f90fe02fSChris Kay
86487d3bf2SRoberto Vargas        __TEXT_RESIDENT_END__ = .;
87*f90fe02fSChris Kay
88ebd6efaeSSamuel Holland        *(SORT_BY_ALIGNMENT(.text*))
89ebd6efaeSSamuel Holland        *(SORT_BY_ALIGNMENT(.rodata*))
90b1d27b48SRoberto Vargas
910a0a7a9aSMasahiro Yamada        RODATA_COMMON
9269af7fcfSMasahiro Yamada
93b1d27b48SRoberto Vargas        *(.vectors)
94*f90fe02fSChris Kay
95b1d27b48SRoberto Vargas        __RO_END_UNALIGNED__ = .;
96*f90fe02fSChris Kay
97b1d27b48SRoberto Vargas        /*
98*f90fe02fSChris Kay         * Memory page(s) mapped to this section will be marked as read-only,
99*f90fe02fSChris Kay         * executable. No RW data from the next section must creep in. Ensure
100*f90fe02fSChris Kay         * that the rest of the current memory page is unused.
101b1d27b48SRoberto Vargas         */
1025629b2b1SRoberto Vargas        . = ALIGN(PAGE_SIZE);
103b1d27b48SRoberto Vargas
104b1d27b48SRoberto Vargas        __RO_END__ = .;
1057d173fc5SJiafei Pan    } >ROM
106*f90fe02fSChris Kay#endif /* SEPARATE_CODE_AND_RODATA */
107b1d27b48SRoberto Vargas
108b1d27b48SRoberto Vargas    ASSERT(__CPU_OPS_END__ > __CPU_OPS_START__,
109b1d27b48SRoberto Vargas        "cpu_ops not defined for this platform.")
110b1d27b48SRoberto Vargas
1117d173fc5SJiafei Pan#if BL2_IN_XIP_MEM
1127d173fc5SJiafei Pan    . = BL2_RW_BASE;
113*f90fe02fSChris Kay
1147d173fc5SJiafei Pan    ASSERT(BL2_RW_BASE == ALIGN(PAGE_SIZE),
1157d173fc5SJiafei Pan           "BL2_RW_BASE address is not aligned on a page boundary.")
116*f90fe02fSChris Kay#endif /* BL2_IN_XIP_MEM */
1177d173fc5SJiafei Pan
118b1d27b48SRoberto Vargas    __RW_START__ = .;
119b1d27b48SRoberto Vargas
120caa3e7e0SMasahiro Yamada    DATA_SECTION >RAM AT>ROM
121*f90fe02fSChris Kay
122caa3e7e0SMasahiro Yamada    __DATA_RAM_START__ = __DATA_START__;
123caa3e7e0SMasahiro Yamada    __DATA_RAM_END__ = __DATA_END__;
124b1d27b48SRoberto Vargas
125e8ad6168SMasahiro Yamada    RELA_SECTION >RAM
126*f90fe02fSChris Kay
12796a8ed14SJiafei Pan#if SEPARATE_BL2_NOLOAD_REGION
12896a8ed14SJiafei Pan    SAVED_ADDR = .;
129*f90fe02fSChris Kay
13096a8ed14SJiafei Pan    . = BL2_NOLOAD_START;
131*f90fe02fSChris Kay
13296a8ed14SJiafei Pan    __BL2_NOLOAD_START__ = .;
133*f90fe02fSChris Kay#endif /* SEPARATE_BL2_NOLOAD_REGION */
134*f90fe02fSChris Kay
13596a8ed14SJiafei Pan    STACK_SECTION >RAM_NOLOAD
13696a8ed14SJiafei Pan    BSS_SECTION >RAM_NOLOAD
13796a8ed14SJiafei Pan    XLAT_TABLE_SECTION >RAM_NOLOAD
138*f90fe02fSChris Kay
13996a8ed14SJiafei Pan#if SEPARATE_BL2_NOLOAD_REGION
14096a8ed14SJiafei Pan    __BL2_NOLOAD_END__ = .;
141*f90fe02fSChris Kay
14296a8ed14SJiafei Pan    . = SAVED_ADDR;
143*f90fe02fSChris Kay#endif /* SEPARATE_BL2_NOLOAD_REGION */
144b1d27b48SRoberto Vargas
145b1d27b48SRoberto Vargas#if USE_COHERENT_MEM
146b1d27b48SRoberto Vargas    /*
147*f90fe02fSChris Kay     * The base address of the coherent memory section must be page-aligned to
148*f90fe02fSChris Kay     * guarantee that the coherent data are stored on their own pages and are
149*f90fe02fSChris Kay     * not mixed with normal data.  This is required to set up the correct
150b1d27b48SRoberto Vargas     * memory attributes for the coherent data page tables.
151b1d27b48SRoberto Vargas     */
152b1d27b48SRoberto Vargas    coherent_ram (NOLOAD) : ALIGN(PAGE_SIZE) {
153b1d27b48SRoberto Vargas        __COHERENT_RAM_START__ = .;
154*f90fe02fSChris Kay
155b1d27b48SRoberto Vargas        *(tzfw_coherent_mem)
156*f90fe02fSChris Kay
157b1d27b48SRoberto Vargas        __COHERENT_RAM_END_UNALIGNED__ = .;
158b1d27b48SRoberto Vargas
159b1d27b48SRoberto Vargas        /*
160*f90fe02fSChris Kay         * Memory page(s) mapped to this section will be marked as device
161*f90fe02fSChris Kay         * memory. No other unexpected data must creep in. Ensure the rest of
162*f90fe02fSChris Kay         * the current memory page is unused.
163b1d27b48SRoberto Vargas         */
164*f90fe02fSChris Kay        . = ALIGN(PAGE_SIZE);
165*f90fe02fSChris Kay
166*f90fe02fSChris Kay        __COHERENT_RAM_END__ = .;
167*f90fe02fSChris Kay    } >RAM
168*f90fe02fSChris Kay#endif /* USE_COHERENT_MEM */
169*f90fe02fSChris Kay
170b1d27b48SRoberto Vargas    __RW_END__ = .;
171b1d27b48SRoberto Vargas    __BL2_END__ = .;
172b1d27b48SRoberto Vargas
17369af7fcfSMasahiro Yamada    /DISCARD/ : {
17469af7fcfSMasahiro Yamada        *(.dynsym .dynstr .hash .gnu.hash)
17569af7fcfSMasahiro Yamada    }
17669af7fcfSMasahiro Yamada
1777d173fc5SJiafei Pan#if BL2_IN_XIP_MEM
1787d173fc5SJiafei Pan    __BL2_RAM_START__ = ADDR(.data);
1797d173fc5SJiafei Pan    __BL2_RAM_END__ = .;
1807d173fc5SJiafei Pan
1817d173fc5SJiafei Pan    __DATA_ROM_START__ = LOADADDR(.data);
1827d173fc5SJiafei Pan    __DATA_SIZE__ = SIZEOF(.data);
1837d173fc5SJiafei Pan
1847d173fc5SJiafei Pan    /*
1857d173fc5SJiafei Pan     * The .data section is the last PROGBITS section so its end marks the end
186*f90fe02fSChris Kay     * of BL2's RO content in XIP memory.
1877d173fc5SJiafei Pan     */
1887d173fc5SJiafei Pan    __BL2_ROM_END__ =  __DATA_ROM_START__ + __DATA_SIZE__;
189*f90fe02fSChris Kay
1907d173fc5SJiafei Pan    ASSERT(__BL2_ROM_END__ <= BL2_RO_LIMIT,
1917d173fc5SJiafei Pan           "BL2's RO content has exceeded its limit.")
192*f90fe02fSChris Kay#endif /* BL2_IN_XIP_MEM */
193b1d27b48SRoberto Vargas
194*f90fe02fSChris Kay    __BSS_SIZE__ = SIZEOF(.bss);
1957d173fc5SJiafei Pan
196b1d27b48SRoberto Vargas#if USE_COHERENT_MEM
197b1d27b48SRoberto Vargas    __COHERENT_RAM_UNALIGNED_SIZE__ =
198b1d27b48SRoberto Vargas        __COHERENT_RAM_END_UNALIGNED__ - __COHERENT_RAM_START__;
199*f90fe02fSChris Kay#endif /* USE_COHERENT_MEM */
200b1d27b48SRoberto Vargas
2017d173fc5SJiafei Pan#if BL2_IN_XIP_MEM
2027d173fc5SJiafei Pan    ASSERT(. <= BL2_RW_LIMIT, "BL2's RW content has exceeded its limit.")
203*f90fe02fSChris Kay#else /* BL2_IN_XIP_MEM */
204b1d27b48SRoberto Vargas    ASSERT(. <= BL2_LIMIT, "BL2 image has exceeded its limit.")
205*f90fe02fSChris Kay#endif /* BL2_IN_XIP_MEM */
206b1d27b48SRoberto Vargas}
207