Link.ld 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. ENTRY( _start )
  2. __stack_size = 2048;
  3. PROVIDE( _stack_size = __stack_size );
  4. MEMORY
  5. {
  6. /* CH32V20x_D6 - CH32V203F6-CH32V203G6-CH32V203C6 */
  7. FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 32K
  8. RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 10K
  9. /* CH32V20x_D6 - CH32V203K8-CH32V203C8-CH32V203G8-CH32V203F8 */
  10. /**/
  11. /*
  12. FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 64K
  13. RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 20K
  14. */
  15. /* CH32V20x_D8 - CH32V203RB
  16. CH32V20x_D8W - CH32V208x
  17. FLASH + RAM supports the following configuration
  18. FLASH-128K + RAM-64K
  19. FLASH-144K + RAM-48K
  20. FLASH-160K + RAM-32K
  21. FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 160K
  22. RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 32K
  23. */
  24. }
  25. SECTIONS
  26. {
  27. .init :
  28. {
  29. _sinit = .;
  30. . = ALIGN(4);
  31. KEEP(*(SORT_NONE(.init)))
  32. . = ALIGN(4);
  33. _einit = .;
  34. } >FLASH AT>FLASH
  35. .vector :
  36. {
  37. *(.vector);
  38. . = ALIGN(64);
  39. } >FLASH AT>FLASH
  40. .text :
  41. {
  42. . = ALIGN(4);
  43. *(.text)
  44. *(.text.*)
  45. *(.rodata)
  46. *(.rodata*)
  47. *(.gnu.linkonce.t.*)
  48. . = ALIGN(4);
  49. } >FLASH AT>FLASH
  50. .fini :
  51. {
  52. KEEP(*(SORT_NONE(.fini)))
  53. . = ALIGN(4);
  54. } >FLASH AT>FLASH
  55. PROVIDE( _etext = . );
  56. PROVIDE( _eitcm = . );
  57. .preinit_array :
  58. {
  59. PROVIDE_HIDDEN (__preinit_array_start = .);
  60. KEEP (*(.preinit_array))
  61. PROVIDE_HIDDEN (__preinit_array_end = .);
  62. } >FLASH AT>FLASH
  63. .init_array :
  64. {
  65. PROVIDE_HIDDEN (__init_array_start = .);
  66. KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
  67. KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors))
  68. PROVIDE_HIDDEN (__init_array_end = .);
  69. } >FLASH AT>FLASH
  70. .fini_array :
  71. {
  72. PROVIDE_HIDDEN (__fini_array_start = .);
  73. KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))
  74. KEEP (*(.fini_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .dtors))
  75. PROVIDE_HIDDEN (__fini_array_end = .);
  76. } >FLASH AT>FLASH
  77. .ctors :
  78. {
  79. /* gcc uses crtbegin.o to find the start of
  80. the constructors, so we make sure it is
  81. first. Because this is a wildcard, it
  82. doesn't matter if the user does not
  83. actually link against crtbegin.o; the
  84. linker won't look for a file to match a
  85. wildcard. The wildcard also means that it
  86. doesn't matter which directory crtbegin.o
  87. is in. */
  88. KEEP (*crtbegin.o(.ctors))
  89. KEEP (*crtbegin?.o(.ctors))
  90. /* We don't want to include the .ctor section from
  91. the crtend.o file until after the sorted ctors.
  92. The .ctor section from the crtend file contains the
  93. end of ctors marker and it must be last */
  94. KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors))
  95. KEEP (*(SORT(.ctors.*)))
  96. KEEP (*(.ctors))
  97. } >FLASH AT>FLASH
  98. .dtors :
  99. {
  100. KEEP (*crtbegin.o(.dtors))
  101. KEEP (*crtbegin?.o(.dtors))
  102. KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))
  103. KEEP (*(SORT(.dtors.*)))
  104. KEEP (*(.dtors))
  105. } >FLASH AT>FLASH
  106. .dalign :
  107. {
  108. . = ALIGN(4);
  109. PROVIDE(_data_vma = .);
  110. } >RAM AT>FLASH
  111. .dlalign :
  112. {
  113. . = ALIGN(4);
  114. PROVIDE(_data_lma = .);
  115. } >FLASH AT>FLASH
  116. .data :
  117. {
  118. *(.gnu.linkonce.r.*)
  119. *(.data .data.*)
  120. *(.gnu.linkonce.d.*)
  121. . = ALIGN(8);
  122. PROVIDE( __global_pointer$ = . + 0x800 );
  123. *(.sdata .sdata.*)
  124. *(.sdata2.*)
  125. *(.gnu.linkonce.s.*)
  126. . = ALIGN(8);
  127. *(.srodata.cst16)
  128. *(.srodata.cst8)
  129. *(.srodata.cst4)
  130. *(.srodata.cst2)
  131. *(.srodata .srodata.*)
  132. . = ALIGN(4);
  133. PROVIDE( _edata = .);
  134. } >RAM AT>FLASH
  135. .bss :
  136. {
  137. . = ALIGN(4);
  138. PROVIDE( _sbss = .);
  139. *(.sbss*)
  140. *(.gnu.linkonce.sb.*)
  141. *(.bss*)
  142. *(.gnu.linkonce.b.*)
  143. *(COMMON*)
  144. . = ALIGN(4);
  145. PROVIDE( _ebss = .);
  146. } >RAM AT>FLASH
  147. PROVIDE( _end = _ebss);
  148. PROVIDE( end = . );
  149. .stack ORIGIN(RAM) + LENGTH(RAM) - __stack_size :
  150. {
  151. PROVIDE( _heap_end = . );
  152. . = ALIGN(4);
  153. PROVIDE(_susrstack = . );
  154. . = . + __stack_size;
  155. PROVIDE( _eusrstack = .);
  156. } >RAM
  157. }