2 * Copyright (c) 2014, Linaro Limited
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
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.
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.
29 * Copyright (c) 2008-2010 Travis Geiselbrecht
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:
39 * The above copyright notice and this permission notice shall be
40 * included in all copies or substantial portions of the Software.
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.
51 #include <platform_config.h>
53 OUTPUT_FORMAT(CFG_KERN_LINKER_FORMAT)
54 OUTPUT_ARCH(CFG_KERN_LINKER_ARCH)
59 . = CFG_TEE_LOAD_ADDR;
61 /* text/read-only data */
64 KEEP(*(.text.boot.vectab1))
65 KEEP(*(.text.boot.vectab2))
78 /* Include list of sections needed for paging */
79 #include <text_unpaged.ld.S>
83 *(.sram.text.glue_7* .gnu.linkonce.t.*)
92 *(.rodata .rodata.__unpaged)
93 #include <rodata_unpaged.ld.S>
98 * 8 to avoid unwanted padding between __start_ta_head_section
99 * and the first structure in ta_head_section, in 64-bit
103 __start_ta_head_section = . ;
104 KEEP(*(ta_head_section))
105 __stop_ta_head_section = . ;
107 __start_phys_mem_map_section = . ;
108 KEEP(*(phys_mem_map_section))
109 __end_phys_mem_map_section = . ;
115 .interp : { *(.interp) }
117 .dynsym : { *(.dynsym) }
118 .dynstr : { *(.dynstr) }
119 .rel.text : { *(.rel.text) *(.rel.gnu.linkonce.t*) }
120 .rela.text : { *(.rela.text) *(.rela.gnu.linkonce.t*) }
121 .rel.data : { *(.rel.data) *(.rel.gnu.linkonce.d*) }
122 .rela.data : { *(.rela.data) *(.rela.gnu.linkonce.d*) }
123 .rel.rodata : { *(.rel.rodata) *(.rel.gnu.linkonce.r*) }
124 .rela.rodata : { *(.rela.rodata) *(.rela.gnu.linkonce.r*) }
125 .rel.got : { *(.rel.got) }
126 .rela.got : { *(.rela.got) }
127 .rel.ctors : { *(.rel.ctors) }
128 .rela.ctors : { *(.rela.ctors) }
129 .rel.dtors : { *(.rel.dtors) }
130 .rela.dtors : { *(.rela.dtors) }
131 .rel.init : { *(.rel.init) }
132 .rela.init : { *(.rela.init) }
133 .rel.fini : { *(.rel.fini) }
134 .rela.fini : { *(.rela.fini) }
135 .rel.bss : { *(.rel.bss) }
136 .rela.bss : { *(.rela.bss) }
137 .rel.plt : { *(.rel.plt) }
138 .rela.plt : { *(.rela.plt) }
139 .init : { *(.init) } =0x9090
142 /* .ARM.exidx is sorted, so has to go in its own output section. */
145 *(.ARM.exidx* .gnu.linkonce.armexidx.*)
157 __data_start_rom = .;
158 /* in one segment binaries, the rom data address is on top
159 of the ram data address */
160 __early_bss_start = .;
161 *(.early_bss .early_bss.*)
165 *(.data .data.* .gnu.linkonce.d.*)
171 KEEP(*(.ctors .ctors.* .init_array .init_array.*))
176 KEEP(*(.dtors .dtors.* .fini_array .fini_array.*))
179 .got : { *(.got.plt) *(.got) }
180 .dynamic : { *(.dynamic) }
183 /* unintialized data */
195 * We're keeping track of the padding added before the
196 * .nozi section so we can do something useful with
197 * this otherwise wasted memory.
200 #ifndef CFG_WITH_PAGER
201 . += CFG_CORE_HEAP_SIZE;
203 . = ALIGN(16 * 1024);
208 * Uninitialized data that shouldn't be zero initialized at
211 * L1 mmu table requires 16 KiB alignment
213 .nozi (NOLOAD) : ALIGN(16 * 1024) {
215 KEEP(*(.nozi .nozi.*))
218 __nozi_stack_start = .;
221 __nozi_stack_end = .;
224 #ifdef CFG_WITH_PAGER
228 * Reserve additional memory for heap, the total should be
229 * at least CFG_CORE_HEAP_SIZE, but count what has already
230 * been reserved in .heap1
232 . += CFG_CORE_HEAP_SIZE - (__heap1_end - __heap1_start);
237 .text_init : ALIGN(4 * 1024) {
238 __text_init_start = .;
240 * Include list of sections needed for boot initialization, this list
241 * overlaps with unpaged.ld.S but since unpaged.ld.S is first all those
242 * sections will go into the unpaged area.
244 #include <text_init.ld.S>
249 .rodata_init : ALIGN(8) {
250 __rodata_init_start = .;
251 #include <rodata_init.ld.S>
253 __start_phys_mem_map_section = . ;
254 KEEP(*(phys_mem_map_section))
255 __end_phys_mem_map_section = . ;
257 __rodata_init_end = .;
259 __init_start = __text_init_start;
261 __init_size = __init_end - __text_init_start;
263 .text_pageable : ALIGN(8) {
264 __text_pageable_start = .;
267 __text_pageable_end = .;
270 .rodata_pageable : ALIGN(8) {
271 __rodata_pageable_start = .;
274 * 8 to avoid unwanted padding between __start_ta_head_section
275 * and the first structure in ta_head_section, in 64-bit
279 __start_ta_head_section = . ;
280 KEEP(*(ta_head_section))
281 __stop_ta_head_section = . ;
283 __rodata_pageable_end = .;
286 __pageable_part_start = __rodata_init_end;
287 __pageable_part_end = __rodata_pageable_end;
288 __pageable_start = __text_init_start;
289 __pageable_end = __pageable_part_end;
292 * Assign a safe spot to store the hashes of the pages before
293 * heap is initialized.
295 __tmp_hashes_start = __rodata_init_end;
296 __tmp_hashes_size = ((__pageable_end - __pageable_start) /
298 __tmp_hashes_end = __tmp_hashes_start + __tmp_hashes_size;
300 __init_mem_usage = __tmp_hashes_end - CFG_TEE_LOAD_ADDR;
302 ASSERT(CFG_TEE_LOAD_ADDR >= CFG_TEE_RAM_START,
303 "Load address before start of physical memory")
304 ASSERT(CFG_TEE_LOAD_ADDR < (CFG_TEE_RAM_START + CFG_TEE_RAM_PH_SIZE),
305 "Load address after end of physical memory")
306 ASSERT(__tmp_hashes_end < (CFG_TEE_RAM_START + CFG_TEE_RAM_PH_SIZE),
307 "OP-TEE can't fit init part into available physical memory")
308 ASSERT((CFG_TEE_RAM_START + CFG_TEE_RAM_PH_SIZE - __init_end) >
309 1 * 4096, "Too few free pages to initialize paging")
312 #endif /*CFG_WITH_PAGER*/
314 #ifdef CFG_CORE_SANITIZE_KADDRESS
315 . = CFG_TEE_RAM_START + (CFG_TEE_RAM_VA_SIZE * 8) / 9 - 8;
318 __asan_shadow_start = .;
319 . += CFG_TEE_RAM_VA_SIZE / 9;
320 __asan_shadow_end = .;
322 #endif /*CFG_CORE_SANITIZE_KADDRESS*/
326 #ifndef CFG_WITH_PAGER
327 __init_size = __data_end - CFG_TEE_LOAD_ADDR;
328 __init_mem_usage = __end - CFG_TEE_LOAD_ADDR;
330 . = CFG_TEE_RAM_START + CFG_TEE_RAM_VA_SIZE;
334 /* Strip unnecessary stuff */
335 *(.comment .note .eh_frame)
336 /* Strip meta variables */