memory.ld.in 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /**
  7. * ESP32-C6 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. * physical memory is mapped twice to the vritual address (IRAM and DRAM).
  17. * `I_D_SRAM_OFFSET` is the offset between the two locations of the same physical memory
  18. */
  19. #define SRAM_IRAM_START 0x40800000
  20. #define SRAM_DRAM_START 0x40800000
  21. #define I_D_SRAM_OFFSET (SRAM_IRAM_START - SRAM_DRAM_START)
  22. #define SRAM_DRAM_END 0x4086E610 - I_D_SRAM_OFFSET /* 2nd stage bootloader iram_loader_seg start address */
  23. #define SRAM_IRAM_ORG (SRAM_IRAM_START)
  24. #define SRAM_DRAM_ORG (SRAM_DRAM_START)
  25. #define I_D_SRAM_SIZE SRAM_DRAM_END - SRAM_DRAM_ORG
  26. #if CONFIG_APP_BUILD_USE_FLASH_SECTIONS
  27. /*
  28. * IDRAM0_2_SEG_SIZE_DEFAULT is used when page size is 64KB
  29. */
  30. #define IDRAM0_2_SEG_SIZE (CONFIG_MMU_PAGE_SIZE << 8)
  31. #endif
  32. #define DRAM0_0_SEG_LEN I_D_SRAM_SIZE
  33. MEMORY
  34. {
  35. /**
  36. * All these values assume the flash cache is on, and have the blocks this uses subtracted from the length
  37. * of the various regions. The 'data access port' dram/drom regions map to the same iram/irom regions but
  38. * are connected to the data port of the CPU and eg allow byte-wise access.
  39. */
  40. /* IRAM for PRO CPU. */
  41. iram0_0_seg (RX) : org = SRAM_IRAM_ORG, len = I_D_SRAM_SIZE
  42. #if CONFIG_APP_BUILD_USE_FLASH_SECTIONS
  43. /* Flash mapped instruction data */
  44. irom_seg (RX) : org = 0x42000020, len = IDRAM0_2_SEG_SIZE - 0x20
  45. /**
  46. * (0x20 offset above is a convenience for the app binary image generation.
  47. * Flash cache has 64KB pages. The .bin file which is flashed to the chip
  48. * has a 0x18 byte file header, and each segment has a 0x08 byte segment
  49. * header. Setting this offset makes it simple to meet the flash cache MMU's
  50. * constraint that (paddr % 64KB == vaddr % 64KB).)
  51. */
  52. #endif // CONFIG_APP_BUILD_USE_FLASH_SECTIONS
  53. /**
  54. * Shared data RAM, excluding memory reserved for ROM bss/data/stack.
  55. * Enabling Bluetooth & Trace Memory features in menuconfig will decrease the amount of RAM available.
  56. */
  57. dram0_0_seg (RW) : org = SRAM_DRAM_ORG, len = DRAM0_0_SEG_LEN
  58. #if CONFIG_APP_BUILD_USE_FLASH_SECTIONS
  59. /* Flash mapped constant data */
  60. drom_seg (R) : org = 0x42000020, len = IDRAM0_2_SEG_SIZE - 0x20
  61. /* (See irom_seg for meaning of 0x20 offset in the above.) */
  62. #endif // CONFIG_APP_BUILD_USE_FLASH_SECTIONS
  63. /**
  64. * lp ram memory (RWX). Persists over deep sleep. // TODO: IDF-5667
  65. */
  66. #if CONFIG_ULP_COPROC_ENABLED
  67. lp_ram_seg(RW) : org = 0x50000000 + CONFIG_ULP_COPROC_RESERVE_MEM,
  68. len = 0x4000 - CONFIG_ULP_COPROC_RESERVE_MEM - RESERVE_RTC_MEM
  69. #else
  70. lp_ram_seg(RW) : org = 0x50000000, len = 0x4000 - RESERVE_RTC_MEM
  71. #endif // CONFIG_ULP_COPROC_ENABLED
  72. /* We reduced the size of lp_ram_seg by RESERVE_RTC_MEM value.
  73. It reserves the amount of LP memory that we use for this memory segment.
  74. This segment is intended for keeping:
  75. - (lower addr) rtc timer data (s_rtc_timer_retain_mem, see esp_clk.c files).
  76. - (higher addr) bootloader rtc data (s_bootloader_retain_mem, when a Kconfig option is on).
  77. The aim of this is to keep data that will not be moved around and have a fixed address.
  78. */
  79. lp_reserved_seg(RW) : org = 0x50000000 + 0x4000 - RESERVE_RTC_MEM, len = RESERVE_RTC_MEM
  80. }
  81. /* Heap ends at top of dram0_0_seg */
  82. _heap_end = 0x40000000;
  83. _data_seg_org = ORIGIN(rtc_data_seg);
  84. /**
  85. * The lines below define location alias for .rtc.data section
  86. * C6 has no distinguished LP(RTC) fast and slow memory sections, instead, there is a unified LP_RAM section
  87. * Thus, the following region segments are not configurable like on other targets
  88. */
  89. REGION_ALIAS("rtc_iram_seg", lp_ram_seg );
  90. REGION_ALIAS("rtc_data_seg", rtc_iram_seg );
  91. REGION_ALIAS("rtc_slow_seg", rtc_iram_seg );
  92. REGION_ALIAS("rtc_data_location", rtc_iram_seg );
  93. REGION_ALIAS("rtc_reserved_seg", lp_reserved_seg );
  94. #if CONFIG_APP_BUILD_USE_FLASH_SECTIONS
  95. REGION_ALIAS("default_code_seg", irom_seg);
  96. #else
  97. REGION_ALIAS("default_code_seg", iram0_0_seg);
  98. #endif // CONFIG_APP_BUILD_USE_FLASH_SECTIONS
  99. #if CONFIG_APP_BUILD_USE_FLASH_SECTIONS
  100. REGION_ALIAS("default_rodata_seg", drom_seg);
  101. #else
  102. REGION_ALIAS("default_rodata_seg", dram0_0_seg);
  103. #endif // CONFIG_APP_BUILD_USE_FLASH_SECTIONS
  104. /**
  105. * If rodata default segment is placed in `drom_seg`, then flash's first rodata section must
  106. * also be first in the segment.
  107. */
  108. #if CONFIG_APP_BUILD_USE_FLASH_SECTIONS
  109. ASSERT(_flash_rodata_dummy_start == ORIGIN(default_rodata_seg),
  110. ".flash_rodata_dummy section must be placed at the beginning of the rodata segment.")
  111. #endif
  112. #if CONFIG_ESP_SYSTEM_USE_EH_FRAME
  113. ASSERT ((__eh_frame_end > __eh_frame), "Error: eh_frame size is null!");
  114. ASSERT ((__eh_frame_hdr_end > __eh_frame_hdr), "Error: eh_frame_hdr size is null!");
  115. #endif