developer | 550bf5e | 2016-07-11 16:05:23 +0800 | [diff] [blame] | 1 | /* |
Masahiro Yamada | 0b67e56 | 2020-03-09 17:39:48 +0900 | [diff] [blame] | 2 | * Copyright (c) 2016-2020, ARM Limited and Contributors. All rights reserved. |
developer | 550bf5e | 2016-07-11 16:05:23 +0800 | [diff] [blame] | 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
developer | 550bf5e | 2016-07-11 16:05:23 +0800 | [diff] [blame] | 5 | */ |
| 6 | |
Masahiro Yamada | 0b67e56 | 2020-03-09 17:39:48 +0900 | [diff] [blame] | 7 | #include <common/bl_common.ld.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 8 | #include <lib/xlat_tables/xlat_tables_defs.h> |
developer | 550bf5e | 2016-07-11 16:05:23 +0800 | [diff] [blame] | 9 | #include <platform_def.h> |
| 10 | |
| 11 | OUTPUT_FORMAT(PLATFORM_LINKER_FORMAT) |
| 12 | OUTPUT_ARCH(PLATFORM_LINKER_ARCH) |
| 13 | ENTRY(bl31_entrypoint) |
| 14 | |
| 15 | |
| 16 | MEMORY { |
| 17 | RAM (rwx): ORIGIN = BL31_BASE, LENGTH = BL31_TZRAM_SIZE |
| 18 | RAM2 (rwx): ORIGIN = TZRAM2_BASE, LENGTH = TZRAM2_SIZE |
| 19 | } |
| 20 | |
| 21 | |
| 22 | SECTIONS |
| 23 | { |
| 24 | . = BL31_BASE; |
| 25 | |
| 26 | ASSERT(. == ALIGN(2048), |
| 27 | "vector base is not aligned on a 2K boundary.") |
| 28 | |
| 29 | __RO_START__ = .; |
| 30 | vector . : { |
| 31 | *(.vectors) |
| 32 | } >RAM |
| 33 | |
Antonio Nino Diaz | 2ce2b09 | 2017-11-15 11:45:35 +0000 | [diff] [blame] | 34 | ASSERT(. == ALIGN(PAGE_SIZE), |
developer | 550bf5e | 2016-07-11 16:05:23 +0800 | [diff] [blame] | 35 | "BL31_BASE address is not aligned on a page boundary.") |
| 36 | |
| 37 | ro . : { |
| 38 | *bl31_entrypoint.o(.text*) |
| 39 | *(.text*) |
| 40 | *(.rodata*) |
| 41 | |
| 42 | /* Ensure 8-byte alignment for descriptors and ensure inclusion */ |
| 43 | . = ALIGN(8); |
| 44 | __RT_SVC_DESCS_START__ = .; |
| 45 | KEEP(*(rt_svc_descs)) |
| 46 | __RT_SVC_DESCS_END__ = .; |
| 47 | |
| 48 | /* |
| 49 | * Ensure 8-byte alignment for cpu_ops so that its fields are also |
| 50 | * aligned. Also ensure cpu_ops inclusion. |
| 51 | */ |
| 52 | . = ALIGN(8); |
| 53 | __CPU_OPS_START__ = .; |
| 54 | KEEP(*(cpu_ops)) |
| 55 | __CPU_OPS_END__ = .; |
| 56 | |
| 57 | __RO_END_UNALIGNED__ = .; |
| 58 | /* |
| 59 | * Memory page(s) mapped to this section will be marked as read-only, |
| 60 | * executable. No RW data from the next section must creep in. |
| 61 | * Ensure the rest of the current memory page is unused. |
| 62 | */ |
Roberto Vargas | d93fde3 | 2018-04-11 11:53:31 +0100 | [diff] [blame] | 63 | . = ALIGN(PAGE_SIZE); |
developer | 550bf5e | 2016-07-11 16:05:23 +0800 | [diff] [blame] | 64 | __RO_END__ = .; |
| 65 | } >RAM |
| 66 | |
| 67 | ASSERT(__CPU_OPS_END__ > __CPU_OPS_START__, |
| 68 | "cpu_ops not defined for this platform.") |
| 69 | |
| 70 | /* |
| 71 | * Define a linker symbol to mark start of the RW memory area for this |
| 72 | * image. |
| 73 | */ |
| 74 | __RW_START__ = . ; |
| 75 | |
Douglas Raillard | 306593d | 2017-02-24 18:14:15 +0000 | [diff] [blame] | 76 | /* |
| 77 | * .data must be placed at a lower address than the stacks if the stack |
| 78 | * protector is enabled. Alternatively, the .data.stack_protector_canary |
| 79 | * section can be placed independently of the main .data section. |
| 80 | */ |
developer | 550bf5e | 2016-07-11 16:05:23 +0800 | [diff] [blame] | 81 | .data . : { |
| 82 | __DATA_START__ = .; |
| 83 | *(.data*) |
| 84 | __DATA_END__ = .; |
| 85 | } >RAM |
| 86 | |
| 87 | #ifdef BL31_PROGBITS_LIMIT |
| 88 | ASSERT(. <= BL31_PROGBITS_LIMIT, "BL3-1 progbits has exceeded its limit.") |
| 89 | #endif |
| 90 | |
| 91 | stacks (NOLOAD) : { |
| 92 | __STACKS_START__ = .; |
| 93 | *(tzfw_normal_stacks) |
| 94 | __STACKS_END__ = .; |
| 95 | } >RAM |
| 96 | |
| 97 | /* |
| 98 | * The .bss section gets initialised to 0 at runtime. |
Douglas Raillard | 21362a9 | 2016-12-02 13:51:54 +0000 | [diff] [blame] | 99 | * Its base address should be 16-byte aligned for better performance of the |
| 100 | * zero-initialization code. |
developer | 550bf5e | 2016-07-11 16:05:23 +0800 | [diff] [blame] | 101 | */ |
| 102 | .bss (NOLOAD) : ALIGN(16) { |
| 103 | __BSS_START__ = .; |
| 104 | *(.bss*) |
| 105 | *(COMMON) |
| 106 | #if !USE_COHERENT_MEM |
| 107 | /* |
| 108 | * Bakery locks are stored in normal .bss memory |
| 109 | * |
| 110 | * Each lock's data is spread across multiple cache lines, one per CPU, |
| 111 | * but multiple locks can share the same cache line. |
| 112 | * The compiler will allocate enough memory for one CPU's bakery locks, |
| 113 | * the remaining cache lines are allocated by the linker script |
| 114 | */ |
| 115 | . = ALIGN(CACHE_WRITEBACK_GRANULE); |
| 116 | __BAKERY_LOCK_START__ = .; |
Varun Wadekar | 77c382c | 2019-01-30 08:26:20 -0800 | [diff] [blame] | 117 | __PERCPU_BAKERY_LOCK_START__ = .; |
developer | 550bf5e | 2016-07-11 16:05:23 +0800 | [diff] [blame] | 118 | *(bakery_lock) |
| 119 | . = ALIGN(CACHE_WRITEBACK_GRANULE); |
Varun Wadekar | 77c382c | 2019-01-30 08:26:20 -0800 | [diff] [blame] | 120 | __PERCPU_BAKERY_LOCK_END__ = .; |
| 121 | __PERCPU_BAKERY_LOCK_SIZE__ = ABSOLUTE(__PERCPU_BAKERY_LOCK_END__ - __PERCPU_BAKERY_LOCK_START__); |
developer | 550bf5e | 2016-07-11 16:05:23 +0800 | [diff] [blame] | 122 | . = . + (__PERCPU_BAKERY_LOCK_SIZE__ * (PLATFORM_CORE_COUNT - 1)); |
| 123 | __BAKERY_LOCK_END__ = .; |
| 124 | #ifdef PLAT_PERCPU_BAKERY_LOCK_SIZE |
| 125 | ASSERT(__PERCPU_BAKERY_LOCK_SIZE__ == PLAT_PERCPU_BAKERY_LOCK_SIZE, |
| 126 | "PLAT_PERCPU_BAKERY_LOCK_SIZE does not match bakery lock requirements"); |
| 127 | #endif |
| 128 | #endif |
| 129 | __BSS_END__ = .; |
| 130 | __RW_END__ = .; |
| 131 | } >RAM |
| 132 | |
| 133 | ASSERT(. <= BL31_LIMIT, "BL3-1 image has exceeded its limit.") |
| 134 | |
Masahiro Yamada | 0b67e56 | 2020-03-09 17:39:48 +0900 | [diff] [blame] | 135 | XLAT_TABLE_SECTION >RAM2 |
developer | 550bf5e | 2016-07-11 16:05:23 +0800 | [diff] [blame] | 136 | |
| 137 | #if USE_COHERENT_MEM |
| 138 | /* |
| 139 | * The base address of the coherent memory section must be page-aligned (4K) |
| 140 | * to guarantee that the coherent data are stored on their own pages and |
| 141 | * are not mixed with normal data. This is required to set up the correct |
| 142 | * memory attributes for the coherent data page tables. |
| 143 | */ |
Antonio Nino Diaz | 2ce2b09 | 2017-11-15 11:45:35 +0000 | [diff] [blame] | 144 | coherent_ram (NOLOAD) : ALIGN(PAGE_SIZE) { |
developer | 550bf5e | 2016-07-11 16:05:23 +0800 | [diff] [blame] | 145 | __COHERENT_RAM_START__ = .; |
| 146 | /* |
| 147 | * Bakery locks are stored in coherent memory |
| 148 | * |
| 149 | * Each lock's data is contiguous and fully allocated by the compiler |
| 150 | */ |
| 151 | *(bakery_lock) |
| 152 | *(tzfw_coherent_mem) |
| 153 | __COHERENT_RAM_END_UNALIGNED__ = .; |
| 154 | /* |
| 155 | * Memory page(s) mapped to this section will be marked |
| 156 | * as device memory. No other unexpected data must creep in. |
| 157 | * Ensure the rest of the current memory page is unused. |
| 158 | */ |
Roberto Vargas | d93fde3 | 2018-04-11 11:53:31 +0100 | [diff] [blame] | 159 | . = ALIGN(PAGE_SIZE); |
developer | 550bf5e | 2016-07-11 16:05:23 +0800 | [diff] [blame] | 160 | __COHERENT_RAM_END__ = .; |
| 161 | } >RAM2 |
| 162 | #endif |
| 163 | |
| 164 | /* |
| 165 | * Define a linker symbol to mark end of the RW memory area for this |
| 166 | * image. |
| 167 | */ |
| 168 | __BL31_END__ = .; |
| 169 | |
| 170 | __BSS_SIZE__ = SIZEOF(.bss); |
| 171 | #if USE_COHERENT_MEM |
| 172 | __COHERENT_RAM_UNALIGNED_SIZE__ = |
| 173 | __COHERENT_RAM_END_UNALIGNED__ - __COHERENT_RAM_START__; |
| 174 | #endif |
| 175 | |
| 176 | ASSERT(. <= TZRAM2_LIMIT, "TZRAM2 image has exceeded its limit.") |
| 177 | } |