xref: /rk3399_ARM-atf/bl1/bl1.ld.S (revision d3604b353e3e560d2c660a0ba8d6f9457a795159)
14f6ad66aSAchin Gupta/*
2*d701b48eSChris Kay * Copyright (c) 2013-2024, Arm Limited and Contributors. All rights reserved.
34f6ad66aSAchin Gupta *
482cb2c1aSdp-arm * SPDX-License-Identifier: BSD-3-Clause
54f6ad66aSAchin Gupta */
64f6ad66aSAchin Gupta
7caa3e7e0SMasahiro Yamada/*
8f90fe02fSChris Kay * The .data section gets copied from ROM to RAM at runtime. Its LMA should be
9f90fe02fSChris Kay * 16-byte aligned to allow efficient copying of 16-bytes aligned regions in it.
10caa3e7e0SMasahiro Yamada * Its VMA must be page-aligned as it marks the first read/write page.
11caa3e7e0SMasahiro Yamada */
12caa3e7e0SMasahiro Yamada#define DATA_ALIGN	16
13caa3e7e0SMasahiro Yamada
14665e71b8SMasahiro Yamada#include <common/bl_common.ld.h>
1509d40e0eSAntonio Nino Diaz#include <lib/xlat_tables/xlat_tables_defs.h>
164f6ad66aSAchin Gupta
174f6ad66aSAchin GuptaOUTPUT_FORMAT(PLATFORM_LINKER_FORMAT)
184f6ad66aSAchin GuptaOUTPUT_ARCH(PLATFORM_LINKER_ARCH)
199f98aa1aSJeenu ViswambharanENTRY(bl1_entrypoint)
204f6ad66aSAchin Gupta
214f6ad66aSAchin GuptaMEMORY {
22d7fbf132SJuan Castillo    ROM (rx): ORIGIN = BL1_RO_BASE, LENGTH = BL1_RO_LIMIT - BL1_RO_BASE
23d7fbf132SJuan Castillo    RAM (rwx): ORIGIN = BL1_RW_BASE, LENGTH = BL1_RW_LIMIT - BL1_RW_BASE
244f6ad66aSAchin Gupta}
254f6ad66aSAchin Gupta
26f90fe02fSChris KaySECTIONS {
275e7e8bfaSHarrison Mutai    ROM_REGION_START = ORIGIN(ROM);
285e7e8bfaSHarrison Mutai    ROM_REGION_LENGTH = LENGTH(ROM);
295e7e8bfaSHarrison Mutai    RAM_REGION_START = ORIGIN(RAM);
305e7e8bfaSHarrison Mutai    RAM_REGION_LENGTH = LENGTH(RAM);
315e7e8bfaSHarrison Mutai
324f59d835SSandrine Bailleux    . = BL1_RO_BASE;
33f90fe02fSChris Kay
34a2aedac2SAntonio Nino Diaz    ASSERT(. == ALIGN(PAGE_SIZE),
354f59d835SSandrine Bailleux        "BL1_RO_BASE address is not aligned on a page boundary.")
364f59d835SSandrine Bailleux
375d1c104fSSandrine Bailleux#if SEPARATE_CODE_AND_RODATA
385d1c104fSSandrine Bailleux    .text . : {
393d6edc32SAndrey Skvortsov        ASSERT(. == ALIGN(PAGE_SIZE),
403d6edc32SAndrey Skvortsov        ".text address is not aligned on a page boundary.");
413d6edc32SAndrey Skvortsov
425d1c104fSSandrine Bailleux        __TEXT_START__ = .;
43f90fe02fSChris Kay
445d1c104fSSandrine Bailleux        *bl1_entrypoint.o(.text*)
45ebd6efaeSSamuel Holland        *(SORT_BY_ALIGNMENT(.text*))
465d1c104fSSandrine Bailleux        *(.vectors)
47f7d445fcSMichal Simek        __TEXT_END_UNALIGNED__ = .;
48f90fe02fSChris Kay
495629b2b1SRoberto Vargas        . = ALIGN(PAGE_SIZE);
50f90fe02fSChris Kay
515d1c104fSSandrine Bailleux        __TEXT_END__ = .;
525d1c104fSSandrine Bailleux    } >ROM
535d1c104fSSandrine Bailleux
54f90fe02fSChris Kay    /* .ARM.extab and .ARM.exidx are only added because Clang needs them */
55ad925094SRoberto Vargas    .ARM.extab . : {
56ad925094SRoberto Vargas        *(.ARM.extab* .gnu.linkonce.armextab.*)
57ad925094SRoberto Vargas    } >ROM
58ad925094SRoberto Vargas
59ad925094SRoberto Vargas    .ARM.exidx . : {
60ad925094SRoberto Vargas        *(.ARM.exidx* .gnu.linkonce.armexidx.*)
61ad925094SRoberto Vargas    } >ROM
62ad925094SRoberto Vargas
635d1c104fSSandrine Bailleux    .rodata . : {
645d1c104fSSandrine Bailleux        __RODATA_START__ = .;
65f90fe02fSChris Kay
66ebd6efaeSSamuel Holland        *(SORT_BY_ALIGNMENT(.rodata*))
675d1c104fSSandrine Bailleux
680a0a7a9aSMasahiro Yamada        RODATA_COMMON
695d1c104fSSandrine Bailleux
705d1c104fSSandrine Bailleux        /*
715d1c104fSSandrine Bailleux         * No need to pad out the .rodata section to a page boundary. Next is
725d1c104fSSandrine Bailleux         * the .data section, which can mapped in ROM with the same memory
735d1c104fSSandrine Bailleux         * attributes as the .rodata section.
7441286590SArve Hjønnevåg         *
75f90fe02fSChris Kay         * Pad out to 16 bytes though as .data section needs to be 16-byte
76f90fe02fSChris Kay         * aligned and lld does not align the LMA to the alignment specified
7741286590SArve Hjønnevåg         * on the .data section.
785d1c104fSSandrine Bailleux         */
79f7d445fcSMichal Simek        __RODATA_END_UNALIGNED__ = .;
805d1c104fSSandrine Bailleux        __RODATA_END__ = .;
81f90fe02fSChris Kay
8241286590SArve Hjønnevåg        . = ALIGN(16);
835d1c104fSSandrine Bailleux    } >ROM
84f90fe02fSChris Kay#else /* SEPARATE_CODE_AND_RODATA */
85da04341eSChris Kay    .ro . : {
863d6edc32SAndrey Skvortsov        ASSERT(. == ALIGN(PAGE_SIZE),
873d6edc32SAndrey Skvortsov        ".ro address is not aligned on a page boundary.");
883d6edc32SAndrey Skvortsov
898d69a03fSSandrine Bailleux        __RO_START__ = .;
90f90fe02fSChris Kay
91dccc537aSAndrew Thoelke        *bl1_entrypoint.o(.text*)
92ebd6efaeSSamuel Holland        *(SORT_BY_ALIGNMENT(.text*))
93ebd6efaeSSamuel Holland        *(SORT_BY_ALIGNMENT(.rodata*))
949b476841SSoby Mathew
950a0a7a9aSMasahiro Yamada        RODATA_COMMON
969b476841SSoby Mathew
97b739f22aSAchin Gupta        *(.vectors)
98f90fe02fSChris Kay
998d69a03fSSandrine Bailleux        __RO_END__ = .;
10041286590SArve Hjønnevåg
10141286590SArve Hjønnevåg        /*
102f90fe02fSChris Kay         * Pad out to 16 bytes as the .data section needs to be 16-byte aligned
103f90fe02fSChris Kay         * and lld does not align the LMA to the alignment specified on the
104f90fe02fSChris Kay         * .data section.
10541286590SArve Hjønnevåg         */
10641286590SArve Hjønnevåg        . = ALIGN(16);
1074f6ad66aSAchin Gupta    } >ROM
108f90fe02fSChris Kay#endif /* SEPARATE_CODE_AND_RODATA */
1094f6ad66aSAchin Gupta
1109b476841SSoby Mathew    ASSERT(__CPU_OPS_END__ > __CPU_OPS_START__,
1119b476841SSoby Mathew        "cpu_ops not defined for this platform.")
1129b476841SSoby Mathew
1135e7e8bfaSHarrison Mutai    ROM_REGION_END = .;
11451faada7SDouglas Raillard    . = BL1_RW_BASE;
115f90fe02fSChris Kay
116a2aedac2SAntonio Nino Diaz    ASSERT(BL1_RW_BASE == ALIGN(PAGE_SIZE),
11751faada7SDouglas Raillard        "BL1_RW_BASE address is not aligned on a page boundary.")
11851faada7SDouglas Raillard
119*d701b48eSChris Kay    __RW_START__ = .;
120*d701b48eSChris Kay
121caa3e7e0SMasahiro Yamada    DATA_SECTION >RAM AT>ROM
122f90fe02fSChris Kay
123caa3e7e0SMasahiro Yamada    __DATA_RAM_START__ = __DATA_START__;
124caa3e7e0SMasahiro Yamada    __DATA_RAM_END__ = __DATA_END__;
1254f6ad66aSAchin Gupta
126a926a9f6SMasahiro Yamada    STACK_SECTION >RAM
127a7739bc7SMasahiro Yamada    BSS_SECTION >RAM
128665e71b8SMasahiro Yamada    XLAT_TABLE_SECTION >RAM
12974cbb839SJeenu Viswambharan
130ab8707e6SSoby Mathew#if USE_COHERENT_MEM
13174cbb839SJeenu Viswambharan    /*
132f90fe02fSChris Kay     * The base address of the coherent memory section must be page-aligned to
133f90fe02fSChris Kay     * guarantee that the coherent data are stored on their own pages and are
134f90fe02fSChris Kay     * not mixed with normal data. This is required to set up the correct memory
135f90fe02fSChris Kay     * attributes for the coherent data page tables.
1368d69a03fSSandrine Bailleux     */
137da04341eSChris Kay    .coherent_ram (NOLOAD) : ALIGN(PAGE_SIZE) {
1388d69a03fSSandrine Bailleux        __COHERENT_RAM_START__ = .;
139da04341eSChris Kay        *(.tzfw_coherent_mem)
1408d69a03fSSandrine Bailleux        __COHERENT_RAM_END_UNALIGNED__ = .;
141f90fe02fSChris Kay
1428d69a03fSSandrine Bailleux        /*
143f90fe02fSChris Kay         * Memory page(s) mapped to this section will be marked as device
144f90fe02fSChris Kay         * memory. No other unexpected data must creep in. Ensure the rest of
145f90fe02fSChris Kay         * the current memory page is unused.
1468d69a03fSSandrine Bailleux         */
1475629b2b1SRoberto Vargas        . = ALIGN(PAGE_SIZE);
148f90fe02fSChris Kay
1498d69a03fSSandrine Bailleux        __COHERENT_RAM_END__ = .;
1508d69a03fSSandrine Bailleux    } >RAM
151f90fe02fSChris Kay#endif /* USE_COHERENT_MEM */
1524f6ad66aSAchin Gupta
153*d701b48eSChris Kay    __RW_END__ = .;
154*d701b48eSChris Kay
1558d69a03fSSandrine Bailleux    __BL1_RAM_START__ = ADDR(.data);
1568d69a03fSSandrine Bailleux    __BL1_RAM_END__ = .;
1574f6ad66aSAchin Gupta
1588d69a03fSSandrine Bailleux    __DATA_ROM_START__ = LOADADDR(.data);
1598d69a03fSSandrine Bailleux    __DATA_SIZE__ = SIZEOF(.data);
160c02fcc4aSSandrine Bailleux
161a37255a2SSandrine Bailleux    /*
162a37255a2SSandrine Bailleux     * The .data section is the last PROGBITS section so its end marks the end
163c02fcc4aSSandrine Bailleux     * of BL1's actual content in Trusted ROM.
164a37255a2SSandrine Bailleux     */
165c02fcc4aSSandrine Bailleux    __BL1_ROM_END__ =  __DATA_ROM_START__ + __DATA_SIZE__;
166f90fe02fSChris Kay
167c02fcc4aSSandrine Bailleux    ASSERT(__BL1_ROM_END__ <= BL1_RO_LIMIT,
168c02fcc4aSSandrine Bailleux        "BL1's ROM content has exceeded its limit.")
1698d69a03fSSandrine Bailleux
1708d69a03fSSandrine Bailleux    __BSS_SIZE__ = SIZEOF(.bss);
1718d69a03fSSandrine Bailleux
172ab8707e6SSoby Mathew#if USE_COHERENT_MEM
1738d69a03fSSandrine Bailleux    __COHERENT_RAM_UNALIGNED_SIZE__ =
1748d69a03fSSandrine Bailleux        __COHERENT_RAM_END_UNALIGNED__ - __COHERENT_RAM_START__;
175f90fe02fSChris Kay#endif /* USE_COHERENT_MEM */
1768d69a03fSSandrine Bailleux
177a37255a2SSandrine Bailleux    ASSERT(. <= BL1_RW_LIMIT, "BL1's RW section has exceeded its limit.")
1785e7e8bfaSHarrison Mutai    RAM_REGION_END = .;
1794f6ad66aSAchin Gupta}
180