1/* 2 * Copyright (c) 2024 Espressif Systems (Shanghai) Co., Ltd. 3 * SPDX-License-Identifier: Apache-2.0 4 */ 5 6#include <zephyr/devicetree.h> 7#include <zephyr/linker/sections.h> 8#include <zephyr/linker/linker-defs.h> 9#include <zephyr/linker/linker-tool.h> 10 11#include "memory.h" 12 13/* Disable all romable LMA */ 14#undef GROUP_DATA_LINK_IN 15#define GROUP_DATA_LINK_IN(vregion, lregion) > vregion 16 17#define RAMABLE_REGION dram_seg 18#define RODATA_REGION dram_seg 19#define ROMABLE_REGION dram_seg 20 21/* Global symbols required for espressif hal build */ 22MEMORY 23{ 24 iram_seg (RX) : org = BOOTLOADER_IRAM_SEG_START, 25 len = BOOTLOADER_IRAM_SEG_LEN 26 iram_loader_seg (RX) : org = BOOTLOADER_IRAM_LOADER_SEG_START, 27 len = BOOTLOADER_IRAM_LOADER_SEG_LEN 28 dram_seg (RW) : org = BOOTLOADER_DRAM_SEG_START, 29 len = BOOTLOADER_DRAM_SEG_LEN 30 31#ifdef CONFIG_GEN_ISR_TABLES 32 IDT_LIST(RW): org = 0x3ebfe010, len = 0x2000 33#endif 34} 35 36/* Default entry point: */ 37ENTRY(CONFIG_KERNEL_ENTRY) 38 39SECTIONS 40{ 41 .iram0.loader_text : 42 { 43 . = ALIGN (16); 44 _loader_text_start = ABSOLUTE(.); 45 *(.stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*) 46 47 *libapp.a:flash_map_extended.*(.literal .text .literal.* .text.*) 48 *libzephyr.a:cbprintf_nano.*(.literal .text .literal.* .text.*) 49 *libzephyr.a:cpu.*(.literal .text .literal.* .text.*) 50 *libzephyr.a:mmu_hal.*(.literal .text .literal.* .text.*) 51 *libzephyr.a:cache_hal.*(.literal .text .literal.* .text.*) 52 *libzephyr.a:flash_map.*(.literal .text .literal.* .text.*) 53 *libzephyr.a:esp_rom_spiflash.*(.literal .text .literal.* .text.*) 54 55 *libzephyr.a:heap.*(.literal .text .literal.* .text.*) 56 57 *libkernel.a:kheap.*(.literal .text .literal.* .text.*) 58 *libkernel.a:mempool.*(.literal .text .literal.* .text.*) 59 60 *(.literal.bootloader_mmap .text.bootloader_mmap) 61 *(.literal.bootloader_munmap .text.bootloader_munmap) 62 63 *libzephyr.a:esp_loader.*(.literal .text .literal.* .text.*) 64 *libzephyr.a:mmu_hal.*(.literal .text .literal.* .text.*) 65 66 *(.literal.esp_intr_disable .literal.esp_intr_disable.* .text.esp_intr_disable .text.esp_intr_disable.*) 67 *(.literal.default_intr_handler .text.default_intr_handler .iram1.*.default_intr_handler) 68 *(.literal.esp_log_timestamp .text.esp_log_timestamp) 69 *(.literal.esp_log_early_timestamp .text.esp_log_early_timestamp) 70 *(.literal.esp_system_abort .text.esp_system_abort) 71 72 *(.fini.literal) 73 *(.fini) 74 *(.gnu.version) 75 _loader_text_end = ABSOLUTE(.); 76 _iram_end = ABSOLUTE(.); 77 } > iram_loader_seg 78 79 .iram0.text : 80 { 81 /* Vectors go to IRAM */ 82 _iram_start = ABSOLUTE(.); 83 _init_start = ABSOLUTE(.); 84 __text_region_start = ABSOLUTE(.); 85 86 KEEP(*(.exception_vectors.text)); 87 . = ALIGN(256); 88 89 _invalid_pc_placeholder = ABSOLUTE(.); 90 91 _iram_text_start = ABSOLUTE(.); 92 93 KEEP(*(.exception.entry*)); /* contains _isr_wrapper */ 94 *(.exception.other*) 95 . = ALIGN(4); 96 97 *(.entry.text) 98 *(.init.literal) 99 *(.init) 100 . = ALIGN(4); 101 *(.iram1 .iram1.*) 102 *(.iram0.literal .iram.literal .iram.text.literal .iram0.text .iram.text) 103 104 /* C6 memprot requires 512 B alignment for split lines */ 105 . = ALIGN (16); 106 _init_end = ABSOLUTE(.); 107 . = ALIGN(16); 108 *(.iram.data) 109 *(.iram.data*) 110 . = ALIGN(16); 111 *(.iram.bss) 112 *(.iram.bss*) 113 114 . = ALIGN(16); 115 116 *(.literal .text .literal.* .text.*) 117 *(.stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*) 118 *(.irom0.text) /* catch stray ICACHE_RODATA_ATTR */ 119 *(.fini.literal) 120 *(.fini) 121 *(.gnu.version) 122 123 /* CPU will try to prefetch up to 16 bytes of 124 * of instructions. This means that any configuration (e.g. MMU, PMS) must allow 125 * safe access to up to 16 bytes after the last real instruction, add 126 * dummy bytes to ensure this 127 */ 128 . += 16; 129 130 _text_end = ABSOLUTE(.); 131 __text_region_end = ABSOLUTE(.); 132 _etext = .; 133 134 /* Similar to _iram_start, this symbol goes here so it is 135 * resolved by addr2line in preference to the first symbol in 136 * the flash.text segment. 137 */ 138 _flash_cache_start = ABSOLUTE(0); 139 } > iram_seg 140 141 .dram0.data : 142 { 143 . = ALIGN(4); 144 __data_start = ABSOLUTE(.); 145 *(.data) 146 *(.data.*) 147 *(.gnu.linkonce.d.*) 148 *(.data1) 149#ifdef CONFIG_RISCV_GP 150 __global_pointer$ = . + 0x800; 151#endif /* CONFIG_RISCV_GP */ 152 *(.sdata) 153 *(.sdata.*) 154 *(.gnu.linkonce.s.*) 155 *(.sdata2) 156 *(.sdata2.*) 157 *(.gnu.linkonce.s2.*) 158 *libzephyr.a:mmu_hal.*(.rodata .rodata.*) 159 *libzephyr.a:rtc_clk.*(.rodata .rodata.*) 160 KEEP(*(.jcr)) 161 *(.dram1 .dram1.*) 162 . = ALIGN(4); 163 164 #include <snippets-rwdata.ld> 165 . = ALIGN(4); 166 167 *(.rodata_desc .rodata_desc.*) 168 *(.rodata_custom_desc .rodata_custom_desc.*) 169 170 . = ALIGN(4); 171 #include <snippets-rodata.ld> 172 . = ALIGN(4); 173 174 *(.rodata) 175 *(.rodata.*) 176 *(.irom1.text) /* catch stray ICACHE_RODATA_ATTR */ 177 *(.gnu.linkonce.r.*) 178 *(.rodata1) 179 __XT_EXCEPTION_TABLE_ = ABSOLUTE(.); 180 *(.xt_except_table) 181 *(.gcc_except_table .gcc_except_table.*) 182 *(.gnu.linkonce.e.*) 183 *(.gnu.version_r) 184 . = (. + 3) & ~ 3; 185 __eh_frame = ABSOLUTE(.); 186 KEEP(*(.eh_frame)) 187 . = (. + 7) & ~ 3; 188 189 /* C++ exception handlers table: */ 190 __XT_EXCEPTION_DESCS_ = ABSOLUTE(.); 191 *(.xt_except_desc) 192 *(.gnu.linkonce.h.*) 193 __XT_EXCEPTION_DESCS_END__ = ABSOLUTE(.); 194 *(.xt_except_desc_end) 195 *(.dynamic) 196 *(.gnu.version_d) 197 __rodata_region_end = .; 198 _rodata_end = ABSOLUTE(.); 199 /* Literals are also RO data. */ 200 _lit4_start = ABSOLUTE(.); 201 *(*.lit4) 202 *(.lit4.*) 203 *(.gnu.linkonce.lit4.*) 204 _lit4_end = ABSOLUTE(.); 205 . = ALIGN(4); 206 _thread_local_start = ABSOLUTE(.); 207 *(.tdata) 208 *(.tdata.*) 209 *(.tbss) 210 *(.tbss.*) 211 *(.srodata) 212 *(.srodata.*) 213 *(.rodata) 214 *(.rodata.*) 215 *(.rodata_wlog) 216 *(.rodata_wlog*) 217 _thread_local_end = ABSOLUTE(.); 218 /* _rodata_reserved_end = ABSOLUTE(.); */ 219 . = ALIGN(4); 220 } > dram_seg 221 222 #include <zephyr/linker/common-rom/common-rom-init.ld> 223 #include <zephyr/linker/common-rom/common-rom-kernel-devices.ld> 224 #include <zephyr/linker/common-rom/common-rom-debug.ld> 225 #include <zephyr/linker/common-rom/common-rom-misc.ld> 226 #include <snippets-sections.ld> 227 228 #include <zephyr/linker/cplusplus-rom.ld> 229 #include <zephyr/linker/thread-local-storage.ld> 230 #include <snippets-data-sections.ld> 231 #include <zephyr/linker/common-ram.ld> 232 #include <snippets-ram-sections.ld> 233 #include <zephyr/linker/cplusplus-ram.ld> 234 235 #include <zephyr/linker/common-rom/common-rom-logging.ld> 236 237 .noinit (NOLOAD): 238 { 239 . = ALIGN(4); 240 *(.noinit) 241 *(.noinit.*) 242 . = ALIGN(4); 243 } > dram_seg 244 245 /* Shared RAM */ 246 .bss (NOLOAD): 247 { 248 . = ALIGN (8); 249 _bss_start = ABSOLUTE(.); 250 __bss_start = ABSOLUTE(.); 251 *(.dynsbss) 252 *(.sbss) 253 *(.sbss.*) 254 *(.gnu.linkonce.sb.*) 255 *(.scommon) 256 *(.sbss2) 257 *(.sbss2.*) 258 *(.gnu.linkonce.sb2.*) 259 *(.dynbss) 260 *(.bss) 261 *(.bss.*) 262 *(.share.mem) 263 *(.gnu.linkonce.b.*) 264 *(COMMON) 265 . = ALIGN (8); 266 __bss_end = ABSOLUTE(.); 267 _bss_end = ABSOLUTE(.); 268 } > dram_seg 269 270 /* linker rel sections*/ 271 #include <zephyr/linker/rel-sections.ld> 272 273#ifdef CONFIG_GEN_ISR_TABLES 274 #include <zephyr/linker/intlist.ld> 275#endif 276 277#include <zephyr/linker/debug-sections.ld> 278 /DISCARD/ : { *(.note.GNU-stack) } 279 280 SECTION_PROLOGUE(.riscv.attributes, 0,) 281 { 282 KEEP(*(.riscv.attributes)) 283 KEEP(*(.gnu.attributes)) 284 } 285} 286