Link.ld 4.0 KB

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