14f6ad66aSAchin Gupta/* 2308d359bSDouglas Raillard * Copyright (c) 2013-2017, 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> 84f6ad66aSAchin Gupta 94f6ad66aSAchin GuptaOUTPUT_FORMAT(PLATFORM_LINKER_FORMAT) 104f6ad66aSAchin GuptaOUTPUT_ARCH(PLATFORM_LINKER_ARCH) 119f98aa1aSJeenu ViswambharanENTRY(bl31_entrypoint) 124f6ad66aSAchin Gupta 134f6ad66aSAchin Gupta 144f6ad66aSAchin GuptaMEMORY { 15d7fbf132SJuan Castillo RAM (rwx): ORIGIN = BL31_BASE, LENGTH = BL31_LIMIT - BL31_BASE 164f6ad66aSAchin Gupta} 174f6ad66aSAchin Gupta 18ec693569SCaesar Wang#ifdef PLAT_EXTRA_LD_SCRIPT 19ec693569SCaesar Wang#include <plat.ld.S> 20ec693569SCaesar Wang#endif 214f6ad66aSAchin Gupta 224f6ad66aSAchin GuptaSECTIONS 234f6ad66aSAchin Gupta{ 244f6ad66aSAchin Gupta . = BL31_BASE; 258d69a03fSSandrine Bailleux ASSERT(. == ALIGN(4096), 268d69a03fSSandrine Bailleux "BL31_BASE address is not aligned on a page boundary.") 274f6ad66aSAchin Gupta 285d1c104fSSandrine Bailleux#if SEPARATE_CODE_AND_RODATA 295d1c104fSSandrine Bailleux .text . : { 305d1c104fSSandrine Bailleux __TEXT_START__ = .; 315d1c104fSSandrine Bailleux *bl31_entrypoint.o(.text*) 325d1c104fSSandrine Bailleux *(.text*) 335d1c104fSSandrine Bailleux *(.vectors) 345d1c104fSSandrine Bailleux . = NEXT(4096); 355d1c104fSSandrine Bailleux __TEXT_END__ = .; 365d1c104fSSandrine Bailleux } >RAM 375d1c104fSSandrine Bailleux 385d1c104fSSandrine Bailleux .rodata . : { 395d1c104fSSandrine Bailleux __RODATA_START__ = .; 405d1c104fSSandrine Bailleux *(.rodata*) 415d1c104fSSandrine Bailleux 425d1c104fSSandrine Bailleux /* Ensure 8-byte alignment for descriptors and ensure inclusion */ 435d1c104fSSandrine Bailleux . = ALIGN(8); 445d1c104fSSandrine Bailleux __RT_SVC_DESCS_START__ = .; 455d1c104fSSandrine Bailleux KEEP(*(rt_svc_descs)) 465d1c104fSSandrine Bailleux __RT_SVC_DESCS_END__ = .; 475d1c104fSSandrine Bailleux 485d1c104fSSandrine Bailleux#if ENABLE_PMF 495d1c104fSSandrine Bailleux /* Ensure 8-byte alignment for descriptors and ensure inclusion */ 505d1c104fSSandrine Bailleux . = ALIGN(8); 515d1c104fSSandrine Bailleux __PMF_SVC_DESCS_START__ = .; 525d1c104fSSandrine Bailleux KEEP(*(pmf_svc_descs)) 535d1c104fSSandrine Bailleux __PMF_SVC_DESCS_END__ = .; 545d1c104fSSandrine Bailleux#endif /* ENABLE_PMF */ 555d1c104fSSandrine Bailleux 565d1c104fSSandrine Bailleux /* 575d1c104fSSandrine Bailleux * Ensure 8-byte alignment for cpu_ops so that its fields are also 585d1c104fSSandrine Bailleux * aligned. Also ensure cpu_ops inclusion. 595d1c104fSSandrine Bailleux */ 605d1c104fSSandrine Bailleux . = ALIGN(8); 615d1c104fSSandrine Bailleux __CPU_OPS_START__ = .; 625d1c104fSSandrine Bailleux KEEP(*(cpu_ops)) 635d1c104fSSandrine Bailleux __CPU_OPS_END__ = .; 645d1c104fSSandrine Bailleux 65*8e743bcdSJeenu Viswambharan /* Place pubsub sections for events */ 66*8e743bcdSJeenu Viswambharan . = ALIGN(8); 67*8e743bcdSJeenu Viswambharan#include <pubsub_events.h> 68*8e743bcdSJeenu Viswambharan 695d1c104fSSandrine Bailleux . = NEXT(4096); 705d1c104fSSandrine Bailleux __RODATA_END__ = .; 715d1c104fSSandrine Bailleux } >RAM 725d1c104fSSandrine Bailleux#else 738d69a03fSSandrine Bailleux ro . : { 748d69a03fSSandrine Bailleux __RO_START__ = .; 75dccc537aSAndrew Thoelke *bl31_entrypoint.o(.text*) 76dccc537aSAndrew Thoelke *(.text*) 778d69a03fSSandrine Bailleux *(.rodata*) 787421b465SAchin Gupta 79dccc537aSAndrew Thoelke /* Ensure 8-byte alignment for descriptors and ensure inclusion */ 807421b465SAchin Gupta . = ALIGN(8); 817421b465SAchin Gupta __RT_SVC_DESCS_START__ = .; 82dccc537aSAndrew Thoelke KEEP(*(rt_svc_descs)) 837421b465SAchin Gupta __RT_SVC_DESCS_END__ = .; 847421b465SAchin Gupta 85a31d8983SYatharth Kochar#if ENABLE_PMF 86a31d8983SYatharth Kochar /* Ensure 8-byte alignment for descriptors and ensure inclusion */ 87a31d8983SYatharth Kochar . = ALIGN(8); 88a31d8983SYatharth Kochar __PMF_SVC_DESCS_START__ = .; 89a31d8983SYatharth Kochar KEEP(*(pmf_svc_descs)) 90a31d8983SYatharth Kochar __PMF_SVC_DESCS_END__ = .; 91a31d8983SYatharth Kochar#endif /* ENABLE_PMF */ 92a31d8983SYatharth Kochar 939b476841SSoby Mathew /* 949b476841SSoby Mathew * Ensure 8-byte alignment for cpu_ops so that its fields are also 959b476841SSoby Mathew * aligned. Also ensure cpu_ops inclusion. 969b476841SSoby Mathew */ 979b476841SSoby Mathew . = ALIGN(8); 989b476841SSoby Mathew __CPU_OPS_START__ = .; 999b476841SSoby Mathew KEEP(*(cpu_ops)) 1009b476841SSoby Mathew __CPU_OPS_END__ = .; 1019b476841SSoby Mathew 102*8e743bcdSJeenu Viswambharan /* Place pubsub sections for events */ 103*8e743bcdSJeenu Viswambharan . = ALIGN(8); 104*8e743bcdSJeenu Viswambharan#include <pubsub_events.h> 105*8e743bcdSJeenu Viswambharan 106b739f22aSAchin Gupta *(.vectors) 1078d69a03fSSandrine Bailleux __RO_END_UNALIGNED__ = .; 1088d69a03fSSandrine Bailleux /* 1098d69a03fSSandrine Bailleux * Memory page(s) mapped to this section will be marked as read-only, 1108d69a03fSSandrine Bailleux * executable. No RW data from the next section must creep in. 1118d69a03fSSandrine Bailleux * Ensure the rest of the current memory page is unused. 1128d69a03fSSandrine Bailleux */ 1138d69a03fSSandrine Bailleux . = NEXT(4096); 1148d69a03fSSandrine Bailleux __RO_END__ = .; 1154f6ad66aSAchin Gupta } >RAM 1165d1c104fSSandrine Bailleux#endif 1174f6ad66aSAchin Gupta 1189b476841SSoby Mathew ASSERT(__CPU_OPS_END__ > __CPU_OPS_START__, 1199b476841SSoby Mathew "cpu_ops not defined for this platform.") 1209b476841SSoby Mathew 12154dc71e7SAchin Gupta /* 12254dc71e7SAchin Gupta * Define a linker symbol to mark start of the RW memory area for this 12354dc71e7SAchin Gupta * image. 12454dc71e7SAchin Gupta */ 12554dc71e7SAchin Gupta __RW_START__ = . ; 12654dc71e7SAchin Gupta 12751faada7SDouglas Raillard /* 12851faada7SDouglas Raillard * .data must be placed at a lower address than the stacks if the stack 12951faada7SDouglas Raillard * protector is enabled. Alternatively, the .data.stack_protector_canary 13051faada7SDouglas Raillard * section can be placed independently of the main .data section. 13151faada7SDouglas Raillard */ 1328d69a03fSSandrine Bailleux .data . : { 1338d69a03fSSandrine Bailleux __DATA_START__ = .; 134dccc537aSAndrew Thoelke *(.data*) 1358d69a03fSSandrine Bailleux __DATA_END__ = .; 1368d69a03fSSandrine Bailleux } >RAM 1378d69a03fSSandrine Bailleux 138a1b6db6cSSandrine Bailleux#ifdef BL31_PROGBITS_LIMIT 139d178637dSJuan Castillo ASSERT(. <= BL31_PROGBITS_LIMIT, "BL31 progbits has exceeded its limit.") 140a1b6db6cSSandrine Bailleux#endif 141a1b6db6cSSandrine Bailleux 1428d69a03fSSandrine Bailleux stacks (NOLOAD) : { 1438d69a03fSSandrine Bailleux __STACKS_START__ = .; 1444f6ad66aSAchin Gupta *(tzfw_normal_stacks) 1458d69a03fSSandrine Bailleux __STACKS_END__ = .; 1464f6ad66aSAchin Gupta } >RAM 1474f6ad66aSAchin Gupta 1488d69a03fSSandrine Bailleux /* 1498d69a03fSSandrine Bailleux * The .bss section gets initialised to 0 at runtime. 150308d359bSDouglas Raillard * Its base address should be 16-byte aligned for better performance of the 151308d359bSDouglas Raillard * zero-initialization code. 1528d69a03fSSandrine Bailleux */ 153ee7b35c4SAndrew Thoelke .bss (NOLOAD) : ALIGN(16) { 1548d69a03fSSandrine Bailleux __BSS_START__ = .; 155dccc537aSAndrew Thoelke *(.bss*) 1564f6ad66aSAchin Gupta *(COMMON) 157ee7b35c4SAndrew Thoelke#if !USE_COHERENT_MEM 158ee7b35c4SAndrew Thoelke /* 159ee7b35c4SAndrew Thoelke * Bakery locks are stored in normal .bss memory 160ee7b35c4SAndrew Thoelke * 161ee7b35c4SAndrew Thoelke * Each lock's data is spread across multiple cache lines, one per CPU, 162ee7b35c4SAndrew Thoelke * but multiple locks can share the same cache line. 163ee7b35c4SAndrew Thoelke * The compiler will allocate enough memory for one CPU's bakery locks, 164ee7b35c4SAndrew Thoelke * the remaining cache lines are allocated by the linker script 165ee7b35c4SAndrew Thoelke */ 166ee7b35c4SAndrew Thoelke . = ALIGN(CACHE_WRITEBACK_GRANULE); 167ee7b35c4SAndrew Thoelke __BAKERY_LOCK_START__ = .; 168ee7b35c4SAndrew Thoelke *(bakery_lock) 169ee7b35c4SAndrew Thoelke . = ALIGN(CACHE_WRITEBACK_GRANULE); 1707173f5f6SVikram Kanigiri __PERCPU_BAKERY_LOCK_SIZE__ = ABSOLUTE(. - __BAKERY_LOCK_START__); 171ee7b35c4SAndrew Thoelke . = . + (__PERCPU_BAKERY_LOCK_SIZE__ * (PLATFORM_CORE_COUNT - 1)); 172ee7b35c4SAndrew Thoelke __BAKERY_LOCK_END__ = .; 173ee7b35c4SAndrew Thoelke#ifdef PLAT_PERCPU_BAKERY_LOCK_SIZE 174ee7b35c4SAndrew Thoelke ASSERT(__PERCPU_BAKERY_LOCK_SIZE__ == PLAT_PERCPU_BAKERY_LOCK_SIZE, 175ee7b35c4SAndrew Thoelke "PLAT_PERCPU_BAKERY_LOCK_SIZE does not match bakery lock requirements"); 176ee7b35c4SAndrew Thoelke#endif 177ee7b35c4SAndrew Thoelke#endif 178a31d8983SYatharth Kochar 179a31d8983SYatharth Kochar#if ENABLE_PMF 180a31d8983SYatharth Kochar /* 181a31d8983SYatharth Kochar * Time-stamps are stored in normal .bss memory 182a31d8983SYatharth Kochar * 183a31d8983SYatharth Kochar * The compiler will allocate enough memory for one CPU's time-stamps, 184a31d8983SYatharth Kochar * the remaining memory for other CPU's is allocated by the 185a31d8983SYatharth Kochar * linker script 186a31d8983SYatharth Kochar */ 187a31d8983SYatharth Kochar . = ALIGN(CACHE_WRITEBACK_GRANULE); 188a31d8983SYatharth Kochar __PMF_TIMESTAMP_START__ = .; 189a31d8983SYatharth Kochar KEEP(*(pmf_timestamp_array)) 190a31d8983SYatharth Kochar . = ALIGN(CACHE_WRITEBACK_GRANULE); 191a31d8983SYatharth Kochar __PMF_PERCPU_TIMESTAMP_END__ = .; 192a31d8983SYatharth Kochar __PERCPU_TIMESTAMP_SIZE__ = ABSOLUTE(. - __PMF_TIMESTAMP_START__); 193a31d8983SYatharth Kochar . = . + (__PERCPU_TIMESTAMP_SIZE__ * (PLATFORM_CORE_COUNT - 1)); 194a31d8983SYatharth Kochar __PMF_TIMESTAMP_END__ = .; 195a31d8983SYatharth Kochar#endif /* ENABLE_PMF */ 1968d69a03fSSandrine Bailleux __BSS_END__ = .; 1974f6ad66aSAchin Gupta } >RAM 1984f6ad66aSAchin Gupta 1998d69a03fSSandrine Bailleux /* 200e3fff153SJeenu Viswambharan * The xlat_table section is for full, aligned page tables (4K). 201a0cd989dSAchin Gupta * Removing them from .bss avoids forcing 4K alignment on 202a0cd989dSAchin Gupta * the .bss section and eliminates the unecessary zero init 203a0cd989dSAchin Gupta */ 204a0cd989dSAchin Gupta xlat_table (NOLOAD) : { 205a0cd989dSAchin Gupta *(xlat_table) 206a0cd989dSAchin Gupta } >RAM 207a0cd989dSAchin Gupta 208ab8707e6SSoby Mathew#if USE_COHERENT_MEM 209a0cd989dSAchin Gupta /* 2108d69a03fSSandrine Bailleux * The base address of the coherent memory section must be page-aligned (4K) 2118d69a03fSSandrine Bailleux * to guarantee that the coherent data are stored on their own pages and 2128d69a03fSSandrine Bailleux * are not mixed with normal data. This is required to set up the correct 2138d69a03fSSandrine Bailleux * memory attributes for the coherent data page tables. 2148d69a03fSSandrine Bailleux */ 2158d69a03fSSandrine Bailleux coherent_ram (NOLOAD) : ALIGN(4096) { 2168d69a03fSSandrine Bailleux __COHERENT_RAM_START__ = .; 217ee7b35c4SAndrew Thoelke /* 218ee7b35c4SAndrew Thoelke * Bakery locks are stored in coherent memory 219ee7b35c4SAndrew Thoelke * 220ee7b35c4SAndrew Thoelke * Each lock's data is contiguous and fully allocated by the compiler 221ee7b35c4SAndrew Thoelke */ 222ee7b35c4SAndrew Thoelke *(bakery_lock) 2238d69a03fSSandrine Bailleux *(tzfw_coherent_mem) 2248d69a03fSSandrine Bailleux __COHERENT_RAM_END_UNALIGNED__ = .; 2258d69a03fSSandrine Bailleux /* 2268d69a03fSSandrine Bailleux * Memory page(s) mapped to this section will be marked 2278d69a03fSSandrine Bailleux * as device memory. No other unexpected data must creep in. 2288d69a03fSSandrine Bailleux * Ensure the rest of the current memory page is unused. 2298d69a03fSSandrine Bailleux */ 2308d69a03fSSandrine Bailleux . = NEXT(4096); 2318d69a03fSSandrine Bailleux __COHERENT_RAM_END__ = .; 2324f6ad66aSAchin Gupta } >RAM 233ab8707e6SSoby Mathew#endif 2344f6ad66aSAchin Gupta 23554dc71e7SAchin Gupta /* 23654dc71e7SAchin Gupta * Define a linker symbol to mark end of the RW memory area for this 23754dc71e7SAchin Gupta * image. 23854dc71e7SAchin Gupta */ 23954dc71e7SAchin Gupta __RW_END__ = .; 2408d69a03fSSandrine Bailleux __BL31_END__ = .; 2414f6ad66aSAchin Gupta 2428d69a03fSSandrine Bailleux __BSS_SIZE__ = SIZEOF(.bss); 243ab8707e6SSoby Mathew#if USE_COHERENT_MEM 2448d69a03fSSandrine Bailleux __COHERENT_RAM_UNALIGNED_SIZE__ = 2458d69a03fSSandrine Bailleux __COHERENT_RAM_END_UNALIGNED__ - __COHERENT_RAM_START__; 246ab8707e6SSoby Mathew#endif 2474f6ad66aSAchin Gupta 248d178637dSJuan Castillo ASSERT(. <= BL31_LIMIT, "BL31 image has exceeded its limit.") 2494f6ad66aSAchin Gupta} 250