xref: /rk3399_ARM-atf/bl31/bl31.ld.S (revision 86acbbe2d88688cdd506192983e315b4e9ca94f7)
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 */
22*86acbbe2SYe Li
23*86acbbe2SYe Li#if SEPARATE_RWDATA_REGION
24*86acbbe2SYe Li    RAM_RW (rw): ORIGIN = BL31_RWDATA_BASE, LENGTH = BL31_RWDATA_LIMIT - BL31_RWDATA_BASE
25*86acbbe2SYe Li#else /* SEPARATE_RWDATA_REGION */
26*86acbbe2SYe Li#define RAM_RW RAM
27*86acbbe2SYe Li#endif /* SEPARATE_RWDATA_REGION */
284f6ad66aSAchin Gupta}
294f6ad66aSAchin Gupta
30ec693569SCaesar Wang#ifdef PLAT_EXTRA_LD_SCRIPT
31ec693569SCaesar Wang#   include <plat.ld.S>
32f90fe02fSChris Kay#endif /* PLAT_EXTRA_LD_SCRIPT */
334f6ad66aSAchin Gupta
34f90fe02fSChris KaySECTIONS {
359b5498a7SHarrison Mutai    RAM_REGION_START = ORIGIN(RAM);
369b5498a7SHarrison Mutai    RAM_REGION_LENGTH = LENGTH(RAM);
374f6ad66aSAchin Gupta    . = BL31_BASE;
38f90fe02fSChris Kay
39a2aedac2SAntonio Nino Diaz    ASSERT(. == ALIGN(PAGE_SIZE),
408d69a03fSSandrine Bailleux        "BL31_BASE address is not aligned on a page boundary.")
414f6ad66aSAchin Gupta
42931f7c61SSoby Mathew    __BL31_START__ = .;
43931f7c61SSoby Mathew
445d1c104fSSandrine Bailleux#if SEPARATE_CODE_AND_RODATA
455d1c104fSSandrine Bailleux    .text . : {
463d6edc32SAndrey Skvortsov        ASSERT(. == ALIGN(PAGE_SIZE),
473d6edc32SAndrey Skvortsov        ".text is not aligned on a page boundary.");
483d6edc32SAndrey Skvortsov
495d1c104fSSandrine Bailleux        __TEXT_START__ = .;
50f90fe02fSChris Kay
515d1c104fSSandrine Bailleux        *bl31_entrypoint.o(.text*)
52d7b5f408SJimmy Brisson        *(SORT_BY_ALIGNMENT(SORT(.text*)))
535d1c104fSSandrine Bailleux        *(.vectors)
54f7d445fcSMichal Simek        __TEXT_END_UNALIGNED__ = .;
55f90fe02fSChris Kay
565629b2b1SRoberto Vargas        . = ALIGN(PAGE_SIZE);
57f90fe02fSChris Kay
585d1c104fSSandrine Bailleux        __TEXT_END__ = .;
595d1c104fSSandrine Bailleux    } >RAM
605d1c104fSSandrine Bailleux
615d1c104fSSandrine Bailleux    .rodata . : {
625d1c104fSSandrine Bailleux        __RODATA_START__ = .;
63f90fe02fSChris Kay
64ebd6efaeSSamuel Holland        *(SORT_BY_ALIGNMENT(.rodata*))
655d1c104fSSandrine Bailleux
668a68e864SLeon Chen#   if PLAT_EXTRA_RODATA_INCLUDES
678a68e864SLeon Chen#       include <plat.ld.rodata.inc>
68f90fe02fSChris Kay#   endif /* PLAT_EXTRA_RODATA_INCLUDES */
698a68e864SLeon Chen
700a0a7a9aSMasahiro Yamada        RODATA_COMMON
71931f7c61SSoby Mathew
728e743bcdSJeenu Viswambharan        . = ALIGN(8);
73f90fe02fSChris Kay
7409d40e0eSAntonio Nino Diaz#   include <lib/el3_runtime/pubsub_events.h>
75f7d445fcSMichal Simek        __RODATA_END_UNALIGNED__ = .;
768e743bcdSJeenu Viswambharan
775629b2b1SRoberto Vargas        . = ALIGN(PAGE_SIZE);
78f90fe02fSChris Kay
795d1c104fSSandrine Bailleux        __RODATA_END__ = .;
805d1c104fSSandrine Bailleux    } >RAM
81f90fe02fSChris Kay#else /* SEPARATE_CODE_AND_RODATA */
82da04341eSChris Kay    .ro . : {
833d6edc32SAndrey Skvortsov        ASSERT(. == ALIGN(PAGE_SIZE),
843d6edc32SAndrey Skvortsov        ".ro is not aligned on a page boundary.");
853d6edc32SAndrey Skvortsov
868d69a03fSSandrine Bailleux        __RO_START__ = .;
87f90fe02fSChris Kay
88dccc537aSAndrew Thoelke        *bl31_entrypoint.o(.text*)
89ebd6efaeSSamuel Holland        *(SORT_BY_ALIGNMENT(.text*))
90ebd6efaeSSamuel Holland        *(SORT_BY_ALIGNMENT(.rodata*))
917421b465SAchin Gupta
920a0a7a9aSMasahiro Yamada        RODATA_COMMON
935bfac4fcSSoby Mathew
948e743bcdSJeenu Viswambharan        . = ALIGN(8);
95f90fe02fSChris Kay
9609d40e0eSAntonio Nino Diaz#   include <lib/el3_runtime/pubsub_events.h>
978e743bcdSJeenu Viswambharan
98b739f22aSAchin Gupta        *(.vectors)
99f90fe02fSChris Kay
1008d69a03fSSandrine Bailleux        __RO_END_UNALIGNED__ = .;
101f90fe02fSChris Kay
1028d69a03fSSandrine Bailleux        /*
1038d69a03fSSandrine Bailleux         * Memory page(s) mapped to this section will be marked as read-only,
104f90fe02fSChris Kay         * executable. No RW data from the next section must creep in. Ensure
105f90fe02fSChris Kay         * that the rest of the current memory page is unused.
1068d69a03fSSandrine Bailleux         */
1075629b2b1SRoberto Vargas        . = ALIGN(PAGE_SIZE);
108f90fe02fSChris Kay
1098d69a03fSSandrine Bailleux        __RO_END__ = .;
1104f6ad66aSAchin Gupta    } >RAM
111f90fe02fSChris Kay#endif /* SEPARATE_CODE_AND_RODATA */
1124f6ad66aSAchin Gupta
1139b476841SSoby Mathew    ASSERT(__CPU_OPS_END__ > __CPU_OPS_START__,
1149b476841SSoby Mathew        "cpu_ops not defined for this platform.")
1159b476841SSoby Mathew
116f5e1bed2SNishant Sharma#if SPM_MM || (SPMC_AT_EL3 && SPMC_AT_EL3_SEL0_SP)
11732e83537SArd Biesheuvel#   ifndef SPM_SHIM_EXCEPTIONS_VMA
11832e83537SArd Biesheuvel#       define SPM_SHIM_EXCEPTIONS_VMA RAM
119f90fe02fSChris Kay#   endif /* SPM_SHIM_EXCEPTIONS_VMA */
12032e83537SArd Biesheuvel
1212fccb228SAntonio Nino Diaz    /*
1222fccb228SAntonio Nino Diaz     * Exception vectors of the SPM shim layer. They must be aligned to a 2K
123f90fe02fSChris Kay     * address but we need to place them in a separate page so that we can set
124f90fe02fSChris Kay     * individual permissions on them, so the actual alignment needed is the
125f90fe02fSChris Kay     * page size.
1262fccb228SAntonio Nino Diaz     *
1272fccb228SAntonio Nino Diaz     * There's no need to include this into the RO section of BL31 because it
1282fccb228SAntonio Nino Diaz     * doesn't need to be accessed by BL31.
1292fccb228SAntonio Nino Diaz     */
130da04341eSChris Kay    .spm_shim_exceptions : ALIGN(PAGE_SIZE) {
1312fccb228SAntonio Nino Diaz        __SPM_SHIM_EXCEPTIONS_START__ = .;
132f90fe02fSChris Kay
1332fccb228SAntonio Nino Diaz        *(.spm_shim_exceptions)
134f90fe02fSChris Kay
1355629b2b1SRoberto Vargas        . = ALIGN(PAGE_SIZE);
136f90fe02fSChris Kay
1372fccb228SAntonio Nino Diaz        __SPM_SHIM_EXCEPTIONS_END__ = .;
13832e83537SArd Biesheuvel    } >SPM_SHIM_EXCEPTIONS_VMA AT>RAM
13932e83537SArd Biesheuvel
140da04341eSChris Kay    PROVIDE(__SPM_SHIM_EXCEPTIONS_LMA__ = LOADADDR(.spm_shim_exceptions));
1412fccb228SAntonio Nino Diaz
142da04341eSChris Kay    . = LOADADDR(.spm_shim_exceptions) + SIZEOF(.spm_shim_exceptions);
143f5e1bed2SNishant Sharma#endif /* SPM_MM || (SPMC_AT_EL3 && SPMC_AT_EL3_SEL0_SP) */
144f90fe02fSChris Kay
145*86acbbe2SYe Li#if SEPARATE_RWDATA_REGION
146*86acbbe2SYe Li    . = BL31_RWDATA_BASE;
147*86acbbe2SYe Li    ASSERT(BL31_RWDATA_BASE == ALIGN(PAGE_SIZE),
148*86acbbe2SYe Li           "BL31_RWDATA_BASE address is not aligned on a page boundary.")
149*86acbbe2SYe Li
150*86acbbe2SYe Li    /*
151*86acbbe2SYe Li     * Define a linker symbol to mark the start of the RW memory area for this
152*86acbbe2SYe Li     * image.
153*86acbbe2SYe Li     */
154*86acbbe2SYe Li    __RW_START__ = . ;
155*86acbbe2SYe Li
156*86acbbe2SYe Li    DATA_SECTION >RAM_RW AT>RAM
157*86acbbe2SYe Li    __DATA_RAM_START__ = __DATA_START__;
158*86acbbe2SYe Li    __DATA_RAM_END__ = __DATA_END__;
159*86acbbe2SYe Li    __DATA_ROM_START__ = LOADADDR(.data);
160*86acbbe2SYe Li
161*86acbbe2SYe Li    . = ALIGN(PAGE_SIZE);
162*86acbbe2SYe Li    __RW_END__ = .;
163*86acbbe2SYe Li
164*86acbbe2SYe Li    RELA_SECTION >RAM
165*86acbbe2SYe Li#else /* SEPARATE_RWDATA_REGION */
166*86acbbe2SYe Li    /*
167*86acbbe2SYe Li     * Define a linker symbol to mark the start of the RW memory area for this
168*86acbbe2SYe Li     * image.
169*86acbbe2SYe Li     */
17054dc71e7SAchin Gupta    __RW_START__ = . ;
17154dc71e7SAchin Gupta
172caa3e7e0SMasahiro Yamada    DATA_SECTION >RAM
173e8ad6168SMasahiro Yamada    RELA_SECTION >RAM
174*86acbbe2SYe Li#endif /* SEPARATE_RWDATA_REGION */
175931f7c61SSoby Mathew
176a1b6db6cSSandrine Bailleux#ifdef BL31_PROGBITS_LIMIT
177138221c2SBoyan Karatotev    ASSERT(
178138221c2SBoyan Karatotev        . <= BL31_PROGBITS_LIMIT,
179138221c2SBoyan Karatotev        "BL31 progbits has exceeded its limit. Consider disabling some features."
180138221c2SBoyan Karatotev    )
181f90fe02fSChris Kay#endif /* BL31_PROGBITS_LIMIT */
182a1b6db6cSSandrine Bailleux
183f8578e64SSamuel Holland#if SEPARATE_NOBITS_REGION
184c367b75eSMadhukar Pappireddy    . = ALIGN(PAGE_SIZE);
185f90fe02fSChris Kay
186*86acbbe2SYe Li#if !SEPARATE_RWDATA_REGION
187f8578e64SSamuel Holland    __RW_END__ = .;
188*86acbbe2SYe Li#endif /* SEPARATE_RWDATA_REGION */
189f8578e64SSamuel Holland    __BL31_END__ = .;
190f8578e64SSamuel Holland
191f8578e64SSamuel Holland    ASSERT(. <= BL31_LIMIT, "BL31 image has exceeded its limit.")
192f8578e64SSamuel Holland
193f8578e64SSamuel Holland    . = BL31_NOBITS_BASE;
194f90fe02fSChris Kay
195f8578e64SSamuel Holland    ASSERT(. == ALIGN(PAGE_SIZE),
196f8578e64SSamuel Holland        "BL31 NOBITS base address is not aligned on a page boundary.")
197f8578e64SSamuel Holland
198f8578e64SSamuel Holland    __NOBITS_START__ = .;
199f90fe02fSChris Kay#endif /* SEPARATE_NOBITS_REGION */
200f8578e64SSamuel Holland
201a926a9f6SMasahiro Yamada    STACK_SECTION >NOBITS
202a7739bc7SMasahiro Yamada    BSS_SECTION >NOBITS
203665e71b8SMasahiro Yamada    XLAT_TABLE_SECTION >NOBITS
204a0cd989dSAchin Gupta
205ab8707e6SSoby Mathew#if USE_COHERENT_MEM
206a0cd989dSAchin Gupta    /*
207f90fe02fSChris Kay     * The base address of the coherent memory section must be page-aligned to
208f90fe02fSChris Kay     * guarantee that the coherent data are stored on their own pages and are
209f90fe02fSChris Kay     * not mixed with normal data.  This is required to set up the correct
2108d69a03fSSandrine Bailleux     * memory attributes for the coherent data page tables.
2118d69a03fSSandrine Bailleux     */
212da04341eSChris Kay    .coherent_ram (NOLOAD) : ALIGN(PAGE_SIZE) {
2138d69a03fSSandrine Bailleux        __COHERENT_RAM_START__ = .;
214f90fe02fSChris Kay
215ee7b35c4SAndrew Thoelke        /*
216f90fe02fSChris Kay         * Bakery locks are stored in coherent memory. Each lock's data is
217f90fe02fSChris Kay         * contiguous and fully allocated by the compiler.
218ee7b35c4SAndrew Thoelke         */
219da04341eSChris Kay        *(.bakery_lock)
220da04341eSChris Kay        *(.tzfw_coherent_mem)
221f90fe02fSChris Kay
2228d69a03fSSandrine Bailleux        __COHERENT_RAM_END_UNALIGNED__ = .;
223f90fe02fSChris Kay
2248d69a03fSSandrine Bailleux        /*
225f90fe02fSChris Kay         * Memory page(s) mapped to this section will be marked as device
226f90fe02fSChris Kay         * memory. No other unexpected data must creep in. Ensure the rest of
227f90fe02fSChris Kay         * the current memory page is unused.
2288d69a03fSSandrine Bailleux         */
2295629b2b1SRoberto Vargas        . = ALIGN(PAGE_SIZE);
230f90fe02fSChris Kay
2318d69a03fSSandrine Bailleux        __COHERENT_RAM_END__ = .;
232f8578e64SSamuel Holland    } >NOBITS
233f90fe02fSChris Kay#endif /* USE_COHERENT_MEM */
2344f6ad66aSAchin Gupta
235f8578e64SSamuel Holland#if SEPARATE_NOBITS_REGION
236f8578e64SSamuel Holland    __NOBITS_END__ = .;
237f8578e64SSamuel Holland
238f8578e64SSamuel Holland    ASSERT(. <= BL31_NOBITS_LIMIT, "BL31 NOBITS region has exceeded its limit.")
239f90fe02fSChris Kay#else /* SEPARATE_NOBITS_REGION */
240*86acbbe2SYe Li    /*
241*86acbbe2SYe Li     * Define a linker symbol to mark the end of the RW memory area for this
242*86acbbe2SYe Li     * image.
243*86acbbe2SYe Li     */
244*86acbbe2SYe Li#if !SEPARATE_RWDATA_REGION
24554dc71e7SAchin Gupta    __RW_END__ = .;
246*86acbbe2SYe Li#endif /* SEPARATE_RWDATA_REGION */
2478d69a03fSSandrine Bailleux    __BL31_END__ = .;
2484f6ad66aSAchin Gupta
24964207f85SSamuel Holland    ASSERT(. <= BL31_LIMIT, "BL31 image has exceeded its limit.")
250f90fe02fSChris Kay#endif /* SEPARATE_NOBITS_REGION */
2519b5498a7SHarrison Mutai    RAM_REGION_END = .;
25264207f85SSamuel Holland
253511046eaSMasahiro Yamada    /DISCARD/ : {
254511046eaSMasahiro Yamada        *(.dynsym .dynstr .hash .gnu.hash)
255511046eaSMasahiro Yamada    }
2564f6ad66aSAchin Gupta}
257