memory.ld.in 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. #ifdef CONFIG_BOOTLOADER_CUSTOM_RESERVE_RTC
  16. #define ESP_BOOTLOADER_RESERVE_RTC (CONFIG_BOOTLOADER_RESERVE_RTC_SIZE + CONFIG_BOOTLOADER_CUSTOM_RESERVE_RTC_SIZE)
  17. #elif defined(CONFIG_BOOTLOADER_SKIP_VALIDATE_IN_DEEP_SLEEP)
  18. #define ESP_BOOTLOADER_RESERVE_RTC (CONFIG_BOOTLOADER_RESERVE_RTC_SIZE)
  19. #else
  20. #define ESP_BOOTLOADER_RESERVE_RTC 0
  21. #endif
  22. /*
  23. * 40370000 <- IRAM/Icache -> 40378000 <- D/IRAM (I) -> 403E0000
  24. * 3FC88000 <- D/IRAM (D) -> 3FCF0000 <- DRAM/DCache -> 3FD00000
  25. *
  26. * Startup code uses the IRAM from 0x403BA000 to 0x403E0000, which is not available for static
  27. * memory, but can only be used after app starts.
  28. *
  29. * D cache use the memory from high address, so when it's configured to 16K/32K, the region
  30. * 0x3FCF000 ~ (3FD00000 - DATA_CACHE_SIZE) should be available. This region is not used as
  31. * static memory, leaving to the heap.
  32. */
  33. #define SRAM_IRAM_START 0x40370000
  34. #define SRAM_DIRAM_I_START 0x40378000
  35. #define SRAM_IRAM_END 0x403BA000
  36. #define I_D_SRAM_OFFSET (SRAM_DIRAM_I_START - SRAM_DRAM_START)
  37. #define SRAM_DRAM_START 0x3FC88000
  38. #define SRAM_DRAM_END (SRAM_IRAM_END - I_D_SRAM_OFFSET) /* 2nd stage bootloader iram_loader_seg start address */
  39. #define I_D_SRAM_SIZE (SRAM_DRAM_END - SRAM_DRAM_START)
  40. #define ICACHE_SIZE 0x8000
  41. #define SRAM_IRAM_ORG (SRAM_IRAM_START + CONFIG_ESP32S3_INSTRUCTION_CACHE_SIZE)
  42. #define SRAM_IRAM_SIZE (I_D_SRAM_SIZE + ICACHE_SIZE - CONFIG_ESP32S3_INSTRUCTION_CACHE_SIZE)
  43. #define DCACHE_SIZE 0x10000
  44. #define SRAM_DRAM_ORG (SRAM_DRAM_START)
  45. #if CONFIG_ESP32S3_USE_FIXED_STATIC_RAM_SIZE
  46. ASSERT((CONFIG_ESP32S3_FIXED_STATIC_RAM_SIZE <= I_D_SRAM_SIZE), "Fixed static ram data does not fit.")
  47. #define DRAM0_0_SEG_LEN CONFIG_ESP32S3_FIXED_STATIC_RAM_SIZE
  48. #else
  49. #define DRAM0_0_SEG_LEN I_D_SRAM_SIZE
  50. #endif // CONFIG_ESP32S3_USE_FIXED_STATIC_RAM_SIZE
  51. MEMORY
  52. {
  53. /**
  54. * All these values assume the flash cache is on, and have the blocks this uses subtracted from the length
  55. * of the various regions. The 'data access port' dram/drom regions map to the same iram/irom regions but
  56. * are connected to the data port of the CPU and eg allow byte-wise access.
  57. */
  58. /* IRAM for PRO CPU. */
  59. iram0_0_seg (RX) : org = SRAM_IRAM_ORG, len = SRAM_IRAM_SIZE
  60. #if CONFIG_APP_BUILD_USE_FLASH_SECTIONS
  61. /* Flash mapped instruction data */
  62. iram0_2_seg (RX) : org = 0x42000020, len = 0x800000-0x20
  63. /**
  64. * (0x20 offset above is a convenience for the app binary image generation.
  65. * Flash cache has 64KB pages. The .bin file which is flashed to the chip
  66. * has a 0x18 byte file header, and each segment has a 0x08 byte segment
  67. * header. Setting this offset makes it simple to meet the flash cache MMU's
  68. * constraint that (paddr % 64KB == vaddr % 64KB).)
  69. */
  70. #endif // CONFIG_APP_BUILD_USE_FLASH_SECTIONS
  71. /**
  72. * Shared data RAM, excluding memory reserved for ROM bss/data/stack.
  73. * Enabling Bluetooth & Trace Memory features in menuconfig will decrease the amount of RAM available.
  74. */
  75. dram0_0_seg (RW) : org = SRAM_DRAM_ORG, len = DRAM0_0_SEG_LEN
  76. #if CONFIG_APP_BUILD_USE_FLASH_SECTIONS
  77. /* Flash mapped constant data */
  78. drom0_0_seg (R) : org = 0x3C000020, len = 0x800000-0x20
  79. /* (See iram0_2_seg for meaning of 0x20 offset in the above.) */
  80. #endif // CONFIG_APP_BUILD_USE_FLASH_SECTIONS
  81. /**
  82. * RTC fast memory (executable). Persists over deep sleep.
  83. */
  84. rtc_iram_seg(RWX) : org = 0x600fe000, len = 0x2000 - ESP_BOOTLOADER_RESERVE_RTC
  85. /**
  86. * RTC fast memory (same block as above), viewed from data bus
  87. */
  88. rtc_data_seg(RW) : org = 0x600fe000, len = 0x2000 - ESP_BOOTLOADER_RESERVE_RTC
  89. /**
  90. * RTC slow memory (data accessible). Persists over deep sleep.
  91. * Start of RTC slow memory is reserved for ULP co-processor code + data, if enabled.
  92. */
  93. rtc_slow_seg(RW) : org = 0x50000000 + CONFIG_ESP32S3_ULP_COPROC_RESERVE_MEM,
  94. len = 0x2000 - CONFIG_ESP32S3_ULP_COPROC_RESERVE_MEM
  95. }
  96. #if CONFIG_ESP32S3_USE_FIXED_STATIC_RAM_SIZE
  97. /* static data ends at defined address */
  98. _static_data_end = 0x3FCA0000 + DRAM0_0_SEG_LEN;
  99. #else
  100. _static_data_end = _bss_end;
  101. #endif // CONFIG_ESP32S3_USE_FIXED_STATIC_RAM_SIZE
  102. /* Heap ends at top of dram0_0_seg */
  103. _heap_end = 0x40000000;
  104. _data_seg_org = ORIGIN(rtc_data_seg);
  105. #if CONFIG_ESP32S3_RTCDATA_IN_FAST_MEM
  106. REGION_ALIAS("rtc_data_location", rtc_data_seg );
  107. #else
  108. REGION_ALIAS("rtc_data_location", rtc_slow_seg );
  109. #endif // CONFIG_ESP32S3_RTCDATA_IN_FAST_MEM
  110. #if CONFIG_APP_BUILD_USE_FLASH_SECTIONS
  111. REGION_ALIAS("default_code_seg", iram0_2_seg);
  112. #else
  113. REGION_ALIAS("default_code_seg", iram0_0_seg);
  114. #endif // CONFIG_APP_BUILD_USE_FLASH_SECTIONS
  115. #if CONFIG_APP_BUILD_USE_FLASH_SECTIONS
  116. REGION_ALIAS("default_rodata_seg", drom0_0_seg);
  117. #else
  118. REGION_ALIAS("default_rodata_seg", dram0_0_seg);
  119. #endif // CONFIG_APP_BUILD_USE_FLASH_SECTIONS
  120. /**
  121. * If rodata default segment is placed in `drom0_0_seg`, then flash's first rodata section must
  122. * also be first in the segment.
  123. */
  124. #if CONFIG_APP_BUILD_USE_FLASH_SECTIONS
  125. ASSERT(_flash_rodata_dummy_start == ORIGIN(default_rodata_seg),
  126. ".flash_rodata_dummy section must be placed at the beginning of the rodata segment.")
  127. #endif