Link.ld 4.5 KB

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