xref: /rk3399_ARM-atf/bl31/bl31.ld.S (revision f7d445fcbbd3d5146d95698ace3381fcf522b9af)
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 {
299b5498a7SHarrison Mutai    RAM_REGION_START = ORIGIN(RAM);
309b5498a7SHarrison 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)
45*f7d445fcSMichal Simek        __TEXT_END_UNALIGNED__ = .;
46f90fe02fSChris Kay
475629b2b1SRoberto Vargas        . = ALIGN(PAGE_SIZE);
48f90fe02fSChris Kay
495d1c104fSSandrine Bailleux        __TEXT_END__ = .;
505d1c104fSSandrine Bailleux    } >RAM
515d1c104fSSandrine Bailleux
525d1c104fSSandrine Bailleux    .rodata . : {
535d1c104fSSandrine Bailleux        __RODATA_START__ = .;
54f90fe02fSChris Kay
55ebd6efaeSSamuel Holland        *(SORT_BY_ALIGNMENT(.rodata*))
565d1c104fSSandrine Bailleux
578a68e864SLeon Chen#   if PLAT_EXTRA_RODATA_INCLUDES
588a68e864SLeon Chen#       include <plat.ld.rodata.inc>
59f90fe02fSChris Kay#   endif /* PLAT_EXTRA_RODATA_INCLUDES */
608a68e864SLeon Chen
610a0a7a9aSMasahiro Yamada        RODATA_COMMON
62931f7c61SSoby Mathew
638e743bcdSJeenu Viswambharan        . = ALIGN(8);
64f90fe02fSChris Kay
6509d40e0eSAntonio Nino Diaz#   include <lib/el3_runtime/pubsub_events.h>
66*f7d445fcSMichal Simek        __RODATA_END_UNALIGNED__ = .;
678e743bcdSJeenu Viswambharan
685629b2b1SRoberto Vargas        . = ALIGN(PAGE_SIZE);
69f90fe02fSChris Kay
705d1c104fSSandrine Bailleux        __RODATA_END__ = .;
715d1c104fSSandrine Bailleux    } >RAM
72f90fe02fSChris Kay#else /* SEPARATE_CODE_AND_RODATA */
73da04341eSChris Kay    .ro . : {
748d69a03fSSandrine Bailleux        __RO_START__ = .;
75f90fe02fSChris Kay
76dccc537aSAndrew Thoelke        *bl31_entrypoint.o(.text*)
77ebd6efaeSSamuel Holland        *(SORT_BY_ALIGNMENT(.text*))
78ebd6efaeSSamuel Holland        *(SORT_BY_ALIGNMENT(.rodata*))
797421b465SAchin Gupta
800a0a7a9aSMasahiro Yamada        RODATA_COMMON
815bfac4fcSSoby Mathew
828e743bcdSJeenu Viswambharan        . = ALIGN(8);
83f90fe02fSChris Kay
8409d40e0eSAntonio Nino Diaz#   include <lib/el3_runtime/pubsub_events.h>
858e743bcdSJeenu Viswambharan
86b739f22aSAchin Gupta        *(.vectors)
87f90fe02fSChris Kay
888d69a03fSSandrine Bailleux        __RO_END_UNALIGNED__ = .;
89f90fe02fSChris Kay
908d69a03fSSandrine Bailleux        /*
918d69a03fSSandrine Bailleux         * Memory page(s) mapped to this section will be marked as read-only,
92f90fe02fSChris Kay         * executable. No RW data from the next section must creep in. Ensure
93f90fe02fSChris Kay         * that the rest of the current memory page is unused.
948d69a03fSSandrine Bailleux         */
955629b2b1SRoberto Vargas        . = ALIGN(PAGE_SIZE);
96f90fe02fSChris Kay
978d69a03fSSandrine Bailleux        __RO_END__ = .;
984f6ad66aSAchin Gupta    } >RAM
99f90fe02fSChris Kay#endif /* SEPARATE_CODE_AND_RODATA */
1004f6ad66aSAchin Gupta
1019b476841SSoby Mathew    ASSERT(__CPU_OPS_END__ > __CPU_OPS_START__,
1029b476841SSoby Mathew        "cpu_ops not defined for this platform.")
1039b476841SSoby Mathew
104538b0020SPaul Beesley#if SPM_MM
10532e83537SArd Biesheuvel#   ifndef SPM_SHIM_EXCEPTIONS_VMA
10632e83537SArd Biesheuvel#       define SPM_SHIM_EXCEPTIONS_VMA RAM
107f90fe02fSChris Kay#   endif /* SPM_SHIM_EXCEPTIONS_VMA */
10832e83537SArd Biesheuvel
1092fccb228SAntonio Nino Diaz    /*
1102fccb228SAntonio Nino Diaz     * Exception vectors of the SPM shim layer. They must be aligned to a 2K
111f90fe02fSChris Kay     * address but we need to place them in a separate page so that we can set
112f90fe02fSChris Kay     * individual permissions on them, so the actual alignment needed is the
113f90fe02fSChris Kay     * page size.
1142fccb228SAntonio Nino Diaz     *
1152fccb228SAntonio Nino Diaz     * There's no need to include this into the RO section of BL31 because it
1162fccb228SAntonio Nino Diaz     * doesn't need to be accessed by BL31.
1172fccb228SAntonio Nino Diaz     */
118da04341eSChris Kay    .spm_shim_exceptions : ALIGN(PAGE_SIZE) {
1192fccb228SAntonio Nino Diaz        __SPM_SHIM_EXCEPTIONS_START__ = .;
120f90fe02fSChris Kay
1212fccb228SAntonio Nino Diaz        *(.spm_shim_exceptions)
122f90fe02fSChris Kay
1235629b2b1SRoberto Vargas        . = ALIGN(PAGE_SIZE);
124f90fe02fSChris Kay
1252fccb228SAntonio Nino Diaz        __SPM_SHIM_EXCEPTIONS_END__ = .;
12632e83537SArd Biesheuvel    } >SPM_SHIM_EXCEPTIONS_VMA AT>RAM
12732e83537SArd Biesheuvel
128da04341eSChris Kay    PROVIDE(__SPM_SHIM_EXCEPTIONS_LMA__ = LOADADDR(.spm_shim_exceptions));
1292fccb228SAntonio Nino Diaz
130da04341eSChris Kay    . = LOADADDR(.spm_shim_exceptions) + SIZEOF(.spm_shim_exceptions);
131f90fe02fSChris Kay#endif /* SPM_MM */
132f90fe02fSChris Kay
13354dc71e7SAchin Gupta    __RW_START__ = .;
13454dc71e7SAchin Gupta
135caa3e7e0SMasahiro Yamada    DATA_SECTION >RAM
136e8ad6168SMasahiro Yamada    RELA_SECTION >RAM
137931f7c61SSoby Mathew
138a1b6db6cSSandrine Bailleux#ifdef BL31_PROGBITS_LIMIT
139138221c2SBoyan Karatotev    ASSERT(
140138221c2SBoyan Karatotev        . <= BL31_PROGBITS_LIMIT,
141138221c2SBoyan Karatotev        "BL31 progbits has exceeded its limit. Consider disabling some features."
142138221c2SBoyan Karatotev    )
143f90fe02fSChris Kay#endif /* BL31_PROGBITS_LIMIT */
144a1b6db6cSSandrine Bailleux
145f8578e64SSamuel Holland#if SEPARATE_NOBITS_REGION
146c367b75eSMadhukar Pappireddy    . = ALIGN(PAGE_SIZE);
147f90fe02fSChris Kay
148f8578e64SSamuel Holland    __RW_END__ = .;
149f8578e64SSamuel Holland    __BL31_END__ = .;
150f8578e64SSamuel Holland
151f8578e64SSamuel Holland    ASSERT(. <= BL31_LIMIT, "BL31 image has exceeded its limit.")
152f8578e64SSamuel Holland
153f8578e64SSamuel Holland    . = BL31_NOBITS_BASE;
154f90fe02fSChris Kay
155f8578e64SSamuel Holland    ASSERT(. == ALIGN(PAGE_SIZE),
156f8578e64SSamuel Holland        "BL31 NOBITS base address is not aligned on a page boundary.")
157f8578e64SSamuel Holland
158f8578e64SSamuel Holland    __NOBITS_START__ = .;
159f90fe02fSChris Kay#endif /* SEPARATE_NOBITS_REGION */
160f8578e64SSamuel Holland
161a926a9f6SMasahiro Yamada    STACK_SECTION >NOBITS
162a7739bc7SMasahiro Yamada    BSS_SECTION >NOBITS
163665e71b8SMasahiro Yamada    XLAT_TABLE_SECTION >NOBITS
164a0cd989dSAchin Gupta
165ab8707e6SSoby Mathew#if USE_COHERENT_MEM
166a0cd989dSAchin Gupta    /*
167f90fe02fSChris Kay     * The base address of the coherent memory section must be page-aligned to
168f90fe02fSChris Kay     * guarantee that the coherent data are stored on their own pages and are
169f90fe02fSChris Kay     * not mixed with normal data.  This is required to set up the correct
1708d69a03fSSandrine Bailleux     * memory attributes for the coherent data page tables.
1718d69a03fSSandrine Bailleux     */
172da04341eSChris Kay    .coherent_ram (NOLOAD) : ALIGN(PAGE_SIZE) {
1738d69a03fSSandrine Bailleux        __COHERENT_RAM_START__ = .;
174f90fe02fSChris Kay
175ee7b35c4SAndrew Thoelke        /*
176f90fe02fSChris Kay         * Bakery locks are stored in coherent memory. Each lock's data is
177f90fe02fSChris Kay         * contiguous and fully allocated by the compiler.
178ee7b35c4SAndrew Thoelke         */
179da04341eSChris Kay        *(.bakery_lock)
180da04341eSChris Kay        *(.tzfw_coherent_mem)
181f90fe02fSChris Kay
1828d69a03fSSandrine Bailleux        __COHERENT_RAM_END_UNALIGNED__ = .;
183f90fe02fSChris Kay
1848d69a03fSSandrine Bailleux        /*
185f90fe02fSChris Kay         * Memory page(s) mapped to this section will be marked as device
186f90fe02fSChris Kay         * memory. No other unexpected data must creep in. Ensure the rest of
187f90fe02fSChris Kay         * the current memory page is unused.
1888d69a03fSSandrine Bailleux         */
1895629b2b1SRoberto Vargas        . = ALIGN(PAGE_SIZE);
190f90fe02fSChris Kay
1918d69a03fSSandrine Bailleux        __COHERENT_RAM_END__ = .;
192f8578e64SSamuel Holland    } >NOBITS
193f90fe02fSChris Kay#endif /* USE_COHERENT_MEM */
1944f6ad66aSAchin Gupta
195f8578e64SSamuel Holland#if SEPARATE_NOBITS_REGION
196f8578e64SSamuel Holland    __NOBITS_END__ = .;
197f8578e64SSamuel Holland
198f8578e64SSamuel Holland    ASSERT(. <= BL31_NOBITS_LIMIT, "BL31 NOBITS region has exceeded its limit.")
199f90fe02fSChris Kay#else /* SEPARATE_NOBITS_REGION */
20054dc71e7SAchin Gupta    __RW_END__ = .;
2018d69a03fSSandrine Bailleux    __BL31_END__ = .;
2024f6ad66aSAchin Gupta
20364207f85SSamuel Holland    ASSERT(. <= BL31_LIMIT, "BL31 image has exceeded its limit.")
204f90fe02fSChris Kay#endif /* SEPARATE_NOBITS_REGION */
2059b5498a7SHarrison Mutai    RAM_REGION_END = .;
20664207f85SSamuel Holland
207511046eaSMasahiro Yamada    /DISCARD/ : {
208511046eaSMasahiro Yamada        *(.dynsym .dynstr .hash .gnu.hash)
209511046eaSMasahiro Yamada    }
2104f6ad66aSAchin Gupta}
211