14f6ad66aSAchin Gupta/* 2308d359bSDouglas Raillard * Copyright (c) 2013-2017, ARM Limited and Contributors. All rights reserved. 34f6ad66aSAchin Gupta * 44f6ad66aSAchin Gupta * Redistribution and use in source and binary forms, with or without 54f6ad66aSAchin Gupta * modification, are permitted provided that the following conditions are met: 64f6ad66aSAchin Gupta * 74f6ad66aSAchin Gupta * Redistributions of source code must retain the above copyright notice, this 84f6ad66aSAchin Gupta * list of conditions and the following disclaimer. 94f6ad66aSAchin Gupta * 104f6ad66aSAchin Gupta * Redistributions in binary form must reproduce the above copyright notice, 114f6ad66aSAchin Gupta * this list of conditions and the following disclaimer in the documentation 124f6ad66aSAchin Gupta * and/or other materials provided with the distribution. 134f6ad66aSAchin Gupta * 144f6ad66aSAchin Gupta * Neither the name of ARM nor the names of its contributors may be used 154f6ad66aSAchin Gupta * to endorse or promote products derived from this software without specific 164f6ad66aSAchin Gupta * prior written permission. 174f6ad66aSAchin Gupta * 184f6ad66aSAchin Gupta * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 194f6ad66aSAchin Gupta * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 204f6ad66aSAchin Gupta * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 214f6ad66aSAchin Gupta * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 224f6ad66aSAchin Gupta * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 234f6ad66aSAchin Gupta * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 244f6ad66aSAchin Gupta * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 254f6ad66aSAchin Gupta * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 264f6ad66aSAchin Gupta * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 274f6ad66aSAchin Gupta * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 284f6ad66aSAchin Gupta * POSSIBILITY OF SUCH DAMAGE. 294f6ad66aSAchin Gupta */ 304f6ad66aSAchin Gupta 315f0cdb05SDan Handley#include <platform_def.h> 324f6ad66aSAchin Gupta 334f6ad66aSAchin GuptaOUTPUT_FORMAT(PLATFORM_LINKER_FORMAT) 344f6ad66aSAchin GuptaOUTPUT_ARCH(PLATFORM_LINKER_ARCH) 359f98aa1aSJeenu ViswambharanENTRY(bl31_entrypoint) 364f6ad66aSAchin Gupta 374f6ad66aSAchin Gupta 384f6ad66aSAchin GuptaMEMORY { 39d7fbf132SJuan Castillo RAM (rwx): ORIGIN = BL31_BASE, LENGTH = BL31_LIMIT - BL31_BASE 404f6ad66aSAchin Gupta} 414f6ad66aSAchin Gupta 42ec693569SCaesar Wang#ifdef PLAT_EXTRA_LD_SCRIPT 43ec693569SCaesar Wang#include <plat.ld.S> 44ec693569SCaesar Wang#endif 454f6ad66aSAchin Gupta 464f6ad66aSAchin GuptaSECTIONS 474f6ad66aSAchin Gupta{ 484f6ad66aSAchin Gupta . = BL31_BASE; 498d69a03fSSandrine Bailleux ASSERT(. == ALIGN(4096), 508d69a03fSSandrine Bailleux "BL31_BASE address is not aligned on a page boundary.") 514f6ad66aSAchin Gupta 525d1c104fSSandrine Bailleux#if SEPARATE_CODE_AND_RODATA 535d1c104fSSandrine Bailleux .text . : { 545d1c104fSSandrine Bailleux __TEXT_START__ = .; 555d1c104fSSandrine Bailleux *bl31_entrypoint.o(.text*) 565d1c104fSSandrine Bailleux *(.text*) 575d1c104fSSandrine Bailleux *(.vectors) 585d1c104fSSandrine Bailleux . = NEXT(4096); 595d1c104fSSandrine Bailleux __TEXT_END__ = .; 605d1c104fSSandrine Bailleux } >RAM 615d1c104fSSandrine Bailleux 625d1c104fSSandrine Bailleux .rodata . : { 635d1c104fSSandrine Bailleux __RODATA_START__ = .; 645d1c104fSSandrine Bailleux *(.rodata*) 655d1c104fSSandrine Bailleux 665d1c104fSSandrine Bailleux /* Ensure 8-byte alignment for descriptors and ensure inclusion */ 675d1c104fSSandrine Bailleux . = ALIGN(8); 685d1c104fSSandrine Bailleux __RT_SVC_DESCS_START__ = .; 695d1c104fSSandrine Bailleux KEEP(*(rt_svc_descs)) 705d1c104fSSandrine Bailleux __RT_SVC_DESCS_END__ = .; 715d1c104fSSandrine Bailleux 725d1c104fSSandrine Bailleux#if ENABLE_PMF 735d1c104fSSandrine Bailleux /* Ensure 8-byte alignment for descriptors and ensure inclusion */ 745d1c104fSSandrine Bailleux . = ALIGN(8); 755d1c104fSSandrine Bailleux __PMF_SVC_DESCS_START__ = .; 765d1c104fSSandrine Bailleux KEEP(*(pmf_svc_descs)) 775d1c104fSSandrine Bailleux __PMF_SVC_DESCS_END__ = .; 785d1c104fSSandrine Bailleux#endif /* ENABLE_PMF */ 795d1c104fSSandrine Bailleux 805d1c104fSSandrine Bailleux /* 815d1c104fSSandrine Bailleux * Ensure 8-byte alignment for cpu_ops so that its fields are also 825d1c104fSSandrine Bailleux * aligned. Also ensure cpu_ops inclusion. 835d1c104fSSandrine Bailleux */ 845d1c104fSSandrine Bailleux . = ALIGN(8); 855d1c104fSSandrine Bailleux __CPU_OPS_START__ = .; 865d1c104fSSandrine Bailleux KEEP(*(cpu_ops)) 875d1c104fSSandrine Bailleux __CPU_OPS_END__ = .; 885d1c104fSSandrine Bailleux 895d1c104fSSandrine Bailleux . = NEXT(4096); 905d1c104fSSandrine Bailleux __RODATA_END__ = .; 915d1c104fSSandrine Bailleux } >RAM 925d1c104fSSandrine Bailleux#else 938d69a03fSSandrine Bailleux ro . : { 948d69a03fSSandrine Bailleux __RO_START__ = .; 95dccc537aSAndrew Thoelke *bl31_entrypoint.o(.text*) 96dccc537aSAndrew Thoelke *(.text*) 978d69a03fSSandrine Bailleux *(.rodata*) 987421b465SAchin Gupta 99dccc537aSAndrew Thoelke /* Ensure 8-byte alignment for descriptors and ensure inclusion */ 1007421b465SAchin Gupta . = ALIGN(8); 1017421b465SAchin Gupta __RT_SVC_DESCS_START__ = .; 102dccc537aSAndrew Thoelke KEEP(*(rt_svc_descs)) 1037421b465SAchin Gupta __RT_SVC_DESCS_END__ = .; 1047421b465SAchin Gupta 105a31d8983SYatharth Kochar#if ENABLE_PMF 106a31d8983SYatharth Kochar /* Ensure 8-byte alignment for descriptors and ensure inclusion */ 107a31d8983SYatharth Kochar . = ALIGN(8); 108a31d8983SYatharth Kochar __PMF_SVC_DESCS_START__ = .; 109a31d8983SYatharth Kochar KEEP(*(pmf_svc_descs)) 110a31d8983SYatharth Kochar __PMF_SVC_DESCS_END__ = .; 111a31d8983SYatharth Kochar#endif /* ENABLE_PMF */ 112a31d8983SYatharth Kochar 1139b476841SSoby Mathew /* 1149b476841SSoby Mathew * Ensure 8-byte alignment for cpu_ops so that its fields are also 1159b476841SSoby Mathew * aligned. Also ensure cpu_ops inclusion. 1169b476841SSoby Mathew */ 1179b476841SSoby Mathew . = ALIGN(8); 1189b476841SSoby Mathew __CPU_OPS_START__ = .; 1199b476841SSoby Mathew KEEP(*(cpu_ops)) 1209b476841SSoby Mathew __CPU_OPS_END__ = .; 1219b476841SSoby Mathew 122b739f22aSAchin Gupta *(.vectors) 1238d69a03fSSandrine Bailleux __RO_END_UNALIGNED__ = .; 1248d69a03fSSandrine Bailleux /* 1258d69a03fSSandrine Bailleux * Memory page(s) mapped to this section will be marked as read-only, 1268d69a03fSSandrine Bailleux * executable. No RW data from the next section must creep in. 1278d69a03fSSandrine Bailleux * Ensure the rest of the current memory page is unused. 1288d69a03fSSandrine Bailleux */ 1298d69a03fSSandrine Bailleux . = NEXT(4096); 1308d69a03fSSandrine Bailleux __RO_END__ = .; 1314f6ad66aSAchin Gupta } >RAM 1325d1c104fSSandrine Bailleux#endif 1334f6ad66aSAchin Gupta 1349b476841SSoby Mathew ASSERT(__CPU_OPS_END__ > __CPU_OPS_START__, 1359b476841SSoby Mathew "cpu_ops not defined for this platform.") 1369b476841SSoby Mathew 13754dc71e7SAchin Gupta /* 13854dc71e7SAchin Gupta * Define a linker symbol to mark start of the RW memory area for this 13954dc71e7SAchin Gupta * image. 14054dc71e7SAchin Gupta */ 14154dc71e7SAchin Gupta __RW_START__ = . ; 14254dc71e7SAchin Gupta 143*51faada7SDouglas Raillard /* 144*51faada7SDouglas Raillard * .data must be placed at a lower address than the stacks if the stack 145*51faada7SDouglas Raillard * protector is enabled. Alternatively, the .data.stack_protector_canary 146*51faada7SDouglas Raillard * section can be placed independently of the main .data section. 147*51faada7SDouglas Raillard */ 1488d69a03fSSandrine Bailleux .data . : { 1498d69a03fSSandrine Bailleux __DATA_START__ = .; 150dccc537aSAndrew Thoelke *(.data*) 1518d69a03fSSandrine Bailleux __DATA_END__ = .; 1528d69a03fSSandrine Bailleux } >RAM 1538d69a03fSSandrine Bailleux 154a1b6db6cSSandrine Bailleux#ifdef BL31_PROGBITS_LIMIT 155d178637dSJuan Castillo ASSERT(. <= BL31_PROGBITS_LIMIT, "BL31 progbits has exceeded its limit.") 156a1b6db6cSSandrine Bailleux#endif 157a1b6db6cSSandrine Bailleux 1588d69a03fSSandrine Bailleux stacks (NOLOAD) : { 1598d69a03fSSandrine Bailleux __STACKS_START__ = .; 1604f6ad66aSAchin Gupta *(tzfw_normal_stacks) 1618d69a03fSSandrine Bailleux __STACKS_END__ = .; 1624f6ad66aSAchin Gupta } >RAM 1634f6ad66aSAchin Gupta 1648d69a03fSSandrine Bailleux /* 1658d69a03fSSandrine Bailleux * The .bss section gets initialised to 0 at runtime. 166308d359bSDouglas Raillard * Its base address should be 16-byte aligned for better performance of the 167308d359bSDouglas Raillard * zero-initialization code. 1688d69a03fSSandrine Bailleux */ 169ee7b35c4SAndrew Thoelke .bss (NOLOAD) : ALIGN(16) { 1708d69a03fSSandrine Bailleux __BSS_START__ = .; 171dccc537aSAndrew Thoelke *(.bss*) 1724f6ad66aSAchin Gupta *(COMMON) 173ee7b35c4SAndrew Thoelke#if !USE_COHERENT_MEM 174ee7b35c4SAndrew Thoelke /* 175ee7b35c4SAndrew Thoelke * Bakery locks are stored in normal .bss memory 176ee7b35c4SAndrew Thoelke * 177ee7b35c4SAndrew Thoelke * Each lock's data is spread across multiple cache lines, one per CPU, 178ee7b35c4SAndrew Thoelke * but multiple locks can share the same cache line. 179ee7b35c4SAndrew Thoelke * The compiler will allocate enough memory for one CPU's bakery locks, 180ee7b35c4SAndrew Thoelke * the remaining cache lines are allocated by the linker script 181ee7b35c4SAndrew Thoelke */ 182ee7b35c4SAndrew Thoelke . = ALIGN(CACHE_WRITEBACK_GRANULE); 183ee7b35c4SAndrew Thoelke __BAKERY_LOCK_START__ = .; 184ee7b35c4SAndrew Thoelke *(bakery_lock) 185ee7b35c4SAndrew Thoelke . = ALIGN(CACHE_WRITEBACK_GRANULE); 1867173f5f6SVikram Kanigiri __PERCPU_BAKERY_LOCK_SIZE__ = ABSOLUTE(. - __BAKERY_LOCK_START__); 187ee7b35c4SAndrew Thoelke . = . + (__PERCPU_BAKERY_LOCK_SIZE__ * (PLATFORM_CORE_COUNT - 1)); 188ee7b35c4SAndrew Thoelke __BAKERY_LOCK_END__ = .; 189ee7b35c4SAndrew Thoelke#ifdef PLAT_PERCPU_BAKERY_LOCK_SIZE 190ee7b35c4SAndrew Thoelke ASSERT(__PERCPU_BAKERY_LOCK_SIZE__ == PLAT_PERCPU_BAKERY_LOCK_SIZE, 191ee7b35c4SAndrew Thoelke "PLAT_PERCPU_BAKERY_LOCK_SIZE does not match bakery lock requirements"); 192ee7b35c4SAndrew Thoelke#endif 193ee7b35c4SAndrew Thoelke#endif 194a31d8983SYatharth Kochar 195a31d8983SYatharth Kochar#if ENABLE_PMF 196a31d8983SYatharth Kochar /* 197a31d8983SYatharth Kochar * Time-stamps are stored in normal .bss memory 198a31d8983SYatharth Kochar * 199a31d8983SYatharth Kochar * The compiler will allocate enough memory for one CPU's time-stamps, 200a31d8983SYatharth Kochar * the remaining memory for other CPU's is allocated by the 201a31d8983SYatharth Kochar * linker script 202a31d8983SYatharth Kochar */ 203a31d8983SYatharth Kochar . = ALIGN(CACHE_WRITEBACK_GRANULE); 204a31d8983SYatharth Kochar __PMF_TIMESTAMP_START__ = .; 205a31d8983SYatharth Kochar KEEP(*(pmf_timestamp_array)) 206a31d8983SYatharth Kochar . = ALIGN(CACHE_WRITEBACK_GRANULE); 207a31d8983SYatharth Kochar __PMF_PERCPU_TIMESTAMP_END__ = .; 208a31d8983SYatharth Kochar __PERCPU_TIMESTAMP_SIZE__ = ABSOLUTE(. - __PMF_TIMESTAMP_START__); 209a31d8983SYatharth Kochar . = . + (__PERCPU_TIMESTAMP_SIZE__ * (PLATFORM_CORE_COUNT - 1)); 210a31d8983SYatharth Kochar __PMF_TIMESTAMP_END__ = .; 211a31d8983SYatharth Kochar#endif /* ENABLE_PMF */ 2128d69a03fSSandrine Bailleux __BSS_END__ = .; 2134f6ad66aSAchin Gupta } >RAM 2144f6ad66aSAchin Gupta 2158d69a03fSSandrine Bailleux /* 216e3fff153SJeenu Viswambharan * The xlat_table section is for full, aligned page tables (4K). 217a0cd989dSAchin Gupta * Removing them from .bss avoids forcing 4K alignment on 218a0cd989dSAchin Gupta * the .bss section and eliminates the unecessary zero init 219a0cd989dSAchin Gupta */ 220a0cd989dSAchin Gupta xlat_table (NOLOAD) : { 221a0cd989dSAchin Gupta *(xlat_table) 222a0cd989dSAchin Gupta } >RAM 223a0cd989dSAchin Gupta 224ab8707e6SSoby Mathew#if USE_COHERENT_MEM 225a0cd989dSAchin Gupta /* 2268d69a03fSSandrine Bailleux * The base address of the coherent memory section must be page-aligned (4K) 2278d69a03fSSandrine Bailleux * to guarantee that the coherent data are stored on their own pages and 2288d69a03fSSandrine Bailleux * are not mixed with normal data. This is required to set up the correct 2298d69a03fSSandrine Bailleux * memory attributes for the coherent data page tables. 2308d69a03fSSandrine Bailleux */ 2318d69a03fSSandrine Bailleux coherent_ram (NOLOAD) : ALIGN(4096) { 2328d69a03fSSandrine Bailleux __COHERENT_RAM_START__ = .; 233ee7b35c4SAndrew Thoelke /* 234ee7b35c4SAndrew Thoelke * Bakery locks are stored in coherent memory 235ee7b35c4SAndrew Thoelke * 236ee7b35c4SAndrew Thoelke * Each lock's data is contiguous and fully allocated by the compiler 237ee7b35c4SAndrew Thoelke */ 238ee7b35c4SAndrew Thoelke *(bakery_lock) 2398d69a03fSSandrine Bailleux *(tzfw_coherent_mem) 2408d69a03fSSandrine Bailleux __COHERENT_RAM_END_UNALIGNED__ = .; 2418d69a03fSSandrine Bailleux /* 2428d69a03fSSandrine Bailleux * Memory page(s) mapped to this section will be marked 2438d69a03fSSandrine Bailleux * as device memory. No other unexpected data must creep in. 2448d69a03fSSandrine Bailleux * Ensure the rest of the current memory page is unused. 2458d69a03fSSandrine Bailleux */ 2468d69a03fSSandrine Bailleux . = NEXT(4096); 2478d69a03fSSandrine Bailleux __COHERENT_RAM_END__ = .; 2484f6ad66aSAchin Gupta } >RAM 249ab8707e6SSoby Mathew#endif 2504f6ad66aSAchin Gupta 25154dc71e7SAchin Gupta /* 25254dc71e7SAchin Gupta * Define a linker symbol to mark end of the RW memory area for this 25354dc71e7SAchin Gupta * image. 25454dc71e7SAchin Gupta */ 25554dc71e7SAchin Gupta __RW_END__ = .; 2568d69a03fSSandrine Bailleux __BL31_END__ = .; 2574f6ad66aSAchin Gupta 2588d69a03fSSandrine Bailleux __BSS_SIZE__ = SIZEOF(.bss); 259ab8707e6SSoby Mathew#if USE_COHERENT_MEM 2608d69a03fSSandrine Bailleux __COHERENT_RAM_UNALIGNED_SIZE__ = 2618d69a03fSSandrine Bailleux __COHERENT_RAM_END_UNALIGNED__ - __COHERENT_RAM_START__; 262ab8707e6SSoby Mathew#endif 2634f6ad66aSAchin Gupta 264d178637dSJuan Castillo ASSERT(. <= BL31_LIMIT, "BL31 image has exceeded its limit.") 2654f6ad66aSAchin Gupta} 266