xref: /rk3399_ARM-atf/bl2/bl2.ld.S (revision 09d40e0e08283a249e7dce0e106c07c5141f9b7e)
14f6ad66aSAchin Gupta/*
2883d1b5dSAntonio Nino Diaz * Copyright (c) 2013-2018, ARM Limited and Contributors. All rights reserved.
34f6ad66aSAchin Gupta *
482cb2c1aSdp-arm * SPDX-License-Identifier: BSD-3-Clause
54f6ad66aSAchin Gupta */
64f6ad66aSAchin Gupta
75f0cdb05SDan Handley#include <platform_def.h>
8*09d40e0eSAntonio Nino Diaz
9*09d40e0eSAntonio Nino Diaz#include <lib/xlat_tables/xlat_tables_defs.h>
104f6ad66aSAchin Gupta
114f6ad66aSAchin GuptaOUTPUT_FORMAT(PLATFORM_LINKER_FORMAT)
124f6ad66aSAchin GuptaOUTPUT_ARCH(PLATFORM_LINKER_ARCH)
139f98aa1aSJeenu ViswambharanENTRY(bl2_entrypoint)
144f6ad66aSAchin Gupta
154f6ad66aSAchin GuptaMEMORY {
16d7fbf132SJuan Castillo    RAM (rwx): ORIGIN = BL2_BASE, LENGTH = BL2_LIMIT - BL2_BASE
174f6ad66aSAchin Gupta}
184f6ad66aSAchin Gupta
194f6ad66aSAchin Gupta
204f6ad66aSAchin GuptaSECTIONS
214f6ad66aSAchin Gupta{
224f6ad66aSAchin Gupta    . = BL2_BASE;
23a2aedac2SAntonio Nino Diaz    ASSERT(. == ALIGN(PAGE_SIZE),
248d69a03fSSandrine Bailleux           "BL2_BASE address is not aligned on a page boundary.")
254f6ad66aSAchin Gupta
265d1c104fSSandrine Bailleux#if SEPARATE_CODE_AND_RODATA
275d1c104fSSandrine Bailleux    .text . : {
285d1c104fSSandrine Bailleux        __TEXT_START__ = .;
295d1c104fSSandrine Bailleux        *bl2_entrypoint.o(.text*)
305d1c104fSSandrine Bailleux        *(.text*)
315d1c104fSSandrine Bailleux        *(.vectors)
325629b2b1SRoberto Vargas        . = ALIGN(PAGE_SIZE);
335d1c104fSSandrine Bailleux        __TEXT_END__ = .;
345d1c104fSSandrine Bailleux     } >RAM
355d1c104fSSandrine Bailleux
36ad925094SRoberto Vargas     /* .ARM.extab and .ARM.exidx are only added because Clang need them */
37ad925094SRoberto Vargas     .ARM.extab . : {
38ad925094SRoberto Vargas        *(.ARM.extab* .gnu.linkonce.armextab.*)
39ad925094SRoberto Vargas     } >RAM
40ad925094SRoberto Vargas
41ad925094SRoberto Vargas     .ARM.exidx . : {
42ad925094SRoberto Vargas        *(.ARM.exidx* .gnu.linkonce.armexidx.*)
43ad925094SRoberto Vargas     } >RAM
44ad925094SRoberto Vargas
455d1c104fSSandrine Bailleux    .rodata . : {
465d1c104fSSandrine Bailleux        __RODATA_START__ = .;
475d1c104fSSandrine Bailleux        *(.rodata*)
485d1c104fSSandrine Bailleux
495d1c104fSSandrine Bailleux        /* Ensure 8-byte alignment for descriptors and ensure inclusion */
505d1c104fSSandrine Bailleux        . = ALIGN(8);
515d1c104fSSandrine Bailleux        __PARSER_LIB_DESCS_START__ = .;
525d1c104fSSandrine Bailleux        KEEP(*(.img_parser_lib_descs))
535d1c104fSSandrine Bailleux        __PARSER_LIB_DESCS_END__ = .;
545d1c104fSSandrine Bailleux
555629b2b1SRoberto Vargas        . = ALIGN(PAGE_SIZE);
565d1c104fSSandrine Bailleux        __RODATA_END__ = .;
575d1c104fSSandrine Bailleux    } >RAM
585d1c104fSSandrine Bailleux#else
598d69a03fSSandrine Bailleux    ro . : {
608d69a03fSSandrine Bailleux        __RO_START__ = .;
61dccc537aSAndrew Thoelke        *bl2_entrypoint.o(.text*)
62dccc537aSAndrew Thoelke        *(.text*)
638d69a03fSSandrine Bailleux        *(.rodata*)
6405799ae0SJuan Castillo
6505799ae0SJuan Castillo        /* Ensure 8-byte alignment for descriptors and ensure inclusion */
6605799ae0SJuan Castillo        . = ALIGN(8);
6705799ae0SJuan Castillo        __PARSER_LIB_DESCS_START__ = .;
6805799ae0SJuan Castillo        KEEP(*(.img_parser_lib_descs))
6905799ae0SJuan Castillo        __PARSER_LIB_DESCS_END__ = .;
7005799ae0SJuan Castillo
71b739f22aSAchin Gupta        *(.vectors)
728d69a03fSSandrine Bailleux        __RO_END_UNALIGNED__ = .;
738d69a03fSSandrine Bailleux        /*
748d69a03fSSandrine Bailleux         * Memory page(s) mapped to this section will be marked as
758d69a03fSSandrine Bailleux         * read-only, executable.  No RW data from the next section must
768d69a03fSSandrine Bailleux         * creep in.  Ensure the rest of the current memory page is unused.
778d69a03fSSandrine Bailleux         */
785629b2b1SRoberto Vargas        . = ALIGN(PAGE_SIZE);
798d69a03fSSandrine Bailleux        __RO_END__ = .;
804f6ad66aSAchin Gupta    } >RAM
815d1c104fSSandrine Bailleux#endif
824f6ad66aSAchin Gupta
8354dc71e7SAchin Gupta    /*
8454dc71e7SAchin Gupta     * Define a linker symbol to mark start of the RW memory area for this
8554dc71e7SAchin Gupta     * image.
8654dc71e7SAchin Gupta     */
8754dc71e7SAchin Gupta    __RW_START__ = . ;
8854dc71e7SAchin Gupta
8951faada7SDouglas Raillard    /*
9051faada7SDouglas Raillard     * .data must be placed at a lower address than the stacks if the stack
9151faada7SDouglas Raillard     * protector is enabled. Alternatively, the .data.stack_protector_canary
9251faada7SDouglas Raillard     * section can be placed independently of the main .data section.
9351faada7SDouglas Raillard     */
948d69a03fSSandrine Bailleux    .data . : {
958d69a03fSSandrine Bailleux        __DATA_START__ = .;
96dccc537aSAndrew Thoelke        *(.data*)
978d69a03fSSandrine Bailleux        __DATA_END__ = .;
988d69a03fSSandrine Bailleux    } >RAM
998d69a03fSSandrine Bailleux
1008d69a03fSSandrine Bailleux    stacks (NOLOAD) : {
1018d69a03fSSandrine Bailleux        __STACKS_START__ = .;
1028d69a03fSSandrine Bailleux        *(tzfw_normal_stacks)
1038d69a03fSSandrine Bailleux        __STACKS_END__ = .;
1048d69a03fSSandrine Bailleux    } >RAM
1058d69a03fSSandrine Bailleux
1068d69a03fSSandrine Bailleux    /*
1078d69a03fSSandrine Bailleux     * The .bss section gets initialised to 0 at runtime.
108308d359bSDouglas Raillard     * Its base address should be 16-byte aligned for better performance of the
109308d359bSDouglas Raillard     * zero-initialization code.
1108d69a03fSSandrine Bailleux     */
1118d69a03fSSandrine Bailleux    .bss : ALIGN(16) {
1128d69a03fSSandrine Bailleux        __BSS_START__ = .;
113dccc537aSAndrew Thoelke        *(SORT_BY_ALIGNMENT(.bss*))
1144f6ad66aSAchin Gupta        *(COMMON)
1158d69a03fSSandrine Bailleux        __BSS_END__ = .;
1164f6ad66aSAchin Gupta    } >RAM
1174f6ad66aSAchin Gupta
1188d69a03fSSandrine Bailleux    /*
119e3fff153SJeenu Viswambharan     * The xlat_table section is for full, aligned page tables (4K).
120a0cd989dSAchin Gupta     * Removing them from .bss avoids forcing 4K alignment on
121883d1b5dSAntonio Nino Diaz     * the .bss section. The tables are initialized to zero by the translation
122883d1b5dSAntonio Nino Diaz     * tables library.
123a0cd989dSAchin Gupta     */
124a0cd989dSAchin Gupta    xlat_table (NOLOAD) : {
125a0cd989dSAchin Gupta        *(xlat_table)
126a0cd989dSAchin Gupta    } >RAM
127a0cd989dSAchin Gupta
128ab8707e6SSoby Mathew#if USE_COHERENT_MEM
129a0cd989dSAchin Gupta    /*
1308d69a03fSSandrine Bailleux     * The base address of the coherent memory section must be page-aligned (4K)
1318d69a03fSSandrine Bailleux     * to guarantee that the coherent data are stored on their own pages and
1328d69a03fSSandrine Bailleux     * are not mixed with normal data.  This is required to set up the correct
1338d69a03fSSandrine Bailleux     * memory attributes for the coherent data page tables.
1348d69a03fSSandrine Bailleux     */
135a2aedac2SAntonio Nino Diaz    coherent_ram (NOLOAD) : ALIGN(PAGE_SIZE) {
1368d69a03fSSandrine Bailleux        __COHERENT_RAM_START__ = .;
1378d69a03fSSandrine Bailleux        *(tzfw_coherent_mem)
1388d69a03fSSandrine Bailleux        __COHERENT_RAM_END_UNALIGNED__ = .;
1398d69a03fSSandrine Bailleux        /*
1408d69a03fSSandrine Bailleux         * Memory page(s) mapped to this section will be marked
1418d69a03fSSandrine Bailleux         * as device memory.  No other unexpected data must creep in.
1428d69a03fSSandrine Bailleux         * Ensure the rest of the current memory page is unused.
1438d69a03fSSandrine Bailleux         */
1445629b2b1SRoberto Vargas        . = ALIGN(PAGE_SIZE);
1458d69a03fSSandrine Bailleux        __COHERENT_RAM_END__ = .;
1464f6ad66aSAchin Gupta    } >RAM
147ab8707e6SSoby Mathew#endif
1484f6ad66aSAchin Gupta
14954dc71e7SAchin Gupta    /*
15054dc71e7SAchin Gupta     * Define a linker symbol to mark end of the RW memory area for this
15154dc71e7SAchin Gupta     * image.
15254dc71e7SAchin Gupta     */
15354dc71e7SAchin Gupta    __RW_END__ = .;
1548d69a03fSSandrine Bailleux    __BL2_END__ = .;
1554f6ad66aSAchin Gupta
1568d69a03fSSandrine Bailleux    __BSS_SIZE__ = SIZEOF(.bss);
157ab8707e6SSoby Mathew
158ab8707e6SSoby Mathew#if USE_COHERENT_MEM
1598d69a03fSSandrine Bailleux    __COHERENT_RAM_UNALIGNED_SIZE__ =
1608d69a03fSSandrine Bailleux        __COHERENT_RAM_END_UNALIGNED__ - __COHERENT_RAM_START__;
161ab8707e6SSoby Mathew#endif
162a37255a2SSandrine Bailleux
163a37255a2SSandrine Bailleux    ASSERT(. <= BL2_LIMIT, "BL2 image has exceeded its limit.")
1644f6ad66aSAchin Gupta}
165