memory.ld.in 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /*
  2. * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /* ESP32S2 Linker Script Memory Layout
  7. This file describes the memory layout (memory blocks) by virtual memory addresses.
  8. This linker script is passed through the C preprocessor to include configuration options.
  9. Please use preprocessor features sparingly!
  10. Restrict to simple macros with numeric values, and/or #if/#endif blocks.
  11. */
  12. #include "sdkconfig.h"
  13. #include "ld.common"
  14. #ifdef CONFIG_ESP32S2_INSTRUCTION_CACHE_8KB
  15. #define CONFIG_ESP32S2_INSTRUCTION_CACHE_SIZE 0x2000
  16. #else
  17. #define CONFIG_ESP32S2_INSTRUCTION_CACHE_SIZE 0x4000
  18. #endif
  19. #ifdef CONFIG_ESP32S2_DATA_CACHE_0KB
  20. #define CONFIG_ESP32S2_DATA_CACHE_SIZE 0
  21. #elif defined CONFIG_ESP32S2_DATA_CACHE_8KB
  22. #define CONFIG_ESP32S2_DATA_CACHE_SIZE 0x2000
  23. #else
  24. #define CONFIG_ESP32S2_DATA_CACHE_SIZE 0x4000
  25. #endif
  26. #define RAM_IRAM_START 0x40020000
  27. #define RAM_DRAM_START 0x3FFB0000
  28. #define DATA_RAM_END 0x3FFDF000 /* 2nd stage bootloader iram_loader_seg starts at end of block 13 (reclaimed after app boots) */
  29. #define IRAM_ORG (RAM_IRAM_START + CONFIG_ESP32S2_INSTRUCTION_CACHE_SIZE \
  30. + CONFIG_ESP32S2_DATA_CACHE_SIZE)
  31. #define DRAM_ORG (RAM_DRAM_START + CONFIG_ESP32S2_INSTRUCTION_CACHE_SIZE \
  32. + CONFIG_ESP32S2_DATA_CACHE_SIZE)
  33. #define I_D_RAM_SIZE DATA_RAM_END - DRAM_ORG
  34. #if CONFIG_ESP32S2_USE_FIXED_STATIC_RAM_SIZE
  35. ASSERT((CONFIG_ESP32S2_FIXED_STATIC_RAM_SIZE <= I_D_RAM_SIZE), "Fixed static ram data does not fit.")
  36. #define DRAM0_0_SEG_LEN CONFIG_ESP32S2_FIXED_STATIC_RAM_SIZE
  37. #else
  38. #define DRAM0_0_SEG_LEN I_D_RAM_SIZE
  39. #endif // CONFIG_ESP32S2_USE_FIXED_STATIC_RAM_SIZE
  40. MEMORY
  41. {
  42. /* All these values assume the flash cache is on, and have the blocks this uses subtracted from the length
  43. of the various regions. The 'data access port' dram/drom regions map to the same iram/irom regions but
  44. are connected to the data port of the CPU and eg allow bytewise access. */
  45. /* IRAM for CPU.*/
  46. iram0_0_seg (RX) : org = IRAM_ORG, len = I_D_RAM_SIZE
  47. #ifdef CONFIG_APP_BUILD_USE_FLASH_SECTIONS
  48. /* Even though the segment name is iram, it is actually mapped to flash
  49. */
  50. iram0_2_seg (RX) : org = 0x40080020, len = 0x780000-0x20
  51. /*
  52. (0x20 offset above is a convenience for the app binary image generation.
  53. Flash cache has 64KB pages. The .bin file which is flashed to the chip
  54. has a 0x18 byte file header, and each segment has a 0x08 byte segment
  55. header. Setting this offset makes it simple to meet the flash cache MMU's
  56. constraint that (paddr % 64KB == vaddr % 64KB).)
  57. */
  58. #endif // CONFIG_APP_BUILD_USE_FLASH_SECTIONS
  59. /* Shared data RAM, excluding memory reserved for bootloader and ROM bss/data/stack. */
  60. dram0_0_seg (RW) : org = DRAM_ORG, len = DRAM0_0_SEG_LEN
  61. #ifdef CONFIG_APP_BUILD_USE_FLASH_SECTIONS
  62. /* Flash mapped constant data */
  63. drom0_0_seg (R) : org = 0x3F000020, len = 0x3f0000-0x20
  64. /* (See iram0_2_seg for meaning of 0x20 offset in the above.) */
  65. #endif // CONFIG_APP_BUILD_USE_FLASH_SECTIONS
  66. /* RTC fast memory (executable). Persists over deep sleep.
  67. */
  68. rtc_iram_seg(RWX) : org = 0x40070000, len = 0x2000 - RESERVE_RTC_MEM
  69. /* RTC slow memory (data accessible). Persists over deep sleep.
  70. Start of RTC slow memory is reserved for ULP co-processor code + data, if enabled.
  71. */
  72. #if CONFIG_ULP_COPROC_ENABLED
  73. rtc_slow_seg(RW) : org = 0x50000000 + CONFIG_ULP_COPROC_RESERVE_MEM,
  74. len = 0x2000 - CONFIG_ULP_COPROC_RESERVE_MEM
  75. #else
  76. rtc_slow_seg(RW) : org = 0x50000000, len = 0x2000
  77. #endif // CONFIG_ULP_COPROC_ENABLED
  78. /* RTC fast memory (same block as above, rtc_iram_seg), viewed from data bus */
  79. rtc_data_seg(RW) : org = 0x3ff9e000, len = 0x2000 - RESERVE_RTC_MEM
  80. /* We reduced the size of rtc_data_seg and rtc_iram_seg by RESERVE_RTC_MEM value.
  81. It reserves the amount of RTC fast memory that we use for this memory segment.
  82. This segment is intended for keeping:
  83. - (lower addr) rtc timer data (s_rtc_timer_retain_mem, see esp_clk.c files).
  84. - (higher addr) bootloader rtc data (s_bootloader_retain_mem, when a Kconfig option is on).
  85. The aim of this is to keep data that will not be moved around and have a fixed address.
  86. */
  87. rtc_reserved_seg(RW) : org = 0x3ff9e000 + 0x2000 - RESERVE_RTC_MEM, len = RESERVE_RTC_MEM
  88. /* external memory, covers the dport, dram0, dram1 cacheable address space */
  89. extern_ram_seg(RWX) : org = 0x3F800000,
  90. len = 0x780000
  91. }
  92. #if defined(CONFIG_ESP32S2_USE_FIXED_STATIC_RAM_SIZE)
  93. /* static data ends at defined address */
  94. _heap_start = DRAM_ORG + DRAM0_0_SEG_LEN;
  95. #else
  96. _heap_start = _heap_low_start;
  97. #endif
  98. _heap_end = 0x40000000;
  99. _data_seg_org = ORIGIN(rtc_data_seg);
  100. /* The lines below define location alias for .rtc.data section based on Kconfig option.
  101. When the option is not defined then use slow memory segment
  102. else the data will be placed in fast memory segment
  103. TODO: check whether the rtc_data_location is correct for esp32s2 - IDF-761 */
  104. #ifndef CONFIG_ESP32S2_RTCDATA_IN_FAST_MEM
  105. REGION_ALIAS("rtc_data_location", rtc_slow_seg );
  106. #else
  107. REGION_ALIAS("rtc_data_location", rtc_data_seg );
  108. #endif
  109. #ifdef CONFIG_APP_BUILD_USE_FLASH_SECTIONS
  110. REGION_ALIAS("default_code_seg", iram0_2_seg);
  111. #else
  112. REGION_ALIAS("default_code_seg", iram0_0_seg);
  113. #endif // CONFIG_APP_BUILD_USE_FLASH_SECTIONS
  114. #ifdef CONFIG_APP_BUILD_USE_FLASH_SECTIONS
  115. REGION_ALIAS("default_rodata_seg", drom0_0_seg);
  116. #else
  117. REGION_ALIAS("default_rodata_seg", dram0_0_seg);
  118. #endif // CONFIG_APP_BUILD_USE_FLASH_SECTIONS
  119. /**
  120. * If rodata default segment is placed in `drom0_0_seg`, then flash's first rodata section must
  121. * also be first in the segment.
  122. */
  123. #ifdef CONFIG_APP_BUILD_USE_FLASH_SECTIONS
  124. ASSERT(_rodata_reserved_start == ORIGIN(default_rodata_seg),
  125. ".flash.appdesc section must be placed at the beginning of the rodata segment.")
  126. #endif