xref: /rk3399_ARM-atf/bl2/bl2_el3.ld.S (revision e8ad6168b0153e09f1a54ee887555db7833019df)
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
560a0a7a9aSMasahiro 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
740a0a7a9aSMasahiro 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
104caa3e7e0SMasahiro Yamada    DATA_SECTION >RAM AT>ROM
105caa3e7e0SMasahiro Yamada    __DATA_RAM_START__ = __DATA_START__;
106caa3e7e0SMasahiro Yamada    __DATA_RAM_END__ = __DATA_END__;
107b1d27b48SRoberto Vargas
108*e8ad6168SMasahiro Yamada    RELA_SECTION >RAM
109a926a9f6SMasahiro Yamada    STACK_SECTION >RAM
110a7739bc7SMasahiro Yamada    BSS_SECTION >RAM
111665e71b8SMasahiro Yamada    XLAT_TABLE_SECTION >RAM
112b1d27b48SRoberto Vargas
113b1d27b48SRoberto Vargas#if USE_COHERENT_MEM
114b1d27b48SRoberto Vargas    /*
115b1d27b48SRoberto Vargas     * The base address of the coherent memory section must be page-aligned (4K)
116b1d27b48SRoberto Vargas     * to guarantee that the coherent data are stored on their own pages and
117b1d27b48SRoberto Vargas     * are not mixed with normal data.  This is required to set up the correct
118b1d27b48SRoberto Vargas     * memory attributes for the coherent data page tables.
119b1d27b48SRoberto Vargas     */
120b1d27b48SRoberto Vargas    coherent_ram (NOLOAD) : ALIGN(PAGE_SIZE) {
121b1d27b48SRoberto Vargas        __COHERENT_RAM_START__ = .;
122b1d27b48SRoberto Vargas        *(tzfw_coherent_mem)
123b1d27b48SRoberto Vargas        __COHERENT_RAM_END_UNALIGNED__ = .;
124b1d27b48SRoberto Vargas        /*
125b1d27b48SRoberto Vargas         * Memory page(s) mapped to this section will be marked
126b1d27b48SRoberto Vargas         * as device memory.  No other unexpected data must creep in.
127b1d27b48SRoberto Vargas         * Ensure the rest of the current memory page is unused.
128b1d27b48SRoberto Vargas         */
1295629b2b1SRoberto Vargas        . = ALIGN(PAGE_SIZE);
130b1d27b48SRoberto Vargas        __COHERENT_RAM_END__ = .;
131b1d27b48SRoberto Vargas    } >RAM
132b1d27b48SRoberto Vargas#endif
133b1d27b48SRoberto Vargas
134b1d27b48SRoberto Vargas    /*
135b1d27b48SRoberto Vargas     * Define a linker symbol to mark end of the RW memory area for this
136b1d27b48SRoberto Vargas     * image.
137b1d27b48SRoberto Vargas     */
138b1d27b48SRoberto Vargas    __RW_END__ = .;
139b1d27b48SRoberto Vargas    __BL2_END__ = .;
140b1d27b48SRoberto Vargas
14169af7fcfSMasahiro Yamada    /DISCARD/ : {
14269af7fcfSMasahiro Yamada        *(.dynsym .dynstr .hash .gnu.hash)
14369af7fcfSMasahiro Yamada    }
14469af7fcfSMasahiro Yamada
1457d173fc5SJiafei Pan#if BL2_IN_XIP_MEM
1467d173fc5SJiafei Pan    __BL2_RAM_START__ = ADDR(.data);
1477d173fc5SJiafei Pan    __BL2_RAM_END__ = .;
1487d173fc5SJiafei Pan
1497d173fc5SJiafei Pan    __DATA_ROM_START__ = LOADADDR(.data);
1507d173fc5SJiafei Pan    __DATA_SIZE__ = SIZEOF(.data);
1517d173fc5SJiafei Pan
1527d173fc5SJiafei Pan    /*
1537d173fc5SJiafei Pan     * The .data section is the last PROGBITS section so its end marks the end
1547d173fc5SJiafei Pan     * of BL2's RO content in XIP memory..
1557d173fc5SJiafei Pan     */
1567d173fc5SJiafei Pan    __BL2_ROM_END__ =  __DATA_ROM_START__ + __DATA_SIZE__;
1577d173fc5SJiafei Pan    ASSERT(__BL2_ROM_END__ <= BL2_RO_LIMIT,
1587d173fc5SJiafei Pan           "BL2's RO content has exceeded its limit.")
1597d173fc5SJiafei Pan#endif
160b1d27b48SRoberto Vargas    __BSS_SIZE__ = SIZEOF(.bss);
161b1d27b48SRoberto Vargas
1627d173fc5SJiafei Pan
163b1d27b48SRoberto Vargas#if USE_COHERENT_MEM
164b1d27b48SRoberto Vargas    __COHERENT_RAM_UNALIGNED_SIZE__ =
165b1d27b48SRoberto Vargas        __COHERENT_RAM_END_UNALIGNED__ - __COHERENT_RAM_START__;
166b1d27b48SRoberto Vargas#endif
167b1d27b48SRoberto Vargas
1687d173fc5SJiafei Pan#if BL2_IN_XIP_MEM
1697d173fc5SJiafei Pan    ASSERT(. <= BL2_RW_LIMIT, "BL2's RW content has exceeded its limit.")
1707d173fc5SJiafei Pan#else
171b1d27b48SRoberto Vargas    ASSERT(. <= BL2_LIMIT, "BL2 image has exceeded its limit.")
1727d173fc5SJiafei Pan#endif
173b1d27b48SRoberto Vargas}
174