1/* 2 * Copyright (c) 2014, Linaro Limited 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright notice, 9 * this list of conditions and the following disclaimer. 10 * 11 * 2. Redistributions in binary form must reproduce the above copyright notice, 12 * this list of conditions and the following disclaimer in the documentation 13 * and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * POSSIBILITY OF SUCH DAMAGE. 26 */ 27 28/* 29 * Copyright (c) 2008-2010 Travis Geiselbrecht 30 * 31 * Permission is hereby granted, free of charge, to any person obtaining 32 * a copy of this software and associated documentation files 33 * (the "Software"), to deal in the Software without restriction, 34 * including without limitation the rights to use, copy, modify, merge, 35 * publish, distribute, sublicense, and/or sell copies of the Software, 36 * and to permit persons to whom the Software is furnished to do so, 37 * subject to the following conditions: 38 * 39 * The above copyright notice and this permission notice shall be 40 * included in all copies or substantial portions of the Software. 41 * 42 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 43 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 44 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 45 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 46 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 47 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 48 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 49 */ 50 51#include <platform_config.h> 52 53#ifndef SMALL_PAGE_SIZE 54#define SMALL_PAGE_SIZE 4096 55#endif 56 57OUTPUT_FORMAT(CFG_KERN_LINKER_FORMAT) 58OUTPUT_ARCH(CFG_KERN_LINKER_ARCH) 59 60ENTRY(_start) 61SECTIONS 62{ 63 . = CFG_TEE_LOAD_ADDR; 64 65 __text_start = .; 66 __flatmap_unpg_rx_start = __text_start; 67 68 .text : { 69 KEEP(*(.text.boot.vectab1)) 70 KEEP(*(.text.boot.vectab2)) 71 KEEP(*(.text.boot)) 72 73 . = ALIGN(8); 74 __initcall_start = .; 75 KEEP(*(.initcall1)) 76 KEEP(*(.initcall2)) 77 KEEP(*(.initcall3)) 78 KEEP(*(.initcall4)) 79 __initcall_end = .; 80 81#ifdef CFG_WITH_PAGER 82 *(.text) 83/* Include list of sections needed for paging */ 84#include <text_unpaged.ld.S> 85#else 86 *(.text .text.*) 87#endif 88 *(.sram.text.glue_7* .gnu.linkonce.t.*) 89 . = ALIGN(8); 90 } 91 __text_end = .; 92 93 __flatmap_unpg_rx_size = . - __flatmap_unpg_rx_start; 94 __flatmap_unpg_ro_start = .; 95 96 .rodata : ALIGN(8) { 97 __rodata_start = .; 98 *(.gnu.linkonce.r.*) 99#ifdef CFG_WITH_PAGER 100 *(.rodata .rodata.__unpaged) 101#include <rodata_unpaged.ld.S> 102#else 103#ifdef CFG_DT 104 __rodata_dtdrv_start = .; 105 KEEP(*(.rodata.dtdrv)) 106 __rodata_dtdrv_end = .; 107#endif 108 *(.rodata .rodata.*) 109 110 /* 111 * 8 to avoid unwanted padding between __start_ta_head_section 112 * and the first structure in ta_head_section, in 64-bit 113 * builds 114 */ 115 . = ALIGN(8); 116 __start_ta_head_section = . ; 117 KEEP(*(ta_head_section)) 118 __stop_ta_head_section = . ; 119 . = ALIGN(8); 120 __start_phys_mem_map_section = . ; 121 KEEP(*(phys_mem_map_section)) 122 __end_phys_mem_map_section = . ; 123 . = ALIGN(8); 124 __start_phys_sdp_mem_section = . ; 125 KEEP(*(phys_sdp_mem_section)) 126 __end_phys_sdp_mem_section = . ; 127#endif 128 . = ALIGN(8); 129 __rodata_end = .; 130 } 131 132 .interp : { *(.interp) } 133 .hash : { *(.hash) } 134 .dynsym : { *(.dynsym) } 135 .dynstr : { *(.dynstr) } 136 .rel.text : { *(.rel.text) *(.rel.gnu.linkonce.t*) } 137 .rela.text : { *(.rela.text) *(.rela.gnu.linkonce.t*) } 138 .rel.data : { *(.rel.data) *(.rel.gnu.linkonce.d*) } 139 .rela.data : { *(.rela.data) *(.rela.gnu.linkonce.d*) } 140 .rel.rodata : { *(.rel.rodata) *(.rel.gnu.linkonce.r*) } 141 .rela.rodata : { *(.rela.rodata) *(.rela.gnu.linkonce.r*) } 142 .rel.got : { *(.rel.got) } 143 .rela.got : { *(.rela.got) } 144 .rel.ctors : { *(.rel.ctors) } 145 .rela.ctors : { *(.rela.ctors) } 146 .rel.dtors : { *(.rel.dtors) } 147 .rela.dtors : { *(.rela.dtors) } 148 .rel.init : { *(.rel.init) } 149 .rela.init : { *(.rela.init) } 150 .rel.fini : { *(.rel.fini) } 151 .rela.fini : { *(.rela.fini) } 152 .rel.bss : { *(.rel.bss) } 153 .rela.bss : { *(.rela.bss) } 154 .rel.plt : { *(.rel.plt) } 155 .rela.plt : { *(.rela.plt) } 156 .init : { *(.init) } =0x9090 157 .plt : { *(.plt) } 158 159 /* .ARM.exidx is sorted, so has to go in its own output section. */ 160 .ARM.exidx : { 161 __exidx_start = .; 162 *(.ARM.exidx* .gnu.linkonce.armexidx.*) 163 __exidx_end = .; 164 } 165 166 .ARM.extab : { 167 __extab_start = .; 168 *(.ARM.extab*) 169 __extab_end = .; 170 } 171 172 __flatmap_unpg_ro_size = . - __flatmap_unpg_ro_start; 173 __flatmap_unpg_rw_start = .; 174 175 .data : ALIGN(8) { 176 /* writable data */ 177 __data_start_rom = .; 178 /* in one segment binaries, the rom data address is on top 179 of the ram data address */ 180 __early_bss_start = .; 181 *(.early_bss .early_bss.*) 182 . = ALIGN(8); 183 __early_bss_end = .; 184 __data_start = .; 185 *(.data .data.* .gnu.linkonce.d.*) 186 . = ALIGN(8); 187 } 188 189 .ctors : ALIGN(8) { 190 __ctor_list = .; 191 KEEP(*(.ctors .ctors.* .init_array .init_array.*)) 192 __ctor_end = .; 193 } 194 .dtors : ALIGN(8) { 195 __dtor_list = .; 196 KEEP(*(.dtors .dtors.* .fini_array .fini_array.*)) 197 __dtor_end = .; 198 } 199 .got : { *(.got.plt) *(.got) } 200 .dynamic : { *(.dynamic) } 201 202 __data_end = .; 203 /* unintialized data */ 204 .bss : ALIGN(8) { 205 __bss_start = .; 206 *(.bss .bss.*) 207 *(.gnu.linkonce.b.*) 208 *(COMMON) 209 . = ALIGN(8); 210 __bss_end = .; 211 } 212 213 .heap1 (NOLOAD) : { 214 /* 215 * We're keeping track of the padding added before the 216 * .nozi section so we can do something useful with 217 * this otherwise wasted memory. 218 */ 219 __heap1_start = .; 220#ifndef CFG_WITH_PAGER 221 . += CFG_CORE_HEAP_SIZE; 222#endif 223 . = ALIGN(16 * 1024); 224 __heap1_end = .; 225 } 226 227 /* 228 * Uninitialized data that shouldn't be zero initialized at 229 * runtime. 230 * 231 * L1 mmu table requires 16 KiB alignment 232 */ 233 .nozi (NOLOAD) : { 234 __nozi_start = .; 235 ASSERT(!(__nozi_start & (16 * 1024 - 1)), "align nozi to 16kB"); 236 237 KEEP(*(.nozi .nozi.*)) 238 . = ALIGN(16); 239 __nozi_end = .; 240 __nozi_stack_start = .; 241 KEEP(*(.nozi_stack)) 242 . = ALIGN(8); 243 __nozi_stack_end = .; 244 } 245 246#ifdef CFG_WITH_PAGER 247 .heap2 (NOLOAD) : { 248 __heap2_start = .; 249 /* 250 * Reserve additional memory for heap, the total should be 251 * at least CFG_CORE_HEAP_SIZE, but count what has already 252 * been reserved in .heap1 253 */ 254 . += CFG_CORE_HEAP_SIZE - (__heap1_end - __heap1_start); 255 . = ALIGN(SMALL_PAGE_SIZE); 256 __heap2_end = .; 257 } 258 259 /* Start page aligned read-only memory */ 260 __flatmap_unpg_rw_size = . - __flatmap_unpg_rw_start; 261 262 __init_start = .; 263 __flatmap_init_rx_start = .; 264 265 ASSERT(!(__flatmap_init_rx_start & (SMALL_PAGE_SIZE - 1)), 266 "read-write memory is not paged aligned") 267 268 .text_init : { 269/* 270 * Include list of sections needed for boot initialization, this list 271 * overlaps with unpaged.ld.S but since unpaged.ld.S is first all those 272 * sections will go into the unpaged area. 273 */ 274#include <text_init.ld.S> 275 . = ALIGN(8); 276 } 277 278 __flatmap_init_rx_size = . - __flatmap_init_rx_start; 279 __flatmap_init_ro_start = .; 280 281 .rodata_init : { 282#include <rodata_init.ld.S> 283 . = ALIGN(8); 284 __start_phys_mem_map_section = . ; 285 KEEP(*(phys_mem_map_section)) 286 __end_phys_mem_map_section = . ; 287 . = ALIGN(8); 288 __start_phys_sdp_mem_section = . ; 289 KEEP(*(phys_sdp_mem_section)) 290 __end_phys_sdp_mem_section = . ; 291 . = ALIGN(8); 292 } 293 294 __init_end = .; 295 __init_size = __init_end - __init_start; 296 297 /* vcore flat map stops here. No need to page align, rodata follows. */ 298 __flatmap_init_ro_size = __init_end - __flatmap_init_ro_start; 299 300 .text_pageable : ALIGN(8) { 301 *(.text*) 302 . = ALIGN(8); 303 } 304 305 .rodata_pageable : ALIGN(8) { 306#ifdef CFG_DT 307 __rodata_dtdrv_start = .; 308 KEEP(*(.rodata.dtdrv)) 309 __rodata_dtdrv_end = .; 310#endif 311 *(.rodata*) 312 /* 313 * 8 to avoid unwanted padding between __start_ta_head_section 314 * and the first structure in ta_head_section, in 64-bit 315 * builds 316 */ 317 . = ALIGN(8); 318 __start_ta_head_section = . ; 319 KEEP(*(ta_head_section)) 320 __stop_ta_head_section = . ; 321 . = ALIGN(SMALL_PAGE_SIZE); 322 } 323 324 __pageable_part_end = .; 325 __pageable_part_start = __init_end; 326 __pageable_start = __init_start; 327 __pageable_end = __pageable_part_end; 328 329 /* 330 * Assign a safe spot to store the hashes of the pages before 331 * heap is initialized. 332 */ 333 __tmp_hashes_start = __init_end; 334 __tmp_hashes_size = ((__pageable_end - __pageable_start) / 335 SMALL_PAGE_SIZE) * 32; 336 __tmp_hashes_end = __tmp_hashes_start + __tmp_hashes_size; 337 338 __init_mem_usage = __tmp_hashes_end - CFG_TEE_LOAD_ADDR; 339 340 ASSERT(CFG_TEE_LOAD_ADDR >= CFG_TEE_RAM_START, 341 "Load address before start of physical memory") 342 ASSERT(CFG_TEE_LOAD_ADDR < (CFG_TEE_RAM_START + CFG_TEE_RAM_PH_SIZE), 343 "Load address after end of physical memory") 344 ASSERT(__tmp_hashes_end < (CFG_TEE_RAM_START + CFG_TEE_RAM_PH_SIZE), 345 "OP-TEE can't fit init part into available physical memory") 346 ASSERT((CFG_TEE_RAM_START + CFG_TEE_RAM_PH_SIZE - __init_end) > 347 SMALL_PAGE_SIZE, "Too few free pages to initialize paging") 348 349 350#endif /*CFG_WITH_PAGER*/ 351 352#ifdef CFG_CORE_SANITIZE_KADDRESS 353 . = CFG_TEE_RAM_START + (CFG_TEE_RAM_VA_SIZE * 8) / 9 - 8; 354 . = ALIGN(8); 355 .asan_shadow : { 356 __asan_shadow_start = .; 357 . += CFG_TEE_RAM_VA_SIZE / 9; 358 __asan_shadow_end = .; 359 } 360#endif /*CFG_CORE_SANITIZE_KADDRESS*/ 361 362 __end = .; 363 364#ifndef CFG_WITH_PAGER 365 __init_size = __data_end - CFG_TEE_LOAD_ADDR; 366 __init_mem_usage = __end - CFG_TEE_LOAD_ADDR; 367#endif 368 . = CFG_TEE_RAM_START + CFG_TEE_RAM_VA_SIZE; 369 370 _end_of_ram = .; 371 372#ifndef CFG_WITH_PAGER 373 __flatmap_unpg_rw_size = _end_of_ram - __flatmap_unpg_rw_start; 374#endif 375 376 /DISCARD/ : { 377 /* Strip unnecessary stuff */ 378 *(.comment .note .eh_frame) 379 /* Strip meta variables */ 380 *(__keep_meta_vars*) 381 } 382 383} 384 385PROVIDE(__vcore_unpg_rwx_start = __flatmap_unpg_rx_start); 386#ifdef CFG_WITH_PAGER 387PROVIDE(__vcore_unpg_rwx_size = CFG_TEE_RAM_START + CFG_TEE_RAM_PH_SIZE - 388 __flatmap_unpg_rx_start); 389#else 390PROVIDE(__vcore_unpg_rwx_size = _end_of_ram - __flatmap_unpg_rx_start); 391#endif 392 393/* Unpaged read-only memories */ 394PROVIDE(__vcore_unpg_rx_start = __flatmap_unpg_rx_start); 395PROVIDE(__vcore_unpg_ro_start = __flatmap_unpg_ro_start); 396PROVIDE(__vcore_unpg_rx_size = __flatmap_unpg_rx_size); 397PROVIDE(__vcore_unpg_ro_size = __flatmap_unpg_ro_size); 398 399/* Unpaged read-write memory */ 400PROVIDE(__vcore_unpg_rw_start = __flatmap_unpg_rw_start); 401PROVIDE(__vcore_unpg_rw_size = __flatmap_unpg_rw_size); 402 403#ifdef CFG_WITH_PAGER 404/* Paged/init read-only memories */ 405PROVIDE(__vcore_init_rx_start = __flatmap_init_rx_start); 406PROVIDE(__vcore_init_ro_start = __flatmap_init_ro_start); 407PROVIDE(__vcore_init_rx_size = __flatmap_init_rx_size); 408PROVIDE(__vcore_init_ro_size = __flatmap_init_ro_size); 409#endif /* CFG_WITH_PAGER */ 410