memory.ld.in 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*
  2. * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /**
  7. * ESP32-S3 Linker Script Memory Layout
  8. * This file describes the memory layout (memory blocks) by virtual memory addresses.
  9. * This linker script is passed through the C preprocessor to include configuration options.
  10. * Please use preprocessor features sparingly!
  11. * Restrict to simple macros with numeric values, and/or #if/#endif blocks.
  12. */
  13. #include "sdkconfig.h"
  14. #include "ld.common"
  15. /*
  16. * 40370000 <- IRAM/Icache -> 40378000 <- D/IRAM (I) -> 403E0000
  17. * 3FC88000 <- D/IRAM (D) -> 3FCF0000 <- DRAM/DCache -> 3FD00000
  18. *
  19. * Startup code uses the IRAM from 0x403B9000 to 0x403E0000, which is not available for static
  20. * memory, but can only be used after app starts.
  21. *
  22. * D cache use the memory from high address, so when it's configured to 16K/32K, the region
  23. * 0x3FCF000 ~ (3FD00000 - DATA_CACHE_SIZE) should be available. This region is not used as
  24. * static memory, leaving to the heap.
  25. */
  26. #define SRAM_IRAM_START 0x40370000
  27. #define SRAM_DIRAM_I_START 0x40378000
  28. #define SRAM_IRAM_END 0x403CC700 /* Please refer to ESP32-S3 bootloader.ld for more information on this */
  29. #define I_D_SRAM_OFFSET (SRAM_DIRAM_I_START - SRAM_DRAM_START)
  30. #define SRAM_DRAM_START 0x3FC88000
  31. #define SRAM_DRAM_END (SRAM_IRAM_END - I_D_SRAM_OFFSET) /* 2nd stage bootloader iram_loader_seg start address */
  32. #define I_D_SRAM_SIZE (SRAM_DRAM_END - SRAM_DRAM_START)
  33. #define ICACHE_SIZE 0x8000
  34. #define SRAM_IRAM_ORG (SRAM_IRAM_START + CONFIG_ESP32S3_INSTRUCTION_CACHE_SIZE)
  35. #define SRAM_IRAM_SIZE (I_D_SRAM_SIZE + ICACHE_SIZE - CONFIG_ESP32S3_INSTRUCTION_CACHE_SIZE)
  36. #define DCACHE_SIZE 0x10000
  37. #define SRAM_DRAM_ORG (SRAM_DRAM_START)
  38. #if CONFIG_ESP32S3_USE_FIXED_STATIC_RAM_SIZE
  39. ASSERT((CONFIG_ESP32S3_FIXED_STATIC_RAM_SIZE <= I_D_SRAM_SIZE), "Fixed static ram data does not fit.")
  40. #define DRAM0_0_SEG_LEN CONFIG_ESP32S3_FIXED_STATIC_RAM_SIZE
  41. #else
  42. #define DRAM0_0_SEG_LEN I_D_SRAM_SIZE
  43. #endif // CONFIG_ESP32S3_USE_FIXED_STATIC_RAM_SIZE
  44. MEMORY
  45. {
  46. /**
  47. * All these values assume the flash cache is on, and have the blocks this uses subtracted from the length
  48. * of the various regions. The 'data access port' dram/drom regions map to the same iram/irom regions but
  49. * are connected to the data port of the CPU and eg allow byte-wise access.
  50. */
  51. /* IRAM for PRO CPU. */
  52. iram0_0_seg (RX) : org = SRAM_IRAM_ORG, len = SRAM_IRAM_SIZE
  53. #if CONFIG_APP_BUILD_USE_FLASH_SECTIONS
  54. /* Flash mapped instruction data */
  55. iram0_2_seg (RX) : org = 0x42000020, len = 0x800000-0x20
  56. /**
  57. * (0x20 offset above is a convenience for the app binary image generation.
  58. * Flash cache has 64KB pages. The .bin file which is flashed to the chip
  59. * has a 0x18 byte file header, and each segment has a 0x08 byte segment
  60. * header. Setting this offset makes it simple to meet the flash cache MMU's
  61. * constraint that (paddr % 64KB == vaddr % 64KB).)
  62. */
  63. #endif // CONFIG_APP_BUILD_USE_FLASH_SECTIONS
  64. /**
  65. * Shared data RAM, excluding memory reserved for ROM bss/data/stack.
  66. * Enabling Bluetooth & Trace Memory features in menuconfig will decrease the amount of RAM available.
  67. */
  68. dram0_0_seg (RW) : org = SRAM_DRAM_ORG, len = DRAM0_0_SEG_LEN
  69. #if CONFIG_APP_BUILD_USE_FLASH_SECTIONS
  70. /* Flash mapped constant data */
  71. drom0_0_seg (R) : org = 0x3C000020, len = 0x2000000-0x20
  72. /* (See iram0_2_seg for meaning of 0x20 offset in the above.) */
  73. #endif // CONFIG_APP_BUILD_USE_FLASH_SECTIONS
  74. /**
  75. * RTC fast memory (executable). Persists over deep sleep.
  76. */
  77. rtc_iram_seg(RWX) : org = 0x600fe000, len = 0x2000 - RESERVE_RTC_MEM
  78. /* We reduced the size of rtc_iram_seg by RESERVE_RTC_MEM value.
  79. It reserves the amount of RTC fast memory that we use for this memory segment.
  80. This segment is intended for keeping:
  81. - (lower addr) rtc timer data (s_rtc_timer_retain_mem, see esp_clk.c files).
  82. - (higher addr) bootloader rtc data (s_bootloader_retain_mem, when a Kconfig option is on).
  83. The aim of this is to keep data that will not be moved around and have a fixed address.
  84. */
  85. rtc_reserved_seg(RW) : org = 0x600fe000 + 0x2000 - RESERVE_RTC_MEM, len = RESERVE_RTC_MEM
  86. /**
  87. * RTC slow memory (data accessible). Persists over deep sleep.
  88. * Start of RTC slow memory is reserved for ULP co-processor code + data, if enabled.
  89. */
  90. #if CONFIG_ULP_COPROC_ENABLED
  91. rtc_slow_seg(RW) : org = 0x50000000 + CONFIG_ULP_COPROC_RESERVE_MEM,
  92. len = 0x2000 - CONFIG_ULP_COPROC_RESERVE_MEM
  93. #else
  94. rtc_slow_seg(RW) : org = 0x50000000 , len = 0x2000
  95. #endif // CONFIG_ULP_COPROC_ENABLED
  96. /**
  97. * `extern_ram_seg` and `drom0_0_seg` share the same bus and the address region.
  98. * A dummy section is used to avoid overlap. See `.ext_ram.dummy` in `sections.ld.in`
  99. */
  100. extern_ram_seg(RWX) : org = 0x3c000020 , len = 0x2000000-0x20
  101. }
  102. #if CONFIG_ESP32S3_USE_FIXED_STATIC_RAM_SIZE
  103. /* static data ends at defined address */
  104. _heap_start = SRAM_DRAM_ORG + DRAM0_0_SEG_LEN;
  105. #else
  106. _heap_start = _heap_low_start;
  107. #endif // CONFIG_ESP32S3_USE_FIXED_STATIC_RAM_SIZE
  108. /* Heap ends at top of dram0_0_seg */
  109. _heap_end = 0x40000000;
  110. _data_seg_org = ORIGIN(rtc_data_seg);
  111. /* RTC fast memory shares the same range for both data and instructions */
  112. REGION_ALIAS("rtc_data_seg", rtc_iram_seg );
  113. #if CONFIG_ESP32S3_RTCDATA_IN_FAST_MEM
  114. REGION_ALIAS("rtc_data_location", rtc_data_seg );
  115. #else
  116. REGION_ALIAS("rtc_data_location", rtc_slow_seg );
  117. #endif // CONFIG_ESP32S3_RTCDATA_IN_FAST_MEM
  118. #if CONFIG_APP_BUILD_USE_FLASH_SECTIONS
  119. REGION_ALIAS("default_code_seg", iram0_2_seg);
  120. #else
  121. REGION_ALIAS("default_code_seg", iram0_0_seg);
  122. #endif // CONFIG_APP_BUILD_USE_FLASH_SECTIONS
  123. #if CONFIG_APP_BUILD_USE_FLASH_SECTIONS
  124. REGION_ALIAS("default_rodata_seg", drom0_0_seg);
  125. #else
  126. REGION_ALIAS("default_rodata_seg", dram0_0_seg);
  127. #endif // CONFIG_APP_BUILD_USE_FLASH_SECTIONS
  128. /**
  129. * If rodata default segment is placed in `drom0_0_seg`, then flash's first rodata section must
  130. * also be first in the segment.
  131. */
  132. #if CONFIG_APP_BUILD_USE_FLASH_SECTIONS
  133. ASSERT(_flash_rodata_dummy_start == ORIGIN(default_rodata_seg),
  134. ".flash_rodata_dummy section must be placed at the beginning of the rodata segment.")
  135. #endif