1b1d27b48SRoberto Vargas/* 2883d1b5dSAntonio Nino Diaz * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved. 3b1d27b48SRoberto Vargas * 4b1d27b48SRoberto Vargas * SPDX-License-Identifier: BSD-3-Clause 5b1d27b48SRoberto Vargas */ 6b1d27b48SRoberto Vargas 7b1d27b48SRoberto Vargas#include <platform_def.h> 809d40e0eSAntonio Nino Diaz 909d40e0eSAntonio Nino Diaz#include <lib/xlat_tables/xlat_tables_defs.h> 10b1d27b48SRoberto Vargas 11b1d27b48SRoberto VargasOUTPUT_FORMAT(PLATFORM_LINKER_FORMAT) 12b1d27b48SRoberto VargasOUTPUT_ARCH(PLATFORM_LINKER_ARCH) 13b1d27b48SRoberto VargasENTRY(bl2_entrypoint) 14b1d27b48SRoberto Vargas 15b1d27b48SRoberto VargasMEMORY { 167d173fc5SJiafei Pan#if BL2_IN_XIP_MEM 177d173fc5SJiafei Pan ROM (rx): ORIGIN = BL2_RO_BASE, LENGTH = BL2_RO_LIMIT - BL2_RO_BASE 187d173fc5SJiafei Pan RAM (rwx): ORIGIN = BL2_RW_BASE, LENGTH = BL2_RW_LIMIT - BL2_RW_BASE 197d173fc5SJiafei Pan#else 20b1d27b48SRoberto Vargas RAM (rwx): ORIGIN = BL2_BASE, LENGTH = BL2_LIMIT - BL2_BASE 217d173fc5SJiafei Pan#endif 22b1d27b48SRoberto Vargas} 23b1d27b48SRoberto Vargas 24*2f6f00dcSMasahiro Yamada#if !BL2_IN_XIP_MEM 25*2f6f00dcSMasahiro Yamada#define ROM RAM 26*2f6f00dcSMasahiro Yamada#endif 27b1d27b48SRoberto Vargas 28b1d27b48SRoberto VargasSECTIONS 29b1d27b48SRoberto Vargas{ 307d173fc5SJiafei Pan#if BL2_IN_XIP_MEM 317d173fc5SJiafei Pan . = BL2_RO_BASE; 327d173fc5SJiafei Pan ASSERT(. == ALIGN(PAGE_SIZE), 337d173fc5SJiafei Pan "BL2_RO_BASE address is not aligned on a page boundary.") 347d173fc5SJiafei Pan#else 35b1d27b48SRoberto Vargas . = BL2_BASE; 36b1d27b48SRoberto Vargas ASSERT(. == ALIGN(PAGE_SIZE), 37b1d27b48SRoberto Vargas "BL2_BASE address is not aligned on a page boundary.") 387d173fc5SJiafei Pan#endif 39b1d27b48SRoberto Vargas 40b1d27b48SRoberto Vargas#if SEPARATE_CODE_AND_RODATA 41b1d27b48SRoberto Vargas .text . : { 42b1d27b48SRoberto Vargas __TEXT_START__ = .; 43487d3bf2SRoberto Vargas __TEXT_RESIDENT_START__ = .; 44b1d27b48SRoberto Vargas *bl2_el3_entrypoint.o(.text*) 45487d3bf2SRoberto Vargas *(.text.asm.*) 46487d3bf2SRoberto Vargas __TEXT_RESIDENT_END__ = .; 47b1d27b48SRoberto Vargas *(.text*) 48b1d27b48SRoberto Vargas *(.vectors) 495629b2b1SRoberto Vargas . = ALIGN(PAGE_SIZE); 50b1d27b48SRoberto Vargas __TEXT_END__ = .; 517d173fc5SJiafei Pan } >ROM 52b1d27b48SRoberto Vargas 53b1d27b48SRoberto Vargas .rodata . : { 54b1d27b48SRoberto Vargas __RODATA_START__ = .; 55b1d27b48SRoberto Vargas *(.rodata*) 56b1d27b48SRoberto Vargas 57b1d27b48SRoberto Vargas /* Ensure 8-byte alignment for descriptors and ensure inclusion */ 58b1d27b48SRoberto Vargas . = ALIGN(8); 59b1d27b48SRoberto Vargas __PARSER_LIB_DESCS_START__ = .; 60b1d27b48SRoberto Vargas KEEP(*(.img_parser_lib_descs)) 61b1d27b48SRoberto Vargas __PARSER_LIB_DESCS_END__ = .; 62b1d27b48SRoberto Vargas 63b1d27b48SRoberto Vargas /* 64b1d27b48SRoberto Vargas * Ensure 8-byte alignment for cpu_ops so that its fields are also 65b1d27b48SRoberto Vargas * aligned. Also ensure cpu_ops inclusion. 66b1d27b48SRoberto Vargas */ 67b1d27b48SRoberto Vargas . = ALIGN(8); 68b1d27b48SRoberto Vargas __CPU_OPS_START__ = .; 69b1d27b48SRoberto Vargas KEEP(*(cpu_ops)) 70b1d27b48SRoberto Vargas __CPU_OPS_END__ = .; 71b1d27b48SRoberto Vargas 725629b2b1SRoberto Vargas . = ALIGN(PAGE_SIZE); 73b1d27b48SRoberto Vargas __RODATA_END__ = .; 747d173fc5SJiafei Pan } >ROM 75487d3bf2SRoberto Vargas 76487d3bf2SRoberto Vargas ASSERT(__TEXT_RESIDENT_END__ - __TEXT_RESIDENT_START__ <= PAGE_SIZE, 77487d3bf2SRoberto Vargas "Resident part of BL2 has exceeded its limit.") 78b1d27b48SRoberto Vargas#else 79b1d27b48SRoberto Vargas ro . : { 80b1d27b48SRoberto Vargas __RO_START__ = .; 81487d3bf2SRoberto Vargas __TEXT_RESIDENT_START__ = .; 82b1d27b48SRoberto Vargas *bl2_el3_entrypoint.o(.text*) 83487d3bf2SRoberto Vargas *(.text.asm.*) 84487d3bf2SRoberto Vargas __TEXT_RESIDENT_END__ = .; 85b1d27b48SRoberto Vargas *(.text*) 86b1d27b48SRoberto Vargas *(.rodata*) 87b1d27b48SRoberto Vargas 88b1d27b48SRoberto Vargas /* 89b1d27b48SRoberto Vargas * Ensure 8-byte alignment for cpu_ops so that its fields are also 90b1d27b48SRoberto Vargas * aligned. Also ensure cpu_ops inclusion. 91b1d27b48SRoberto Vargas */ 92b1d27b48SRoberto Vargas . = ALIGN(8); 93b1d27b48SRoberto Vargas __CPU_OPS_START__ = .; 94b1d27b48SRoberto Vargas KEEP(*(cpu_ops)) 95b1d27b48SRoberto Vargas __CPU_OPS_END__ = .; 96b1d27b48SRoberto Vargas 97b1d27b48SRoberto Vargas /* Ensure 8-byte alignment for descriptors and ensure inclusion */ 98b1d27b48SRoberto Vargas . = ALIGN(8); 99b1d27b48SRoberto Vargas __PARSER_LIB_DESCS_START__ = .; 100b1d27b48SRoberto Vargas KEEP(*(.img_parser_lib_descs)) 101b1d27b48SRoberto Vargas __PARSER_LIB_DESCS_END__ = .; 102b1d27b48SRoberto Vargas 103b1d27b48SRoberto Vargas *(.vectors) 104b1d27b48SRoberto Vargas __RO_END_UNALIGNED__ = .; 105b1d27b48SRoberto Vargas /* 106b1d27b48SRoberto Vargas * Memory page(s) mapped to this section will be marked as 107b1d27b48SRoberto Vargas * read-only, executable. No RW data from the next section must 108b1d27b48SRoberto Vargas * creep in. Ensure the rest of the current memory page is unused. 109b1d27b48SRoberto Vargas */ 1105629b2b1SRoberto Vargas . = ALIGN(PAGE_SIZE); 111b1d27b48SRoberto Vargas 112b1d27b48SRoberto Vargas __RO_END__ = .; 1137d173fc5SJiafei Pan } >ROM 1147d173fc5SJiafei Pan#endif 115b1d27b48SRoberto Vargas 116b1d27b48SRoberto Vargas ASSERT(__CPU_OPS_END__ > __CPU_OPS_START__, 117b1d27b48SRoberto Vargas "cpu_ops not defined for this platform.") 118b1d27b48SRoberto Vargas 1197d173fc5SJiafei Pan#if BL2_IN_XIP_MEM 1207d173fc5SJiafei Pan . = BL2_RW_BASE; 1217d173fc5SJiafei Pan ASSERT(BL2_RW_BASE == ALIGN(PAGE_SIZE), 1227d173fc5SJiafei Pan "BL2_RW_BASE address is not aligned on a page boundary.") 1237d173fc5SJiafei Pan#endif 1247d173fc5SJiafei Pan 125b1d27b48SRoberto Vargas /* 126b1d27b48SRoberto Vargas * Define a linker symbol to mark start of the RW memory area for this 127b1d27b48SRoberto Vargas * image. 128b1d27b48SRoberto Vargas */ 129b1d27b48SRoberto Vargas __RW_START__ = . ; 130b1d27b48SRoberto Vargas 131b1d27b48SRoberto Vargas /* 132b1d27b48SRoberto Vargas * .data must be placed at a lower address than the stacks if the stack 133b1d27b48SRoberto Vargas * protector is enabled. Alternatively, the .data.stack_protector_canary 134b1d27b48SRoberto Vargas * section can be placed independently of the main .data section. 135b1d27b48SRoberto Vargas */ 136b1d27b48SRoberto Vargas .data . : { 1377d173fc5SJiafei Pan __DATA_RAM_START__ = .; 138b1d27b48SRoberto Vargas *(.data*) 1397d173fc5SJiafei Pan __DATA_RAM_END__ = .; 1407d173fc5SJiafei Pan } >RAM AT>ROM 141b1d27b48SRoberto Vargas 142b1d27b48SRoberto Vargas stacks (NOLOAD) : { 143b1d27b48SRoberto Vargas __STACKS_START__ = .; 144b1d27b48SRoberto Vargas *(tzfw_normal_stacks) 145b1d27b48SRoberto Vargas __STACKS_END__ = .; 146b1d27b48SRoberto Vargas } >RAM 147b1d27b48SRoberto Vargas 148b1d27b48SRoberto Vargas /* 149b1d27b48SRoberto Vargas * The .bss section gets initialised to 0 at runtime. 150b1d27b48SRoberto Vargas * Its base address should be 16-byte aligned for better performance of the 151b1d27b48SRoberto Vargas * zero-initialization code. 152b1d27b48SRoberto Vargas */ 153b1d27b48SRoberto Vargas .bss : ALIGN(16) { 154b1d27b48SRoberto Vargas __BSS_START__ = .; 155b1d27b48SRoberto Vargas *(SORT_BY_ALIGNMENT(.bss*)) 156b1d27b48SRoberto Vargas *(COMMON) 157b1d27b48SRoberto Vargas __BSS_END__ = .; 158b1d27b48SRoberto Vargas } >RAM 159b1d27b48SRoberto Vargas 160b1d27b48SRoberto Vargas /* 161b1d27b48SRoberto Vargas * The xlat_table section is for full, aligned page tables (4K). 162b1d27b48SRoberto Vargas * Removing them from .bss avoids forcing 4K alignment on 163883d1b5dSAntonio Nino Diaz * the .bss section. The tables are initialized to zero by the translation 164883d1b5dSAntonio Nino Diaz * tables library. 165b1d27b48SRoberto Vargas */ 166b1d27b48SRoberto Vargas xlat_table (NOLOAD) : { 167b1d27b48SRoberto Vargas *(xlat_table) 168b1d27b48SRoberto Vargas } >RAM 169b1d27b48SRoberto Vargas 170b1d27b48SRoberto Vargas#if USE_COHERENT_MEM 171b1d27b48SRoberto Vargas /* 172b1d27b48SRoberto Vargas * The base address of the coherent memory section must be page-aligned (4K) 173b1d27b48SRoberto Vargas * to guarantee that the coherent data are stored on their own pages and 174b1d27b48SRoberto Vargas * are not mixed with normal data. This is required to set up the correct 175b1d27b48SRoberto Vargas * memory attributes for the coherent data page tables. 176b1d27b48SRoberto Vargas */ 177b1d27b48SRoberto Vargas coherent_ram (NOLOAD) : ALIGN(PAGE_SIZE) { 178b1d27b48SRoberto Vargas __COHERENT_RAM_START__ = .; 179b1d27b48SRoberto Vargas *(tzfw_coherent_mem) 180b1d27b48SRoberto Vargas __COHERENT_RAM_END_UNALIGNED__ = .; 181b1d27b48SRoberto Vargas /* 182b1d27b48SRoberto Vargas * Memory page(s) mapped to this section will be marked 183b1d27b48SRoberto Vargas * as device memory. No other unexpected data must creep in. 184b1d27b48SRoberto Vargas * Ensure the rest of the current memory page is unused. 185b1d27b48SRoberto Vargas */ 1865629b2b1SRoberto Vargas . = ALIGN(PAGE_SIZE); 187b1d27b48SRoberto Vargas __COHERENT_RAM_END__ = .; 188b1d27b48SRoberto Vargas } >RAM 189b1d27b48SRoberto Vargas#endif 190b1d27b48SRoberto Vargas 191b1d27b48SRoberto Vargas /* 192b1d27b48SRoberto Vargas * Define a linker symbol to mark end of the RW memory area for this 193b1d27b48SRoberto Vargas * image. 194b1d27b48SRoberto Vargas */ 195b1d27b48SRoberto Vargas __RW_END__ = .; 196b1d27b48SRoberto Vargas __BL2_END__ = .; 197b1d27b48SRoberto Vargas 1987d173fc5SJiafei Pan#if BL2_IN_XIP_MEM 1997d173fc5SJiafei Pan __BL2_RAM_START__ = ADDR(.data); 2007d173fc5SJiafei Pan __BL2_RAM_END__ = .; 2017d173fc5SJiafei Pan 2027d173fc5SJiafei Pan __DATA_ROM_START__ = LOADADDR(.data); 2037d173fc5SJiafei Pan __DATA_SIZE__ = SIZEOF(.data); 2047d173fc5SJiafei Pan 2057d173fc5SJiafei Pan /* 2067d173fc5SJiafei Pan * The .data section is the last PROGBITS section so its end marks the end 2077d173fc5SJiafei Pan * of BL2's RO content in XIP memory.. 2087d173fc5SJiafei Pan */ 2097d173fc5SJiafei Pan __BL2_ROM_END__ = __DATA_ROM_START__ + __DATA_SIZE__; 2107d173fc5SJiafei Pan ASSERT(__BL2_ROM_END__ <= BL2_RO_LIMIT, 2117d173fc5SJiafei Pan "BL2's RO content has exceeded its limit.") 2127d173fc5SJiafei Pan#endif 213b1d27b48SRoberto Vargas __BSS_SIZE__ = SIZEOF(.bss); 214b1d27b48SRoberto Vargas 2157d173fc5SJiafei Pan 216b1d27b48SRoberto Vargas#if USE_COHERENT_MEM 217b1d27b48SRoberto Vargas __COHERENT_RAM_UNALIGNED_SIZE__ = 218b1d27b48SRoberto Vargas __COHERENT_RAM_END_UNALIGNED__ - __COHERENT_RAM_START__; 219b1d27b48SRoberto Vargas#endif 220b1d27b48SRoberto Vargas 2217d173fc5SJiafei Pan#if BL2_IN_XIP_MEM 2227d173fc5SJiafei Pan ASSERT(. <= BL2_RW_LIMIT, "BL2's RW content has exceeded its limit.") 2237d173fc5SJiafei Pan#else 224b1d27b48SRoberto Vargas ASSERT(. <= BL2_LIMIT, "BL2 image has exceeded its limit.") 2257d173fc5SJiafei Pan#endif 226b1d27b48SRoberto Vargas} 227