stm32l031x4.ld 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. /*
  2. stm32l031x4.ld
  3. Modified for stm32l0 from the original nokeep.ld script from the
  4. arm-none-eabi examples by olikraus@gmail.com
  5. Assuming, that the original nokeep.ld file is available under
  6. the GNU General Public License, this file is available under the
  7. same license.
  8. There are three modifications:
  9. 1. Provide symbols for the stm32l0 startup code
  10. The following symbols are required for the stm32l0 startup
  11. code (e.g. startup_stm32l031xx.s)
  12. _sidata start address for the initialization values of the .data section
  13. _sdata start address for the .data section. defined in linker script
  14. _edata end address for the .data section. defined in linker script
  15. _sbss start address for the .bss section. defined in linker script
  16. _ebss end address for the .bss section. defined in linker script
  17. _estack top address of the stack
  18. 2. Stack size estimation / calculation
  19. _Stack_Size has been added to allow better stack size calculation
  20. 3. KEEP keywords
  21. Additionall KEEPs added for .init and .fini. Without this KEEP the
  22. generated code will not work, because of the missing _init function.
  23. 4. Bugfix: Allign the end of the flash area
  24. */
  25. _Stack_Size = 0x400; /* stm32l0: estimated amount of stack */
  26. /* Linker script to configure memory regions.
  27. * Need modifying for a specific board.
  28. * FLASH.ORIGIN: starting address of flash
  29. * FLASH.LENGTH: length of flash
  30. * RAM.ORIGIN: starting address of RAM bank 0
  31. * RAM.LENGTH: length of RAM bank 0
  32. */
  33. MEMORY
  34. {
  35. FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 16K
  36. RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 8K
  37. }
  38. /* Linker script to place sections and symbol values. Should be used together
  39. * with other linker script that defines memory regions FLASH and RAM.
  40. * It references following symbols, which must be defined in code:
  41. * Reset_Handler : Entry of reset handler
  42. *
  43. * It defines following symbols, which code can use without definition:
  44. * __exidx_start
  45. * __exidx_end
  46. * __copy_table_start__
  47. * __copy_table_end__
  48. * __zero_table_start__
  49. * __zero_table_end__
  50. * __etext
  51. * __data_start__
  52. * __preinit_array_start
  53. * __preinit_array_end
  54. * __init_array_start
  55. * __init_array_end
  56. * __fini_array_start
  57. * __fini_array_end
  58. * __data_end__
  59. * __bss_start__
  60. * __bss_end__
  61. * __end__
  62. * end
  63. * __HeapLimit
  64. * __StackLimit
  65. * __StackTop
  66. * __stack
  67. */
  68. ENTRY(Reset_Handler)
  69. SECTIONS
  70. {
  71. .text :
  72. {
  73. KEEP(*(.isr_vector))
  74. *(.text*)
  75. /* the st32l0 startup code calls __libc_init_array, which calls the _init */
  76. /* ... sooo.... better keep the init and fini sections */
  77. KEEP ( *(.init) )
  78. KEEP ( *(.fini) )
  79. /* .ctors */
  80. *crtbegin.o(.ctors)
  81. *crtbegin?.o(.ctors)
  82. *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)
  83. *(SORT(.ctors.*))
  84. *(.ctors)
  85. /* .dtors */
  86. *crtbegin.o(.dtors)
  87. *crtbegin?.o(.dtors)
  88. *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)
  89. *(SORT(.dtors.*))
  90. *(.dtors)
  91. *(.rodata*)
  92. *(.eh_frame*)
  93. /* allign the end of the flash area */
  94. . = ALIGN(4);
  95. } > FLASH
  96. .ARM.extab :
  97. {
  98. *(.ARM.extab* .gnu.linkonce.armextab.*)
  99. } > FLASH
  100. __exidx_start = .;
  101. .ARM.exidx :
  102. {
  103. *(.ARM.exidx* .gnu.linkonce.armexidx.*)
  104. } > FLASH
  105. __exidx_end = .;
  106. /* To copy multiple ROM to RAM sections,
  107. * uncomment .copy.table section and,
  108. * define __STARTUP_COPY_MULTIPLE in startup_ARMCMx.S */
  109. /*
  110. .copy.table :
  111. {
  112. . = ALIGN(4);
  113. __copy_table_start__ = .;
  114. LONG (__etext)
  115. LONG (__data_start__)
  116. LONG (__data_end__ - __data_start__)
  117. LONG (__etext2)
  118. LONG (__data2_start__)
  119. LONG (__data2_end__ - __data2_start__)
  120. __copy_table_end__ = .;
  121. } > FLASH
  122. */
  123. /* To clear multiple BSS sections,
  124. * uncomment .zero.table section and,
  125. * define __STARTUP_CLEAR_BSS_MULTIPLE in startup_ARMCMx.S */
  126. /*
  127. .zero.table :
  128. {
  129. . = ALIGN(4);
  130. __zero_table_start__ = .;
  131. LONG (__bss_start__)
  132. LONG (__bss_end__ - __bss_start__)
  133. LONG (__bss2_start__)
  134. LONG (__bss2_end__ - __bss2_start__)
  135. __zero_table_end__ = .;
  136. } > FLASH
  137. */
  138. __etext = .;
  139. _sidata = .; /* for stm32l0 startup code */
  140. .data : AT (__etext)
  141. {
  142. __data_start__ = .;
  143. _sdata = .; /* for stm32l0 startup code */
  144. *(vtable)
  145. *(.data*)
  146. . = ALIGN(4);
  147. /* preinit data */
  148. PROVIDE_HIDDEN (__preinit_array_start = .);
  149. *(.preinit_array)
  150. PROVIDE_HIDDEN (__preinit_array_end = .);
  151. . = ALIGN(4);
  152. /* init data */
  153. PROVIDE_HIDDEN (__init_array_start = .);
  154. *(SORT(.init_array.*))
  155. *(.init_array)
  156. PROVIDE_HIDDEN (__init_array_end = .);
  157. . = ALIGN(4);
  158. /* finit data */
  159. PROVIDE_HIDDEN (__fini_array_start = .);
  160. *(SORT(.fini_array.*))
  161. *(.fini_array)
  162. PROVIDE_HIDDEN (__fini_array_end = .);
  163. *(.jcr)
  164. . = ALIGN(4);
  165. /* All data end */
  166. __data_end__ = .;
  167. _edata = .; /* for stm32l0 startup code */
  168. } > RAM
  169. .bss :
  170. {
  171. . = ALIGN(4);
  172. __bss_start__ = .;
  173. _sbss = .; /* for stm32l0 startup code */
  174. *(.bss*)
  175. *(COMMON)
  176. . = ALIGN(4);
  177. __bss_end__ = .;
  178. _ebss = .; /* for stm32l0 startup code */
  179. } > RAM
  180. .heap (COPY):
  181. {
  182. __end__ = .;
  183. PROVIDE(end = .);
  184. *(.heap*)
  185. __HeapLimit = .;
  186. } > RAM
  187. /* .stack_dummy section doesn't contains any symbols. It is only
  188. * used for linker to calculate size of stack sections, and assign
  189. * values to stack symbols later */
  190. .stack_dummy (COPY):
  191. {
  192. *(.stack*)
  193. . = . + _Stack_Size; /* estimated stack size */
  194. } > RAM
  195. /* Set stack top to end of RAM, and stack limit move down by
  196. * size of stack_dummy section */
  197. __StackTop = ORIGIN(RAM) + LENGTH(RAM);
  198. _estack = __StackTop; /* for stm32l0 startup code */
  199. __StackLimit = __StackTop - SIZEOF(.stack_dummy);
  200. PROVIDE(__stack = __StackTop);
  201. /* Check if data + heap + stack exceeds RAM limit */
  202. ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed with stack")
  203. }