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/* The "user_iram_end" represents the 2nd stage bootloader
14 * "iram_loader_seg" start address (that should not be overlapped).
15 * If no bootloader is used, we can extend it to gain more user ram.
16 */
17#ifdef CONFIG_ESP_SIMPLE_BOOT
18user_iram_end = (DRAM_BUFFERS_START + IRAM_DRAM_OFFSET);
19#else
20user_iram_end = BOOTLOADER_IRAM_LOADER_SEG_START;
21#endif
22
23/* User available SRAM memory segments */
24user_iram_seg_org = SRAM1_IRAM_START;
25user_dram_seg_org = SRAM1_DRAM_START;
26user_dram_end = (user_iram_end - IRAM_DRAM_OFFSET);
27user_idram_size = (user_dram_end - user_dram_seg_org);
28user_iram_seg_len = user_idram_size;
29user_dram_seg_len = user_idram_size;
30
31/* Aliases */
32#define FLASH_CODE_REGION  irom0_0_seg
33#define RODATA_REGION      drom0_0_seg
34#define IRAM_REGION        iram0_0_seg
35#define DRAM_REGION        dram0_0_seg
36#define RAMABLE_REGION     dram0_0_seg
37#define ROMABLE_REGION     FLASH
38
39#undef GROUP_DATA_LINK_IN
40#define GROUP_DATA_LINK_IN(vregion, lregion) > vregion AT > lregion
41
42#undef GROUP_NOLOAD_LINK_IN
43#define GROUP_NOLOAD_LINK_IN(vregion, lregion) > vregion
44
45/* Flash segments (rodata and text) should be mapped in the virtual address spaces.
46 * Executing directly from LMA is not possible. */
47#undef GROUP_ROM_LINK_IN
48#define GROUP_ROM_LINK_IN(vregion, lregion) > RODATA_REGION AT > lregion
49
50/* Make sure new sections have consistent alignment between input and output sections */
51#undef SECTION_DATA_PROLOGUE
52#define SECTION_DATA_PROLOGUE(name, options, align) name options : ALIGN_WITH_INPUT
53
54#undef SECTION_PROLOGUE
55#define SECTION_PROLOGUE SECTION_DATA_PROLOGUE
56
57/* Global symbols required for espressif hal build */
58MEMORY
59{
60#ifdef CONFIG_BOOTLOADER_MCUBOOT
61  mcuboot_hdr (R): org = 0x0,  len = 0x20
62  metadata (R):    org = 0x20, len = 0x20
63  FLASH (R):       org = 0x40, len = FLASH_SIZE - 0x40
64#else
65  /* Make safety margin in the FLASH memory size so the
66   * (esp_img_header + (n*esp_seg_headers)) would fit */
67  FLASH (R): org = 0x0, len = FLASH_SIZE - 0x100
68#endif
69
70  iram0_0_seg(RX): org = user_iram_seg_org, len = user_iram_seg_len
71  dram0_0_seg(RW): org = user_dram_seg_org, len = user_dram_seg_len
72
73  irom0_0_seg(RX): org = IROM_SEG_ORG, len = IROM_SEG_LEN
74  drom0_0_seg (R): org = DROM_SEG_ORG, len = DROM_SEG_LEN
75
76  rtc_iram_seg(RWX): org = 0x50000000, len = 0x2000
77
78#ifdef CONFIG_GEN_ISR_TABLES
79  IDT_LIST(RW): org = 0x3ebfe010, len = 0x2000
80#endif
81}
82
83/* The line below defines location alias for .rtc.data section
84 * As C3 only has RTC fast memory, this is not configurable like
85 * on other targets.
86 */
87REGION_ALIAS("rtc_slow_seg", rtc_iram_seg);
88
89/*  Default entry point:  */
90ENTRY(CONFIG_KERNEL_ENTRY)
91
92_rom_store_table = 0;
93
94_iram_dram_offset = IRAM_DRAM_OFFSET;
95
96/* Stack sentry */
97_heap_sentry = DRAM_RESERVED_START;
98
99SECTIONS
100{
101#ifdef CONFIG_BOOTLOADER_MCUBOOT
102  /* Reserve space for MCUboot header in the binary */
103  .mcuboot_header :
104  {
105    QUAD(0x0)
106    QUAD(0x0)
107    QUAD(0x0)
108    QUAD(0x0)
109  } > mcuboot_hdr
110  .metadata :
111  {
112    /* 0. Magic byte for load header */
113    LONG(0xace637d3)
114
115    /* 1. Application entry point address */
116    KEEP(*(.entry_addr))
117
118    /* IRAM metadata:
119     * 2. Destination address (VMA) for IRAM region
120     * 3. Flash offset (LMA) for start of IRAM region
121     * 4. Size of IRAM region
122     */
123    LONG(ADDR(.iram0.text))
124    LONG(LOADADDR(.iram0.text))
125    LONG(LOADADDR(.iram0.data) - LOADADDR(.iram0.text))
126
127    /* DRAM metadata:
128     * 5. Destination address (VMA) for DRAM region
129     * 6. Flash offset (LMA) for start of DRAM region
130     * 7. Size of DRAM region
131     */
132    LONG(ADDR(.dram0.data))
133    LONG(LOADADDR(.dram0.data))
134    LONG(LOADADDR(.dram0.end) - LOADADDR(.dram0.data))
135  } > metadata
136#endif /* CONFIG_BOOTLOADER_MCUBOOT */
137
138  iram_vma = ADDR(.iram0.text);
139  iram_lma = LOADADDR(.iram0.text);
140  iram_size_field = LOADADDR(.iram0.data) - LOADADDR(.iram0.text);
141
142  dram_vma = ADDR(.dram0.data);
143  dram_lma = LOADADDR(.dram0.data);
144  dram_size_field = LOADADDR(.dram0.end) - LOADADDR(.dram0.data);
145
146  #include <zephyr/linker/rel-sections.ld>
147
148#ifdef CONFIG_LLEXT
149  #include <zephyr/linker/llext-sections.ld>
150#endif
151
152  /* --- START OF RTC --- */
153
154  .rtc.text :
155  {
156    . = ALIGN(4);
157    *(.rtc.literal .rtc.text)
158    *rtc_wake_stub*.o(.literal .text .literal.* .text.*)
159  } GROUP_DATA_LINK_IN(rtc_iram_seg, ROMABLE_REGION)
160
161  /* This section is required to skip rtc.text area because the text and
162   * data segments reflect the same address space on different buses.
163   */
164  .rtc.dummy (NOLOAD):
165  {
166    . = SIZEOF(.rtc.text);
167  } GROUP_LINK_IN(rtc_iram_seg)
168
169  .rtc.data :
170  {
171    _rtc_data_start = ABSOLUTE(.);
172    *(.rtc.data)
173    *(.rtc.rodata)
174    *rtc_wake_stub*.o(.data .rodata .data.* .rodata.* .bss .bss.*)
175    _rtc_data_end = ABSOLUTE(.);
176  } GROUP_DATA_LINK_IN(rtc_iram_seg, ROMABLE_REGION)
177
178  .rtc.bss (NOLOAD) :
179  {
180    _rtc_bss_start = ABSOLUTE(.);
181    *rtc_wake_stub*.o(.bss .bss.*)
182    *rtc_wake_stub*.o(COMMON)
183    _rtc_bss_end = ABSOLUTE(.);
184  } GROUP_LINK_IN(rtc_iram_seg)
185
186  /* This section located in RTC SLOW Memory area.
187   * It holds data marked with RTC_SLOW_ATTR attribute.
188   * See the file "esp_attr.h" for more information.
189   */
190  .rtc.force_slow :
191  {
192    . = ALIGN(4);
193    _rtc_force_slow_start = ABSOLUTE(.);
194    *(.rtc.force_slow .rtc.force_slow.*)
195    . = ALIGN(4) ;
196    _rtc_force_slow_end = ABSOLUTE(.);
197  } > rtc_slow_seg
198
199  /* Get size of rtc slow data */
200  _rtc_slow_length = (_rtc_force_slow_end - _rtc_data_start);
201
202  /* --- END OF RTC --- */
203
204  /* --- START OF IRAM --- */
205
206  .iram0.text : ALIGN(4)
207  {
208    /* Vectors go to IRAM */
209    _iram_start = ABSOLUTE(.);
210    _init_start = ABSOLUTE(.);
211
212    KEEP(*(.exception_vectors.text));
213    . = ALIGN(256);
214
215    _invalid_pc_placeholder = ABSOLUTE(.);
216
217    KEEP(*(.exception.entry*)); /* contains _isr_wrapper */
218    *(.exception.other*)
219    . = ALIGN(4);
220
221    *(.entry.text)
222    *(.init.literal)
223    *(.init)
224    . = ALIGN(4);
225
226    _init_end = ABSOLUTE(.);
227    _iram_text_start = ABSOLUTE(.);
228
229    *(.iram1 .iram1.*)
230    *(.iram0.literal .iram.literal .iram.text.literal .iram0.text .iram.text)
231    *libzephyr.a:panic.*(.literal .text .literal.* .text.*)
232    *libzephyr.a:loader.*(.literal .text .literal.* .text.*)
233    *libzephyr.a:flash_init.*(.literal .text .literal.* .text.*)
234    *libzephyr.a:soc_flash_init.*(.literal .text .literal.* .text.*)
235    *libzephyr.a:console_init.*(.literal .text .literal.* .text.*)
236    *libzephyr.a:soc_init.*(.literal .text .literal.* .text.*)
237    *libzephyr.a:hw_init.*(.literal .text .literal.* .text.*)
238    *libzephyr.a:soc_random.*(.literal .text .literal.* .text.*)
239
240    *libarch__riscv__core.a:(.literal .text .literal.* .text.*)
241    *libsubsys__net__l2__ethernet.a:(.literal .text .literal.* .text.*)
242    *libsubsys__net__lib__config.a:(.literal .text .literal.* .text.*)
243    *libsubsys__net__ip.a:(.literal .text .literal.* .text.*)
244    *libsubsys__net.a:(.literal .text .literal.* .text.*)
245    *libkernel.a:(.literal .text .literal.* .text.*)
246    *libgcc.a:lib2funcs.*(.literal .text .literal.* .text.*)
247    *libdrivers__flash.a:flash_esp32.*(.literal .text .literal.* .text.*)
248    *libzephyr.a:log_noos.*(.literal .text .literal.* .text.*)
249    *libdrivers__timer.a:esp32c3_sys_timer.*(.literal .text .literal.* .text.*)
250    *libzephyr.a:log_core.*(.literal .text .literal.* .text.*)
251    *libzephyr.a:cbprintf_complete.*(.literal .text .literal.* .text.*)
252    *libzephyr.a:printk.*(.literal.printk .literal.vprintk .literal.char_out .text.printk .text.vprintk .text.char_out)
253    *libzephyr.a:log_msg.*(.literal .text .literal.* .text.*)
254    *libzephyr.a:log_list.*(.literal .text .literal.* .text.*)
255    *libdrivers__console.a:uart_console.*(.literal.console_out .text.console_out)
256    *libzephyr.a:log_output.*(.literal .text .literal.* .text.*)
257    *libzephyr.a:log_backend_uart.*(.literal .text .literal.* .text.*)
258    *libzephyr.a:rtc_*.*(.literal .text .literal.* .text.*)
259    *liblib__libc__newlib.a:string.*(.literal .text .literal.* .text.*)
260    *liblib__libc__minimal.a:string.*(.literal .text .literal.* .text.*)
261    *liblib__libc__picolib.a:string.*(.literal .text .literal.* .text.*)
262    *libzephyr.a:periph_ctrl.*(.literal .text .literal.* .text.*)
263    *libgcov.a:(.literal .text .literal.* .text.*)
264    *libphy.a:( .phyiram .phyiram.*)
265    *libc.a:*(.literal .text .literal.* .text.*)
266
267    /* [mapping:hal] */
268    *libzephyr.a:mmu_hal.*(.literal .text .literal.* .text.*)
269    *libzephyr.a:spi_flash_hal_iram.*(.literal .literal.* .text .text.*)
270    *libzephyr.a:spi_flash_encrypt_hal_iram.*(.literal .text .literal.* .text.*)
271    *libzephyr.a:cache_hal.*(.literal .text .literal.* .text.*)
272    *libzephyr.a:ledc_hal_iram.*(.literal .text .literal.* .text.*)
273    *libzephyr.a:i2c_hal_iram.*(.literal .text .literal.* .text.*)
274    *libzephyr.a:wdt_hal_iram.*(.literal .text .literal.* .text.*)
275    *libzephyr.a:systimer_hal.*(.literal .text .literal.* .text.*)
276    *libzephyr.a:spi_flash_hal_gpspi.*(.literal .literal.* .text .text.*)
277
278    /* [mapping:soc] */
279    *libzephyr.a:lldesc.*(.literal .literal.* .text .text.*)
280
281    /* [mapping:log] */
282    *(.literal.esp_log_write .text.esp_log_write)
283    *(.literal.esp_log_timestamp .text.esp_log_timestamp)
284    *(.literal.esp_log_early_timestamp .text.esp_log_early_timestamp)
285    *(.literal.esp_log_impl_lock .text.esp_log_impl_lock)
286    *(.literal.esp_log_impl_lock_timeout .text.esp_log_impl_lock_timeout)
287    *(.literal.esp_log_impl_unlock .text.esp_log_impl_unlock)
288
289    /* [mapping:spi_flash] */
290    *libzephyr.a:spi_flash_chip_boya.*(.literal .literal.* .text .text.*)
291    *libzephyr.a:spi_flash_chip_gd.*(.literal .literal.* .text .text.*)
292    *libzephyr.a:spi_flash_chip_generic.*(.literal .literal.* .text .text.*)
293    *libzephyr.a:spi_flash_chip_issi.*(.literal .literal.* .text .text.*)
294    *libzephyr.a:spi_flash_chip_mxic.*(.literal .literal.* .text .text.*)
295    *libzephyr.a:spi_flash_chip_mxic_opi.*(.literal .literal.* .text .text.*)
296    *libzephyr.a:spi_flash_chip_th.*(.literal .literal.* .text .text.*)
297    *libzephyr.a:spi_flash_chip_winbond.*(.literal .literal.* .text .text.*)
298    *libzephyr.a:memspi_host_driver.*(.literal .literal.* .text .text.*)
299    *libzephyr.a:flash_brownout_hook.*(.literal .literal.* .text .text.*)
300    *libzephyr.a:spi_flash_wrap.*(.literal .literal.* .text .text.*)
301    *libzephyr.a:spi_flash_hpm_enable.*(.literal .literal.* .text .text.*)
302    *libzephyr.a:flash_ops.*(.literal .text .literal.* .text.*)
303
304    /* [mapping:esp_system] */
305    *libzephyr.a:esp_err.*(.literal .literal.* .text .text.*)
306    *(.literal.esp_system_abort .text.esp_system_abort)
307
308    /* [mapping:esp_hw_support] */
309    *(.literal.esp_cpu_stall .text.esp_cpu_stall)
310    *(.literal.esp_cpu_unstall .text.esp_cpu_unstall)
311    *(.literal.esp_cpu_reset .text.esp_cpu_reset)
312    *(.literal.esp_cpu_wait_for_intr .text.esp_cpu_wait_for_intr)
313    *(.literal.esp_cpu_compare_and_set .text.esp_cpu_compare_and_set)
314    *(.literal.esp_gpio_reserve_pins .text.esp_gpio_reserve_pins)
315    *(.literal.esp_gpio_is_pin_reserved .text.esp_gpio_is_pin_reserved)
316    *(.literal.rtc_vddsdio_get_config .text.rtc_vddsdio_get_config)
317    *(.literal.rtc_vddsdio_set_config .text.rtc_vddsdio_set_config)
318    *libzephyr.a:esp_memory_utils.*(.literal .literal.* .text .text.*)
319    *libzephyr.a:rtc_clk.*(.literal .literal.* .text .text.*)
320    *libzephyr.a:rtc_clk_init.*(.literal .literal.* .text .text.*)
321    *libzephyr.a:rtc_time.*(.literal .literal.* .text .text.*)
322    *libzephyr.a:rtc_sleep.*(.literal .literal.* .text .text.*)
323    *libzephyr.a:systimer.*(.literal .literal.* .text .text.*)
324    *libzephyr.a:mspi_timing_config.*(.literal .literal.* .text .text.*)
325    *libzephyr.a:mspi_timing_tuning.*(.literal .literal.* .text .text.*)
326    *(.literal.sar_periph_ctrl_power_enable .text.sar_periph_ctrl_power_enable)
327
328    /* [mapping:soc_pm] */
329    *(.literal.GPIO_HOLD_MASK .text.GPIO_HOLD_MASK)
330
331    /* [mapping:esp_rom] */
332    *libzephyr.a:esp_rom_spiflash.*(.literal .literal.* .text .text.*)
333    *libzephyr.a:esp_rom_systimer.*(.literal .literal.* .text .text.*)
334    *libzephyr.a:esp_rom_wdt.*(.literal .literal.* .text .text.*)
335
336    /* [mapping:esp_mm] */
337    *libzephyr.a:esp_cache.*(.literal .literal.* .text .text.*)
338    *libzephyr.a:cache_utils.*(.literal .text .literal.* .text.*)
339
340    *libzephyr.a:bootloader_random*.*(.literal.bootloader_random_disable .text.bootloader_random_disable)
341    *libzephyr.a:bootloader_random*.*(.literal.bootloader_random_enable .text.bootloader_random_enable)
342
343#if defined(CONFIG_ESP32_WIFI_IRAM_OPT)
344    *libnet80211.a:( .wifi0iram  .wifi0iram.* .wifislpiram .wifislpiram.* .wifiextrairam .wifiextrairam.*)
345    *libpp.a:( .wifi0iram  .wifi0iram.* .wifislpiram .wifislpiram.* .wifiextrairam .wifiextrairam.*)
346    *libcoexist.a:(.wifi_slp_iram .wifi_slp_iram.*)
347
348    /* [mapping:esp_wifi] */
349    *(.literal.wifi_clock_enable_wrapper .text.wifi_clock_enable_wrapper)
350    *(.literal.wifi_clock_disable_wrapper .text.wifi_clock_disable_wrapper)
351
352    /* [mapping:esp_phy] */
353    *(.literal.esp_phy_enable .text.esp_phy_enable)
354    *(.literal.esp_phy_disable .text.esp_phy_disable)
355    *(.literal.esp_wifi_bt_power_domain_off .text.esp_wifi_bt_power_domain_off)
356#endif /* CONFIG_ESP32_WIFI_IRAM_OPT */
357
358#if defined(CONFIG_ESP32_WIFI_RX_IRAM_OPT)
359    *libnet80211.a:( .wifirxiram  .wifirxiram.* .wifislprxiram .wifislprxiram.*)
360    *libpp.a:( .wifirxiram  .wifirxiram.* .wifislprxiram .wifislprxiram.*)
361#endif /* CONFIG_ESP32_WIFI_RX_IRAM_OPT */
362
363    . = ALIGN(4) + 16;
364
365  } GROUP_DATA_LINK_IN(IRAM_REGION, ROMABLE_REGION)
366
367#ifdef CONFIG_ESP_SIMPLE_BOOT
368  .loader.text :
369  {
370    . =  ALIGN(4);
371    _loader_text_start = ABSOLUTE(.);
372    *libzephyr.a:bootloader_clock_init.*(.literal .text .literal.* .text.*)
373    *libzephyr.a:bootloader_wdt.*(.literal .text .literal.* .text.*)
374    *libzephyr.a:bootloader_flash.*(.literal .text .literal.* .text.*)
375    *libzephyr.a:bootloader_clock_loader.*(.literal .text .literal.* .text.*)
376    *libzephyr.a:bootloader_panic.*(.literal .text .literal.* .text.*)
377    *libzephyr.a:bootloader_random.*(.literal .text .literal.* .text.*)
378    *libzephyr.a:bootloader_efuse.*(.literal .text .literal.* .text.*)
379    *libzephyr.a:bootloader_utility.*(.literal .text .literal.* .text.*)
380    *libzephyr.a:bootloader_sha.*(.literal .text .literal.* .text.*)
381
382    *libzephyr.a:esp_image_format.*(.literal .text .literal.* .text.*)
383    *libzephyr.a:flash_encrypt.*(.literal .text .literal.* .text.*)
384    *libzephyr.a:flash_encryption_secure_features.*(.literal .text .literal.* .text.*)
385    *libzephyr.a:flash_partitions.*(.literal .text .literal.* .text.*)
386    *libzephyr.a:flash_qio_mode.*(.literal .text .literal.* .text.*)
387    *libzephyr.a:spi_flash_hal.*(.literal .literal.* .text .text.*)
388    *libzephyr.a:spi_flash_hal_common.*(.literal .literal.* .text .text.*)
389    *libzephyr.a:esp_flash_api.*(.literal .text .literal.* .text.*)
390    *libzephyr.a:esp_flash_spi_init.*(.literal .text .literal.* .text.*)
391
392    *libzephyr.a:esp_efuse_table.*(.literal .text .literal.* .text.*)
393    *libzephyr.a:esp_efuse_fields.*(.literal .text .literal.* .text.*)
394    *libzephyr.a:esp_efuse_api.*(.literal .text .literal.* .text.*)
395    *libzephyr.a:esp_efuse_utility.*(.literal .text .literal.* .text.*)
396    *libzephyr.a:esp_efuse_api_key_esp32xx.*(.literal .text .literal.* .text.*)
397    *libzephyr.a:secure_boot.*(.literal .text .literal.* .text.*)
398    *libzephyr.a:secure_boot_secure_features.*(.literal .text .literal.* .text.*)
399    *libzephyr.a:secure_boot_signatures_bootloader.*(.literal .text .literal.* .text.*)
400
401    *libzephyr.a:cpu_region_protect.*(.literal .text .literal.* .text.*)
402
403    /* ??? */
404    *libzephyr.a:esp_gpio_reserve.*(.literal .text .literal.* .text.*)
405
406    . = ALIGN(0x10) + 0x10;
407    _loader_text_end = ABSOLUTE(.);
408  } GROUP_DATA_LINK_IN(IRAM_REGION, ROMABLE_REGION)
409#endif /* CONFIG_ESP_SIMPLE_BOOT */
410
411  .iram0.text_end (NOLOAD) :
412  {
413    /* C3 memprot requires 512 B alignment for split lines */
414    . = ALIGN (16);
415    _iram_text_end = ABSOLUTE(.);
416  } GROUP_LINK_IN(IRAM_REGION)
417
418  .iram0.data :
419  {
420    . = ALIGN(16);
421    *(.iram.data)
422    *(.iram.data*)
423  } GROUP_DATA_LINK_IN(IRAM_REGION, ROMABLE_REGION)
424
425  .iram0.bss (NOLOAD) :
426  {
427    . = ALIGN(16);
428    *(.iram.bss)
429    *(.iram.bss*)
430
431    . = ALIGN(16);
432    _iram_end = ABSOLUTE(.);
433  } GROUP_LINK_IN(IRAM_REGION)
434
435  /* --- END OF IRAM --- */
436
437  /* --- START OF DRAM --- */
438
439  .dram0.dummy (NOLOAD):
440  {
441    /* Spacer section is required to skip .iram0.text area because
442     * iram0_0_seg and dram0_0_seg reflect the same address space on different buses.
443     */
444    . = ORIGIN(dram0_0_seg) + MAX(_iram_end, user_iram_seg_org) - user_iram_seg_org;
445    . = ALIGN(16) + 16;
446  } GROUP_LINK_IN(RAMABLE_REGION)
447
448  .dram0.data :
449  {
450    . = ALIGN(4);
451    _data_start = ABSOLUTE(.);
452    __data_start = ABSOLUTE(.);
453
454    *(.data)
455    *(.data.*)
456    *(.gnu.linkonce.d.*)
457    *(.data1)
458
459#ifdef CONFIG_RISCV_GP
460    . = ALIGN(8);
461    __global_pointer$ = . + 0x800;
462#endif /* CONFIG_RISCV_GP */
463
464    *(.sdata)
465    *(.sdata.*)
466    *(.gnu.linkonce.s.*)
467    *(.sdata2)
468    *(.sdata2.*)
469    *(.gnu.linkonce.s2.*)
470
471    /* All dependent functions should be placed in DRAM to avoid issue
472     * when flash cache is disabled */
473    *libkernel.a:fatal.*(.rodata .rodata.* .srodata .srodata.*)
474    *libkernel.a:init.*(.rodata .rodata.* .srodata .srodata.*)
475    *libzephyr.a:cbprintf_complete*(.rodata .rodata.* .srodata .srodata.*)
476    *libzephyr.a:log_core.*(.rodata .rodata.* .srodata .srodata.*)
477    *libzephyr.a:log_backend_uart.*(.rodata .rodata.* .srodata .srodata.*)
478    *libzephyr.a:log_output.*(.rodata .rodata.* .srodata .srodata.*)
479    *libdrivers__flash.a:flash_esp32.*(.rodata  .rodata.* .srodata .srodata.*)
480    *libdrivers__serial.a:uart_esp32.*(.rodata .rodata.* .srodata .srodata.*)
481    *libzephyr.a:periph_ctrl.*(.rodata .rodata.* .srodata .srodata.*)
482    *libzephyr.a:loader.*(.rodata .rodata.* .srodata .srodata.*)
483    *libzephyr.a:flash_init.*(.rodata .rodata.*)
484    *libzephyr.a:soc_flash_init.*(.rodata .rodata.*)
485    *libzephyr.a:console_init.*(.rodata .rodata.*)
486    *libzephyr.a:soc_init.*(.rodata .rodata.*)
487    *libzephyr.a:hw_init.*(.rodata .rodata.*)
488    *libzephyr.a:soc_random.*(.rodata .rodata.*)
489
490    *libzephyr.a:cache_utils.*(.rodata .rodata.* .srodata .srodata.*)
491
492    /* [mapping:hal] */
493    *libzephyr.a:mmu_hal.*(.rodata .rodata.* .srodata .srodata.*)
494    *libzephyr.a:spi_flash_hal_iram.*(.rodata .rodata.* .srodata .srodata.*)
495    *libzephyr.a:spi_flash_encrypt_hal_iram.*(.rodata .rodata.* .srodata .srodata.*)
496    *libzephyr.a:cache_hal.*(.rodata .rodata.* .srodata .srodata.*)
497    *libzephyr.a:ledc_hal_iram.*(.rodata .rodata.* .srodata .srodata.*)
498    *libzephyr.a:i2c_hal_iram.*(.rodata .rodata.* .srodata .srodata.*)
499    *libzephyr.a:wdt_hal_iram.*(.rodata .rodata.* .srodata .srodata.*)
500    *libzephyr.a:systimer_hal.*(.rodata .rodata.* .srodata .srodata.*)
501    *libzephyr.a:spi_flash_hal_gpspi.*(.rodata .rodata.* .srodata .srodata.*)
502
503    /* [mapping:soc] */
504    *libzephyr.a:lldesc.*(.rodata .rodata.* .srodata .srodata.*)
505
506    /* [mapping:log] */
507    *(.rodata.esp_log_write)
508    *(.rodata.esp_log_timestamp)
509    *(.rodata.esp_log_early_timestamp)
510    *(.rodata.esp_log_impl_lock)
511    *(.rodata.esp_log_impl_lock_timeout)
512    *(.rodata.esp_log_impl_unlock)
513
514    /* [mapping:spi_flash] */
515    *libzephyr.a:spi_flash_chip_boya.*(.rodata .rodata.* .srodata .srodata.*)
516    *libzephyr.a:spi_flash_chip_gd.*(.rodata .rodata.* .srodata .srodata.*)
517    *libzephyr.a:spi_flash_chip_generic.*(.rodata .rodata.* .srodata .srodata.*)
518    *libzephyr.a:spi_flash_chip_issi.*(.rodata .rodata.* .srodata .srodata.*)
519    *libzephyr.a:spi_flash_chip_mxic.*(.rodata .rodata.* .srodata .srodata.*)
520    *libzephyr.a:spi_flash_chip_mxic_opi.*(.rodata .rodata.* .srodata .srodata.*)
521    *libzephyr.a:spi_flash_chip_th.*(.rodata .rodata.* .srodata .srodata.*)
522    *libzephyr.a:spi_flash_chip_winbond.*(.rodata .rodata.* .srodata .srodata.*)
523    *libzephyr.a:memspi_host_driver.*(.rodata .rodata.* .srodata .srodata.*)
524    *libzephyr.a:flash_brownout_hook.*(.rodata .rodata.* .srodata .srodata.*)
525    *libzephyr.a:spi_flash_wrap.*(.rodata .rodata.* .srodata .srodata.*)
526    *libzephyr.a:spi_flash_hpm_enable.*(.rodata .rodata.* .srodata .srodata.*)
527    *libzephyr.a:flash_ops.*(.rodata .rodata.* .srodata .srodata.*)
528    *libzephyr.a:flash_qio_mode.*(.rodata .rodata.* .srodata .srodata.*)
529
530    /* [mapping:esp_mm] */
531    *libzephyr.a:esp_cache.*(.rodata .rodata.* .srodata .srodata.*)
532
533    /* [mapping:esp_hw_support] */
534    *(.rodata.esp_cpu_stall)
535    *(.rodata.esp_cpu_unstall)
536    *(.rodata.esp_cpu_reset)
537    *(.rodata.esp_cpu_wait_for_intr)
538    *(.rodata.esp_cpu_compare_and_set)
539    *(.rodata.esp_gpio_reserve_pins)
540    *(.rodata.esp_gpio_is_pin_reserved)
541    *(.rodata.rtc_vddsdio_get_config)
542    *(.rodata.rtc_vddsdio_set_config)
543    *libzephyr.a:esp_memory_utils.*(.rodata .rodata.* .srodata .srodata.*)
544    *libzephyr.a:rtc_clk.*(.rodata .rodata.* .srodata .srodata.*)
545    *libzephyr.a:rtc_clk_init.*(.rodata .rodata.* .srodata .srodata.*)
546    *libzephyr.a:systimer.*(.rodata .rodata.* .srodata .srodata.*)
547    *libzephyr.a:mspi_timing_config.*(.rodata .rodata.* .srodata .srodata.*)
548    *libzephyr.a:mspi_timing_tuning.*(.rodata .rodata.* .srodata .srodata.*)
549    *(.rodata.sar_periph_ctrl_power_enable)
550
551    /* [mapping:esp_system] */
552    *libzephyr.a:esp_err.*(.rodata .rodata.*)
553    *(.rodata.esp_system_abort)
554
555    . = ALIGN(4);
556    #include <snippets-rwdata.ld>
557    . = ALIGN(4);
558
559    KEEP(*(.jcr))
560    *(.dram1 .dram1.*)
561    . = ALIGN(4);
562  } GROUP_DATA_LINK_IN(RAMABLE_REGION, ROMABLE_REGION)
563
564#ifdef CONFIG_ESP_SIMPLE_BOOT
565  /* Secondary loader sections */
566  .loader.data :
567  {
568    . = ALIGN(4);
569    _loader_data_start = ABSOLUTE(.);
570    *libzephyr.a:bootloader_clock_init.*(.rodata .rodata.* .srodata .srodata.*)
571    *libzephyr.a:bootloader_wdt.*(.rodata .rodata.* .srodata .srodata.*)
572    *libzephyr.a:bootloader_flash.*(.srodata .srodata.* .rodata .rodata.*)
573    *libzephyr.a:bootloader_clock_loader.*(.rodata .rodata.* .srodata .srodata.*)
574    *libzephyr.a:bootloader_panic.*(.rodata .rodata.* .srodata .srodata.*)
575
576    *libzephyr.a:cpu_region_protect.*(.rodata .rodata.* .srodata .srodata.*)
577    *libzephyr.a:clk.*(.rodata .rodata.* .srodata .srodata.*)
578    *libzephyr.a:esp_clk.*(.rodata .rodata.* .srodata .srodata.*)
579    *libzephyr.a:flash_mmap.*(.rodata .rodata.* .srodata .srodata.*)
580    *libzephyr.a:flash_ops.*(.rodata .rodata.* .srodata .srodata.*)
581
582    *libzephyr.a:esp_gpio_reserve.*(.rodata .rodata.* .srodata .srodata.*)
583    *libzephyr.a:spi_flash_hal.*(.rodata .rodata.* .srodata .srodata.*)
584    *libzephyr.a:spi_flash_hal_common.*(.rodata .rodata.* .srodata .srodata.*)
585    *libzephyr.a:esp_flash_api.*(.rodata .rodata.* .srodata .srodata.*)
586    *libzephyr.a:esp_flash_spi_init.*(.rodata .rodata.* .srodata .srodata.*)
587
588    . = ALIGN(16);
589    _loader_data_end = ABSOLUTE(.);
590  } GROUP_DATA_LINK_IN(RAMABLE_REGION, ROMABLE_REGION)
591#endif /* CONFIG_ESP_SIMPLE_BOOT */
592
593  #include <snippets-data-sections.ld>
594  #include <zephyr/linker/common-ram.ld>
595  #include <snippets-ram-sections.ld>
596  #include <zephyr/linker/cplusplus-ram.ld>
597
598  /* logging sections should be placed in RAM area to avoid flash cache disabled issues */
599  #pragma push_macro("GROUP_ROM_LINK_IN")
600  #undef GROUP_ROM_LINK_IN
601  #define GROUP_ROM_LINK_IN GROUP_DATA_LINK_IN
602  #include <zephyr/linker/common-rom/common-rom-logging.ld>
603  #pragma pop_macro("GROUP_ROM_LINK_IN")
604
605  .dram0.end :
606  {
607    . = ALIGN(4);
608    _data_end = ABSOLUTE(.);
609    __data_end = ABSOLUTE(.);
610  } GROUP_DATA_LINK_IN(RAMABLE_REGION, ROMABLE_REGION)
611
612  .dram0.noinit (NOLOAD):
613  {
614    . = ALIGN(4);
615    *(.noinit)
616    *(.noinit.*)
617    . = ALIGN(4);
618  } GROUP_LINK_IN(RAMABLE_REGION)
619
620  /* Shared RAM */
621  .dram0.bss (NOLOAD) :
622  {
623    . = ALIGN (8);
624    __bss_start = ABSOLUTE(.);
625    _bss_start = ABSOLUTE(.);
626
627    /*  bluetooth library requires this symbol to be defined */
628    _btdm_bss_start = ABSOLUTE(.);
629    *libbtdm_app.a:(.bss .bss.* COMMON)
630    . = ALIGN (4);
631    _btdm_bss_end = ABSOLUTE(.);
632
633    *(.dynsbss)
634    *(.sbss)
635    *(.sbss.*)
636    *(.gnu.linkonce.sb.*)
637    *(.scommon)
638    *(.sbss2)
639    *(.sbss2.*)
640    *(.gnu.linkonce.sb2.*)
641    *(.dynbss)
642    *(.bss)
643    *(.bss.*)
644    *(.share.mem)
645    *(.gnu.linkonce.b.*)
646    *(COMMON)
647    . = ALIGN (16);
648    __bss_end = ABSOLUTE(.);
649    _bss_end = ABSOLUTE(.);
650  } GROUP_LINK_IN(RAMABLE_REGION)
651
652  /* Provide total SRAM usage, including IRAM and DRAM */
653  _image_ram_start = _iram_start - IRAM_DRAM_OFFSET;
654  #include <zephyr/linker/ram-end.ld>
655
656  ASSERT(((_end - ORIGIN(dram0_0_seg)) <= LENGTH(dram0_0_seg)), "SRAM instruction/data does not fit.")
657
658  /* --- END OF DRAM --- */
659
660  /* --- START OF .flash.text --- */
661
662  .flash.text_dummy (NOLOAD):
663  {
664    . = ALIGN(CACHE_ALIGN);
665  } GROUP_LINK_IN(ROMABLE_REGION)
666
667  /* Symbols used during the application memory mapping */
668  _image_irom_start = LOADADDR(.flash.text);
669  _image_irom_size = SIZEOF(.flash.text);
670  _image_irom_vaddr = ADDR(.flash.text);
671
672  .flash.text : ALIGN(CACHE_ALIGN)
673  {
674    _stext = .;
675    _instruction_reserved_start = ABSOLUTE(.);
676    _text_start = ABSOLUTE(.);
677    _instruction_reserved_start = ABSOLUTE(.);
678    __text_region_start = ABSOLUTE(.);
679    __rom_region_start = ABSOLUTE(.);
680
681#if !defined(CONFIG_ESP32_WIFI_IRAM_OPT)
682    *libnet80211.a:( .wifi0iram  .wifi0iram.* .wifislpiram .wifislpiram.* .wifiextrairam .wifiextrairam.*)
683    *libpp.a:( .wifi0iram  .wifi0iram.* .wifislpiram .wifislpiram.* .wifiextrairam .wifiextrairam.*)
684#endif /* CONFIG_ESP32_WIFI_IRAM_OPT */
685
686#if !defined(CONFIG_ESP32_WIFI_RX_IRAM_OPT)
687    *libnet80211.a:( .wifirxiram  .wifirxiram.* .wifislprxiram .wifislprxiram.*)
688    *libpp.a:( .wifirxiram  .wifirxiram.* .wifislprxiram .wifislprxiram.*)
689#endif /* CONFIG_ESP32_WIFI_RX_IRAM_OPT */
690
691    *(.literal .text .literal.* .text.*)
692    *(.stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*)
693    *(.irom0.text) /* catch stray ICACHE_RODATA_ATTR */
694
695    *(.fini.literal)
696    *(.fini)
697
698    *(.gnu.version)
699
700    /* CPU will try to prefetch up to 16 bytes of
701     * of instructions. This means that any configuration (e.g. MMU, PMS) must allow
702     * safe access to up to 16 bytes after the last real instruction, add
703     * dummy bytes to ensure this
704     */
705    . += 16;
706
707    _instruction_reserved_end = ABSOLUTE(.);
708    _text_end = ABSOLUTE(.);
709    _instruction_reserved_end = ABSOLUTE(.);
710    __text_region_end = ABSOLUTE(.);
711    __rom_region_end = ABSOLUTE(.);
712    _etext = .;
713
714  } GROUP_DATA_LINK_IN(FLASH_CODE_REGION, ROMABLE_REGION)
715
716  /* --- END OF .flash.text --- */
717
718  /* --- START OF .rodata --- */
719
720  /* Align next section to 64k to allow mapping */
721  .flash.dummy (NOLOAD) :
722  {
723    . = ALIGN(CACHE_ALIGN);
724  } GROUP_LINK_IN(ROMABLE_REGION)
725
726  .flash.rodata_dummy (NOLOAD) :
727  {
728    /* Spacer in the IROM address to avoid interfering with the DROM address
729     * because DROM and IROM regions share the same address space */
730    . += SIZEOF(.flash.text);
731    . = ALIGN(CACHE_ALIGN);
732  } GROUP_LINK_IN(RODATA_REGION)
733
734  /* Symbols used during the application memory mapping */
735  _image_drom_start = LOADADDR(.flash.rodata);
736  _image_drom_size = _image_rodata_end - _image_rodata_start;
737  _image_drom_vaddr = ADDR(.flash.rodata);
738
739  .flash.rodata : ALIGN(0x10)
740  {
741    _rodata_reserved_start = ABSOLUTE(.);
742    _image_rodata_start = ABSOLUTE(.);
743
744    *(.rodata_desc .rodata_desc.*)
745    *(.rodata_custom_desc .rodata_custom_desc.*)
746
747    __rodata_region_start = ABSOLUTE(.);
748
749    . = ALIGN(4);
750    #include <snippets-rodata.ld>
751
752    *(.irom1.text) /* catch stray ICACHE_RODATA_ATTR */
753    *(.gnu.linkonce.r.*)
754    *(.rodata1)
755    __XT_EXCEPTION_TABLE_ = ABSOLUTE(.);
756    *(.xt_except_table)
757    *(.gcc_except_table .gcc_except_table.*)
758    *(.gnu.linkonce.e.*)
759    *(.gnu.version_r)
760    . = (. + 3) & ~ 3;
761    __eh_frame = ABSOLUTE(.);
762    KEEP(*(.eh_frame))
763    . = (. + 7) & ~ 3;
764
765    /* C++ exception handlers table: */
766    __XT_EXCEPTION_DESCS_ = ABSOLUTE(.);
767    *(.xt_except_desc)
768    *(.gnu.linkonce.h.*)
769    __XT_EXCEPTION_DESCS_END__ = ABSOLUTE(.);
770    *(.xt_except_desc_end)
771    *(.dynamic)
772    *(.gnu.version_d)
773    __rodata_region_end = ABSOLUTE(.);
774    _rodata_end = ABSOLUTE(.);
775    /* Literals are also RO data. */
776    _lit4_start = ABSOLUTE(.);
777    *(*.lit4)
778    *(.lit4.*)
779    *(.gnu.linkonce.lit4.*)
780    _lit4_end = ABSOLUTE(.);
781    . = ALIGN(4);
782    *(.srodata)
783    *(.srodata.*)
784    *(.rodata)
785    *(.rodata.*)
786    *(.rodata_wlog)
787    *(.rodata_wlog*)
788    . = ALIGN(4);
789  } GROUP_DATA_LINK_IN(RODATA_REGION, ROMABLE_REGION)
790
791  #include <zephyr/linker/cplusplus-rom.ld>
792  #include <zephyr/linker/common-rom/common-rom-init.ld>
793  #include <zephyr/linker/common-rom/common-rom-kernel-devices.ld>
794  #include <zephyr/linker/common-rom/common-rom-ztest.ld>
795  #include <zephyr/linker/common-rom/common-rom-net.ld>
796  #include <zephyr/linker/common-rom/common-rom-bt.ld>
797  #include <zephyr/linker/common-rom/common-rom-debug.ld>
798  #include <zephyr/linker/common-rom/common-rom-misc.ld>
799  #include <zephyr/linker/thread-local-storage.ld>
800  #include <snippets-sections.ld>
801
802  /* Create an explicit section at the end of all the data that shall be mapped into drom.
803   * This is used to calculate the size of the _image_drom_size variable */
804  .flash.rodata_end : ALIGN(0x10)
805  {
806    . = ALIGN(4);
807    _rodata_reserved_end = ABSOLUTE(.);
808    _image_rodata_end = ABSOLUTE(.);
809  } GROUP_DATA_LINK_IN(RODATA_REGION, ROMABLE_REGION)
810
811  /* --- END OF .rodata --- */
812
813#ifdef CONFIG_GEN_ISR_TABLES
814  #include <zephyr/linker/intlist.ld>
815#endif
816
817  #include <zephyr/linker/debug-sections.ld>
818  /DISCARD/ : { *(.note.GNU-stack) }
819
820  SECTION_PROLOGUE(.riscv.attributes, 0,)
821    {
822    KEEP(*(.riscv.attributes))
823    KEEP(*(.gnu.attributes))
824    }
825}
826