xref: /rk3399_ARM-atf/bl31/bl31.ld.S (revision 3d6edc325c52082ab63ffd003c55a4ed875a52c5)
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 . : {
40*3d6edc32SAndrey Skvortsov        ASSERT(. == ALIGN(PAGE_SIZE),
41*3d6edc32SAndrey Skvortsov        ".text is not aligned on a page boundary.");
42*3d6edc32SAndrey Skvortsov
435d1c104fSSandrine Bailleux        __TEXT_START__ = .;
44f90fe02fSChris Kay
455d1c104fSSandrine Bailleux        *bl31_entrypoint.o(.text*)
46d7b5f408SJimmy Brisson        *(SORT_BY_ALIGNMENT(SORT(.text*)))
475d1c104fSSandrine Bailleux        *(.vectors)
48f7d445fcSMichal Simek        __TEXT_END_UNALIGNED__ = .;
49f90fe02fSChris Kay
505629b2b1SRoberto Vargas        . = ALIGN(PAGE_SIZE);
51f90fe02fSChris Kay
525d1c104fSSandrine Bailleux        __TEXT_END__ = .;
535d1c104fSSandrine Bailleux    } >RAM
545d1c104fSSandrine Bailleux
555d1c104fSSandrine Bailleux    .rodata . : {
565d1c104fSSandrine Bailleux        __RODATA_START__ = .;
57f90fe02fSChris Kay
58ebd6efaeSSamuel Holland        *(SORT_BY_ALIGNMENT(.rodata*))
595d1c104fSSandrine Bailleux
608a68e864SLeon Chen#   if PLAT_EXTRA_RODATA_INCLUDES
618a68e864SLeon Chen#       include <plat.ld.rodata.inc>
62f90fe02fSChris Kay#   endif /* PLAT_EXTRA_RODATA_INCLUDES */
638a68e864SLeon Chen
640a0a7a9aSMasahiro Yamada        RODATA_COMMON
65931f7c61SSoby Mathew
668e743bcdSJeenu Viswambharan        . = ALIGN(8);
67f90fe02fSChris Kay
6809d40e0eSAntonio Nino Diaz#   include <lib/el3_runtime/pubsub_events.h>
69f7d445fcSMichal Simek        __RODATA_END_UNALIGNED__ = .;
708e743bcdSJeenu Viswambharan
715629b2b1SRoberto Vargas        . = ALIGN(PAGE_SIZE);
72f90fe02fSChris Kay
735d1c104fSSandrine Bailleux        __RODATA_END__ = .;
745d1c104fSSandrine Bailleux    } >RAM
75f90fe02fSChris Kay#else /* SEPARATE_CODE_AND_RODATA */
76da04341eSChris Kay    .ro . : {
77*3d6edc32SAndrey Skvortsov        ASSERT(. == ALIGN(PAGE_SIZE),
78*3d6edc32SAndrey Skvortsov        ".ro is not aligned on a page boundary.");
79*3d6edc32SAndrey Skvortsov
808d69a03fSSandrine Bailleux        __RO_START__ = .;
81f90fe02fSChris Kay
82dccc537aSAndrew Thoelke        *bl31_entrypoint.o(.text*)
83ebd6efaeSSamuel Holland        *(SORT_BY_ALIGNMENT(.text*))
84ebd6efaeSSamuel Holland        *(SORT_BY_ALIGNMENT(.rodata*))
857421b465SAchin Gupta
860a0a7a9aSMasahiro Yamada        RODATA_COMMON
875bfac4fcSSoby Mathew
888e743bcdSJeenu Viswambharan        . = ALIGN(8);
89f90fe02fSChris Kay
9009d40e0eSAntonio Nino Diaz#   include <lib/el3_runtime/pubsub_events.h>
918e743bcdSJeenu Viswambharan
92b739f22aSAchin Gupta        *(.vectors)
93f90fe02fSChris Kay
948d69a03fSSandrine Bailleux        __RO_END_UNALIGNED__ = .;
95f90fe02fSChris Kay
968d69a03fSSandrine Bailleux        /*
978d69a03fSSandrine Bailleux         * Memory page(s) mapped to this section will be marked as read-only,
98f90fe02fSChris Kay         * executable. No RW data from the next section must creep in. Ensure
99f90fe02fSChris Kay         * that the rest of the current memory page is unused.
1008d69a03fSSandrine Bailleux         */
1015629b2b1SRoberto Vargas        . = ALIGN(PAGE_SIZE);
102f90fe02fSChris Kay
1038d69a03fSSandrine Bailleux        __RO_END__ = .;
1044f6ad66aSAchin Gupta    } >RAM
105f90fe02fSChris Kay#endif /* SEPARATE_CODE_AND_RODATA */
1064f6ad66aSAchin Gupta
1079b476841SSoby Mathew    ASSERT(__CPU_OPS_END__ > __CPU_OPS_START__,
1089b476841SSoby Mathew        "cpu_ops not defined for this platform.")
1099b476841SSoby Mathew
110f5e1bed2SNishant Sharma#if SPM_MM || (SPMC_AT_EL3 && SPMC_AT_EL3_SEL0_SP)
11132e83537SArd Biesheuvel#   ifndef SPM_SHIM_EXCEPTIONS_VMA
11232e83537SArd Biesheuvel#       define SPM_SHIM_EXCEPTIONS_VMA RAM
113f90fe02fSChris Kay#   endif /* SPM_SHIM_EXCEPTIONS_VMA */
11432e83537SArd Biesheuvel
1152fccb228SAntonio Nino Diaz    /*
1162fccb228SAntonio Nino Diaz     * Exception vectors of the SPM shim layer. They must be aligned to a 2K
117f90fe02fSChris Kay     * address but we need to place them in a separate page so that we can set
118f90fe02fSChris Kay     * individual permissions on them, so the actual alignment needed is the
119f90fe02fSChris Kay     * page size.
1202fccb228SAntonio Nino Diaz     *
1212fccb228SAntonio Nino Diaz     * There's no need to include this into the RO section of BL31 because it
1222fccb228SAntonio Nino Diaz     * doesn't need to be accessed by BL31.
1232fccb228SAntonio Nino Diaz     */
124da04341eSChris Kay    .spm_shim_exceptions : ALIGN(PAGE_SIZE) {
1252fccb228SAntonio Nino Diaz        __SPM_SHIM_EXCEPTIONS_START__ = .;
126f90fe02fSChris Kay
1272fccb228SAntonio Nino Diaz        *(.spm_shim_exceptions)
128f90fe02fSChris Kay
1295629b2b1SRoberto Vargas        . = ALIGN(PAGE_SIZE);
130f90fe02fSChris Kay
1312fccb228SAntonio Nino Diaz        __SPM_SHIM_EXCEPTIONS_END__ = .;
13232e83537SArd Biesheuvel    } >SPM_SHIM_EXCEPTIONS_VMA AT>RAM
13332e83537SArd Biesheuvel
134da04341eSChris Kay    PROVIDE(__SPM_SHIM_EXCEPTIONS_LMA__ = LOADADDR(.spm_shim_exceptions));
1352fccb228SAntonio Nino Diaz
136da04341eSChris Kay    . = LOADADDR(.spm_shim_exceptions) + SIZEOF(.spm_shim_exceptions);
137f5e1bed2SNishant Sharma#endif /* SPM_MM || (SPMC_AT_EL3 && SPMC_AT_EL3_SEL0_SP) */
138f90fe02fSChris Kay
13954dc71e7SAchin Gupta    __RW_START__ = .;
14054dc71e7SAchin Gupta
141caa3e7e0SMasahiro Yamada    DATA_SECTION >RAM
142e8ad6168SMasahiro Yamada    RELA_SECTION >RAM
143931f7c61SSoby Mathew
144a1b6db6cSSandrine Bailleux#ifdef BL31_PROGBITS_LIMIT
145138221c2SBoyan Karatotev    ASSERT(
146138221c2SBoyan Karatotev        . <= BL31_PROGBITS_LIMIT,
147138221c2SBoyan Karatotev        "BL31 progbits has exceeded its limit. Consider disabling some features."
148138221c2SBoyan Karatotev    )
149f90fe02fSChris Kay#endif /* BL31_PROGBITS_LIMIT */
150a1b6db6cSSandrine Bailleux
151f8578e64SSamuel Holland#if SEPARATE_NOBITS_REGION
152c367b75eSMadhukar Pappireddy    . = ALIGN(PAGE_SIZE);
153f90fe02fSChris Kay
154f8578e64SSamuel Holland    __RW_END__ = .;
155f8578e64SSamuel Holland    __BL31_END__ = .;
156f8578e64SSamuel Holland
157f8578e64SSamuel Holland    ASSERT(. <= BL31_LIMIT, "BL31 image has exceeded its limit.")
158f8578e64SSamuel Holland
159f8578e64SSamuel Holland    . = BL31_NOBITS_BASE;
160f90fe02fSChris Kay
161f8578e64SSamuel Holland    ASSERT(. == ALIGN(PAGE_SIZE),
162f8578e64SSamuel Holland        "BL31 NOBITS base address is not aligned on a page boundary.")
163f8578e64SSamuel Holland
164f8578e64SSamuel Holland    __NOBITS_START__ = .;
165f90fe02fSChris Kay#endif /* SEPARATE_NOBITS_REGION */
166f8578e64SSamuel Holland
167a926a9f6SMasahiro Yamada    STACK_SECTION >NOBITS
168a7739bc7SMasahiro Yamada    BSS_SECTION >NOBITS
169665e71b8SMasahiro Yamada    XLAT_TABLE_SECTION >NOBITS
170a0cd989dSAchin Gupta
171ab8707e6SSoby Mathew#if USE_COHERENT_MEM
172a0cd989dSAchin Gupta    /*
173f90fe02fSChris Kay     * The base address of the coherent memory section must be page-aligned to
174f90fe02fSChris Kay     * guarantee that the coherent data are stored on their own pages and are
175f90fe02fSChris Kay     * not mixed with normal data.  This is required to set up the correct
1768d69a03fSSandrine Bailleux     * memory attributes for the coherent data page tables.
1778d69a03fSSandrine Bailleux     */
178da04341eSChris Kay    .coherent_ram (NOLOAD) : ALIGN(PAGE_SIZE) {
1798d69a03fSSandrine Bailleux        __COHERENT_RAM_START__ = .;
180f90fe02fSChris Kay
181ee7b35c4SAndrew Thoelke        /*
182f90fe02fSChris Kay         * Bakery locks are stored in coherent memory. Each lock's data is
183f90fe02fSChris Kay         * contiguous and fully allocated by the compiler.
184ee7b35c4SAndrew Thoelke         */
185da04341eSChris Kay        *(.bakery_lock)
186da04341eSChris Kay        *(.tzfw_coherent_mem)
187f90fe02fSChris Kay
1888d69a03fSSandrine Bailleux        __COHERENT_RAM_END_UNALIGNED__ = .;
189f90fe02fSChris Kay
1908d69a03fSSandrine Bailleux        /*
191f90fe02fSChris Kay         * Memory page(s) mapped to this section will be marked as device
192f90fe02fSChris Kay         * memory. No other unexpected data must creep in. Ensure the rest of
193f90fe02fSChris Kay         * the current memory page is unused.
1948d69a03fSSandrine Bailleux         */
1955629b2b1SRoberto Vargas        . = ALIGN(PAGE_SIZE);
196f90fe02fSChris Kay
1978d69a03fSSandrine Bailleux        __COHERENT_RAM_END__ = .;
198f8578e64SSamuel Holland    } >NOBITS
199f90fe02fSChris Kay#endif /* USE_COHERENT_MEM */
2004f6ad66aSAchin Gupta
201f8578e64SSamuel Holland#if SEPARATE_NOBITS_REGION
202f8578e64SSamuel Holland    __NOBITS_END__ = .;
203f8578e64SSamuel Holland
204f8578e64SSamuel Holland    ASSERT(. <= BL31_NOBITS_LIMIT, "BL31 NOBITS region has exceeded its limit.")
205f90fe02fSChris Kay#else /* SEPARATE_NOBITS_REGION */
20654dc71e7SAchin Gupta    __RW_END__ = .;
2078d69a03fSSandrine Bailleux    __BL31_END__ = .;
2084f6ad66aSAchin Gupta
20964207f85SSamuel Holland    ASSERT(. <= BL31_LIMIT, "BL31 image has exceeded its limit.")
210f90fe02fSChris Kay#endif /* SEPARATE_NOBITS_REGION */
2119b5498a7SHarrison Mutai    RAM_REGION_END = .;
21264207f85SSamuel Holland
213511046eaSMasahiro Yamada    /DISCARD/ : {
214511046eaSMasahiro Yamada        *(.dynsym .dynstr .hash .gnu.hash)
215511046eaSMasahiro Yamada    }
2164f6ad66aSAchin Gupta}
217