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