xref: /rk3399_ARM-atf/bl31/bl31.ld.S (revision 5bfac4fc2f95647e57cc4e9ca3aaa46662890743)
14f6ad66aSAchin Gupta/*
2883d1b5dSAntonio Nino Diaz * Copyright (c) 2013-2018, ARM Limited and Contributors. All rights reserved.
34f6ad66aSAchin Gupta *
482cb2c1aSdp-arm * SPDX-License-Identifier: BSD-3-Clause
54f6ad66aSAchin Gupta */
64f6ad66aSAchin Gupta
75f0cdb05SDan Handley#include <platform_def.h>
8a2aedac2SAntonio Nino Diaz#include <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 Gupta
154f6ad66aSAchin GuptaMEMORY {
16d7fbf132SJuan Castillo    RAM (rwx): ORIGIN = BL31_BASE, LENGTH = BL31_LIMIT - BL31_BASE
174f6ad66aSAchin Gupta}
184f6ad66aSAchin Gupta
19ec693569SCaesar Wang#ifdef PLAT_EXTRA_LD_SCRIPT
20ec693569SCaesar Wang#include <plat.ld.S>
21ec693569SCaesar Wang#endif
224f6ad66aSAchin Gupta
234f6ad66aSAchin GuptaSECTIONS
244f6ad66aSAchin Gupta{
254f6ad66aSAchin Gupta    . = BL31_BASE;
26a2aedac2SAntonio Nino Diaz    ASSERT(. == ALIGN(PAGE_SIZE),
278d69a03fSSandrine Bailleux           "BL31_BASE address is not aligned on a page boundary.")
284f6ad66aSAchin Gupta
29931f7c61SSoby Mathew    __BL31_START__ = .;
30931f7c61SSoby Mathew
315d1c104fSSandrine Bailleux#if SEPARATE_CODE_AND_RODATA
325d1c104fSSandrine Bailleux    .text . : {
335d1c104fSSandrine Bailleux        __TEXT_START__ = .;
345d1c104fSSandrine Bailleux        *bl31_entrypoint.o(.text*)
355d1c104fSSandrine Bailleux        *(.text*)
365d1c104fSSandrine Bailleux        *(.vectors)
375629b2b1SRoberto Vargas        . = ALIGN(PAGE_SIZE);
385d1c104fSSandrine Bailleux        __TEXT_END__ = .;
395d1c104fSSandrine Bailleux    } >RAM
405d1c104fSSandrine Bailleux
415d1c104fSSandrine Bailleux    .rodata . : {
425d1c104fSSandrine Bailleux        __RODATA_START__ = .;
435d1c104fSSandrine Bailleux        *(.rodata*)
445d1c104fSSandrine Bailleux
455d1c104fSSandrine Bailleux        /* Ensure 8-byte alignment for descriptors and ensure inclusion */
465d1c104fSSandrine Bailleux        . = ALIGN(8);
475d1c104fSSandrine Bailleux        __RT_SVC_DESCS_START__ = .;
485d1c104fSSandrine Bailleux        KEEP(*(rt_svc_descs))
495d1c104fSSandrine Bailleux        __RT_SVC_DESCS_END__ = .;
505d1c104fSSandrine Bailleux
515d1c104fSSandrine Bailleux#if ENABLE_PMF
525d1c104fSSandrine Bailleux        /* Ensure 8-byte alignment for descriptors and ensure inclusion */
535d1c104fSSandrine Bailleux        . = ALIGN(8);
545d1c104fSSandrine Bailleux        __PMF_SVC_DESCS_START__ = .;
555d1c104fSSandrine Bailleux        KEEP(*(pmf_svc_descs))
565d1c104fSSandrine Bailleux        __PMF_SVC_DESCS_END__ = .;
575d1c104fSSandrine Bailleux#endif /* ENABLE_PMF */
585d1c104fSSandrine Bailleux
595d1c104fSSandrine Bailleux        /*
605d1c104fSSandrine Bailleux         * Ensure 8-byte alignment for cpu_ops so that its fields are also
615d1c104fSSandrine Bailleux         * aligned. Also ensure cpu_ops inclusion.
625d1c104fSSandrine Bailleux         */
635d1c104fSSandrine Bailleux        . = ALIGN(8);
645d1c104fSSandrine Bailleux        __CPU_OPS_START__ = .;
655d1c104fSSandrine Bailleux        KEEP(*(cpu_ops))
665d1c104fSSandrine Bailleux        __CPU_OPS_END__ = .;
675d1c104fSSandrine Bailleux
68931f7c61SSoby Mathew        /*
69*5bfac4fcSSoby Mathew         * Keep the .got section in the RO section as it is patched
70931f7c61SSoby Mathew         * prior to enabling the MMU and having the .got in RO is better for
71*5bfac4fcSSoby Mathew         * security. GOT is a table of addresses so ensure 8-byte alignment.
72931f7c61SSoby Mathew         */
73*5bfac4fcSSoby Mathew        . = ALIGN(8);
74931f7c61SSoby Mathew        __GOT_START__ = .;
75931f7c61SSoby Mathew        *(.got)
76931f7c61SSoby Mathew        __GOT_END__ = .;
77931f7c61SSoby Mathew
788e743bcdSJeenu Viswambharan        /* Place pubsub sections for events */
798e743bcdSJeenu Viswambharan        . = ALIGN(8);
808e743bcdSJeenu Viswambharan#include <pubsub_events.h>
818e743bcdSJeenu Viswambharan
825629b2b1SRoberto Vargas        . = ALIGN(PAGE_SIZE);
835d1c104fSSandrine Bailleux        __RODATA_END__ = .;
845d1c104fSSandrine Bailleux    } >RAM
855d1c104fSSandrine Bailleux#else
868d69a03fSSandrine Bailleux    ro . : {
878d69a03fSSandrine Bailleux        __RO_START__ = .;
88dccc537aSAndrew Thoelke        *bl31_entrypoint.o(.text*)
89dccc537aSAndrew Thoelke        *(.text*)
908d69a03fSSandrine Bailleux        *(.rodata*)
917421b465SAchin Gupta
92dccc537aSAndrew Thoelke        /* Ensure 8-byte alignment for descriptors and ensure inclusion */
937421b465SAchin Gupta        . = ALIGN(8);
947421b465SAchin Gupta        __RT_SVC_DESCS_START__ = .;
95dccc537aSAndrew Thoelke        KEEP(*(rt_svc_descs))
967421b465SAchin Gupta        __RT_SVC_DESCS_END__ = .;
977421b465SAchin Gupta
98a31d8983SYatharth Kochar#if ENABLE_PMF
99a31d8983SYatharth Kochar        /* Ensure 8-byte alignment for descriptors and ensure inclusion */
100a31d8983SYatharth Kochar        . = ALIGN(8);
101a31d8983SYatharth Kochar        __PMF_SVC_DESCS_START__ = .;
102a31d8983SYatharth Kochar        KEEP(*(pmf_svc_descs))
103a31d8983SYatharth Kochar        __PMF_SVC_DESCS_END__ = .;
104a31d8983SYatharth Kochar#endif /* ENABLE_PMF */
105a31d8983SYatharth Kochar
1069b476841SSoby Mathew        /*
1079b476841SSoby Mathew         * Ensure 8-byte alignment for cpu_ops so that its fields are also
1089b476841SSoby Mathew         * aligned. Also ensure cpu_ops inclusion.
1099b476841SSoby Mathew         */
1109b476841SSoby Mathew        . = ALIGN(8);
1119b476841SSoby Mathew        __CPU_OPS_START__ = .;
1129b476841SSoby Mathew        KEEP(*(cpu_ops))
1139b476841SSoby Mathew        __CPU_OPS_END__ = .;
1149b476841SSoby Mathew
115*5bfac4fcSSoby Mathew        /*
116*5bfac4fcSSoby Mathew         * Keep the .got section in the RO section as it is patched
117*5bfac4fcSSoby Mathew         * prior to enabling the MMU and having the .got in RO is better for
118*5bfac4fcSSoby Mathew         * security. GOT is a table of addresses so ensure 8-byte alignment.
119*5bfac4fcSSoby Mathew         */
120*5bfac4fcSSoby Mathew        . = ALIGN(8);
121*5bfac4fcSSoby Mathew        __GOT_START__ = .;
122*5bfac4fcSSoby Mathew        *(.got)
123*5bfac4fcSSoby Mathew        __GOT_END__ = .;
124*5bfac4fcSSoby Mathew
1258e743bcdSJeenu Viswambharan        /* Place pubsub sections for events */
1268e743bcdSJeenu Viswambharan        . = ALIGN(8);
1278e743bcdSJeenu Viswambharan#include <pubsub_events.h>
1288e743bcdSJeenu Viswambharan
129b739f22aSAchin Gupta        *(.vectors)
1308d69a03fSSandrine Bailleux        __RO_END_UNALIGNED__ = .;
1318d69a03fSSandrine Bailleux        /*
1328d69a03fSSandrine Bailleux         * Memory page(s) mapped to this section will be marked as read-only,
1338d69a03fSSandrine Bailleux         * executable.  No RW data from the next section must creep in.
1348d69a03fSSandrine Bailleux         * Ensure the rest of the current memory page is unused.
1358d69a03fSSandrine Bailleux         */
1365629b2b1SRoberto Vargas        . = ALIGN(PAGE_SIZE);
1378d69a03fSSandrine Bailleux        __RO_END__ = .;
1384f6ad66aSAchin Gupta    } >RAM
1395d1c104fSSandrine Bailleux#endif
1404f6ad66aSAchin Gupta
1419b476841SSoby Mathew    ASSERT(__CPU_OPS_END__ > __CPU_OPS_START__,
1429b476841SSoby Mathew           "cpu_ops not defined for this platform.")
1439b476841SSoby Mathew
1442fccb228SAntonio Nino Diaz#if ENABLE_SPM
1452fccb228SAntonio Nino Diaz    /*
1462fccb228SAntonio Nino Diaz     * Exception vectors of the SPM shim layer. They must be aligned to a 2K
1472fccb228SAntonio Nino Diaz     * address, but we need to place them in a separate page so that we can set
1482fccb228SAntonio Nino Diaz     * individual permissions to them, so the actual alignment needed is 4K.
1492fccb228SAntonio Nino Diaz     *
1502fccb228SAntonio Nino Diaz     * There's no need to include this into the RO section of BL31 because it
1512fccb228SAntonio Nino Diaz     * doesn't need to be accessed by BL31.
1522fccb228SAntonio Nino Diaz     */
153a2aedac2SAntonio Nino Diaz    spm_shim_exceptions : ALIGN(PAGE_SIZE) {
1542fccb228SAntonio Nino Diaz        __SPM_SHIM_EXCEPTIONS_START__ = .;
1552fccb228SAntonio Nino Diaz        *(.spm_shim_exceptions)
1565629b2b1SRoberto Vargas        . = ALIGN(PAGE_SIZE);
1572fccb228SAntonio Nino Diaz        __SPM_SHIM_EXCEPTIONS_END__ = .;
1582fccb228SAntonio Nino Diaz    } >RAM
1592fccb228SAntonio Nino Diaz#endif
1602fccb228SAntonio Nino Diaz
16154dc71e7SAchin Gupta    /*
16254dc71e7SAchin Gupta     * Define a linker symbol to mark start of the RW memory area for this
16354dc71e7SAchin Gupta     * image.
16454dc71e7SAchin Gupta     */
16554dc71e7SAchin Gupta    __RW_START__ = . ;
16654dc71e7SAchin Gupta
16751faada7SDouglas Raillard    /*
16851faada7SDouglas Raillard     * .data must be placed at a lower address than the stacks if the stack
16951faada7SDouglas Raillard     * protector is enabled. Alternatively, the .data.stack_protector_canary
17051faada7SDouglas Raillard     * section can be placed independently of the main .data section.
17151faada7SDouglas Raillard     */
1728d69a03fSSandrine Bailleux   .data . : {
1738d69a03fSSandrine Bailleux        __DATA_START__ = .;
174dccc537aSAndrew Thoelke        *(.data*)
1758d69a03fSSandrine Bailleux        __DATA_END__ = .;
1768d69a03fSSandrine Bailleux    } >RAM
1778d69a03fSSandrine Bailleux
178931f7c61SSoby Mathew    /*
179931f7c61SSoby Mathew     * .rela.dyn needs to come after .data for the read-elf utility to parse
180*5bfac4fcSSoby Mathew     * this section correctly. Ensure 8-byte alignment so that the fields of
181*5bfac4fcSSoby Mathew     * RELA data structure are aligned.
182931f7c61SSoby Mathew     */
183*5bfac4fcSSoby Mathew    . = ALIGN(8);
184931f7c61SSoby Mathew    __RELA_START__ = .;
185931f7c61SSoby Mathew    .rela.dyn . : {
186931f7c61SSoby Mathew    } >RAM
187931f7c61SSoby Mathew    __RELA_END__ = .;
188931f7c61SSoby Mathew
189a1b6db6cSSandrine Bailleux#ifdef BL31_PROGBITS_LIMIT
190d178637dSJuan Castillo    ASSERT(. <= BL31_PROGBITS_LIMIT, "BL31 progbits has exceeded its limit.")
191a1b6db6cSSandrine Bailleux#endif
192a1b6db6cSSandrine Bailleux
1938d69a03fSSandrine Bailleux    stacks (NOLOAD) : {
1948d69a03fSSandrine Bailleux        __STACKS_START__ = .;
1954f6ad66aSAchin Gupta        *(tzfw_normal_stacks)
1968d69a03fSSandrine Bailleux        __STACKS_END__ = .;
1974f6ad66aSAchin Gupta    } >RAM
1984f6ad66aSAchin Gupta
1998d69a03fSSandrine Bailleux    /*
2008d69a03fSSandrine Bailleux     * The .bss section gets initialised to 0 at runtime.
201308d359bSDouglas Raillard     * Its base address should be 16-byte aligned for better performance of the
202308d359bSDouglas Raillard     * zero-initialization code.
2038d69a03fSSandrine Bailleux     */
204ee7b35c4SAndrew Thoelke    .bss (NOLOAD) : ALIGN(16) {
2058d69a03fSSandrine Bailleux        __BSS_START__ = .;
206dccc537aSAndrew Thoelke        *(.bss*)
2074f6ad66aSAchin Gupta        *(COMMON)
208ee7b35c4SAndrew Thoelke#if !USE_COHERENT_MEM
209ee7b35c4SAndrew Thoelke        /*
210ee7b35c4SAndrew Thoelke         * Bakery locks are stored in normal .bss memory
211ee7b35c4SAndrew Thoelke         *
212ee7b35c4SAndrew Thoelke         * Each lock's data is spread across multiple cache lines, one per CPU,
213ee7b35c4SAndrew Thoelke         * but multiple locks can share the same cache line.
214ee7b35c4SAndrew Thoelke         * The compiler will allocate enough memory for one CPU's bakery locks,
215ee7b35c4SAndrew Thoelke         * the remaining cache lines are allocated by the linker script
216ee7b35c4SAndrew Thoelke         */
217ee7b35c4SAndrew Thoelke        . = ALIGN(CACHE_WRITEBACK_GRANULE);
218ee7b35c4SAndrew Thoelke        __BAKERY_LOCK_START__ = .;
219ee7b35c4SAndrew Thoelke        *(bakery_lock)
220ee7b35c4SAndrew Thoelke        . = ALIGN(CACHE_WRITEBACK_GRANULE);
2217173f5f6SVikram Kanigiri        __PERCPU_BAKERY_LOCK_SIZE__ = ABSOLUTE(. - __BAKERY_LOCK_START__);
222ee7b35c4SAndrew Thoelke        . = . + (__PERCPU_BAKERY_LOCK_SIZE__ * (PLATFORM_CORE_COUNT - 1));
223ee7b35c4SAndrew Thoelke        __BAKERY_LOCK_END__ = .;
22432aee841SRoberto Vargas
22532aee841SRoberto Vargas	/*
22632aee841SRoberto Vargas	 * If BL31 doesn't use any bakery lock then __PERCPU_BAKERY_LOCK_SIZE__
22732aee841SRoberto Vargas	 * will be zero. For this reason, the only two valid values for
22832aee841SRoberto Vargas	 * __PERCPU_BAKERY_LOCK_SIZE__ are 0 or the platform defined value
22932aee841SRoberto Vargas	 * PLAT_PERCPU_BAKERY_LOCK_SIZE.
23032aee841SRoberto Vargas	 */
231ee7b35c4SAndrew Thoelke#ifdef PLAT_PERCPU_BAKERY_LOCK_SIZE
23232aee841SRoberto Vargas    ASSERT((__PERCPU_BAKERY_LOCK_SIZE__ == 0) || (__PERCPU_BAKERY_LOCK_SIZE__ == PLAT_PERCPU_BAKERY_LOCK_SIZE),
233ee7b35c4SAndrew Thoelke        "PLAT_PERCPU_BAKERY_LOCK_SIZE does not match bakery lock requirements");
234ee7b35c4SAndrew Thoelke#endif
235ee7b35c4SAndrew Thoelke#endif
236a31d8983SYatharth Kochar
237a31d8983SYatharth Kochar#if ENABLE_PMF
238a31d8983SYatharth Kochar        /*
239a31d8983SYatharth Kochar         * Time-stamps are stored in normal .bss memory
240a31d8983SYatharth Kochar         *
241a31d8983SYatharth Kochar         * The compiler will allocate enough memory for one CPU's time-stamps,
242a31d8983SYatharth Kochar         * the remaining memory for other CPU's is allocated by the
243a31d8983SYatharth Kochar         * linker script
244a31d8983SYatharth Kochar         */
245a31d8983SYatharth Kochar        . = ALIGN(CACHE_WRITEBACK_GRANULE);
246a31d8983SYatharth Kochar        __PMF_TIMESTAMP_START__ = .;
247a31d8983SYatharth Kochar        KEEP(*(pmf_timestamp_array))
248a31d8983SYatharth Kochar        . = ALIGN(CACHE_WRITEBACK_GRANULE);
249a31d8983SYatharth Kochar        __PMF_PERCPU_TIMESTAMP_END__ = .;
250a31d8983SYatharth Kochar        __PERCPU_TIMESTAMP_SIZE__ = ABSOLUTE(. - __PMF_TIMESTAMP_START__);
251a31d8983SYatharth Kochar        . = . + (__PERCPU_TIMESTAMP_SIZE__ * (PLATFORM_CORE_COUNT - 1));
252a31d8983SYatharth Kochar        __PMF_TIMESTAMP_END__ = .;
253a31d8983SYatharth Kochar#endif /* ENABLE_PMF */
2548d69a03fSSandrine Bailleux        __BSS_END__ = .;
2554f6ad66aSAchin Gupta    } >RAM
2564f6ad66aSAchin Gupta
2578d69a03fSSandrine Bailleux    /*
258e3fff153SJeenu Viswambharan     * The xlat_table section is for full, aligned page tables (4K).
259a0cd989dSAchin Gupta     * Removing them from .bss avoids forcing 4K alignment on
260883d1b5dSAntonio Nino Diaz     * the .bss section. The tables are initialized to zero by the translation
261883d1b5dSAntonio Nino Diaz     * tables library.
262a0cd989dSAchin Gupta     */
263a0cd989dSAchin Gupta    xlat_table (NOLOAD) : {
264a0cd989dSAchin Gupta        *(xlat_table)
265a0cd989dSAchin Gupta    } >RAM
266a0cd989dSAchin Gupta
267ab8707e6SSoby Mathew#if USE_COHERENT_MEM
268a0cd989dSAchin Gupta    /*
2698d69a03fSSandrine Bailleux     * The base address of the coherent memory section must be page-aligned (4K)
2708d69a03fSSandrine Bailleux     * to guarantee that the coherent data are stored on their own pages and
2718d69a03fSSandrine Bailleux     * are not mixed with normal data.  This is required to set up the correct
2728d69a03fSSandrine Bailleux     * memory attributes for the coherent data page tables.
2738d69a03fSSandrine Bailleux     */
274a2aedac2SAntonio Nino Diaz    coherent_ram (NOLOAD) : ALIGN(PAGE_SIZE) {
2758d69a03fSSandrine Bailleux        __COHERENT_RAM_START__ = .;
276ee7b35c4SAndrew Thoelke        /*
277ee7b35c4SAndrew Thoelke         * Bakery locks are stored in coherent memory
278ee7b35c4SAndrew Thoelke         *
279ee7b35c4SAndrew Thoelke         * Each lock's data is contiguous and fully allocated by the compiler
280ee7b35c4SAndrew Thoelke         */
281ee7b35c4SAndrew Thoelke        *(bakery_lock)
2828d69a03fSSandrine Bailleux        *(tzfw_coherent_mem)
2838d69a03fSSandrine Bailleux        __COHERENT_RAM_END_UNALIGNED__ = .;
2848d69a03fSSandrine Bailleux        /*
2858d69a03fSSandrine Bailleux         * Memory page(s) mapped to this section will be marked
2868d69a03fSSandrine Bailleux         * as device memory.  No other unexpected data must creep in.
2878d69a03fSSandrine Bailleux         * Ensure the rest of the current memory page is unused.
2888d69a03fSSandrine Bailleux         */
2895629b2b1SRoberto Vargas        . = ALIGN(PAGE_SIZE);
2908d69a03fSSandrine Bailleux        __COHERENT_RAM_END__ = .;
2914f6ad66aSAchin Gupta    } >RAM
292ab8707e6SSoby Mathew#endif
2934f6ad66aSAchin Gupta
29454dc71e7SAchin Gupta    /*
29554dc71e7SAchin Gupta     * Define a linker symbol to mark end of the RW memory area for this
29654dc71e7SAchin Gupta     * image.
29754dc71e7SAchin Gupta     */
29854dc71e7SAchin Gupta    __RW_END__ = .;
2998d69a03fSSandrine Bailleux    __BL31_END__ = .;
3004f6ad66aSAchin Gupta
301d178637dSJuan Castillo    ASSERT(. <= BL31_LIMIT, "BL31 image has exceeded its limit.")
3024f6ad66aSAchin Gupta}
303