xref: /rk3399_ARM-atf/bl31/bl31.ld.S (revision 9b5498a721f68d1e5cad397fc0d84303dbac1557)
14f6ad66aSAchin Gupta/*
2da04341eSChris Kay * Copyright (c) 2013-2023, Arm Limited and Contributors. All rights reserved.
34f6ad66aSAchin Gupta *
482cb2c1aSdp-arm * SPDX-License-Identifier: BSD-3-Clause
54f6ad66aSAchin Gupta */
64f6ad66aSAchin Gupta
7665e71b8SMasahiro Yamada#include <common/bl_common.ld.h>
809d40e0eSAntonio Nino Diaz#include <lib/xlat_tables/xlat_tables_defs.h>
94f6ad66aSAchin Gupta
104f6ad66aSAchin GuptaOUTPUT_FORMAT(PLATFORM_LINKER_FORMAT)
114f6ad66aSAchin GuptaOUTPUT_ARCH(PLATFORM_LINKER_ARCH)
129f98aa1aSJeenu ViswambharanENTRY(bl31_entrypoint)
134f6ad66aSAchin Gupta
144f6ad66aSAchin GuptaMEMORY {
15d7fbf132SJuan Castillo    RAM (rwx): ORIGIN = BL31_BASE, LENGTH = BL31_LIMIT - BL31_BASE
16f90fe02fSChris Kay
17f8578e64SSamuel Holland#if SEPARATE_NOBITS_REGION
18f8578e64SSamuel Holland    NOBITS (rw!a): ORIGIN = BL31_NOBITS_BASE, LENGTH = BL31_NOBITS_LIMIT - BL31_NOBITS_BASE
19f90fe02fSChris Kay#else /* SEPARATE_NOBITS_REGION */
20f8578e64SSamuel Holland#   define NOBITS RAM
21f90fe02fSChris Kay#endif /* SEPARATE_NOBITS_REGION */
224f6ad66aSAchin Gupta}
234f6ad66aSAchin Gupta
24ec693569SCaesar Wang#ifdef PLAT_EXTRA_LD_SCRIPT
25ec693569SCaesar Wang#   include <plat.ld.S>
26f90fe02fSChris Kay#endif /* PLAT_EXTRA_LD_SCRIPT */
274f6ad66aSAchin Gupta
28f90fe02fSChris KaySECTIONS {
29*9b5498a7SHarrison Mutai    RAM_REGION_START = ORIGIN(RAM);
30*9b5498a7SHarrison Mutai    RAM_REGION_LENGTH = LENGTH(RAM);
314f6ad66aSAchin Gupta    . = BL31_BASE;
32f90fe02fSChris Kay
33a2aedac2SAntonio Nino Diaz    ASSERT(. == ALIGN(PAGE_SIZE),
348d69a03fSSandrine Bailleux        "BL31_BASE address is not aligned on a page boundary.")
354f6ad66aSAchin Gupta
36931f7c61SSoby Mathew    __BL31_START__ = .;
37931f7c61SSoby Mathew
385d1c104fSSandrine Bailleux#if SEPARATE_CODE_AND_RODATA
395d1c104fSSandrine Bailleux    .text . : {
405d1c104fSSandrine Bailleux        __TEXT_START__ = .;
41f90fe02fSChris Kay
425d1c104fSSandrine Bailleux        *bl31_entrypoint.o(.text*)
43d7b5f408SJimmy Brisson        *(SORT_BY_ALIGNMENT(SORT(.text*)))
445d1c104fSSandrine Bailleux        *(.vectors)
45f90fe02fSChris Kay
465629b2b1SRoberto Vargas        . = ALIGN(PAGE_SIZE);
47f90fe02fSChris Kay
485d1c104fSSandrine Bailleux        __TEXT_END__ = .;
495d1c104fSSandrine Bailleux    } >RAM
505d1c104fSSandrine Bailleux
515d1c104fSSandrine Bailleux    .rodata . : {
525d1c104fSSandrine Bailleux        __RODATA_START__ = .;
53f90fe02fSChris Kay
54ebd6efaeSSamuel Holland        *(SORT_BY_ALIGNMENT(.rodata*))
555d1c104fSSandrine Bailleux
568a68e864SLeon Chen#   if PLAT_EXTRA_RODATA_INCLUDES
578a68e864SLeon Chen#       include <plat.ld.rodata.inc>
58f90fe02fSChris Kay#   endif /* PLAT_EXTRA_RODATA_INCLUDES */
598a68e864SLeon Chen
600a0a7a9aSMasahiro Yamada        RODATA_COMMON
61931f7c61SSoby Mathew
628e743bcdSJeenu Viswambharan        . = ALIGN(8);
63f90fe02fSChris Kay
6409d40e0eSAntonio Nino Diaz#   include <lib/el3_runtime/pubsub_events.h>
658e743bcdSJeenu Viswambharan
665629b2b1SRoberto Vargas        . = ALIGN(PAGE_SIZE);
67f90fe02fSChris Kay
685d1c104fSSandrine Bailleux        __RODATA_END__ = .;
695d1c104fSSandrine Bailleux    } >RAM
70f90fe02fSChris Kay#else /* SEPARATE_CODE_AND_RODATA */
71da04341eSChris Kay    .ro . : {
728d69a03fSSandrine Bailleux        __RO_START__ = .;
73f90fe02fSChris Kay
74dccc537aSAndrew Thoelke        *bl31_entrypoint.o(.text*)
75ebd6efaeSSamuel Holland        *(SORT_BY_ALIGNMENT(.text*))
76ebd6efaeSSamuel Holland        *(SORT_BY_ALIGNMENT(.rodata*))
777421b465SAchin Gupta
780a0a7a9aSMasahiro Yamada        RODATA_COMMON
795bfac4fcSSoby Mathew
808e743bcdSJeenu Viswambharan        . = ALIGN(8);
81f90fe02fSChris Kay
8209d40e0eSAntonio Nino Diaz#   include <lib/el3_runtime/pubsub_events.h>
838e743bcdSJeenu Viswambharan
84b739f22aSAchin Gupta        *(.vectors)
85f90fe02fSChris Kay
868d69a03fSSandrine Bailleux        __RO_END_UNALIGNED__ = .;
87f90fe02fSChris Kay
888d69a03fSSandrine Bailleux        /*
898d69a03fSSandrine Bailleux         * Memory page(s) mapped to this section will be marked as read-only,
90f90fe02fSChris Kay         * executable. No RW data from the next section must creep in. Ensure
91f90fe02fSChris Kay         * that the rest of the current memory page is unused.
928d69a03fSSandrine Bailleux         */
935629b2b1SRoberto Vargas        . = ALIGN(PAGE_SIZE);
94f90fe02fSChris Kay
958d69a03fSSandrine Bailleux        __RO_END__ = .;
964f6ad66aSAchin Gupta    } >RAM
97f90fe02fSChris Kay#endif /* SEPARATE_CODE_AND_RODATA */
984f6ad66aSAchin Gupta
999b476841SSoby Mathew    ASSERT(__CPU_OPS_END__ > __CPU_OPS_START__,
1009b476841SSoby Mathew        "cpu_ops not defined for this platform.")
1019b476841SSoby Mathew
102538b0020SPaul Beesley#if SPM_MM
10332e83537SArd Biesheuvel#   ifndef SPM_SHIM_EXCEPTIONS_VMA
10432e83537SArd Biesheuvel#       define SPM_SHIM_EXCEPTIONS_VMA RAM
105f90fe02fSChris Kay#   endif /* SPM_SHIM_EXCEPTIONS_VMA */
10632e83537SArd Biesheuvel
1072fccb228SAntonio Nino Diaz    /*
1082fccb228SAntonio Nino Diaz     * Exception vectors of the SPM shim layer. They must be aligned to a 2K
109f90fe02fSChris Kay     * address but we need to place them in a separate page so that we can set
110f90fe02fSChris Kay     * individual permissions on them, so the actual alignment needed is the
111f90fe02fSChris Kay     * page size.
1122fccb228SAntonio Nino Diaz     *
1132fccb228SAntonio Nino Diaz     * There's no need to include this into the RO section of BL31 because it
1142fccb228SAntonio Nino Diaz     * doesn't need to be accessed by BL31.
1152fccb228SAntonio Nino Diaz     */
116da04341eSChris Kay    .spm_shim_exceptions : ALIGN(PAGE_SIZE) {
1172fccb228SAntonio Nino Diaz        __SPM_SHIM_EXCEPTIONS_START__ = .;
118f90fe02fSChris Kay
1192fccb228SAntonio Nino Diaz        *(.spm_shim_exceptions)
120f90fe02fSChris Kay
1215629b2b1SRoberto Vargas        . = ALIGN(PAGE_SIZE);
122f90fe02fSChris Kay
1232fccb228SAntonio Nino Diaz        __SPM_SHIM_EXCEPTIONS_END__ = .;
12432e83537SArd Biesheuvel    } >SPM_SHIM_EXCEPTIONS_VMA AT>RAM
12532e83537SArd Biesheuvel
126da04341eSChris Kay    PROVIDE(__SPM_SHIM_EXCEPTIONS_LMA__ = LOADADDR(.spm_shim_exceptions));
1272fccb228SAntonio Nino Diaz
128da04341eSChris Kay    . = LOADADDR(.spm_shim_exceptions) + SIZEOF(.spm_shim_exceptions);
129f90fe02fSChris Kay#endif /* SPM_MM */
130f90fe02fSChris Kay
13154dc71e7SAchin Gupta    __RW_START__ = .;
13254dc71e7SAchin Gupta
133caa3e7e0SMasahiro Yamada    DATA_SECTION >RAM
134e8ad6168SMasahiro Yamada    RELA_SECTION >RAM
135931f7c61SSoby Mathew
136a1b6db6cSSandrine Bailleux#ifdef BL31_PROGBITS_LIMIT
137138221c2SBoyan Karatotev    ASSERT(
138138221c2SBoyan Karatotev        . <= BL31_PROGBITS_LIMIT,
139138221c2SBoyan Karatotev        "BL31 progbits has exceeded its limit. Consider disabling some features."
140138221c2SBoyan Karatotev    )
141f90fe02fSChris Kay#endif /* BL31_PROGBITS_LIMIT */
142a1b6db6cSSandrine Bailleux
143f8578e64SSamuel Holland#if SEPARATE_NOBITS_REGION
144c367b75eSMadhukar Pappireddy    . = ALIGN(PAGE_SIZE);
145f90fe02fSChris Kay
146f8578e64SSamuel Holland    __RW_END__ = .;
147f8578e64SSamuel Holland    __BL31_END__ = .;
148f8578e64SSamuel Holland
149f8578e64SSamuel Holland    ASSERT(. <= BL31_LIMIT, "BL31 image has exceeded its limit.")
150f8578e64SSamuel Holland
151f8578e64SSamuel Holland    . = BL31_NOBITS_BASE;
152f90fe02fSChris Kay
153f8578e64SSamuel Holland    ASSERT(. == ALIGN(PAGE_SIZE),
154f8578e64SSamuel Holland        "BL31 NOBITS base address is not aligned on a page boundary.")
155f8578e64SSamuel Holland
156f8578e64SSamuel Holland    __NOBITS_START__ = .;
157f90fe02fSChris Kay#endif /* SEPARATE_NOBITS_REGION */
158f8578e64SSamuel Holland
159a926a9f6SMasahiro Yamada    STACK_SECTION >NOBITS
160a7739bc7SMasahiro Yamada    BSS_SECTION >NOBITS
161665e71b8SMasahiro Yamada    XLAT_TABLE_SECTION >NOBITS
162a0cd989dSAchin Gupta
163ab8707e6SSoby Mathew#if USE_COHERENT_MEM
164a0cd989dSAchin Gupta    /*
165f90fe02fSChris Kay     * The base address of the coherent memory section must be page-aligned to
166f90fe02fSChris Kay     * guarantee that the coherent data are stored on their own pages and are
167f90fe02fSChris Kay     * not mixed with normal data.  This is required to set up the correct
1688d69a03fSSandrine Bailleux     * memory attributes for the coherent data page tables.
1698d69a03fSSandrine Bailleux     */
170da04341eSChris Kay    .coherent_ram (NOLOAD) : ALIGN(PAGE_SIZE) {
1718d69a03fSSandrine Bailleux        __COHERENT_RAM_START__ = .;
172f90fe02fSChris Kay
173ee7b35c4SAndrew Thoelke        /*
174f90fe02fSChris Kay         * Bakery locks are stored in coherent memory. Each lock's data is
175f90fe02fSChris Kay         * contiguous and fully allocated by the compiler.
176ee7b35c4SAndrew Thoelke         */
177da04341eSChris Kay        *(.bakery_lock)
178da04341eSChris Kay        *(.tzfw_coherent_mem)
179f90fe02fSChris Kay
1808d69a03fSSandrine Bailleux        __COHERENT_RAM_END_UNALIGNED__ = .;
181f90fe02fSChris Kay
1828d69a03fSSandrine Bailleux        /*
183f90fe02fSChris Kay         * Memory page(s) mapped to this section will be marked as device
184f90fe02fSChris Kay         * memory. No other unexpected data must creep in. Ensure the rest of
185f90fe02fSChris Kay         * the current memory page is unused.
1868d69a03fSSandrine Bailleux         */
1875629b2b1SRoberto Vargas        . = ALIGN(PAGE_SIZE);
188f90fe02fSChris Kay
1898d69a03fSSandrine Bailleux        __COHERENT_RAM_END__ = .;
190f8578e64SSamuel Holland    } >NOBITS
191f90fe02fSChris Kay#endif /* USE_COHERENT_MEM */
1924f6ad66aSAchin Gupta
193f8578e64SSamuel Holland#if SEPARATE_NOBITS_REGION
194f8578e64SSamuel Holland    __NOBITS_END__ = .;
195f8578e64SSamuel Holland
196f8578e64SSamuel Holland    ASSERT(. <= BL31_NOBITS_LIMIT, "BL31 NOBITS region has exceeded its limit.")
197f90fe02fSChris Kay#else /* SEPARATE_NOBITS_REGION */
19854dc71e7SAchin Gupta    __RW_END__ = .;
1998d69a03fSSandrine Bailleux    __BL31_END__ = .;
2004f6ad66aSAchin Gupta
20164207f85SSamuel Holland    ASSERT(. <= BL31_LIMIT, "BL31 image has exceeded its limit.")
202f90fe02fSChris Kay#endif /* SEPARATE_NOBITS_REGION */
203*9b5498a7SHarrison Mutai    RAM_REGION_END = .;
20464207f85SSamuel Holland
205511046eaSMasahiro Yamada    /DISCARD/ : {
206511046eaSMasahiro Yamada        *(.dynsym .dynstr .hash .gnu.hash)
207511046eaSMasahiro Yamada    }
2084f6ad66aSAchin Gupta}
209