xref: /rk3399_ARM-atf/bl1/bl1.ld.S (revision 665e71b8ea28162ec7737c1411bca3ea89e5957e)
14f6ad66aSAchin Gupta/*
2*665e71b8SMasahiro Yamada * Copyright (c) 2013-2020, 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>
809d40e0eSAntonio Nino Diaz
9*665e71b8SMasahiro Yamada#include <common/bl_common.ld.h>
1009d40e0eSAntonio Nino Diaz#include <lib/xlat_tables/xlat_tables_defs.h>
114f6ad66aSAchin Gupta
124f6ad66aSAchin GuptaOUTPUT_FORMAT(PLATFORM_LINKER_FORMAT)
134f6ad66aSAchin GuptaOUTPUT_ARCH(PLATFORM_LINKER_ARCH)
149f98aa1aSJeenu ViswambharanENTRY(bl1_entrypoint)
154f6ad66aSAchin Gupta
164f6ad66aSAchin GuptaMEMORY {
17d7fbf132SJuan Castillo    ROM (rx): ORIGIN = BL1_RO_BASE, LENGTH = BL1_RO_LIMIT - BL1_RO_BASE
18d7fbf132SJuan Castillo    RAM (rwx): ORIGIN = BL1_RW_BASE, LENGTH = BL1_RW_LIMIT - BL1_RW_BASE
194f6ad66aSAchin Gupta}
204f6ad66aSAchin Gupta
214f6ad66aSAchin GuptaSECTIONS
224f6ad66aSAchin Gupta{
234f59d835SSandrine Bailleux    . = BL1_RO_BASE;
24a2aedac2SAntonio Nino Diaz    ASSERT(. == ALIGN(PAGE_SIZE),
254f59d835SSandrine Bailleux           "BL1_RO_BASE address is not aligned on a page boundary.")
264f59d835SSandrine Bailleux
275d1c104fSSandrine Bailleux#if SEPARATE_CODE_AND_RODATA
285d1c104fSSandrine Bailleux    .text . : {
295d1c104fSSandrine Bailleux        __TEXT_START__ = .;
305d1c104fSSandrine Bailleux        *bl1_entrypoint.o(.text*)
31ebd6efaeSSamuel Holland        *(SORT_BY_ALIGNMENT(.text*))
325d1c104fSSandrine Bailleux        *(.vectors)
335629b2b1SRoberto Vargas        . = ALIGN(PAGE_SIZE);
345d1c104fSSandrine Bailleux        __TEXT_END__ = .;
355d1c104fSSandrine Bailleux     } >ROM
365d1c104fSSandrine Bailleux
37ad925094SRoberto Vargas     /* .ARM.extab and .ARM.exidx are only added because Clang need them */
38ad925094SRoberto Vargas     .ARM.extab . : {
39ad925094SRoberto Vargas        *(.ARM.extab* .gnu.linkonce.armextab.*)
40ad925094SRoberto Vargas     } >ROM
41ad925094SRoberto Vargas
42ad925094SRoberto Vargas     .ARM.exidx . : {
43ad925094SRoberto Vargas        *(.ARM.exidx* .gnu.linkonce.armexidx.*)
44ad925094SRoberto Vargas     } >ROM
45ad925094SRoberto Vargas
465d1c104fSSandrine Bailleux    .rodata . : {
475d1c104fSSandrine Bailleux        __RODATA_START__ = .;
48ebd6efaeSSamuel Holland        *(SORT_BY_ALIGNMENT(.rodata*))
495d1c104fSSandrine Bailleux
505d1c104fSSandrine Bailleux        /* Ensure 8-byte alignment for descriptors and ensure inclusion */
515d1c104fSSandrine Bailleux        . = ALIGN(8);
525d1c104fSSandrine Bailleux        __PARSER_LIB_DESCS_START__ = .;
535d1c104fSSandrine Bailleux        KEEP(*(.img_parser_lib_descs))
545d1c104fSSandrine Bailleux        __PARSER_LIB_DESCS_END__ = .;
555d1c104fSSandrine Bailleux
565d1c104fSSandrine Bailleux        /*
575d1c104fSSandrine Bailleux         * Ensure 8-byte alignment for cpu_ops so that its fields are also
585d1c104fSSandrine Bailleux         * aligned. Also ensure cpu_ops inclusion.
595d1c104fSSandrine Bailleux         */
605d1c104fSSandrine Bailleux        . = ALIGN(8);
615d1c104fSSandrine Bailleux        __CPU_OPS_START__ = .;
625d1c104fSSandrine Bailleux        KEEP(*(cpu_ops))
635d1c104fSSandrine Bailleux        __CPU_OPS_END__ = .;
645d1c104fSSandrine Bailleux
655d1c104fSSandrine Bailleux        /*
665d1c104fSSandrine Bailleux         * No need to pad out the .rodata section to a page boundary. Next is
675d1c104fSSandrine Bailleux         * the .data section, which can mapped in ROM with the same memory
685d1c104fSSandrine Bailleux         * attributes as the .rodata section.
6941286590SArve Hjønnevåg         *
7041286590SArve Hjønnevåg         * Pad out to 16 bytes though as .data section needs to be 16 byte
7141286590SArve Hjønnevåg         * aligned and lld does not align the LMA to the aligment specified
7241286590SArve Hjønnevåg         * on the .data section.
735d1c104fSSandrine Bailleux         */
745d1c104fSSandrine Bailleux        __RODATA_END__ = .;
7541286590SArve Hjønnevåg         . = ALIGN(16);
765d1c104fSSandrine Bailleux    } >ROM
775d1c104fSSandrine Bailleux#else
784f59d835SSandrine Bailleux    ro . : {
798d69a03fSSandrine Bailleux        __RO_START__ = .;
80dccc537aSAndrew Thoelke        *bl1_entrypoint.o(.text*)
81ebd6efaeSSamuel Holland        *(SORT_BY_ALIGNMENT(.text*))
82ebd6efaeSSamuel Holland        *(SORT_BY_ALIGNMENT(.rodata*))
839b476841SSoby Mathew
8405799ae0SJuan Castillo        /* Ensure 8-byte alignment for descriptors and ensure inclusion */
8505799ae0SJuan Castillo        . = ALIGN(8);
8605799ae0SJuan Castillo        __PARSER_LIB_DESCS_START__ = .;
8705799ae0SJuan Castillo        KEEP(*(.img_parser_lib_descs))
8805799ae0SJuan Castillo        __PARSER_LIB_DESCS_END__ = .;
8905799ae0SJuan Castillo
909b476841SSoby Mathew        /*
919b476841SSoby Mathew         * Ensure 8-byte alignment for cpu_ops so that its fields are also
929b476841SSoby Mathew         * aligned. Also ensure cpu_ops inclusion.
939b476841SSoby Mathew         */
949b476841SSoby Mathew        . = ALIGN(8);
959b476841SSoby Mathew        __CPU_OPS_START__ = .;
969b476841SSoby Mathew        KEEP(*(cpu_ops))
979b476841SSoby Mathew        __CPU_OPS_END__ = .;
989b476841SSoby Mathew
99b739f22aSAchin Gupta        *(.vectors)
1008d69a03fSSandrine Bailleux        __RO_END__ = .;
10141286590SArve Hjønnevåg
10241286590SArve Hjønnevåg        /*
10341286590SArve Hjønnevåg         * Pad out to 16 bytes as .data section needs to be 16 byte aligned and
10441286590SArve Hjønnevåg         * lld does not align the LMA to the aligment specified on the .data
10541286590SArve Hjønnevåg         * section.
10641286590SArve Hjønnevåg         */
10741286590SArve Hjønnevåg         . = ALIGN(16);
1084f6ad66aSAchin Gupta    } >ROM
1095d1c104fSSandrine Bailleux#endif
1104f6ad66aSAchin Gupta
1119b476841SSoby Mathew    ASSERT(__CPU_OPS_END__ > __CPU_OPS_START__,
1129b476841SSoby Mathew           "cpu_ops not defined for this platform.")
1139b476841SSoby Mathew
11451faada7SDouglas Raillard    . = BL1_RW_BASE;
115a2aedac2SAntonio Nino Diaz    ASSERT(BL1_RW_BASE == ALIGN(PAGE_SIZE),
11651faada7SDouglas Raillard           "BL1_RW_BASE address is not aligned on a page boundary.")
11751faada7SDouglas Raillard
1188d69a03fSSandrine Bailleux    /*
1198d69a03fSSandrine Bailleux     * The .data section gets copied from ROM to RAM at runtime.
12051faada7SDouglas Raillard     * Its LMA should be 16-byte aligned to allow efficient copying of 16-bytes
12151faada7SDouglas Raillard     * aligned regions in it.
1224f59d835SSandrine Bailleux     * Its VMA must be page-aligned as it marks the first read/write page.
12351faada7SDouglas Raillard     *
12451faada7SDouglas Raillard     * It must be placed at a lower address than the stacks if the stack
12551faada7SDouglas Raillard     * protector is enabled. Alternatively, the .data.stack_protector_canary
12651faada7SDouglas Raillard     * section can be placed independently of the main .data section.
1278d69a03fSSandrine Bailleux     */
1284f59d835SSandrine Bailleux    .data . : ALIGN(16) {
1294f6ad66aSAchin Gupta        __DATA_RAM_START__ = .;
130ebd6efaeSSamuel Holland        *(SORT_BY_ALIGNMENT(.data*))
1318d69a03fSSandrine Bailleux        __DATA_RAM_END__ = .;
1324f6ad66aSAchin Gupta    } >RAM AT>ROM
1334f6ad66aSAchin Gupta
1344f59d835SSandrine Bailleux    stacks . (NOLOAD) : {
1358d69a03fSSandrine Bailleux        __STACKS_START__ = .;
1364f6ad66aSAchin Gupta        *(tzfw_normal_stacks)
1378d69a03fSSandrine Bailleux        __STACKS_END__ = .;
1384f6ad66aSAchin Gupta    } >RAM
1394f6ad66aSAchin Gupta
1408d69a03fSSandrine Bailleux    /*
1418d69a03fSSandrine Bailleux     * The .bss section gets initialised to 0 at runtime.
142308d359bSDouglas Raillard     * Its base address should be 16-byte aligned for better performance of the
143308d359bSDouglas Raillard     * zero-initialization code.
1448d69a03fSSandrine Bailleux     */
1458d69a03fSSandrine Bailleux    .bss : ALIGN(16) {
1468d69a03fSSandrine Bailleux        __BSS_START__ = .;
147ebd6efaeSSamuel Holland        *(SORT_BY_ALIGNMENT(.bss*))
1488d69a03fSSandrine Bailleux        *(COMMON)
1498d69a03fSSandrine Bailleux        __BSS_END__ = .;
1508d69a03fSSandrine Bailleux    } >RAM
1514f6ad66aSAchin Gupta
152*665e71b8SMasahiro Yamada    XLAT_TABLE_SECTION >RAM
15374cbb839SJeenu Viswambharan
154ab8707e6SSoby Mathew#if USE_COHERENT_MEM
15574cbb839SJeenu Viswambharan    /*
1568d69a03fSSandrine Bailleux     * The base address of the coherent memory section must be page-aligned (4K)
1578d69a03fSSandrine Bailleux     * to guarantee that the coherent data are stored on their own pages and
1588d69a03fSSandrine Bailleux     * are not mixed with normal data.  This is required to set up the correct
1598d69a03fSSandrine Bailleux     * memory attributes for the coherent data page tables.
1608d69a03fSSandrine Bailleux     */
161a2aedac2SAntonio Nino Diaz    coherent_ram (NOLOAD) : ALIGN(PAGE_SIZE) {
1628d69a03fSSandrine Bailleux        __COHERENT_RAM_START__ = .;
1638d69a03fSSandrine Bailleux        *(tzfw_coherent_mem)
1648d69a03fSSandrine Bailleux        __COHERENT_RAM_END_UNALIGNED__ = .;
1658d69a03fSSandrine Bailleux        /*
1668d69a03fSSandrine Bailleux         * Memory page(s) mapped to this section will be marked
1678d69a03fSSandrine Bailleux         * as device memory.  No other unexpected data must creep in.
1688d69a03fSSandrine Bailleux         * Ensure the rest of the current memory page is unused.
1698d69a03fSSandrine Bailleux         */
1705629b2b1SRoberto Vargas        . = ALIGN(PAGE_SIZE);
1718d69a03fSSandrine Bailleux        __COHERENT_RAM_END__ = .;
1728d69a03fSSandrine Bailleux    } >RAM
173ab8707e6SSoby Mathew#endif
1744f6ad66aSAchin Gupta
1758d69a03fSSandrine Bailleux    __BL1_RAM_START__ = ADDR(.data);
1768d69a03fSSandrine Bailleux    __BL1_RAM_END__ = .;
1774f6ad66aSAchin Gupta
1788d69a03fSSandrine Bailleux    __DATA_ROM_START__ = LOADADDR(.data);
1798d69a03fSSandrine Bailleux    __DATA_SIZE__ = SIZEOF(.data);
180c02fcc4aSSandrine Bailleux
181a37255a2SSandrine Bailleux    /*
182a37255a2SSandrine Bailleux     * The .data section is the last PROGBITS section so its end marks the end
183c02fcc4aSSandrine Bailleux     * of BL1's actual content in Trusted ROM.
184a37255a2SSandrine Bailleux     */
185c02fcc4aSSandrine Bailleux    __BL1_ROM_END__ =  __DATA_ROM_START__ + __DATA_SIZE__;
186c02fcc4aSSandrine Bailleux    ASSERT(__BL1_ROM_END__ <= BL1_RO_LIMIT,
187c02fcc4aSSandrine Bailleux           "BL1's ROM content has exceeded its limit.")
1888d69a03fSSandrine Bailleux
1898d69a03fSSandrine Bailleux    __BSS_SIZE__ = SIZEOF(.bss);
1908d69a03fSSandrine Bailleux
191ab8707e6SSoby Mathew#if USE_COHERENT_MEM
1928d69a03fSSandrine Bailleux    __COHERENT_RAM_UNALIGNED_SIZE__ =
1938d69a03fSSandrine Bailleux        __COHERENT_RAM_END_UNALIGNED__ - __COHERENT_RAM_START__;
194ab8707e6SSoby Mathew#endif
1958d69a03fSSandrine Bailleux
196a37255a2SSandrine Bailleux    ASSERT(. <= BL1_RW_LIMIT, "BL1's RW section has exceeded its limit.")
1974f6ad66aSAchin Gupta}
198