xref: /rk3399_ARM-atf/bl31/bl31.ld.S (revision 883d1b5d4a1a4da956310a951df9eb2056c84597)
14f6ad66aSAchin Gupta/*
2*883d1b5dSAntonio 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
295d1c104fSSandrine Bailleux#if SEPARATE_CODE_AND_RODATA
305d1c104fSSandrine Bailleux    .text . : {
315d1c104fSSandrine Bailleux        __TEXT_START__ = .;
325d1c104fSSandrine Bailleux        *bl31_entrypoint.o(.text*)
335d1c104fSSandrine Bailleux        *(.text*)
345d1c104fSSandrine Bailleux        *(.vectors)
35a2aedac2SAntonio Nino Diaz        . = NEXT(PAGE_SIZE);
365d1c104fSSandrine Bailleux        __TEXT_END__ = .;
375d1c104fSSandrine Bailleux    } >RAM
385d1c104fSSandrine Bailleux
395d1c104fSSandrine Bailleux    .rodata . : {
405d1c104fSSandrine Bailleux        __RODATA_START__ = .;
415d1c104fSSandrine Bailleux        *(.rodata*)
425d1c104fSSandrine Bailleux
435d1c104fSSandrine Bailleux        /* Ensure 8-byte alignment for descriptors and ensure inclusion */
445d1c104fSSandrine Bailleux        . = ALIGN(8);
455d1c104fSSandrine Bailleux        __RT_SVC_DESCS_START__ = .;
465d1c104fSSandrine Bailleux        KEEP(*(rt_svc_descs))
475d1c104fSSandrine Bailleux        __RT_SVC_DESCS_END__ = .;
485d1c104fSSandrine Bailleux
495d1c104fSSandrine Bailleux#if ENABLE_PMF
505d1c104fSSandrine Bailleux        /* Ensure 8-byte alignment for descriptors and ensure inclusion */
515d1c104fSSandrine Bailleux        . = ALIGN(8);
525d1c104fSSandrine Bailleux        __PMF_SVC_DESCS_START__ = .;
535d1c104fSSandrine Bailleux        KEEP(*(pmf_svc_descs))
545d1c104fSSandrine Bailleux        __PMF_SVC_DESCS_END__ = .;
555d1c104fSSandrine Bailleux#endif /* ENABLE_PMF */
565d1c104fSSandrine Bailleux
575d1c104fSSandrine Bailleux        /*
585d1c104fSSandrine Bailleux         * Ensure 8-byte alignment for cpu_ops so that its fields are also
595d1c104fSSandrine Bailleux         * aligned. Also ensure cpu_ops inclusion.
605d1c104fSSandrine Bailleux         */
615d1c104fSSandrine Bailleux        . = ALIGN(8);
625d1c104fSSandrine Bailleux        __CPU_OPS_START__ = .;
635d1c104fSSandrine Bailleux        KEEP(*(cpu_ops))
645d1c104fSSandrine Bailleux        __CPU_OPS_END__ = .;
655d1c104fSSandrine Bailleux
668e743bcdSJeenu Viswambharan        /* Place pubsub sections for events */
678e743bcdSJeenu Viswambharan        . = ALIGN(8);
688e743bcdSJeenu Viswambharan#include <pubsub_events.h>
698e743bcdSJeenu Viswambharan
70a2aedac2SAntonio Nino Diaz        . = NEXT(PAGE_SIZE);
715d1c104fSSandrine Bailleux        __RODATA_END__ = .;
725d1c104fSSandrine Bailleux    } >RAM
735d1c104fSSandrine Bailleux#else
748d69a03fSSandrine Bailleux    ro . : {
758d69a03fSSandrine Bailleux        __RO_START__ = .;
76dccc537aSAndrew Thoelke        *bl31_entrypoint.o(.text*)
77dccc537aSAndrew Thoelke        *(.text*)
788d69a03fSSandrine Bailleux        *(.rodata*)
797421b465SAchin Gupta
80dccc537aSAndrew Thoelke        /* Ensure 8-byte alignment for descriptors and ensure inclusion */
817421b465SAchin Gupta        . = ALIGN(8);
827421b465SAchin Gupta        __RT_SVC_DESCS_START__ = .;
83dccc537aSAndrew Thoelke        KEEP(*(rt_svc_descs))
847421b465SAchin Gupta        __RT_SVC_DESCS_END__ = .;
857421b465SAchin Gupta
86a31d8983SYatharth Kochar#if ENABLE_PMF
87a31d8983SYatharth Kochar        /* Ensure 8-byte alignment for descriptors and ensure inclusion */
88a31d8983SYatharth Kochar        . = ALIGN(8);
89a31d8983SYatharth Kochar        __PMF_SVC_DESCS_START__ = .;
90a31d8983SYatharth Kochar        KEEP(*(pmf_svc_descs))
91a31d8983SYatharth Kochar        __PMF_SVC_DESCS_END__ = .;
92a31d8983SYatharth Kochar#endif /* ENABLE_PMF */
93a31d8983SYatharth Kochar
949b476841SSoby Mathew        /*
959b476841SSoby Mathew         * Ensure 8-byte alignment for cpu_ops so that its fields are also
969b476841SSoby Mathew         * aligned. Also ensure cpu_ops inclusion.
979b476841SSoby Mathew         */
989b476841SSoby Mathew        . = ALIGN(8);
999b476841SSoby Mathew        __CPU_OPS_START__ = .;
1009b476841SSoby Mathew        KEEP(*(cpu_ops))
1019b476841SSoby Mathew        __CPU_OPS_END__ = .;
1029b476841SSoby Mathew
1038e743bcdSJeenu Viswambharan        /* Place pubsub sections for events */
1048e743bcdSJeenu Viswambharan        . = ALIGN(8);
1058e743bcdSJeenu Viswambharan#include <pubsub_events.h>
1068e743bcdSJeenu Viswambharan
107b739f22aSAchin Gupta        *(.vectors)
1088d69a03fSSandrine Bailleux        __RO_END_UNALIGNED__ = .;
1098d69a03fSSandrine Bailleux        /*
1108d69a03fSSandrine Bailleux         * Memory page(s) mapped to this section will be marked as read-only,
1118d69a03fSSandrine Bailleux         * executable.  No RW data from the next section must creep in.
1128d69a03fSSandrine Bailleux         * Ensure the rest of the current memory page is unused.
1138d69a03fSSandrine Bailleux         */
114a2aedac2SAntonio Nino Diaz        . = NEXT(PAGE_SIZE);
1158d69a03fSSandrine Bailleux        __RO_END__ = .;
1164f6ad66aSAchin Gupta    } >RAM
1175d1c104fSSandrine Bailleux#endif
1184f6ad66aSAchin Gupta
1199b476841SSoby Mathew    ASSERT(__CPU_OPS_END__ > __CPU_OPS_START__,
1209b476841SSoby Mathew           "cpu_ops not defined for this platform.")
1219b476841SSoby Mathew
1222fccb228SAntonio Nino Diaz#if ENABLE_SPM
1232fccb228SAntonio Nino Diaz    /*
1242fccb228SAntonio Nino Diaz     * Exception vectors of the SPM shim layer. They must be aligned to a 2K
1252fccb228SAntonio Nino Diaz     * address, but we need to place them in a separate page so that we can set
1262fccb228SAntonio Nino Diaz     * individual permissions to them, so the actual alignment needed is 4K.
1272fccb228SAntonio Nino Diaz     *
1282fccb228SAntonio Nino Diaz     * There's no need to include this into the RO section of BL31 because it
1292fccb228SAntonio Nino Diaz     * doesn't need to be accessed by BL31.
1302fccb228SAntonio Nino Diaz     */
131a2aedac2SAntonio Nino Diaz    spm_shim_exceptions : ALIGN(PAGE_SIZE) {
1322fccb228SAntonio Nino Diaz        __SPM_SHIM_EXCEPTIONS_START__ = .;
1332fccb228SAntonio Nino Diaz        *(.spm_shim_exceptions)
134a2aedac2SAntonio Nino Diaz        . = NEXT(PAGE_SIZE);
1352fccb228SAntonio Nino Diaz        __SPM_SHIM_EXCEPTIONS_END__ = .;
1362fccb228SAntonio Nino Diaz    } >RAM
1372fccb228SAntonio Nino Diaz#endif
1382fccb228SAntonio Nino Diaz
13954dc71e7SAchin Gupta    /*
14054dc71e7SAchin Gupta     * Define a linker symbol to mark start of the RW memory area for this
14154dc71e7SAchin Gupta     * image.
14254dc71e7SAchin Gupta     */
14354dc71e7SAchin Gupta    __RW_START__ = . ;
14454dc71e7SAchin Gupta
14551faada7SDouglas Raillard    /*
14651faada7SDouglas Raillard     * .data must be placed at a lower address than the stacks if the stack
14751faada7SDouglas Raillard     * protector is enabled. Alternatively, the .data.stack_protector_canary
14851faada7SDouglas Raillard     * section can be placed independently of the main .data section.
14951faada7SDouglas Raillard     */
1508d69a03fSSandrine Bailleux   .data . : {
1518d69a03fSSandrine Bailleux        __DATA_START__ = .;
152dccc537aSAndrew Thoelke        *(.data*)
1538d69a03fSSandrine Bailleux        __DATA_END__ = .;
1548d69a03fSSandrine Bailleux    } >RAM
1558d69a03fSSandrine Bailleux
156a1b6db6cSSandrine Bailleux#ifdef BL31_PROGBITS_LIMIT
157d178637dSJuan Castillo    ASSERT(. <= BL31_PROGBITS_LIMIT, "BL31 progbits has exceeded its limit.")
158a1b6db6cSSandrine Bailleux#endif
159a1b6db6cSSandrine Bailleux
1608d69a03fSSandrine Bailleux    stacks (NOLOAD) : {
1618d69a03fSSandrine Bailleux        __STACKS_START__ = .;
1624f6ad66aSAchin Gupta        *(tzfw_normal_stacks)
1638d69a03fSSandrine Bailleux        __STACKS_END__ = .;
1644f6ad66aSAchin Gupta    } >RAM
1654f6ad66aSAchin Gupta
1668d69a03fSSandrine Bailleux    /*
1678d69a03fSSandrine Bailleux     * The .bss section gets initialised to 0 at runtime.
168308d359bSDouglas Raillard     * Its base address should be 16-byte aligned for better performance of the
169308d359bSDouglas Raillard     * zero-initialization code.
1708d69a03fSSandrine Bailleux     */
171ee7b35c4SAndrew Thoelke    .bss (NOLOAD) : ALIGN(16) {
1728d69a03fSSandrine Bailleux        __BSS_START__ = .;
173dccc537aSAndrew Thoelke        *(.bss*)
1744f6ad66aSAchin Gupta        *(COMMON)
175ee7b35c4SAndrew Thoelke#if !USE_COHERENT_MEM
176ee7b35c4SAndrew Thoelke        /*
177ee7b35c4SAndrew Thoelke         * Bakery locks are stored in normal .bss memory
178ee7b35c4SAndrew Thoelke         *
179ee7b35c4SAndrew Thoelke         * Each lock's data is spread across multiple cache lines, one per CPU,
180ee7b35c4SAndrew Thoelke         * but multiple locks can share the same cache line.
181ee7b35c4SAndrew Thoelke         * The compiler will allocate enough memory for one CPU's bakery locks,
182ee7b35c4SAndrew Thoelke         * the remaining cache lines are allocated by the linker script
183ee7b35c4SAndrew Thoelke         */
184ee7b35c4SAndrew Thoelke        . = ALIGN(CACHE_WRITEBACK_GRANULE);
185ee7b35c4SAndrew Thoelke        __BAKERY_LOCK_START__ = .;
186ee7b35c4SAndrew Thoelke        *(bakery_lock)
187ee7b35c4SAndrew Thoelke        . = ALIGN(CACHE_WRITEBACK_GRANULE);
1887173f5f6SVikram Kanigiri        __PERCPU_BAKERY_LOCK_SIZE__ = ABSOLUTE(. - __BAKERY_LOCK_START__);
189ee7b35c4SAndrew Thoelke        . = . + (__PERCPU_BAKERY_LOCK_SIZE__ * (PLATFORM_CORE_COUNT - 1));
190ee7b35c4SAndrew Thoelke        __BAKERY_LOCK_END__ = .;
191ee7b35c4SAndrew Thoelke#ifdef PLAT_PERCPU_BAKERY_LOCK_SIZE
192ee7b35c4SAndrew Thoelke    ASSERT(__PERCPU_BAKERY_LOCK_SIZE__ == PLAT_PERCPU_BAKERY_LOCK_SIZE,
193ee7b35c4SAndrew Thoelke        "PLAT_PERCPU_BAKERY_LOCK_SIZE does not match bakery lock requirements");
194ee7b35c4SAndrew Thoelke#endif
195ee7b35c4SAndrew Thoelke#endif
196a31d8983SYatharth Kochar
197a31d8983SYatharth Kochar#if ENABLE_PMF
198a31d8983SYatharth Kochar        /*
199a31d8983SYatharth Kochar         * Time-stamps are stored in normal .bss memory
200a31d8983SYatharth Kochar         *
201a31d8983SYatharth Kochar         * The compiler will allocate enough memory for one CPU's time-stamps,
202a31d8983SYatharth Kochar         * the remaining memory for other CPU's is allocated by the
203a31d8983SYatharth Kochar         * linker script
204a31d8983SYatharth Kochar         */
205a31d8983SYatharth Kochar        . = ALIGN(CACHE_WRITEBACK_GRANULE);
206a31d8983SYatharth Kochar        __PMF_TIMESTAMP_START__ = .;
207a31d8983SYatharth Kochar        KEEP(*(pmf_timestamp_array))
208a31d8983SYatharth Kochar        . = ALIGN(CACHE_WRITEBACK_GRANULE);
209a31d8983SYatharth Kochar        __PMF_PERCPU_TIMESTAMP_END__ = .;
210a31d8983SYatharth Kochar        __PERCPU_TIMESTAMP_SIZE__ = ABSOLUTE(. - __PMF_TIMESTAMP_START__);
211a31d8983SYatharth Kochar        . = . + (__PERCPU_TIMESTAMP_SIZE__ * (PLATFORM_CORE_COUNT - 1));
212a31d8983SYatharth Kochar        __PMF_TIMESTAMP_END__ = .;
213a31d8983SYatharth Kochar#endif /* ENABLE_PMF */
2148d69a03fSSandrine Bailleux        __BSS_END__ = .;
2154f6ad66aSAchin Gupta    } >RAM
2164f6ad66aSAchin Gupta
2178d69a03fSSandrine Bailleux    /*
218e3fff153SJeenu Viswambharan     * The xlat_table section is for full, aligned page tables (4K).
219a0cd989dSAchin Gupta     * Removing them from .bss avoids forcing 4K alignment on
220*883d1b5dSAntonio Nino Diaz     * the .bss section. The tables are initialized to zero by the translation
221*883d1b5dSAntonio Nino Diaz     * tables library.
222a0cd989dSAchin Gupta     */
223a0cd989dSAchin Gupta    xlat_table (NOLOAD) : {
2242fccb228SAntonio Nino Diaz#if ENABLE_SPM
2252fccb228SAntonio Nino Diaz        __SP_IMAGE_XLAT_TABLES_START__ = .;
2262fccb228SAntonio Nino Diaz        *secure_partition*.o(xlat_table)
2272fccb228SAntonio Nino Diaz        /* Make sure that the rest of the page is empty. */
228a2aedac2SAntonio Nino Diaz        . = NEXT(PAGE_SIZE);
2292fccb228SAntonio Nino Diaz        __SP_IMAGE_XLAT_TABLES_END__ = .;
2302fccb228SAntonio Nino Diaz#endif
231a0cd989dSAchin Gupta        *(xlat_table)
232a0cd989dSAchin Gupta    } >RAM
233a0cd989dSAchin Gupta
234ab8707e6SSoby Mathew#if USE_COHERENT_MEM
235a0cd989dSAchin Gupta    /*
2368d69a03fSSandrine Bailleux     * The base address of the coherent memory section must be page-aligned (4K)
2378d69a03fSSandrine Bailleux     * to guarantee that the coherent data are stored on their own pages and
2388d69a03fSSandrine Bailleux     * are not mixed with normal data.  This is required to set up the correct
2398d69a03fSSandrine Bailleux     * memory attributes for the coherent data page tables.
2408d69a03fSSandrine Bailleux     */
241a2aedac2SAntonio Nino Diaz    coherent_ram (NOLOAD) : ALIGN(PAGE_SIZE) {
2428d69a03fSSandrine Bailleux        __COHERENT_RAM_START__ = .;
243ee7b35c4SAndrew Thoelke        /*
244ee7b35c4SAndrew Thoelke         * Bakery locks are stored in coherent memory
245ee7b35c4SAndrew Thoelke         *
246ee7b35c4SAndrew Thoelke         * Each lock's data is contiguous and fully allocated by the compiler
247ee7b35c4SAndrew Thoelke         */
248ee7b35c4SAndrew Thoelke        *(bakery_lock)
2498d69a03fSSandrine Bailleux        *(tzfw_coherent_mem)
2508d69a03fSSandrine Bailleux        __COHERENT_RAM_END_UNALIGNED__ = .;
2518d69a03fSSandrine Bailleux        /*
2528d69a03fSSandrine Bailleux         * Memory page(s) mapped to this section will be marked
2538d69a03fSSandrine Bailleux         * as device memory.  No other unexpected data must creep in.
2548d69a03fSSandrine Bailleux         * Ensure the rest of the current memory page is unused.
2558d69a03fSSandrine Bailleux         */
256a2aedac2SAntonio Nino Diaz        . = NEXT(PAGE_SIZE);
2578d69a03fSSandrine Bailleux        __COHERENT_RAM_END__ = .;
2584f6ad66aSAchin Gupta    } >RAM
259ab8707e6SSoby Mathew#endif
2604f6ad66aSAchin Gupta
26154dc71e7SAchin Gupta    /*
26254dc71e7SAchin Gupta     * Define a linker symbol to mark end of the RW memory area for this
26354dc71e7SAchin Gupta     * image.
26454dc71e7SAchin Gupta     */
26554dc71e7SAchin Gupta    __RW_END__ = .;
2668d69a03fSSandrine Bailleux    __BL31_END__ = .;
2674f6ad66aSAchin Gupta
2688d69a03fSSandrine Bailleux    __BSS_SIZE__ = SIZEOF(.bss);
269ab8707e6SSoby Mathew#if USE_COHERENT_MEM
2708d69a03fSSandrine Bailleux    __COHERENT_RAM_UNALIGNED_SIZE__ =
2718d69a03fSSandrine Bailleux        __COHERENT_RAM_END_UNALIGNED__ - __COHERENT_RAM_START__;
272ab8707e6SSoby Mathew#endif
2734f6ad66aSAchin Gupta
274d178637dSJuan Castillo    ASSERT(. <= BL31_LIMIT, "BL31 image has exceeded its limit.")
2754f6ad66aSAchin Gupta}
276