14f6ad66aSAchin Gupta/* 2*7256cf0aSRohit Mathew * Copyright (c) 2013-2025, Arm Limited and Contributors. All rights reserved. 34f6ad66aSAchin Gupta * 482cb2c1aSdp-arm * SPDX-License-Identifier: BSD-3-Clause 54f6ad66aSAchin Gupta */ 64f6ad66aSAchin Gupta 7665e71b8SMasahiro Yamada#include <common/bl_common.ld.h> 8*7256cf0aSRohit Mathew#include <lib/per_cpu/per_cpu_defs.h> 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 GuptaMEMORY { 16d7fbf132SJuan Castillo RAM (rwx): ORIGIN = BL31_BASE, LENGTH = BL31_LIMIT - BL31_BASE 17f90fe02fSChris Kay 18f8578e64SSamuel Holland#if SEPARATE_NOBITS_REGION 19f8578e64SSamuel Holland NOBITS (rw!a): ORIGIN = BL31_NOBITS_BASE, LENGTH = BL31_NOBITS_LIMIT - BL31_NOBITS_BASE 20f90fe02fSChris Kay#else /* SEPARATE_NOBITS_REGION */ 21f8578e64SSamuel Holland# define NOBITS RAM 22f90fe02fSChris Kay#endif /* SEPARATE_NOBITS_REGION */ 2386acbbe2SYe Li 2486acbbe2SYe Li#if SEPARATE_RWDATA_REGION 2586acbbe2SYe Li RAM_RW (rw): ORIGIN = BL31_RWDATA_BASE, LENGTH = BL31_RWDATA_LIMIT - BL31_RWDATA_BASE 2686acbbe2SYe Li#else /* SEPARATE_RWDATA_REGION */ 2786acbbe2SYe Li#define RAM_RW RAM 2886acbbe2SYe Li#endif /* SEPARATE_RWDATA_REGION */ 294f6ad66aSAchin Gupta} 304f6ad66aSAchin Gupta 315be66449SBoyan Karatotev#if PLAT_EXTRA_LD_SCRIPT 32ec693569SCaesar Wang# include <plat.ld.S> 33f90fe02fSChris Kay#endif /* PLAT_EXTRA_LD_SCRIPT */ 344f6ad66aSAchin Gupta 35f90fe02fSChris KaySECTIONS { 369b5498a7SHarrison Mutai RAM_REGION_START = ORIGIN(RAM); 379b5498a7SHarrison Mutai RAM_REGION_LENGTH = LENGTH(RAM); 384f6ad66aSAchin Gupta . = BL31_BASE; 39f90fe02fSChris Kay 40a2aedac2SAntonio Nino Diaz ASSERT(. == ALIGN(PAGE_SIZE), 418d69a03fSSandrine Bailleux "BL31_BASE address is not aligned on a page boundary.") 424f6ad66aSAchin Gupta 43931f7c61SSoby Mathew __BL31_START__ = .; 44931f7c61SSoby Mathew 455d1c104fSSandrine Bailleux#if SEPARATE_CODE_AND_RODATA 465d1c104fSSandrine Bailleux .text . : { 473d6edc32SAndrey Skvortsov ASSERT(. == ALIGN(PAGE_SIZE), 483d6edc32SAndrey Skvortsov ".text is not aligned on a page boundary."); 493d6edc32SAndrey Skvortsov 505d1c104fSSandrine Bailleux __TEXT_START__ = .; 51f90fe02fSChris Kay 525d1c104fSSandrine Bailleux *bl31_entrypoint.o(.text*) 53d7b5f408SJimmy Brisson *(SORT_BY_ALIGNMENT(SORT(.text*))) 545d1c104fSSandrine Bailleux *(.vectors) 55f7d445fcSMichal Simek __TEXT_END_UNALIGNED__ = .; 56f90fe02fSChris Kay 575629b2b1SRoberto Vargas . = ALIGN(PAGE_SIZE); 58f90fe02fSChris Kay 595d1c104fSSandrine Bailleux __TEXT_END__ = .; 605d1c104fSSandrine Bailleux } >RAM 615d1c104fSSandrine Bailleux 625d1c104fSSandrine Bailleux .rodata . : { 635d1c104fSSandrine Bailleux __RODATA_START__ = .; 64f90fe02fSChris Kay 65ebd6efaeSSamuel Holland *(SORT_BY_ALIGNMENT(.rodata*)) 665d1c104fSSandrine Bailleux 678a68e864SLeon Chen# if PLAT_EXTRA_RODATA_INCLUDES 688a68e864SLeon Chen# include <plat.ld.rodata.inc> 69f90fe02fSChris Kay# endif /* PLAT_EXTRA_RODATA_INCLUDES */ 708a68e864SLeon Chen 710a0a7a9aSMasahiro Yamada RODATA_COMMON 72931f7c61SSoby Mathew 738e743bcdSJeenu Viswambharan . = ALIGN(8); 74f90fe02fSChris Kay 7509d40e0eSAntonio Nino Diaz# include <lib/el3_runtime/pubsub_events.h> 76f7d445fcSMichal Simek __RODATA_END_UNALIGNED__ = .; 778e743bcdSJeenu Viswambharan 785629b2b1SRoberto Vargas . = ALIGN(PAGE_SIZE); 79f90fe02fSChris Kay 805d1c104fSSandrine Bailleux __RODATA_END__ = .; 815d1c104fSSandrine Bailleux } >RAM 82f90fe02fSChris Kay#else /* SEPARATE_CODE_AND_RODATA */ 83da04341eSChris Kay .ro . : { 843d6edc32SAndrey Skvortsov ASSERT(. == ALIGN(PAGE_SIZE), 853d6edc32SAndrey Skvortsov ".ro is not aligned on a page boundary."); 863d6edc32SAndrey Skvortsov 878d69a03fSSandrine Bailleux __RO_START__ = .; 88f90fe02fSChris Kay 89dccc537aSAndrew Thoelke *bl31_entrypoint.o(.text*) 90ebd6efaeSSamuel Holland *(SORT_BY_ALIGNMENT(.text*)) 91ebd6efaeSSamuel Holland *(SORT_BY_ALIGNMENT(.rodata*)) 927421b465SAchin Gupta 930a0a7a9aSMasahiro Yamada RODATA_COMMON 945bfac4fcSSoby Mathew 958e743bcdSJeenu Viswambharan . = ALIGN(8); 96f90fe02fSChris Kay 9709d40e0eSAntonio Nino Diaz# include <lib/el3_runtime/pubsub_events.h> 988e743bcdSJeenu Viswambharan 99b739f22aSAchin Gupta *(.vectors) 100f90fe02fSChris Kay 1018d69a03fSSandrine Bailleux __RO_END_UNALIGNED__ = .; 102f90fe02fSChris Kay 1038d69a03fSSandrine Bailleux /* 1048d69a03fSSandrine Bailleux * Memory page(s) mapped to this section will be marked as read-only, 105f90fe02fSChris Kay * executable. No RW data from the next section must creep in. Ensure 106f90fe02fSChris Kay * that the rest of the current memory page is unused. 1078d69a03fSSandrine Bailleux */ 1085629b2b1SRoberto Vargas . = ALIGN(PAGE_SIZE); 109f90fe02fSChris Kay 1108d69a03fSSandrine Bailleux __RO_END__ = .; 1114f6ad66aSAchin Gupta } >RAM 112f90fe02fSChris Kay#endif /* SEPARATE_CODE_AND_RODATA */ 1134f6ad66aSAchin Gupta 1149b476841SSoby Mathew ASSERT(__CPU_OPS_END__ > __CPU_OPS_START__, 1159b476841SSoby Mathew "cpu_ops not defined for this platform.") 1169b476841SSoby Mathew 117f5e1bed2SNishant Sharma#if SPM_MM || (SPMC_AT_EL3 && SPMC_AT_EL3_SEL0_SP) 11832e83537SArd Biesheuvel# ifndef SPM_SHIM_EXCEPTIONS_VMA 11932e83537SArd Biesheuvel# define SPM_SHIM_EXCEPTIONS_VMA RAM 120f90fe02fSChris Kay# endif /* SPM_SHIM_EXCEPTIONS_VMA */ 12132e83537SArd Biesheuvel 1222fccb228SAntonio Nino Diaz /* 1232fccb228SAntonio Nino Diaz * Exception vectors of the SPM shim layer. They must be aligned to a 2K 124f90fe02fSChris Kay * address but we need to place them in a separate page so that we can set 125f90fe02fSChris Kay * individual permissions on them, so the actual alignment needed is the 126f90fe02fSChris Kay * page size. 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 */ 131da04341eSChris Kay .spm_shim_exceptions : ALIGN(PAGE_SIZE) { 1322fccb228SAntonio Nino Diaz __SPM_SHIM_EXCEPTIONS_START__ = .; 133f90fe02fSChris Kay 1342fccb228SAntonio Nino Diaz *(.spm_shim_exceptions) 135f90fe02fSChris Kay 1365629b2b1SRoberto Vargas . = ALIGN(PAGE_SIZE); 137f90fe02fSChris Kay 1382fccb228SAntonio Nino Diaz __SPM_SHIM_EXCEPTIONS_END__ = .; 13932e83537SArd Biesheuvel } >SPM_SHIM_EXCEPTIONS_VMA AT>RAM 14032e83537SArd Biesheuvel 141da04341eSChris Kay PROVIDE(__SPM_SHIM_EXCEPTIONS_LMA__ = LOADADDR(.spm_shim_exceptions)); 1422fccb228SAntonio Nino Diaz 143da04341eSChris Kay . = LOADADDR(.spm_shim_exceptions) + SIZEOF(.spm_shim_exceptions); 144f5e1bed2SNishant Sharma#endif /* SPM_MM || (SPMC_AT_EL3 && SPMC_AT_EL3_SEL0_SP) */ 145f90fe02fSChris Kay 14686acbbe2SYe Li#if SEPARATE_RWDATA_REGION 14786acbbe2SYe Li . = BL31_RWDATA_BASE; 14886acbbe2SYe Li ASSERT(BL31_RWDATA_BASE == ALIGN(PAGE_SIZE), 14986acbbe2SYe Li "BL31_RWDATA_BASE address is not aligned on a page boundary.") 15086acbbe2SYe Li 15186acbbe2SYe Li /* 15286acbbe2SYe Li * Define a linker symbol to mark the start of the RW memory area for this 15386acbbe2SYe Li * image. 15486acbbe2SYe Li */ 15586acbbe2SYe Li __RW_START__ = . ; 15686acbbe2SYe Li 15786acbbe2SYe Li DATA_SECTION >RAM_RW AT>RAM 15886acbbe2SYe Li __DATA_RAM_START__ = __DATA_START__; 15986acbbe2SYe Li __DATA_RAM_END__ = __DATA_END__; 16086acbbe2SYe Li __DATA_ROM_START__ = LOADADDR(.data); 16186acbbe2SYe Li 16286acbbe2SYe Li . = ALIGN(PAGE_SIZE); 16386acbbe2SYe Li __RW_END__ = .; 16486acbbe2SYe Li 16586acbbe2SYe Li RELA_SECTION >RAM 16686acbbe2SYe Li#else /* SEPARATE_RWDATA_REGION */ 16786acbbe2SYe Li /* 16886acbbe2SYe Li * Define a linker symbol to mark the start of the RW memory area for this 16986acbbe2SYe Li * image. 17086acbbe2SYe Li */ 17154dc71e7SAchin Gupta __RW_START__ = . ; 17254dc71e7SAchin Gupta 173caa3e7e0SMasahiro Yamada DATA_SECTION >RAM 174e8ad6168SMasahiro Yamada RELA_SECTION >RAM 17586acbbe2SYe Li#endif /* SEPARATE_RWDATA_REGION */ 176931f7c61SSoby Mathew 177a1b6db6cSSandrine Bailleux#ifdef BL31_PROGBITS_LIMIT 178138221c2SBoyan Karatotev ASSERT( 179138221c2SBoyan Karatotev . <= BL31_PROGBITS_LIMIT, 180138221c2SBoyan Karatotev "BL31 progbits has exceeded its limit. Consider disabling some features." 181138221c2SBoyan Karatotev ) 182f90fe02fSChris Kay#endif /* BL31_PROGBITS_LIMIT */ 183a1b6db6cSSandrine Bailleux 184f8578e64SSamuel Holland#if SEPARATE_NOBITS_REGION 185c367b75eSMadhukar Pappireddy . = ALIGN(PAGE_SIZE); 186f90fe02fSChris Kay 18786acbbe2SYe Li#if !SEPARATE_RWDATA_REGION 188f8578e64SSamuel Holland __RW_END__ = .; 18986acbbe2SYe Li#endif /* SEPARATE_RWDATA_REGION */ 190f8578e64SSamuel Holland __BL31_END__ = .; 191f8578e64SSamuel Holland 192f8578e64SSamuel Holland ASSERT(. <= BL31_LIMIT, "BL31 image has exceeded its limit.") 193f8578e64SSamuel Holland 194f8578e64SSamuel Holland . = BL31_NOBITS_BASE; 195f90fe02fSChris Kay 196f8578e64SSamuel Holland ASSERT(. == ALIGN(PAGE_SIZE), 197f8578e64SSamuel Holland "BL31 NOBITS base address is not aligned on a page boundary.") 198f8578e64SSamuel Holland 199f8578e64SSamuel Holland __NOBITS_START__ = .; 200f90fe02fSChris Kay#endif /* SEPARATE_NOBITS_REGION */ 201f8578e64SSamuel Holland 202a926a9f6SMasahiro Yamada STACK_SECTION >NOBITS 203a7739bc7SMasahiro Yamada BSS_SECTION >NOBITS 204*7256cf0aSRohit Mathew PER_CPU >NOBITS 205665e71b8SMasahiro Yamada XLAT_TABLE_SECTION >NOBITS 206a0cd989dSAchin Gupta 207ab8707e6SSoby Mathew#if USE_COHERENT_MEM 208a0cd989dSAchin Gupta /* 209f90fe02fSChris Kay * The base address of the coherent memory section must be page-aligned to 210f90fe02fSChris Kay * guarantee that the coherent data are stored on their own pages and are 211f90fe02fSChris Kay * not mixed with normal data. This is required to set up the correct 2128d69a03fSSandrine Bailleux * memory attributes for the coherent data page tables. 2138d69a03fSSandrine Bailleux */ 214da04341eSChris Kay .coherent_ram (NOLOAD) : ALIGN(PAGE_SIZE) { 2158d69a03fSSandrine Bailleux __COHERENT_RAM_START__ = .; 216f90fe02fSChris Kay 217ee7b35c4SAndrew Thoelke /* 218f90fe02fSChris Kay * Bakery locks are stored in coherent memory. Each lock's data is 219f90fe02fSChris Kay * contiguous and fully allocated by the compiler. 220ee7b35c4SAndrew Thoelke */ 221da04341eSChris Kay *(.bakery_lock) 222da04341eSChris Kay *(.tzfw_coherent_mem) 223f90fe02fSChris Kay 2248d69a03fSSandrine Bailleux __COHERENT_RAM_END_UNALIGNED__ = .; 225f90fe02fSChris Kay 2268d69a03fSSandrine Bailleux /* 227f90fe02fSChris Kay * Memory page(s) mapped to this section will be marked as device 228f90fe02fSChris Kay * memory. No other unexpected data must creep in. Ensure the rest of 229f90fe02fSChris Kay * the current memory page is unused. 2308d69a03fSSandrine Bailleux */ 2315629b2b1SRoberto Vargas . = ALIGN(PAGE_SIZE); 232f90fe02fSChris Kay 2338d69a03fSSandrine Bailleux __COHERENT_RAM_END__ = .; 234f8578e64SSamuel Holland } >NOBITS 235f90fe02fSChris Kay#endif /* USE_COHERENT_MEM */ 2364f6ad66aSAchin Gupta 237f8578e64SSamuel Holland#if SEPARATE_NOBITS_REGION 238f8578e64SSamuel Holland __NOBITS_END__ = .; 239f8578e64SSamuel Holland 240f8578e64SSamuel Holland ASSERT(. <= BL31_NOBITS_LIMIT, "BL31 NOBITS region has exceeded its limit.") 241f90fe02fSChris Kay#else /* SEPARATE_NOBITS_REGION */ 24286acbbe2SYe Li /* 24386acbbe2SYe Li * Define a linker symbol to mark the end of the RW memory area for this 24486acbbe2SYe Li * image. 24586acbbe2SYe Li */ 24686acbbe2SYe Li#if !SEPARATE_RWDATA_REGION 24754dc71e7SAchin Gupta __RW_END__ = .; 24886acbbe2SYe Li#endif /* SEPARATE_RWDATA_REGION */ 2498d69a03fSSandrine Bailleux __BL31_END__ = .; 2504f6ad66aSAchin Gupta 25164207f85SSamuel Holland ASSERT(. <= BL31_LIMIT, "BL31 image has exceeded its limit.") 252f90fe02fSChris Kay#endif /* SEPARATE_NOBITS_REGION */ 2539b5498a7SHarrison Mutai RAM_REGION_END = .; 25464207f85SSamuel Holland 255511046eaSMasahiro Yamada /DISCARD/ : { 256511046eaSMasahiro Yamada *(.dynsym .dynstr .hash .gnu.hash) 257511046eaSMasahiro Yamada } 2584f6ad66aSAchin Gupta} 259