14f6ad66aSAchin Gupta/* 28aabea33SPaul Beesley * Copyright (c) 2013-2019, 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> 809d40e0eSAntonio Nino Diaz 909d40e0eSAntonio Nino Diaz#include <lib/xlat_tables/xlat_tables_defs.h> 104f6ad66aSAchin Gupta 114f6ad66aSAchin GuptaOUTPUT_FORMAT(PLATFORM_LINKER_FORMAT) 124f6ad66aSAchin GuptaOUTPUT_ARCH(PLATFORM_LINKER_ARCH) 139f98aa1aSJeenu ViswambharanENTRY(bl31_entrypoint) 144f6ad66aSAchin Gupta 154f6ad66aSAchin Gupta 164f6ad66aSAchin GuptaMEMORY { 17d7fbf132SJuan Castillo RAM (rwx): ORIGIN = BL31_BASE, LENGTH = BL31_LIMIT - BL31_BASE 184f6ad66aSAchin Gupta} 194f6ad66aSAchin Gupta 20ec693569SCaesar Wang#ifdef PLAT_EXTRA_LD_SCRIPT 21ec693569SCaesar Wang#include <plat.ld.S> 22ec693569SCaesar Wang#endif 234f6ad66aSAchin Gupta 244f6ad66aSAchin GuptaSECTIONS 254f6ad66aSAchin Gupta{ 264f6ad66aSAchin Gupta . = BL31_BASE; 27a2aedac2SAntonio Nino Diaz ASSERT(. == ALIGN(PAGE_SIZE), 288d69a03fSSandrine Bailleux "BL31_BASE address is not aligned on a page boundary.") 294f6ad66aSAchin Gupta 30931f7c61SSoby Mathew __BL31_START__ = .; 31931f7c61SSoby Mathew 325d1c104fSSandrine Bailleux#if SEPARATE_CODE_AND_RODATA 335d1c104fSSandrine Bailleux .text . : { 345d1c104fSSandrine Bailleux __TEXT_START__ = .; 355d1c104fSSandrine Bailleux *bl31_entrypoint.o(.text*) 36*ebd6efaeSSamuel Holland *(SORT_BY_ALIGNMENT(.text*)) 375d1c104fSSandrine Bailleux *(.vectors) 385629b2b1SRoberto Vargas . = ALIGN(PAGE_SIZE); 395d1c104fSSandrine Bailleux __TEXT_END__ = .; 405d1c104fSSandrine Bailleux } >RAM 415d1c104fSSandrine Bailleux 425d1c104fSSandrine Bailleux .rodata . : { 435d1c104fSSandrine Bailleux __RODATA_START__ = .; 44*ebd6efaeSSamuel Holland *(SORT_BY_ALIGNMENT(.rodata*)) 455d1c104fSSandrine Bailleux 465d1c104fSSandrine Bailleux /* Ensure 8-byte alignment for descriptors and ensure inclusion */ 475d1c104fSSandrine Bailleux . = ALIGN(8); 485d1c104fSSandrine Bailleux __RT_SVC_DESCS_START__ = .; 495d1c104fSSandrine Bailleux KEEP(*(rt_svc_descs)) 505d1c104fSSandrine Bailleux __RT_SVC_DESCS_END__ = .; 515d1c104fSSandrine Bailleux 525d1c104fSSandrine Bailleux#if ENABLE_PMF 535d1c104fSSandrine Bailleux /* Ensure 8-byte alignment for descriptors and ensure inclusion */ 545d1c104fSSandrine Bailleux . = ALIGN(8); 555d1c104fSSandrine Bailleux __PMF_SVC_DESCS_START__ = .; 565d1c104fSSandrine Bailleux KEEP(*(pmf_svc_descs)) 575d1c104fSSandrine Bailleux __PMF_SVC_DESCS_END__ = .; 585d1c104fSSandrine Bailleux#endif /* ENABLE_PMF */ 595d1c104fSSandrine Bailleux 605d1c104fSSandrine Bailleux /* 615d1c104fSSandrine Bailleux * Ensure 8-byte alignment for cpu_ops so that its fields are also 625d1c104fSSandrine Bailleux * aligned. Also ensure cpu_ops inclusion. 635d1c104fSSandrine Bailleux */ 645d1c104fSSandrine Bailleux . = ALIGN(8); 655d1c104fSSandrine Bailleux __CPU_OPS_START__ = .; 665d1c104fSSandrine Bailleux KEEP(*(cpu_ops)) 675d1c104fSSandrine Bailleux __CPU_OPS_END__ = .; 685d1c104fSSandrine Bailleux 69931f7c61SSoby Mathew /* 705bfac4fcSSoby Mathew * Keep the .got section in the RO section as it is patched 71931f7c61SSoby Mathew * prior to enabling the MMU and having the .got in RO is better for 725bfac4fcSSoby Mathew * security. GOT is a table of addresses so ensure 8-byte alignment. 73931f7c61SSoby Mathew */ 745bfac4fcSSoby Mathew . = ALIGN(8); 75931f7c61SSoby Mathew __GOT_START__ = .; 76931f7c61SSoby Mathew *(.got) 77931f7c61SSoby Mathew __GOT_END__ = .; 78931f7c61SSoby Mathew 798e743bcdSJeenu Viswambharan /* Place pubsub sections for events */ 808e743bcdSJeenu Viswambharan . = ALIGN(8); 8109d40e0eSAntonio Nino Diaz#include <lib/el3_runtime/pubsub_events.h> 828e743bcdSJeenu Viswambharan 835629b2b1SRoberto Vargas . = ALIGN(PAGE_SIZE); 845d1c104fSSandrine Bailleux __RODATA_END__ = .; 855d1c104fSSandrine Bailleux } >RAM 865d1c104fSSandrine Bailleux#else 878d69a03fSSandrine Bailleux ro . : { 888d69a03fSSandrine Bailleux __RO_START__ = .; 89dccc537aSAndrew Thoelke *bl31_entrypoint.o(.text*) 90*ebd6efaeSSamuel Holland *(SORT_BY_ALIGNMENT(.text*)) 91*ebd6efaeSSamuel Holland *(SORT_BY_ALIGNMENT(.rodata*)) 927421b465SAchin Gupta 93dccc537aSAndrew Thoelke /* Ensure 8-byte alignment for descriptors and ensure inclusion */ 947421b465SAchin Gupta . = ALIGN(8); 957421b465SAchin Gupta __RT_SVC_DESCS_START__ = .; 96dccc537aSAndrew Thoelke KEEP(*(rt_svc_descs)) 977421b465SAchin Gupta __RT_SVC_DESCS_END__ = .; 987421b465SAchin Gupta 99a31d8983SYatharth Kochar#if ENABLE_PMF 100a31d8983SYatharth Kochar /* Ensure 8-byte alignment for descriptors and ensure inclusion */ 101a31d8983SYatharth Kochar . = ALIGN(8); 102a31d8983SYatharth Kochar __PMF_SVC_DESCS_START__ = .; 103a31d8983SYatharth Kochar KEEP(*(pmf_svc_descs)) 104a31d8983SYatharth Kochar __PMF_SVC_DESCS_END__ = .; 105a31d8983SYatharth Kochar#endif /* ENABLE_PMF */ 106a31d8983SYatharth Kochar 1079b476841SSoby Mathew /* 1089b476841SSoby Mathew * Ensure 8-byte alignment for cpu_ops so that its fields are also 1099b476841SSoby Mathew * aligned. Also ensure cpu_ops inclusion. 1109b476841SSoby Mathew */ 1119b476841SSoby Mathew . = ALIGN(8); 1129b476841SSoby Mathew __CPU_OPS_START__ = .; 1139b476841SSoby Mathew KEEP(*(cpu_ops)) 1149b476841SSoby Mathew __CPU_OPS_END__ = .; 1159b476841SSoby Mathew 1165bfac4fcSSoby Mathew /* 1175bfac4fcSSoby Mathew * Keep the .got section in the RO section as it is patched 1185bfac4fcSSoby Mathew * prior to enabling the MMU and having the .got in RO is better for 1195bfac4fcSSoby Mathew * security. GOT is a table of addresses so ensure 8-byte alignment. 1205bfac4fcSSoby Mathew */ 1215bfac4fcSSoby Mathew . = ALIGN(8); 1225bfac4fcSSoby Mathew __GOT_START__ = .; 1235bfac4fcSSoby Mathew *(.got) 1245bfac4fcSSoby Mathew __GOT_END__ = .; 1255bfac4fcSSoby Mathew 1268e743bcdSJeenu Viswambharan /* Place pubsub sections for events */ 1278e743bcdSJeenu Viswambharan . = ALIGN(8); 12809d40e0eSAntonio Nino Diaz#include <lib/el3_runtime/pubsub_events.h> 1298e743bcdSJeenu Viswambharan 130b739f22aSAchin Gupta *(.vectors) 1318d69a03fSSandrine Bailleux __RO_END_UNALIGNED__ = .; 1328d69a03fSSandrine Bailleux /* 1338d69a03fSSandrine Bailleux * Memory page(s) mapped to this section will be marked as read-only, 1348d69a03fSSandrine Bailleux * executable. No RW data from the next section must creep in. 1358d69a03fSSandrine Bailleux * Ensure the rest of the current memory page is unused. 1368d69a03fSSandrine Bailleux */ 1375629b2b1SRoberto Vargas . = ALIGN(PAGE_SIZE); 1388d69a03fSSandrine Bailleux __RO_END__ = .; 1394f6ad66aSAchin Gupta } >RAM 1405d1c104fSSandrine Bailleux#endif 1414f6ad66aSAchin Gupta 1429b476841SSoby Mathew ASSERT(__CPU_OPS_END__ > __CPU_OPS_START__, 1439b476841SSoby Mathew "cpu_ops not defined for this platform.") 1449b476841SSoby Mathew 1452fccb228SAntonio Nino Diaz#if ENABLE_SPM 14632e83537SArd Biesheuvel#ifndef SPM_SHIM_EXCEPTIONS_VMA 14732e83537SArd Biesheuvel#define SPM_SHIM_EXCEPTIONS_VMA RAM 14832e83537SArd Biesheuvel#endif 14932e83537SArd Biesheuvel 1502fccb228SAntonio Nino Diaz /* 1512fccb228SAntonio Nino Diaz * Exception vectors of the SPM shim layer. They must be aligned to a 2K 1522fccb228SAntonio Nino Diaz * address, but we need to place them in a separate page so that we can set 1532fccb228SAntonio Nino Diaz * individual permissions to them, so the actual alignment needed is 4K. 1542fccb228SAntonio Nino Diaz * 1552fccb228SAntonio Nino Diaz * There's no need to include this into the RO section of BL31 because it 1562fccb228SAntonio Nino Diaz * doesn't need to be accessed by BL31. 1572fccb228SAntonio Nino Diaz */ 158a2aedac2SAntonio Nino Diaz spm_shim_exceptions : ALIGN(PAGE_SIZE) { 1592fccb228SAntonio Nino Diaz __SPM_SHIM_EXCEPTIONS_START__ = .; 1602fccb228SAntonio Nino Diaz *(.spm_shim_exceptions) 1615629b2b1SRoberto Vargas . = ALIGN(PAGE_SIZE); 1622fccb228SAntonio Nino Diaz __SPM_SHIM_EXCEPTIONS_END__ = .; 16332e83537SArd Biesheuvel } >SPM_SHIM_EXCEPTIONS_VMA AT>RAM 16432e83537SArd Biesheuvel 16532e83537SArd Biesheuvel PROVIDE(__SPM_SHIM_EXCEPTIONS_LMA__ = LOADADDR(spm_shim_exceptions)); 16632e83537SArd Biesheuvel . = LOADADDR(spm_shim_exceptions) + SIZEOF(spm_shim_exceptions); 1672fccb228SAntonio Nino Diaz#endif 1682fccb228SAntonio Nino Diaz 16954dc71e7SAchin Gupta /* 17054dc71e7SAchin Gupta * Define a linker symbol to mark start of the RW memory area for this 17154dc71e7SAchin Gupta * image. 17254dc71e7SAchin Gupta */ 17354dc71e7SAchin Gupta __RW_START__ = . ; 17454dc71e7SAchin Gupta 17551faada7SDouglas Raillard /* 17651faada7SDouglas Raillard * .data must be placed at a lower address than the stacks if the stack 17751faada7SDouglas Raillard * protector is enabled. Alternatively, the .data.stack_protector_canary 17851faada7SDouglas Raillard * section can be placed independently of the main .data section. 17951faada7SDouglas Raillard */ 1808d69a03fSSandrine Bailleux .data . : { 1818d69a03fSSandrine Bailleux __DATA_START__ = .; 182*ebd6efaeSSamuel Holland *(SORT_BY_ALIGNMENT(.data*)) 1838d69a03fSSandrine Bailleux __DATA_END__ = .; 1848d69a03fSSandrine Bailleux } >RAM 1858d69a03fSSandrine Bailleux 186931f7c61SSoby Mathew /* 187931f7c61SSoby Mathew * .rela.dyn needs to come after .data for the read-elf utility to parse 1885bfac4fcSSoby Mathew * this section correctly. Ensure 8-byte alignment so that the fields of 1895bfac4fcSSoby Mathew * RELA data structure are aligned. 190931f7c61SSoby Mathew */ 1915bfac4fcSSoby Mathew . = ALIGN(8); 192931f7c61SSoby Mathew __RELA_START__ = .; 193931f7c61SSoby Mathew .rela.dyn . : { 194931f7c61SSoby Mathew } >RAM 195931f7c61SSoby Mathew __RELA_END__ = .; 196931f7c61SSoby Mathew 197a1b6db6cSSandrine Bailleux#ifdef BL31_PROGBITS_LIMIT 198d178637dSJuan Castillo ASSERT(. <= BL31_PROGBITS_LIMIT, "BL31 progbits has exceeded its limit.") 199a1b6db6cSSandrine Bailleux#endif 200a1b6db6cSSandrine Bailleux 2018d69a03fSSandrine Bailleux stacks (NOLOAD) : { 2028d69a03fSSandrine Bailleux __STACKS_START__ = .; 2034f6ad66aSAchin Gupta *(tzfw_normal_stacks) 2048d69a03fSSandrine Bailleux __STACKS_END__ = .; 2054f6ad66aSAchin Gupta } >RAM 2064f6ad66aSAchin Gupta 2078d69a03fSSandrine Bailleux /* 2088d69a03fSSandrine Bailleux * The .bss section gets initialised to 0 at runtime. 209308d359bSDouglas Raillard * Its base address should be 16-byte aligned for better performance of the 210308d359bSDouglas Raillard * zero-initialization code. 2118d69a03fSSandrine Bailleux */ 212ee7b35c4SAndrew Thoelke .bss (NOLOAD) : ALIGN(16) { 2138d69a03fSSandrine Bailleux __BSS_START__ = .; 214*ebd6efaeSSamuel Holland *(SORT_BY_ALIGNMENT(.bss*)) 2154f6ad66aSAchin Gupta *(COMMON) 216ee7b35c4SAndrew Thoelke#if !USE_COHERENT_MEM 217ee7b35c4SAndrew Thoelke /* 218ee7b35c4SAndrew Thoelke * Bakery locks are stored in normal .bss memory 219ee7b35c4SAndrew Thoelke * 220ee7b35c4SAndrew Thoelke * Each lock's data is spread across multiple cache lines, one per CPU, 221ee7b35c4SAndrew Thoelke * but multiple locks can share the same cache line. 222ee7b35c4SAndrew Thoelke * The compiler will allocate enough memory for one CPU's bakery locks, 223ee7b35c4SAndrew Thoelke * the remaining cache lines are allocated by the linker script 224ee7b35c4SAndrew Thoelke */ 225ee7b35c4SAndrew Thoelke . = ALIGN(CACHE_WRITEBACK_GRANULE); 226ee7b35c4SAndrew Thoelke __BAKERY_LOCK_START__ = .; 227596929b9SVarun Wadekar __PERCPU_BAKERY_LOCK_START__ = .; 228ee7b35c4SAndrew Thoelke *(bakery_lock) 229ee7b35c4SAndrew Thoelke . = ALIGN(CACHE_WRITEBACK_GRANULE); 230596929b9SVarun Wadekar __PERCPU_BAKERY_LOCK_END__ = .; 231596929b9SVarun Wadekar __PERCPU_BAKERY_LOCK_SIZE__ = ABSOLUTE(__PERCPU_BAKERY_LOCK_END__ - __PERCPU_BAKERY_LOCK_START__); 232ee7b35c4SAndrew Thoelke . = . + (__PERCPU_BAKERY_LOCK_SIZE__ * (PLATFORM_CORE_COUNT - 1)); 233ee7b35c4SAndrew Thoelke __BAKERY_LOCK_END__ = .; 23432aee841SRoberto Vargas 23532aee841SRoberto Vargas /* 23632aee841SRoberto Vargas * If BL31 doesn't use any bakery lock then __PERCPU_BAKERY_LOCK_SIZE__ 23732aee841SRoberto Vargas * will be zero. For this reason, the only two valid values for 23832aee841SRoberto Vargas * __PERCPU_BAKERY_LOCK_SIZE__ are 0 or the platform defined value 23932aee841SRoberto Vargas * PLAT_PERCPU_BAKERY_LOCK_SIZE. 24032aee841SRoberto Vargas */ 241ee7b35c4SAndrew Thoelke#ifdef PLAT_PERCPU_BAKERY_LOCK_SIZE 24232aee841SRoberto Vargas ASSERT((__PERCPU_BAKERY_LOCK_SIZE__ == 0) || (__PERCPU_BAKERY_LOCK_SIZE__ == PLAT_PERCPU_BAKERY_LOCK_SIZE), 243ee7b35c4SAndrew Thoelke "PLAT_PERCPU_BAKERY_LOCK_SIZE does not match bakery lock requirements"); 244ee7b35c4SAndrew Thoelke#endif 245ee7b35c4SAndrew Thoelke#endif 246a31d8983SYatharth Kochar 247a31d8983SYatharth Kochar#if ENABLE_PMF 248a31d8983SYatharth Kochar /* 249a31d8983SYatharth Kochar * Time-stamps are stored in normal .bss memory 250a31d8983SYatharth Kochar * 251a31d8983SYatharth Kochar * The compiler will allocate enough memory for one CPU's time-stamps, 2528aabea33SPaul Beesley * the remaining memory for other CPUs is allocated by the 253a31d8983SYatharth Kochar * linker script 254a31d8983SYatharth Kochar */ 255a31d8983SYatharth Kochar . = ALIGN(CACHE_WRITEBACK_GRANULE); 256a31d8983SYatharth Kochar __PMF_TIMESTAMP_START__ = .; 257a31d8983SYatharth Kochar KEEP(*(pmf_timestamp_array)) 258a31d8983SYatharth Kochar . = ALIGN(CACHE_WRITEBACK_GRANULE); 259a31d8983SYatharth Kochar __PMF_PERCPU_TIMESTAMP_END__ = .; 260a31d8983SYatharth Kochar __PERCPU_TIMESTAMP_SIZE__ = ABSOLUTE(. - __PMF_TIMESTAMP_START__); 261a31d8983SYatharth Kochar . = . + (__PERCPU_TIMESTAMP_SIZE__ * (PLATFORM_CORE_COUNT - 1)); 262a31d8983SYatharth Kochar __PMF_TIMESTAMP_END__ = .; 263a31d8983SYatharth Kochar#endif /* ENABLE_PMF */ 2648d69a03fSSandrine Bailleux __BSS_END__ = .; 2654f6ad66aSAchin Gupta } >RAM 2664f6ad66aSAchin Gupta 2678d69a03fSSandrine Bailleux /* 268e3fff153SJeenu Viswambharan * The xlat_table section is for full, aligned page tables (4K). 269a0cd989dSAchin Gupta * Removing them from .bss avoids forcing 4K alignment on 270883d1b5dSAntonio Nino Diaz * the .bss section. The tables are initialized to zero by the translation 271883d1b5dSAntonio Nino Diaz * tables library. 272a0cd989dSAchin Gupta */ 273a0cd989dSAchin Gupta xlat_table (NOLOAD) : { 274a0cd989dSAchin Gupta *(xlat_table) 275a0cd989dSAchin Gupta } >RAM 276a0cd989dSAchin Gupta 277ab8707e6SSoby Mathew#if USE_COHERENT_MEM 278a0cd989dSAchin Gupta /* 2798d69a03fSSandrine Bailleux * The base address of the coherent memory section must be page-aligned (4K) 2808d69a03fSSandrine Bailleux * to guarantee that the coherent data are stored on their own pages and 2818d69a03fSSandrine Bailleux * are not mixed with normal data. This is required to set up the correct 2828d69a03fSSandrine Bailleux * memory attributes for the coherent data page tables. 2838d69a03fSSandrine Bailleux */ 284a2aedac2SAntonio Nino Diaz coherent_ram (NOLOAD) : ALIGN(PAGE_SIZE) { 2858d69a03fSSandrine Bailleux __COHERENT_RAM_START__ = .; 286ee7b35c4SAndrew Thoelke /* 287ee7b35c4SAndrew Thoelke * Bakery locks are stored in coherent memory 288ee7b35c4SAndrew Thoelke * 289ee7b35c4SAndrew Thoelke * Each lock's data is contiguous and fully allocated by the compiler 290ee7b35c4SAndrew Thoelke */ 291ee7b35c4SAndrew Thoelke *(bakery_lock) 2928d69a03fSSandrine Bailleux *(tzfw_coherent_mem) 2938d69a03fSSandrine Bailleux __COHERENT_RAM_END_UNALIGNED__ = .; 2948d69a03fSSandrine Bailleux /* 2958d69a03fSSandrine Bailleux * Memory page(s) mapped to this section will be marked 2968d69a03fSSandrine Bailleux * as device memory. No other unexpected data must creep in. 2978d69a03fSSandrine Bailleux * Ensure the rest of the current memory page is unused. 2988d69a03fSSandrine Bailleux */ 2995629b2b1SRoberto Vargas . = ALIGN(PAGE_SIZE); 3008d69a03fSSandrine Bailleux __COHERENT_RAM_END__ = .; 3014f6ad66aSAchin Gupta } >RAM 302ab8707e6SSoby Mathew#endif 3034f6ad66aSAchin Gupta 30454dc71e7SAchin Gupta /* 30554dc71e7SAchin Gupta * Define a linker symbol to mark end of the RW memory area for this 30654dc71e7SAchin Gupta * image. 30754dc71e7SAchin Gupta */ 30854dc71e7SAchin Gupta __RW_END__ = .; 3098d69a03fSSandrine Bailleux __BL31_END__ = .; 3104f6ad66aSAchin Gupta 311d178637dSJuan Castillo ASSERT(. <= BL31_LIMIT, "BL31 image has exceeded its limit.") 3124f6ad66aSAchin Gupta} 313