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