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> 8*09d40e0eSAntonio Nino Diaz 9*09d40e0eSAntonio 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 24b1d27b48SRoberto Vargas 25b1d27b48SRoberto VargasSECTIONS 26b1d27b48SRoberto Vargas{ 277d173fc5SJiafei Pan#if BL2_IN_XIP_MEM 287d173fc5SJiafei Pan . = BL2_RO_BASE; 297d173fc5SJiafei Pan ASSERT(. == ALIGN(PAGE_SIZE), 307d173fc5SJiafei Pan "BL2_RO_BASE address is not aligned on a page boundary.") 317d173fc5SJiafei Pan#else 32b1d27b48SRoberto Vargas . = BL2_BASE; 33b1d27b48SRoberto Vargas ASSERT(. == ALIGN(PAGE_SIZE), 34b1d27b48SRoberto Vargas "BL2_BASE address is not aligned on a page boundary.") 357d173fc5SJiafei Pan#endif 36b1d27b48SRoberto Vargas 37b1d27b48SRoberto Vargas#if SEPARATE_CODE_AND_RODATA 38b1d27b48SRoberto Vargas .text . : { 39b1d27b48SRoberto Vargas __TEXT_START__ = .; 40487d3bf2SRoberto Vargas __TEXT_RESIDENT_START__ = .; 41b1d27b48SRoberto Vargas *bl2_el3_entrypoint.o(.text*) 42487d3bf2SRoberto Vargas *(.text.asm.*) 43487d3bf2SRoberto Vargas __TEXT_RESIDENT_END__ = .; 44b1d27b48SRoberto Vargas *(.text*) 45b1d27b48SRoberto Vargas *(.vectors) 465629b2b1SRoberto Vargas . = ALIGN(PAGE_SIZE); 47b1d27b48SRoberto Vargas __TEXT_END__ = .; 487d173fc5SJiafei Pan#if BL2_IN_XIP_MEM 497d173fc5SJiafei Pan } >ROM 507d173fc5SJiafei Pan#else 51b1d27b48SRoberto Vargas } >RAM 527d173fc5SJiafei Pan#endif 53b1d27b48SRoberto Vargas 54b1d27b48SRoberto Vargas .rodata . : { 55b1d27b48SRoberto Vargas __RODATA_START__ = .; 56b1d27b48SRoberto Vargas *(.rodata*) 57b1d27b48SRoberto Vargas 58b1d27b48SRoberto Vargas /* Ensure 8-byte alignment for descriptors and ensure inclusion */ 59b1d27b48SRoberto Vargas . = ALIGN(8); 60b1d27b48SRoberto Vargas __PARSER_LIB_DESCS_START__ = .; 61b1d27b48SRoberto Vargas KEEP(*(.img_parser_lib_descs)) 62b1d27b48SRoberto Vargas __PARSER_LIB_DESCS_END__ = .; 63b1d27b48SRoberto Vargas 64b1d27b48SRoberto Vargas /* 65b1d27b48SRoberto Vargas * Ensure 8-byte alignment for cpu_ops so that its fields are also 66b1d27b48SRoberto Vargas * aligned. Also ensure cpu_ops inclusion. 67b1d27b48SRoberto Vargas */ 68b1d27b48SRoberto Vargas . = ALIGN(8); 69b1d27b48SRoberto Vargas __CPU_OPS_START__ = .; 70b1d27b48SRoberto Vargas KEEP(*(cpu_ops)) 71b1d27b48SRoberto Vargas __CPU_OPS_END__ = .; 72b1d27b48SRoberto Vargas 735629b2b1SRoberto Vargas . = ALIGN(PAGE_SIZE); 74b1d27b48SRoberto Vargas __RODATA_END__ = .; 757d173fc5SJiafei Pan#if BL2_IN_XIP_MEM 767d173fc5SJiafei Pan } >ROM 777d173fc5SJiafei Pan#else 78b1d27b48SRoberto Vargas } >RAM 797d173fc5SJiafei Pan#endif 80487d3bf2SRoberto Vargas 81487d3bf2SRoberto Vargas ASSERT(__TEXT_RESIDENT_END__ - __TEXT_RESIDENT_START__ <= PAGE_SIZE, 82487d3bf2SRoberto Vargas "Resident part of BL2 has exceeded its limit.") 83b1d27b48SRoberto Vargas#else 84b1d27b48SRoberto Vargas ro . : { 85b1d27b48SRoberto Vargas __RO_START__ = .; 86487d3bf2SRoberto Vargas __TEXT_RESIDENT_START__ = .; 87b1d27b48SRoberto Vargas *bl2_el3_entrypoint.o(.text*) 88487d3bf2SRoberto Vargas *(.text.asm.*) 89487d3bf2SRoberto Vargas __TEXT_RESIDENT_END__ = .; 90b1d27b48SRoberto Vargas *(.text*) 91b1d27b48SRoberto Vargas *(.rodata*) 92b1d27b48SRoberto Vargas 93b1d27b48SRoberto Vargas /* 94b1d27b48SRoberto Vargas * Ensure 8-byte alignment for cpu_ops so that its fields are also 95b1d27b48SRoberto Vargas * aligned. Also ensure cpu_ops inclusion. 96b1d27b48SRoberto Vargas */ 97b1d27b48SRoberto Vargas . = ALIGN(8); 98b1d27b48SRoberto Vargas __CPU_OPS_START__ = .; 99b1d27b48SRoberto Vargas KEEP(*(cpu_ops)) 100b1d27b48SRoberto Vargas __CPU_OPS_END__ = .; 101b1d27b48SRoberto Vargas 102b1d27b48SRoberto Vargas /* Ensure 8-byte alignment for descriptors and ensure inclusion */ 103b1d27b48SRoberto Vargas . = ALIGN(8); 104b1d27b48SRoberto Vargas __PARSER_LIB_DESCS_START__ = .; 105b1d27b48SRoberto Vargas KEEP(*(.img_parser_lib_descs)) 106b1d27b48SRoberto Vargas __PARSER_LIB_DESCS_END__ = .; 107b1d27b48SRoberto Vargas 108b1d27b48SRoberto Vargas *(.vectors) 109b1d27b48SRoberto Vargas __RO_END_UNALIGNED__ = .; 110b1d27b48SRoberto Vargas /* 111b1d27b48SRoberto Vargas * Memory page(s) mapped to this section will be marked as 112b1d27b48SRoberto Vargas * read-only, executable. No RW data from the next section must 113b1d27b48SRoberto Vargas * creep in. Ensure the rest of the current memory page is unused. 114b1d27b48SRoberto Vargas */ 1155629b2b1SRoberto Vargas . = ALIGN(PAGE_SIZE); 116b1d27b48SRoberto Vargas 117b1d27b48SRoberto Vargas __RO_END__ = .; 1187d173fc5SJiafei Pan#if BL2_IN_XIP_MEM 1197d173fc5SJiafei Pan } >ROM 1207d173fc5SJiafei Pan#else 121b1d27b48SRoberto Vargas } >RAM 122b1d27b48SRoberto Vargas#endif 1237d173fc5SJiafei Pan#endif 124b1d27b48SRoberto Vargas 125b1d27b48SRoberto Vargas ASSERT(__CPU_OPS_END__ > __CPU_OPS_START__, 126b1d27b48SRoberto Vargas "cpu_ops not defined for this platform.") 127b1d27b48SRoberto Vargas 1287d173fc5SJiafei Pan#if BL2_IN_XIP_MEM 1297d173fc5SJiafei Pan . = BL2_RW_BASE; 1307d173fc5SJiafei Pan ASSERT(BL2_RW_BASE == ALIGN(PAGE_SIZE), 1317d173fc5SJiafei Pan "BL2_RW_BASE address is not aligned on a page boundary.") 1327d173fc5SJiafei Pan#endif 1337d173fc5SJiafei Pan 134b1d27b48SRoberto Vargas /* 135b1d27b48SRoberto Vargas * Define a linker symbol to mark start of the RW memory area for this 136b1d27b48SRoberto Vargas * image. 137b1d27b48SRoberto Vargas */ 138b1d27b48SRoberto Vargas __RW_START__ = . ; 139b1d27b48SRoberto Vargas 140b1d27b48SRoberto Vargas /* 141b1d27b48SRoberto Vargas * .data must be placed at a lower address than the stacks if the stack 142b1d27b48SRoberto Vargas * protector is enabled. Alternatively, the .data.stack_protector_canary 143b1d27b48SRoberto Vargas * section can be placed independently of the main .data section. 144b1d27b48SRoberto Vargas */ 145b1d27b48SRoberto Vargas .data . : { 1467d173fc5SJiafei Pan __DATA_RAM_START__ = .; 147b1d27b48SRoberto Vargas *(.data*) 1487d173fc5SJiafei Pan __DATA_RAM_END__ = .; 1497d173fc5SJiafei Pan#if BL2_IN_XIP_MEM 1507d173fc5SJiafei Pan } >RAM AT>ROM 1517d173fc5SJiafei Pan#else 152b1d27b48SRoberto Vargas } >RAM 1537d173fc5SJiafei Pan#endif 154b1d27b48SRoberto Vargas 155b1d27b48SRoberto Vargas stacks (NOLOAD) : { 156b1d27b48SRoberto Vargas __STACKS_START__ = .; 157b1d27b48SRoberto Vargas *(tzfw_normal_stacks) 158b1d27b48SRoberto Vargas __STACKS_END__ = .; 159b1d27b48SRoberto Vargas } >RAM 160b1d27b48SRoberto Vargas 161b1d27b48SRoberto Vargas /* 162b1d27b48SRoberto Vargas * The .bss section gets initialised to 0 at runtime. 163b1d27b48SRoberto Vargas * Its base address should be 16-byte aligned for better performance of the 164b1d27b48SRoberto Vargas * zero-initialization code. 165b1d27b48SRoberto Vargas */ 166b1d27b48SRoberto Vargas .bss : ALIGN(16) { 167b1d27b48SRoberto Vargas __BSS_START__ = .; 168b1d27b48SRoberto Vargas *(SORT_BY_ALIGNMENT(.bss*)) 169b1d27b48SRoberto Vargas *(COMMON) 170b1d27b48SRoberto Vargas __BSS_END__ = .; 171b1d27b48SRoberto Vargas } >RAM 172b1d27b48SRoberto Vargas 173b1d27b48SRoberto Vargas /* 174b1d27b48SRoberto Vargas * The xlat_table section is for full, aligned page tables (4K). 175b1d27b48SRoberto Vargas * Removing them from .bss avoids forcing 4K alignment on 176883d1b5dSAntonio Nino Diaz * the .bss section. The tables are initialized to zero by the translation 177883d1b5dSAntonio Nino Diaz * tables library. 178b1d27b48SRoberto Vargas */ 179b1d27b48SRoberto Vargas xlat_table (NOLOAD) : { 180b1d27b48SRoberto Vargas *(xlat_table) 181b1d27b48SRoberto Vargas } >RAM 182b1d27b48SRoberto Vargas 183b1d27b48SRoberto Vargas#if USE_COHERENT_MEM 184b1d27b48SRoberto Vargas /* 185b1d27b48SRoberto Vargas * The base address of the coherent memory section must be page-aligned (4K) 186b1d27b48SRoberto Vargas * to guarantee that the coherent data are stored on their own pages and 187b1d27b48SRoberto Vargas * are not mixed with normal data. This is required to set up the correct 188b1d27b48SRoberto Vargas * memory attributes for the coherent data page tables. 189b1d27b48SRoberto Vargas */ 190b1d27b48SRoberto Vargas coherent_ram (NOLOAD) : ALIGN(PAGE_SIZE) { 191b1d27b48SRoberto Vargas __COHERENT_RAM_START__ = .; 192b1d27b48SRoberto Vargas *(tzfw_coherent_mem) 193b1d27b48SRoberto Vargas __COHERENT_RAM_END_UNALIGNED__ = .; 194b1d27b48SRoberto Vargas /* 195b1d27b48SRoberto Vargas * Memory page(s) mapped to this section will be marked 196b1d27b48SRoberto Vargas * as device memory. No other unexpected data must creep in. 197b1d27b48SRoberto Vargas * Ensure the rest of the current memory page is unused. 198b1d27b48SRoberto Vargas */ 1995629b2b1SRoberto Vargas . = ALIGN(PAGE_SIZE); 200b1d27b48SRoberto Vargas __COHERENT_RAM_END__ = .; 201b1d27b48SRoberto Vargas } >RAM 202b1d27b48SRoberto Vargas#endif 203b1d27b48SRoberto Vargas 204b1d27b48SRoberto Vargas /* 205b1d27b48SRoberto Vargas * Define a linker symbol to mark end of the RW memory area for this 206b1d27b48SRoberto Vargas * image. 207b1d27b48SRoberto Vargas */ 208b1d27b48SRoberto Vargas __RW_END__ = .; 209b1d27b48SRoberto Vargas __BL2_END__ = .; 210b1d27b48SRoberto Vargas 2117d173fc5SJiafei Pan#if BL2_IN_XIP_MEM 2127d173fc5SJiafei Pan __BL2_RAM_START__ = ADDR(.data); 2137d173fc5SJiafei Pan __BL2_RAM_END__ = .; 2147d173fc5SJiafei Pan 2157d173fc5SJiafei Pan __DATA_ROM_START__ = LOADADDR(.data); 2167d173fc5SJiafei Pan __DATA_SIZE__ = SIZEOF(.data); 2177d173fc5SJiafei Pan 2187d173fc5SJiafei Pan /* 2197d173fc5SJiafei Pan * The .data section is the last PROGBITS section so its end marks the end 2207d173fc5SJiafei Pan * of BL2's RO content in XIP memory.. 2217d173fc5SJiafei Pan */ 2227d173fc5SJiafei Pan __BL2_ROM_END__ = __DATA_ROM_START__ + __DATA_SIZE__; 2237d173fc5SJiafei Pan ASSERT(__BL2_ROM_END__ <= BL2_RO_LIMIT, 2247d173fc5SJiafei Pan "BL2's RO content has exceeded its limit.") 2257d173fc5SJiafei Pan#endif 226b1d27b48SRoberto Vargas __BSS_SIZE__ = SIZEOF(.bss); 227b1d27b48SRoberto Vargas 2287d173fc5SJiafei Pan 229b1d27b48SRoberto Vargas#if USE_COHERENT_MEM 230b1d27b48SRoberto Vargas __COHERENT_RAM_UNALIGNED_SIZE__ = 231b1d27b48SRoberto Vargas __COHERENT_RAM_END_UNALIGNED__ - __COHERENT_RAM_START__; 232b1d27b48SRoberto Vargas#endif 233b1d27b48SRoberto Vargas 2347d173fc5SJiafei Pan#if BL2_IN_XIP_MEM 2357d173fc5SJiafei Pan ASSERT(. <= BL2_RW_LIMIT, "BL2's RW content has exceeded its limit.") 2367d173fc5SJiafei Pan#else 237b1d27b48SRoberto Vargas ASSERT(. <= BL2_LIMIT, "BL2 image has exceeded its limit.") 2387d173fc5SJiafei Pan#endif 239b1d27b48SRoberto Vargas} 240