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 .text : { 67 KEEP(*(.text.boot.vectab1)) 68 KEEP(*(.text.boot.vectab2)) 69 KEEP(*(.text.boot)) 70 71 . = ALIGN(8); 72 __initcall_start = .; 73 KEEP(*(.initcall1)) 74 KEEP(*(.initcall2)) 75 KEEP(*(.initcall3)) 76 KEEP(*(.initcall4)) 77 __initcall_end = .; 78 79#ifdef CFG_WITH_PAGER 80 *(.text) 81/* Include list of sections needed for paging */ 82#include <text_unpaged.ld.S> 83#else 84 *(.text .text.*) 85#endif 86 *(.sram.text.glue_7* .gnu.linkonce.t.*) 87 . = ALIGN(8); 88 } 89 __text_end = .; 90 91 .rodata : ALIGN(8) { 92 __rodata_start = .; 93 *(.gnu.linkonce.r.*) 94#ifdef CFG_WITH_PAGER 95 *(.rodata .rodata.__unpaged) 96#include <rodata_unpaged.ld.S> 97#else 98#ifdef CFG_DT 99 __rodata_dtdrv_start = .; 100 KEEP(*(.rodata.dtdrv)) 101 __rodata_dtdrv_end = .; 102#endif 103 *(.rodata .rodata.*) 104 105 /* 106 * 8 to avoid unwanted padding between __start_ta_head_section 107 * and the first structure in ta_head_section, in 64-bit 108 * builds 109 */ 110 . = ALIGN(8); 111 __start_ta_head_section = . ; 112 KEEP(*(ta_head_section)) 113 __stop_ta_head_section = . ; 114 . = ALIGN(8); 115 __start_phys_mem_map_section = . ; 116 KEEP(*(phys_mem_map_section)) 117 __end_phys_mem_map_section = . ; 118 . = ALIGN(8); 119 __start_phys_sdp_mem_section = . ; 120 KEEP(*(phys_sdp_mem_section)) 121 __end_phys_sdp_mem_section = . ; 122#endif 123 . = ALIGN(8); 124 __rodata_end = .; 125 } 126 127 .interp : { *(.interp) } 128 .hash : { *(.hash) } 129 .dynsym : { *(.dynsym) } 130 .dynstr : { *(.dynstr) } 131 .rel.text : { *(.rel.text) *(.rel.gnu.linkonce.t*) } 132 .rela.text : { *(.rela.text) *(.rela.gnu.linkonce.t*) } 133 .rel.data : { *(.rel.data) *(.rel.gnu.linkonce.d*) } 134 .rela.data : { *(.rela.data) *(.rela.gnu.linkonce.d*) } 135 .rel.rodata : { *(.rel.rodata) *(.rel.gnu.linkonce.r*) } 136 .rela.rodata : { *(.rela.rodata) *(.rela.gnu.linkonce.r*) } 137 .rel.got : { *(.rel.got) } 138 .rela.got : { *(.rela.got) } 139 .rel.ctors : { *(.rel.ctors) } 140 .rela.ctors : { *(.rela.ctors) } 141 .rel.dtors : { *(.rel.dtors) } 142 .rela.dtors : { *(.rela.dtors) } 143 .rel.init : { *(.rel.init) } 144 .rela.init : { *(.rela.init) } 145 .rel.fini : { *(.rel.fini) } 146 .rela.fini : { *(.rela.fini) } 147 .rel.bss : { *(.rel.bss) } 148 .rela.bss : { *(.rela.bss) } 149 .rel.plt : { *(.rel.plt) } 150 .rela.plt : { *(.rela.plt) } 151 .init : { *(.init) } =0x9090 152 .plt : { *(.plt) } 153 154 /* .ARM.exidx is sorted, so has to go in its own output section. */ 155 .ARM.exidx : { 156 __exidx_start = .; 157 *(.ARM.exidx* .gnu.linkonce.armexidx.*) 158 __exidx_end = .; 159 } 160 161 .ARM.extab : { 162 __extab_start = .; 163 *(.ARM.extab*) 164 __extab_end = .; 165 } 166 167 .data : ALIGN(8) { 168 /* writable data */ 169 __data_start_rom = .; 170 /* in one segment binaries, the rom data address is on top 171 of the ram data address */ 172 __early_bss_start = .; 173 *(.early_bss .early_bss.*) 174 . = ALIGN(8); 175 __early_bss_end = .; 176 __data_start = .; 177 *(.data .data.* .gnu.linkonce.d.*) 178 . = ALIGN(8); 179 } 180 181 .ctors : ALIGN(8) { 182 __ctor_list = .; 183 KEEP(*(.ctors .ctors.* .init_array .init_array.*)) 184 __ctor_end = .; 185 } 186 .dtors : ALIGN(8) { 187 __dtor_list = .; 188 KEEP(*(.dtors .dtors.* .fini_array .fini_array.*)) 189 __dtor_end = .; 190 } 191 .got : { *(.got.plt) *(.got) } 192 .dynamic : { *(.dynamic) } 193 194 __data_end = .; 195 /* unintialized data */ 196 .bss : ALIGN(8) { 197 __bss_start = .; 198 *(.bss .bss.*) 199 *(.gnu.linkonce.b.*) 200 *(COMMON) 201 . = ALIGN(8); 202 __bss_end = .; 203 } 204 205 .heap1 (NOLOAD) : { 206 /* 207 * We're keeping track of the padding added before the 208 * .nozi section so we can do something useful with 209 * this otherwise wasted memory. 210 */ 211 __heap1_start = .; 212#ifndef CFG_WITH_PAGER 213 . += CFG_CORE_HEAP_SIZE; 214#endif 215 . = ALIGN(16 * 1024); 216 __heap1_end = .; 217 } 218 219 /* 220 * Uninitialized data that shouldn't be zero initialized at 221 * runtime. 222 * 223 * L1 mmu table requires 16 KiB alignment 224 */ 225 .nozi (NOLOAD) : { 226 __nozi_start = .; 227 ASSERT(!(__nozi_start & (16 * 1024 - 1)), "align nozi to 16kB"); 228 229 KEEP(*(.nozi .nozi.*)) 230 . = ALIGN(16); 231 __nozi_end = .; 232 __nozi_stack_start = .; 233 KEEP(*(.nozi_stack)) 234 . = ALIGN(8); 235 __nozi_stack_end = .; 236 } 237 238#ifdef CFG_WITH_PAGER 239 .heap2 (NOLOAD) : { 240 __heap2_start = .; 241 /* 242 * Reserve additional memory for heap, the total should be 243 * at least CFG_CORE_HEAP_SIZE, but count what has already 244 * been reserved in .heap1 245 */ 246 . += CFG_CORE_HEAP_SIZE - (__heap1_end - __heap1_start); 247 . = ALIGN(SMALL_PAGE_SIZE); 248 __heap2_end = .; 249 } 250 251 __init_start = .; 252 .text_init : { 253/* 254 * Include list of sections needed for boot initialization, this list 255 * overlaps with unpaged.ld.S but since unpaged.ld.S is first all those 256 * sections will go into the unpaged area. 257 */ 258#include <text_init.ld.S> 259 . = ALIGN(8); 260 } 261 262 .rodata_init : { 263#include <rodata_init.ld.S> 264 . = ALIGN(8); 265 __start_phys_mem_map_section = . ; 266 KEEP(*(phys_mem_map_section)) 267 __end_phys_mem_map_section = . ; 268 . = ALIGN(8); 269 __start_phys_sdp_mem_section = . ; 270 KEEP(*(phys_sdp_mem_section)) 271 __end_phys_sdp_mem_section = . ; 272 . = ALIGN(8); 273 } 274 275 __init_end = .; 276 __init_size = __init_end - __init_start; 277 278 .text_pageable : ALIGN(8) { 279 *(.text*) 280 . = ALIGN(8); 281 } 282 283 .rodata_pageable : ALIGN(8) { 284#ifdef CFG_DT 285 __rodata_dtdrv_start = .; 286 KEEP(*(.rodata.dtdrv)) 287 __rodata_dtdrv_end = .; 288#endif 289 *(.rodata*) 290 /* 291 * 8 to avoid unwanted padding between __start_ta_head_section 292 * and the first structure in ta_head_section, in 64-bit 293 * builds 294 */ 295 . = ALIGN(8); 296 __start_ta_head_section = . ; 297 KEEP(*(ta_head_section)) 298 __stop_ta_head_section = . ; 299 . = ALIGN(SMALL_PAGE_SIZE); 300 } 301 302 __pageable_part_end = .; 303 __pageable_part_start = __init_end; 304 __pageable_start = __init_start; 305 __pageable_end = __pageable_part_end; 306 307 /* 308 * Assign a safe spot to store the hashes of the pages before 309 * heap is initialized. 310 */ 311 __tmp_hashes_start = __init_end; 312 __tmp_hashes_size = ((__pageable_end - __pageable_start) / 313 SMALL_PAGE_SIZE) * 32; 314 __tmp_hashes_end = __tmp_hashes_start + __tmp_hashes_size; 315 316 __init_mem_usage = __tmp_hashes_end - CFG_TEE_LOAD_ADDR; 317 318 ASSERT(CFG_TEE_LOAD_ADDR >= CFG_TEE_RAM_START, 319 "Load address before start of physical memory") 320 ASSERT(CFG_TEE_LOAD_ADDR < (CFG_TEE_RAM_START + CFG_TEE_RAM_PH_SIZE), 321 "Load address after end of physical memory") 322 ASSERT(__tmp_hashes_end < (CFG_TEE_RAM_START + CFG_TEE_RAM_PH_SIZE), 323 "OP-TEE can't fit init part into available physical memory") 324 ASSERT((CFG_TEE_RAM_START + CFG_TEE_RAM_PH_SIZE - __init_end) > 325 SMALL_PAGE_SIZE, "Too few free pages to initialize paging") 326 327 328#endif /*CFG_WITH_PAGER*/ 329 330#ifdef CFG_CORE_SANITIZE_KADDRESS 331 . = CFG_TEE_RAM_START + (CFG_TEE_RAM_VA_SIZE * 8) / 9 - 8; 332 . = ALIGN(8); 333 .asan_shadow : { 334 __asan_shadow_start = .; 335 . += CFG_TEE_RAM_VA_SIZE / 9; 336 __asan_shadow_end = .; 337 } 338#endif /*CFG_CORE_SANITIZE_KADDRESS*/ 339 340 __end = .; 341 342#ifndef CFG_WITH_PAGER 343 __init_size = __data_end - CFG_TEE_LOAD_ADDR; 344 __init_mem_usage = __end - CFG_TEE_LOAD_ADDR; 345#endif 346 . = CFG_TEE_RAM_START + CFG_TEE_RAM_VA_SIZE; 347 _end_of_ram = .; 348 349 /DISCARD/ : { 350 /* Strip unnecessary stuff */ 351 *(.comment .note .eh_frame) 352 /* Strip meta variables */ 353 *(__keep_meta_vars*) 354 } 355 356} 357