esp32s2.ld 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /* ESP32S2 Linker Script Memory Layout
  2. This file describes the memory layout (memory blocks) by virtual memory addresses.
  3. This linker script is passed through the C preprocessor to include configuration options.
  4. Please use preprocessor features sparingly!
  5. Restrict to simple macros with numeric values, and/or #if/#endif blocks.
  6. */
  7. #include "sdkconfig.h"
  8. #ifdef CONFIG_BOOTLOADER_CUSTOM_RESERVE_RTC
  9. #define ESP_BOOTLOADER_RESERVE_RTC (CONFIG_BOOTLOADER_RESERVE_RTC_SIZE + CONFIG_BOOTLOADER_CUSTOM_RESERVE_RTC_SIZE)
  10. #elif defined(CONFIG_BOOTLOADER_SKIP_VALIDATE_IN_DEEP_SLEEP)
  11. #define ESP_BOOTLOADER_RESERVE_RTC (CONFIG_BOOTLOADER_RESERVE_RTC_SIZE)
  12. #else
  13. #define ESP_BOOTLOADER_RESERVE_RTC 0
  14. #endif
  15. #ifdef CONFIG_ESP32S2_INSTRUCTION_CACHE_8KB
  16. #define CONFIG_ESP32S2_INSTRUCTION_CACHE_SIZE 0x2000
  17. #else
  18. #define CONFIG_ESP32S2_INSTRUCTION_CACHE_SIZE 0x4000
  19. #endif
  20. #ifdef CONFIG_ESP32S2_DATA_CACHE_0KB
  21. #define CONFIG_ESP32S2_DATA_CACHE_SIZE 0
  22. #elif defined CONFIG_ESP32S2_DATA_CACHE_8KB
  23. #define CONFIG_ESP32S2_DATA_CACHE_SIZE 0x2000
  24. #else
  25. #define CONFIG_ESP32S2_DATA_CACHE_SIZE 0x4000
  26. #endif
  27. #define RAM_IRAM_START 0x40020000
  28. #define RAM_DRAM_START 0x3FFB0000
  29. #define DATA_RAM_END 0x3FFE0000 /* 2nd stage bootloader iram_loader_seg starts at SRAM block 14 (reclaimed after app boots) */
  30. #define IRAM_ORG (RAM_IRAM_START + CONFIG_ESP32S2_INSTRUCTION_CACHE_SIZE \
  31. + CONFIG_ESP32S2_DATA_CACHE_SIZE)
  32. #define DRAM_ORG (RAM_DRAM_START + CONFIG_ESP32S2_INSTRUCTION_CACHE_SIZE \
  33. + CONFIG_ESP32S2_DATA_CACHE_SIZE)
  34. #define I_D_RAM_SIZE DATA_RAM_END - DRAM_ORG
  35. MEMORY
  36. {
  37. /* All these values assume the flash cache is on, and have the blocks this uses subtracted from the length
  38. of the various regions. The 'data access port' dram/drom regions map to the same iram/irom regions but
  39. are connected to the data port of the CPU and eg allow bytewise access. */
  40. /* IRAM for CPU.*/
  41. iram0_0_seg (RX) : org = IRAM_ORG, len = I_D_RAM_SIZE
  42. #ifdef CONFIG_APP_BUILD_USE_FLASH_SECTIONS
  43. /* Even though the segment name is iram, it is actually mapped to flash
  44. */
  45. iram0_2_seg (RX) : org = 0x40080020, len = 0x780000-0x20
  46. /*
  47. (0x20 offset above is a convenience for the app binary image generation.
  48. Flash cache has 64KB pages. The .bin file which is flashed to the chip
  49. has a 0x18 byte file header, and each segment has a 0x08 byte segment
  50. header. Setting this offset makes it simple to meet the flash cache MMU's
  51. constraint that (paddr % 64KB == vaddr % 64KB).)
  52. */
  53. #endif // CONFIG_APP_BUILD_USE_FLASH_SECTIONS
  54. /* Shared data RAM, excluding memory reserved for bootloader and ROM bss/data/stack. */
  55. dram0_0_seg (RW) : org = DRAM_ORG, len = I_D_RAM_SIZE
  56. #ifdef CONFIG_APP_BUILD_USE_FLASH_SECTIONS
  57. /* Flash mapped constant data */
  58. drom0_0_seg (R) : org = 0x3F000020, len = 0x3f0000-0x20
  59. /* (See iram0_2_seg for meaning of 0x20 offset in the above.) */
  60. #endif // CONFIG_APP_BUILD_USE_FLASH_SECTIONS
  61. /* RTC fast memory (executable). Persists over deep sleep.
  62. */
  63. rtc_iram_seg(RWX) : org = 0x40070000, len = 0x2000
  64. /* RTC slow memory (data accessible). Persists over deep sleep.
  65. Start of RTC slow memory is reserved for ULP co-processor code + data, if enabled.
  66. */
  67. rtc_slow_seg(RW) : org = 0x50000000 + CONFIG_ESP32S2_ULP_COPROC_RESERVE_MEM,
  68. len = 0x2000 - CONFIG_ESP32S2_ULP_COPROC_RESERVE_MEM
  69. /* RTC fast memory (same block as above), viewed from data bus */
  70. rtc_data_seg(RW) : org = 0x3ff9e000, len = 0x2000 - ESP_BOOTLOADER_RESERVE_RTC
  71. }
  72. _static_data_end = _bss_end;
  73. _heap_end = 0x40000000;
  74. _data_seg_org = ORIGIN(rtc_data_seg);
  75. /* The lines below define location alias for .rtc.data section based on Kconfig option.
  76. When the option is not defined then use slow memory segment
  77. else the data will be placed in fast memory segment
  78. TODO: check whether the rtc_data_location is correct for esp32s2 - IDF-761 */
  79. #ifndef CONFIG_ESP32S2_RTCDATA_IN_FAST_MEM
  80. REGION_ALIAS("rtc_data_location", rtc_slow_seg );
  81. #else
  82. REGION_ALIAS("rtc_data_location", rtc_data_seg );
  83. #endif
  84. #ifdef CONFIG_APP_BUILD_USE_FLASH_SECTIONS
  85. REGION_ALIAS("default_code_seg", iram0_2_seg);
  86. #else
  87. REGION_ALIAS("default_code_seg", iram0_0_seg);
  88. #endif // CONFIG_APP_BUILD_USE_FLASH_SECTIONS
  89. #ifdef CONFIG_APP_BUILD_USE_FLASH_SECTIONS
  90. REGION_ALIAS("default_rodata_seg", drom0_0_seg);
  91. #else
  92. REGION_ALIAS("default_rodata_seg", dram0_0_seg);
  93. #endif // CONFIG_APP_BUILD_USE_FLASH_SECTIONS
  94. /**
  95. * If rodata default segment is placed in `drom0_0_seg`, then flash's first rodata section must
  96. * also be first in the segment.
  97. */
  98. #ifdef CONFIG_APP_BUILD_USE_FLASH_SECTIONS
  99. ASSERT(_rodata_reserved_start == ORIGIN(default_rodata_seg),
  100. ".flash.appdesc section must be placed at the beginning of the rodata segment.")
  101. #endif