1b1d27b48SRoberto Vargas/* 2*96a8ed14SJiafei Pan * Copyright (c) 2017-2022, ARM Limited and Contributors. All rights reserved. 3b1d27b48SRoberto Vargas * 4b1d27b48SRoberto Vargas * SPDX-License-Identifier: BSD-3-Clause 5b1d27b48SRoberto Vargas */ 6b1d27b48SRoberto Vargas 7665e71b8SMasahiro Yamada#include <common/bl_common.ld.h> 809d40e0eSAntonio Nino Diaz#include <lib/xlat_tables/xlat_tables_defs.h> 9b1d27b48SRoberto Vargas 10b1d27b48SRoberto VargasOUTPUT_FORMAT(PLATFORM_LINKER_FORMAT) 11b1d27b48SRoberto VargasOUTPUT_ARCH(PLATFORM_LINKER_ARCH) 12b1d27b48SRoberto VargasENTRY(bl2_entrypoint) 13b1d27b48SRoberto Vargas 14b1d27b48SRoberto VargasMEMORY { 157d173fc5SJiafei Pan#if BL2_IN_XIP_MEM 167d173fc5SJiafei Pan ROM (rx): ORIGIN = BL2_RO_BASE, LENGTH = BL2_RO_LIMIT - BL2_RO_BASE 177d173fc5SJiafei Pan RAM (rwx): ORIGIN = BL2_RW_BASE, LENGTH = BL2_RW_LIMIT - BL2_RW_BASE 187d173fc5SJiafei Pan#else 19b1d27b48SRoberto Vargas RAM (rwx): ORIGIN = BL2_BASE, LENGTH = BL2_LIMIT - BL2_BASE 20*96a8ed14SJiafei Pan#if SEPARATE_BL2_NOLOAD_REGION 21*96a8ed14SJiafei Pan RAM_NOLOAD (rw!a): ORIGIN = BL2_NOLOAD_START, LENGTH = BL2_NOLOAD_LIMIT - BL2_NOLOAD_START 22*96a8ed14SJiafei Pan#else 23*96a8ed14SJiafei Pan#define RAM_NOLOAD RAM 24*96a8ed14SJiafei Pan#endif 257d173fc5SJiafei Pan#endif 26b1d27b48SRoberto Vargas} 27b1d27b48SRoberto Vargas 282f6f00dcSMasahiro Yamada#if !BL2_IN_XIP_MEM 292f6f00dcSMasahiro Yamada#define ROM RAM 302f6f00dcSMasahiro Yamada#endif 31b1d27b48SRoberto Vargas 32b1d27b48SRoberto VargasSECTIONS 33b1d27b48SRoberto Vargas{ 347d173fc5SJiafei Pan#if BL2_IN_XIP_MEM 357d173fc5SJiafei Pan . = BL2_RO_BASE; 367d173fc5SJiafei Pan ASSERT(. == ALIGN(PAGE_SIZE), 377d173fc5SJiafei Pan "BL2_RO_BASE address is not aligned on a page boundary.") 387d173fc5SJiafei Pan#else 39b1d27b48SRoberto Vargas . = BL2_BASE; 40b1d27b48SRoberto Vargas ASSERT(. == ALIGN(PAGE_SIZE), 41b1d27b48SRoberto Vargas "BL2_BASE address is not aligned on a page boundary.") 427d173fc5SJiafei Pan#endif 43b1d27b48SRoberto Vargas 44b1d27b48SRoberto Vargas#if SEPARATE_CODE_AND_RODATA 45b1d27b48SRoberto Vargas .text . : { 46b1d27b48SRoberto Vargas __TEXT_START__ = .; 47487d3bf2SRoberto Vargas __TEXT_RESIDENT_START__ = .; 48b1d27b48SRoberto Vargas *bl2_el3_entrypoint.o(.text*) 49487d3bf2SRoberto Vargas *(.text.asm.*) 50487d3bf2SRoberto Vargas __TEXT_RESIDENT_END__ = .; 51ebd6efaeSSamuel Holland *(SORT_BY_ALIGNMENT(.text*)) 52b1d27b48SRoberto Vargas *(.vectors) 535629b2b1SRoberto Vargas . = ALIGN(PAGE_SIZE); 54b1d27b48SRoberto Vargas __TEXT_END__ = .; 557d173fc5SJiafei Pan } >ROM 56b1d27b48SRoberto Vargas 57b1d27b48SRoberto Vargas .rodata . : { 58b1d27b48SRoberto Vargas __RODATA_START__ = .; 59ebd6efaeSSamuel Holland *(SORT_BY_ALIGNMENT(.rodata*)) 60b1d27b48SRoberto Vargas 610a0a7a9aSMasahiro Yamada RODATA_COMMON 6269af7fcfSMasahiro Yamada 635629b2b1SRoberto Vargas . = ALIGN(PAGE_SIZE); 64b1d27b48SRoberto Vargas __RODATA_END__ = .; 657d173fc5SJiafei Pan } >ROM 66487d3bf2SRoberto Vargas 67487d3bf2SRoberto Vargas ASSERT(__TEXT_RESIDENT_END__ - __TEXT_RESIDENT_START__ <= PAGE_SIZE, 68487d3bf2SRoberto Vargas "Resident part of BL2 has exceeded its limit.") 69b1d27b48SRoberto Vargas#else 70b1d27b48SRoberto Vargas ro . : { 71b1d27b48SRoberto Vargas __RO_START__ = .; 72487d3bf2SRoberto Vargas __TEXT_RESIDENT_START__ = .; 73b1d27b48SRoberto Vargas *bl2_el3_entrypoint.o(.text*) 74487d3bf2SRoberto Vargas *(.text.asm.*) 75487d3bf2SRoberto Vargas __TEXT_RESIDENT_END__ = .; 76ebd6efaeSSamuel Holland *(SORT_BY_ALIGNMENT(.text*)) 77ebd6efaeSSamuel Holland *(SORT_BY_ALIGNMENT(.rodata*)) 78b1d27b48SRoberto Vargas 790a0a7a9aSMasahiro Yamada RODATA_COMMON 8069af7fcfSMasahiro Yamada 81b1d27b48SRoberto Vargas *(.vectors) 82b1d27b48SRoberto Vargas __RO_END_UNALIGNED__ = .; 83b1d27b48SRoberto Vargas /* 84b1d27b48SRoberto Vargas * Memory page(s) mapped to this section will be marked as 85b1d27b48SRoberto Vargas * read-only, executable. No RW data from the next section must 86b1d27b48SRoberto Vargas * creep in. Ensure the rest of the current memory page is unused. 87b1d27b48SRoberto Vargas */ 885629b2b1SRoberto Vargas . = ALIGN(PAGE_SIZE); 89b1d27b48SRoberto Vargas 90b1d27b48SRoberto Vargas __RO_END__ = .; 917d173fc5SJiafei Pan } >ROM 927d173fc5SJiafei Pan#endif 93b1d27b48SRoberto Vargas 94b1d27b48SRoberto Vargas ASSERT(__CPU_OPS_END__ > __CPU_OPS_START__, 95b1d27b48SRoberto Vargas "cpu_ops not defined for this platform.") 96b1d27b48SRoberto Vargas 977d173fc5SJiafei Pan#if BL2_IN_XIP_MEM 987d173fc5SJiafei Pan . = BL2_RW_BASE; 997d173fc5SJiafei Pan ASSERT(BL2_RW_BASE == ALIGN(PAGE_SIZE), 1007d173fc5SJiafei Pan "BL2_RW_BASE address is not aligned on a page boundary.") 1017d173fc5SJiafei Pan#endif 1027d173fc5SJiafei Pan 103b1d27b48SRoberto Vargas /* 104b1d27b48SRoberto Vargas * Define a linker symbol to mark start of the RW memory area for this 105b1d27b48SRoberto Vargas * image. 106b1d27b48SRoberto Vargas */ 107b1d27b48SRoberto Vargas __RW_START__ = . ; 108b1d27b48SRoberto Vargas 109caa3e7e0SMasahiro Yamada DATA_SECTION >RAM AT>ROM 110caa3e7e0SMasahiro Yamada __DATA_RAM_START__ = __DATA_START__; 111caa3e7e0SMasahiro Yamada __DATA_RAM_END__ = __DATA_END__; 112b1d27b48SRoberto Vargas 113e8ad6168SMasahiro Yamada RELA_SECTION >RAM 114*96a8ed14SJiafei Pan#if SEPARATE_BL2_NOLOAD_REGION 115*96a8ed14SJiafei Pan SAVED_ADDR = .; 116*96a8ed14SJiafei Pan . = BL2_NOLOAD_START; 117*96a8ed14SJiafei Pan __BL2_NOLOAD_START__ = .; 118*96a8ed14SJiafei Pan#endif 119*96a8ed14SJiafei Pan STACK_SECTION >RAM_NOLOAD 120*96a8ed14SJiafei Pan BSS_SECTION >RAM_NOLOAD 121*96a8ed14SJiafei Pan XLAT_TABLE_SECTION >RAM_NOLOAD 122*96a8ed14SJiafei Pan#if SEPARATE_BL2_NOLOAD_REGION 123*96a8ed14SJiafei Pan __BL2_NOLOAD_END__ = .; 124*96a8ed14SJiafei Pan . = SAVED_ADDR; 125*96a8ed14SJiafei Pan#endif 126b1d27b48SRoberto Vargas 127b1d27b48SRoberto Vargas#if USE_COHERENT_MEM 128b1d27b48SRoberto Vargas /* 129b1d27b48SRoberto Vargas * The base address of the coherent memory section must be page-aligned (4K) 130b1d27b48SRoberto Vargas * to guarantee that the coherent data are stored on their own pages and 131b1d27b48SRoberto Vargas * are not mixed with normal data. This is required to set up the correct 132b1d27b48SRoberto Vargas * memory attributes for the coherent data page tables. 133b1d27b48SRoberto Vargas */ 134b1d27b48SRoberto Vargas coherent_ram (NOLOAD) : ALIGN(PAGE_SIZE) { 135b1d27b48SRoberto Vargas __COHERENT_RAM_START__ = .; 136b1d27b48SRoberto Vargas *(tzfw_coherent_mem) 137b1d27b48SRoberto Vargas __COHERENT_RAM_END_UNALIGNED__ = .; 138b1d27b48SRoberto Vargas /* 139b1d27b48SRoberto Vargas * Memory page(s) mapped to this section will be marked 140b1d27b48SRoberto Vargas * as device memory. No other unexpected data must creep in. 141b1d27b48SRoberto Vargas * Ensure the rest of the current memory page is unused. 142b1d27b48SRoberto Vargas */ 1435629b2b1SRoberto Vargas . = ALIGN(PAGE_SIZE); 144b1d27b48SRoberto Vargas __COHERENT_RAM_END__ = .; 145b1d27b48SRoberto Vargas } >RAM 146b1d27b48SRoberto Vargas#endif 147b1d27b48SRoberto Vargas 148b1d27b48SRoberto Vargas /* 149b1d27b48SRoberto Vargas * Define a linker symbol to mark end of the RW memory area for this 150b1d27b48SRoberto Vargas * image. 151b1d27b48SRoberto Vargas */ 152b1d27b48SRoberto Vargas __RW_END__ = .; 153b1d27b48SRoberto Vargas __BL2_END__ = .; 154b1d27b48SRoberto Vargas 15569af7fcfSMasahiro Yamada /DISCARD/ : { 15669af7fcfSMasahiro Yamada *(.dynsym .dynstr .hash .gnu.hash) 15769af7fcfSMasahiro Yamada } 15869af7fcfSMasahiro Yamada 1597d173fc5SJiafei Pan#if BL2_IN_XIP_MEM 1607d173fc5SJiafei Pan __BL2_RAM_START__ = ADDR(.data); 1617d173fc5SJiafei Pan __BL2_RAM_END__ = .; 1627d173fc5SJiafei Pan 1637d173fc5SJiafei Pan __DATA_ROM_START__ = LOADADDR(.data); 1647d173fc5SJiafei Pan __DATA_SIZE__ = SIZEOF(.data); 1657d173fc5SJiafei Pan 1667d173fc5SJiafei Pan /* 1677d173fc5SJiafei Pan * The .data section is the last PROGBITS section so its end marks the end 1687d173fc5SJiafei Pan * of BL2's RO content in XIP memory.. 1697d173fc5SJiafei Pan */ 1707d173fc5SJiafei Pan __BL2_ROM_END__ = __DATA_ROM_START__ + __DATA_SIZE__; 1717d173fc5SJiafei Pan ASSERT(__BL2_ROM_END__ <= BL2_RO_LIMIT, 1727d173fc5SJiafei Pan "BL2's RO content has exceeded its limit.") 1737d173fc5SJiafei Pan#endif 174b1d27b48SRoberto Vargas __BSS_SIZE__ = SIZEOF(.bss); 175b1d27b48SRoberto Vargas 1767d173fc5SJiafei Pan 177b1d27b48SRoberto Vargas#if USE_COHERENT_MEM 178b1d27b48SRoberto Vargas __COHERENT_RAM_UNALIGNED_SIZE__ = 179b1d27b48SRoberto Vargas __COHERENT_RAM_END_UNALIGNED__ - __COHERENT_RAM_START__; 180b1d27b48SRoberto Vargas#endif 181b1d27b48SRoberto Vargas 1827d173fc5SJiafei Pan#if BL2_IN_XIP_MEM 1837d173fc5SJiafei Pan ASSERT(. <= BL2_RW_LIMIT, "BL2's RW content has exceeded its limit.") 1847d173fc5SJiafei Pan#else 185b1d27b48SRoberto Vargas ASSERT(. <= BL2_LIMIT, "BL2 image has exceeded its limit.") 1867d173fc5SJiafei Pan#endif 187b1d27b48SRoberto Vargas} 188