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