Link.ld 4.5 KB

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