xref: /rk3399_ARM-atf/bl2/bl2_el3.ld.S (revision caa3e7e0a4aeb657873bbd2c002c0e33a614eb1d)
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
104*caa3e7e0SMasahiro Yamada    DATA_SECTION >RAM AT>ROM
105*caa3e7e0SMasahiro Yamada    __DATA_RAM_START__ = __DATA_START__;
106*caa3e7e0SMasahiro Yamada    __DATA_RAM_END__ = __DATA_END__;
107b1d27b48SRoberto Vargas
10869af7fcfSMasahiro Yamada    /*
10969af7fcfSMasahiro Yamada     * .rela.dyn needs to come after .data for the read-elf utility to parse
11069af7fcfSMasahiro Yamada     * this section correctly. Ensure 8-byte alignment so that the fields of
11169af7fcfSMasahiro Yamada     * RELA data structure are aligned.
11269af7fcfSMasahiro Yamada     */
11369af7fcfSMasahiro Yamada    . = ALIGN(8);
11469af7fcfSMasahiro Yamada    __RELA_START__ = .;
11569af7fcfSMasahiro Yamada    .rela.dyn . : {
11669af7fcfSMasahiro Yamada    } >RAM
11769af7fcfSMasahiro Yamada    __RELA_END__ = .;
11869af7fcfSMasahiro Yamada
119a926a9f6SMasahiro Yamada    STACK_SECTION >RAM
120a7739bc7SMasahiro Yamada    BSS_SECTION >RAM
121665e71b8SMasahiro Yamada    XLAT_TABLE_SECTION >RAM
122b1d27b48SRoberto Vargas
123b1d27b48SRoberto Vargas#if USE_COHERENT_MEM
124b1d27b48SRoberto Vargas    /*
125b1d27b48SRoberto Vargas     * The base address of the coherent memory section must be page-aligned (4K)
126b1d27b48SRoberto Vargas     * to guarantee that the coherent data are stored on their own pages and
127b1d27b48SRoberto Vargas     * are not mixed with normal data.  This is required to set up the correct
128b1d27b48SRoberto Vargas     * memory attributes for the coherent data page tables.
129b1d27b48SRoberto Vargas     */
130b1d27b48SRoberto Vargas    coherent_ram (NOLOAD) : ALIGN(PAGE_SIZE) {
131b1d27b48SRoberto Vargas        __COHERENT_RAM_START__ = .;
132b1d27b48SRoberto Vargas        *(tzfw_coherent_mem)
133b1d27b48SRoberto Vargas        __COHERENT_RAM_END_UNALIGNED__ = .;
134b1d27b48SRoberto Vargas        /*
135b1d27b48SRoberto Vargas         * Memory page(s) mapped to this section will be marked
136b1d27b48SRoberto Vargas         * as device memory.  No other unexpected data must creep in.
137b1d27b48SRoberto Vargas         * Ensure the rest of the current memory page is unused.
138b1d27b48SRoberto Vargas         */
1395629b2b1SRoberto Vargas        . = ALIGN(PAGE_SIZE);
140b1d27b48SRoberto Vargas        __COHERENT_RAM_END__ = .;
141b1d27b48SRoberto Vargas    } >RAM
142b1d27b48SRoberto Vargas#endif
143b1d27b48SRoberto Vargas
144b1d27b48SRoberto Vargas    /*
145b1d27b48SRoberto Vargas     * Define a linker symbol to mark end of the RW memory area for this
146b1d27b48SRoberto Vargas     * image.
147b1d27b48SRoberto Vargas     */
148b1d27b48SRoberto Vargas    __RW_END__ = .;
149b1d27b48SRoberto Vargas    __BL2_END__ = .;
150b1d27b48SRoberto Vargas
15169af7fcfSMasahiro Yamada    /DISCARD/ : {
15269af7fcfSMasahiro Yamada        *(.dynsym .dynstr .hash .gnu.hash)
15369af7fcfSMasahiro Yamada    }
15469af7fcfSMasahiro Yamada
1557d173fc5SJiafei Pan#if BL2_IN_XIP_MEM
1567d173fc5SJiafei Pan    __BL2_RAM_START__ = ADDR(.data);
1577d173fc5SJiafei Pan    __BL2_RAM_END__ = .;
1587d173fc5SJiafei Pan
1597d173fc5SJiafei Pan    __DATA_ROM_START__ = LOADADDR(.data);
1607d173fc5SJiafei Pan    __DATA_SIZE__ = SIZEOF(.data);
1617d173fc5SJiafei Pan
1627d173fc5SJiafei Pan    /*
1637d173fc5SJiafei Pan     * The .data section is the last PROGBITS section so its end marks the end
1647d173fc5SJiafei Pan     * of BL2's RO content in XIP memory..
1657d173fc5SJiafei Pan     */
1667d173fc5SJiafei Pan    __BL2_ROM_END__ =  __DATA_ROM_START__ + __DATA_SIZE__;
1677d173fc5SJiafei Pan    ASSERT(__BL2_ROM_END__ <= BL2_RO_LIMIT,
1687d173fc5SJiafei Pan           "BL2's RO content has exceeded its limit.")
1697d173fc5SJiafei Pan#endif
170b1d27b48SRoberto Vargas    __BSS_SIZE__ = SIZEOF(.bss);
171b1d27b48SRoberto Vargas
1727d173fc5SJiafei Pan
173b1d27b48SRoberto Vargas#if USE_COHERENT_MEM
174b1d27b48SRoberto Vargas    __COHERENT_RAM_UNALIGNED_SIZE__ =
175b1d27b48SRoberto Vargas        __COHERENT_RAM_END_UNALIGNED__ - __COHERENT_RAM_START__;
176b1d27b48SRoberto Vargas#endif
177b1d27b48SRoberto Vargas
1787d173fc5SJiafei Pan#if BL2_IN_XIP_MEM
1797d173fc5SJiafei Pan    ASSERT(. <= BL2_RW_LIMIT, "BL2's RW content has exceeded its limit.")
1807d173fc5SJiafei Pan#else
181b1d27b48SRoberto Vargas    ASSERT(. <= BL2_LIMIT, "BL2 image has exceeded its limit.")
1827d173fc5SJiafei Pan#endif
183b1d27b48SRoberto Vargas}
184