xref: /rk3399_ARM-atf/bl31/bl31.ld.S (revision 138221c2457b9d04101b84084c07d576b0eb5a51)
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 {
294f6ad66aSAchin Gupta    . = BL31_BASE;
30f90fe02fSChris Kay
31a2aedac2SAntonio Nino Diaz    ASSERT(. == ALIGN(PAGE_SIZE),
328d69a03fSSandrine Bailleux        "BL31_BASE address is not aligned on a page boundary.")
334f6ad66aSAchin Gupta
34931f7c61SSoby Mathew    __BL31_START__ = .;
35931f7c61SSoby Mathew
365d1c104fSSandrine Bailleux#if SEPARATE_CODE_AND_RODATA
375d1c104fSSandrine Bailleux    .text . : {
385d1c104fSSandrine Bailleux        __TEXT_START__ = .;
39f90fe02fSChris Kay
405d1c104fSSandrine Bailleux        *bl31_entrypoint.o(.text*)
41d7b5f408SJimmy Brisson        *(SORT_BY_ALIGNMENT(SORT(.text*)))
425d1c104fSSandrine Bailleux        *(.vectors)
43f90fe02fSChris Kay
445629b2b1SRoberto Vargas        . = ALIGN(PAGE_SIZE);
45f90fe02fSChris Kay
465d1c104fSSandrine Bailleux        __TEXT_END__ = .;
475d1c104fSSandrine Bailleux    } >RAM
485d1c104fSSandrine Bailleux
495d1c104fSSandrine Bailleux    .rodata . : {
505d1c104fSSandrine Bailleux        __RODATA_START__ = .;
51f90fe02fSChris Kay
52ebd6efaeSSamuel Holland        *(SORT_BY_ALIGNMENT(.rodata*))
535d1c104fSSandrine Bailleux
548a68e864SLeon Chen#   if PLAT_EXTRA_RODATA_INCLUDES
558a68e864SLeon Chen#       include <plat.ld.rodata.inc>
56f90fe02fSChris Kay#   endif /* PLAT_EXTRA_RODATA_INCLUDES */
578a68e864SLeon Chen
580a0a7a9aSMasahiro Yamada        RODATA_COMMON
59931f7c61SSoby Mathew
608e743bcdSJeenu Viswambharan        . = ALIGN(8);
61f90fe02fSChris Kay
6209d40e0eSAntonio Nino Diaz#   include <lib/el3_runtime/pubsub_events.h>
638e743bcdSJeenu Viswambharan
645629b2b1SRoberto Vargas        . = ALIGN(PAGE_SIZE);
65f90fe02fSChris Kay
665d1c104fSSandrine Bailleux        __RODATA_END__ = .;
675d1c104fSSandrine Bailleux    } >RAM
68f90fe02fSChris Kay#else /* SEPARATE_CODE_AND_RODATA */
69da04341eSChris Kay    .ro . : {
708d69a03fSSandrine Bailleux        __RO_START__ = .;
71f90fe02fSChris Kay
72dccc537aSAndrew Thoelke        *bl31_entrypoint.o(.text*)
73ebd6efaeSSamuel Holland        *(SORT_BY_ALIGNMENT(.text*))
74ebd6efaeSSamuel Holland        *(SORT_BY_ALIGNMENT(.rodata*))
757421b465SAchin Gupta
760a0a7a9aSMasahiro Yamada        RODATA_COMMON
775bfac4fcSSoby Mathew
788e743bcdSJeenu Viswambharan        . = ALIGN(8);
79f90fe02fSChris Kay
8009d40e0eSAntonio Nino Diaz#   include <lib/el3_runtime/pubsub_events.h>
818e743bcdSJeenu Viswambharan
82b739f22aSAchin Gupta        *(.vectors)
83f90fe02fSChris Kay
848d69a03fSSandrine Bailleux        __RO_END_UNALIGNED__ = .;
85f90fe02fSChris Kay
868d69a03fSSandrine Bailleux        /*
878d69a03fSSandrine Bailleux         * Memory page(s) mapped to this section will be marked as read-only,
88f90fe02fSChris Kay         * executable. No RW data from the next section must creep in. Ensure
89f90fe02fSChris Kay         * that the rest of the current memory page is unused.
908d69a03fSSandrine Bailleux         */
915629b2b1SRoberto Vargas        . = ALIGN(PAGE_SIZE);
92f90fe02fSChris Kay
938d69a03fSSandrine Bailleux        __RO_END__ = .;
944f6ad66aSAchin Gupta    } >RAM
95f90fe02fSChris Kay#endif /* SEPARATE_CODE_AND_RODATA */
964f6ad66aSAchin Gupta
979b476841SSoby Mathew    ASSERT(__CPU_OPS_END__ > __CPU_OPS_START__,
989b476841SSoby Mathew        "cpu_ops not defined for this platform.")
999b476841SSoby Mathew
100538b0020SPaul Beesley#if SPM_MM
10132e83537SArd Biesheuvel#   ifndef SPM_SHIM_EXCEPTIONS_VMA
10232e83537SArd Biesheuvel#       define SPM_SHIM_EXCEPTIONS_VMA RAM
103f90fe02fSChris Kay#   endif /* SPM_SHIM_EXCEPTIONS_VMA */
10432e83537SArd Biesheuvel
1052fccb228SAntonio Nino Diaz    /*
1062fccb228SAntonio Nino Diaz     * Exception vectors of the SPM shim layer. They must be aligned to a 2K
107f90fe02fSChris Kay     * address but we need to place them in a separate page so that we can set
108f90fe02fSChris Kay     * individual permissions on them, so the actual alignment needed is the
109f90fe02fSChris Kay     * page size.
1102fccb228SAntonio Nino Diaz     *
1112fccb228SAntonio Nino Diaz     * There's no need to include this into the RO section of BL31 because it
1122fccb228SAntonio Nino Diaz     * doesn't need to be accessed by BL31.
1132fccb228SAntonio Nino Diaz     */
114da04341eSChris Kay    .spm_shim_exceptions : ALIGN(PAGE_SIZE) {
1152fccb228SAntonio Nino Diaz        __SPM_SHIM_EXCEPTIONS_START__ = .;
116f90fe02fSChris Kay
1172fccb228SAntonio Nino Diaz        *(.spm_shim_exceptions)
118f90fe02fSChris Kay
1195629b2b1SRoberto Vargas        . = ALIGN(PAGE_SIZE);
120f90fe02fSChris Kay
1212fccb228SAntonio Nino Diaz        __SPM_SHIM_EXCEPTIONS_END__ = .;
12232e83537SArd Biesheuvel    } >SPM_SHIM_EXCEPTIONS_VMA AT>RAM
12332e83537SArd Biesheuvel
124da04341eSChris Kay    PROVIDE(__SPM_SHIM_EXCEPTIONS_LMA__ = LOADADDR(.spm_shim_exceptions));
1252fccb228SAntonio Nino Diaz
126da04341eSChris Kay    . = LOADADDR(.spm_shim_exceptions) + SIZEOF(.spm_shim_exceptions);
127f90fe02fSChris Kay#endif /* SPM_MM */
128f90fe02fSChris Kay
12954dc71e7SAchin Gupta    __RW_START__ = .;
13054dc71e7SAchin Gupta
131caa3e7e0SMasahiro Yamada    DATA_SECTION >RAM
132e8ad6168SMasahiro Yamada    RELA_SECTION >RAM
133931f7c61SSoby Mathew
134a1b6db6cSSandrine Bailleux#ifdef BL31_PROGBITS_LIMIT
135*138221c2SBoyan Karatotev    ASSERT(
136*138221c2SBoyan Karatotev        . <= BL31_PROGBITS_LIMIT,
137*138221c2SBoyan Karatotev        "BL31 progbits has exceeded its limit. Consider disabling some features."
138*138221c2SBoyan Karatotev    )
139f90fe02fSChris Kay#endif /* BL31_PROGBITS_LIMIT */
140a1b6db6cSSandrine Bailleux
141f8578e64SSamuel Holland#if SEPARATE_NOBITS_REGION
142c367b75eSMadhukar Pappireddy    . = ALIGN(PAGE_SIZE);
143f90fe02fSChris Kay
144f8578e64SSamuel Holland    __RW_END__ = .;
145f8578e64SSamuel Holland    __BL31_END__ = .;
146f8578e64SSamuel Holland
147f8578e64SSamuel Holland    ASSERT(. <= BL31_LIMIT, "BL31 image has exceeded its limit.")
148f8578e64SSamuel Holland
149f8578e64SSamuel Holland    . = BL31_NOBITS_BASE;
150f90fe02fSChris Kay
151f8578e64SSamuel Holland    ASSERT(. == ALIGN(PAGE_SIZE),
152f8578e64SSamuel Holland        "BL31 NOBITS base address is not aligned on a page boundary.")
153f8578e64SSamuel Holland
154f8578e64SSamuel Holland    __NOBITS_START__ = .;
155f90fe02fSChris Kay#endif /* SEPARATE_NOBITS_REGION */
156f8578e64SSamuel Holland
157a926a9f6SMasahiro Yamada    STACK_SECTION >NOBITS
158a7739bc7SMasahiro Yamada    BSS_SECTION >NOBITS
159665e71b8SMasahiro Yamada    XLAT_TABLE_SECTION >NOBITS
160a0cd989dSAchin Gupta
161ab8707e6SSoby Mathew#if USE_COHERENT_MEM
162a0cd989dSAchin Gupta    /*
163f90fe02fSChris Kay     * The base address of the coherent memory section must be page-aligned to
164f90fe02fSChris Kay     * guarantee that the coherent data are stored on their own pages and are
165f90fe02fSChris Kay     * not mixed with normal data.  This is required to set up the correct
1668d69a03fSSandrine Bailleux     * memory attributes for the coherent data page tables.
1678d69a03fSSandrine Bailleux     */
168da04341eSChris Kay    .coherent_ram (NOLOAD) : ALIGN(PAGE_SIZE) {
1698d69a03fSSandrine Bailleux        __COHERENT_RAM_START__ = .;
170f90fe02fSChris Kay
171ee7b35c4SAndrew Thoelke        /*
172f90fe02fSChris Kay         * Bakery locks are stored in coherent memory. Each lock's data is
173f90fe02fSChris Kay         * contiguous and fully allocated by the compiler.
174ee7b35c4SAndrew Thoelke         */
175da04341eSChris Kay        *(.bakery_lock)
176da04341eSChris Kay        *(.tzfw_coherent_mem)
177f90fe02fSChris Kay
1788d69a03fSSandrine Bailleux        __COHERENT_RAM_END_UNALIGNED__ = .;
179f90fe02fSChris Kay
1808d69a03fSSandrine Bailleux        /*
181f90fe02fSChris Kay         * Memory page(s) mapped to this section will be marked as device
182f90fe02fSChris Kay         * memory. No other unexpected data must creep in. Ensure the rest of
183f90fe02fSChris Kay         * the current memory page is unused.
1848d69a03fSSandrine Bailleux         */
1855629b2b1SRoberto Vargas        . = ALIGN(PAGE_SIZE);
186f90fe02fSChris Kay
1878d69a03fSSandrine Bailleux        __COHERENT_RAM_END__ = .;
188f8578e64SSamuel Holland    } >NOBITS
189f90fe02fSChris Kay#endif /* USE_COHERENT_MEM */
1904f6ad66aSAchin Gupta
191f8578e64SSamuel Holland#if SEPARATE_NOBITS_REGION
192f8578e64SSamuel Holland    __NOBITS_END__ = .;
193f8578e64SSamuel Holland
194f8578e64SSamuel Holland    ASSERT(. <= BL31_NOBITS_LIMIT, "BL31 NOBITS region has exceeded its limit.")
195f90fe02fSChris Kay#else /* SEPARATE_NOBITS_REGION */
19654dc71e7SAchin Gupta    __RW_END__ = .;
1978d69a03fSSandrine Bailleux    __BL31_END__ = .;
1984f6ad66aSAchin Gupta
19964207f85SSamuel Holland    ASSERT(. <= BL31_LIMIT, "BL31 image has exceeded its limit.")
200f90fe02fSChris Kay#endif /* SEPARATE_NOBITS_REGION */
20164207f85SSamuel Holland
202511046eaSMasahiro Yamada    /DISCARD/ : {
203511046eaSMasahiro Yamada        *(.dynsym .dynstr .hash .gnu.hash)
204511046eaSMasahiro Yamada    }
2054f6ad66aSAchin Gupta}
206