stm32_flash.ld 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /*
  2. *****************************************************************************
  3. **
  4. ** File : stm32_flash.ld
  5. **
  6. ** Abstract : Linker script for STM32F407VG Device with
  7. ** 512KByte FLASH, 192KByte RAM
  8. **
  9. ** Set heap size, stack size and stack location according
  10. ** to application requirements.
  11. **
  12. ** Set memory bank area and size if external memory is used.
  13. **
  14. ** Target : STMicroelectronics STM32
  15. **
  16. ** Environment : Atollic TrueSTUDIO(R)
  17. **
  18. ** Distribution: The file is distributed �as is,� without any warranty
  19. ** of any kind.
  20. **
  21. ** (c)Copyright Atollic AB.
  22. ** You may use this file as-is or modify it according to the needs of your
  23. ** project. Distribution of this file (unmodified or modified) is not
  24. ** permitted. Atollic AB permit registered Atollic TrueSTUDIO(R) users the
  25. ** rights to distribute the assembled, compiled & linked contents of this
  26. ** file as part of an application binary file, provided that it is built
  27. ** using the Atollic TrueSTUDIO(R) toolchain.
  28. **
  29. *****************************************************************************
  30. */
  31. /* Entry Point */
  32. ENTRY(Reset_Handler)
  33. /* Highest address of the user mode stack */
  34. _estack = 0x2001ffff; /* end of 128K RAM on AHB bus*/
  35. /* Generate a link error if heap and stack don't fit into RAM */
  36. _Min_Heap_Size = 0x800; /* required amount of heap */
  37. _Min_Stack_Size = 0x100; /* required amount of stack */
  38. /* Specify the memory areas */
  39. MEMORY
  40. {
  41. BOOTLOADER_P1 (rx) : ORIGIN = 0x08000000, LENGTH = 16K
  42. SETTINGS (rx) : ORIGIN = 0x08004000, LENGTH = 16K
  43. BOOTLOADER (rx) : ORIGIN = 0x08008000, LENGTH = 96K
  44. FLASH (rx) : ORIGIN = 0x08020000, LENGTH = 384K
  45. CRC (rx) : ORIGIN = 0x0807FFFC, LENGTH = 4
  46. RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
  47. MEMORY_B1 (rx) : ORIGIN = 0x10000000, LENGTH = 64K
  48. }
  49. /* Define output sections */
  50. SECTIONS
  51. {
  52. /* The startup code goes first into FLASH */
  53. .isr_vector :
  54. {
  55. . = ALIGN(4);
  56. KEEP(*(.isr_vector)) /* Startup code */
  57. . = ALIGN(4);
  58. } >BOOTLOADER_P1
  59. /* The program code and other data goes into FLASH */
  60. .text :
  61. {
  62. . = ALIGN(4);
  63. *(.text) /* .text sections (code) */
  64. *(.text*) /* .text* sections (code) */
  65. *(.rodata) /* .rodata sections (constants, strings, etc.) */
  66. *(.rodata*) /* .rodata* sections (constants, strings, etc.) */
  67. *(.glue_7) /* glue arm to thumb code */
  68. *(.glue_7t) /* glue thumb to arm code */
  69. *(.eh_frame)
  70. KEEP (*(.init))
  71. KEEP (*(.fini))
  72. . = ALIGN(4);
  73. _etext = .; /* define a global symbols at end of code */
  74. _exit = .;
  75. } >BOOTLOADER
  76. .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >BOOTLOADER
  77. .ARM : {
  78. __exidx_start = .;
  79. *(.ARM.exidx*)
  80. __exidx_end = .;
  81. } >BOOTLOADER
  82. .preinit_array :
  83. {
  84. PROVIDE_HIDDEN (__preinit_array_start = .);
  85. KEEP (*(.preinit_array*))
  86. PROVIDE_HIDDEN (__preinit_array_end = .);
  87. } >BOOTLOADER
  88. .init_array :
  89. {
  90. PROVIDE_HIDDEN (__init_array_start = .);
  91. KEEP (*(SORT(.init_array.*)))
  92. KEEP (*(.init_array*))
  93. PROVIDE_HIDDEN (__init_array_end = .);
  94. } >BOOTLOADER
  95. .fini_array :
  96. {
  97. PROVIDE_HIDDEN (__fini_array_start = .);
  98. /* _fini = .; */
  99. KEEP (*(.fini_array*))
  100. KEEP (*(SORT(.fini_array.*)))
  101. PROVIDE_HIDDEN (__fini_array_end = .);
  102. } >BOOTLOADER
  103. /* used by the startup to initialize data */
  104. _sidata = .;
  105. /* Initialized data sections goes into RAM, load LMA copy after code */
  106. .data : AT ( _sidata )
  107. {
  108. . = ALIGN(4);
  109. _sdata = .; /* create a global symbol at data start */
  110. *(.data) /* .data sections */
  111. *(.data*) /* .data* sections */
  112. . = ALIGN(4);
  113. _edata = .; /* define a global symbol at data end */
  114. } >RAM
  115. .fill LOADADDR(.data) + SIZEOF(.data) :
  116. {
  117. FILL(0xFFFFFFFF);
  118. /* . = ORIGIN(FLASH) + LENGTH(FLASH) - 4 - 1; */
  119. . = ORIGIN(CRC) - 1;
  120. BYTE(0xFF)
  121. /* PROVIDE_HIDDEN (__fini_array_end = .); */
  122. } > FLASH
  123. .crc :
  124. {
  125. . = ALIGN(4);
  126. KEEP(*(.crc))
  127. . = ALIGN(4);
  128. }>CRC
  129. /* Uninitialized data section */
  130. . = ALIGN(4);
  131. .bss :
  132. {
  133. /* This is used by the startup in order to initialize the .bss secion */
  134. _sbss = .; /* define a global symbol at bss start */
  135. __bss_start__ = _sbss;
  136. *(.bss)
  137. *(.bss*)
  138. *(COMMON)
  139. . = ALIGN(4);
  140. _ebss = .; /* define a global symbol at bss end */
  141. __bss_end__ = _ebss;
  142. } >RAM
  143. /* User_heap_stack section, used to check that there is enough RAM left */
  144. ._user_heap_stack :
  145. {
  146. . = ALIGN(4);
  147. PROVIDE ( end = . );
  148. PROVIDE ( _end = . );
  149. . = . + _Min_Heap_Size;
  150. . = . + _Min_Stack_Size;
  151. . = ALIGN(4);
  152. } >RAM
  153. /* MEMORY_bank1 section, code must be located here explicitly */
  154. /* Example: extern int foo(void) __attribute__ ((section (".mb1text"))); */
  155. .memory_b1_text :
  156. {
  157. *(.mb1text) /* .mb1text sections (code) */
  158. *(.mb1text*) /* .mb1text* sections (code) */
  159. *(.mb1rodata) /* read-only data (constants) */
  160. *(.mb1rodata*)
  161. } >MEMORY_B1
  162. /* Remove information from the standard libraries */
  163. /DISCARD/ :
  164. {
  165. libc.a ( * )
  166. libm.a ( * )
  167. libgcc.a ( * )
  168. }
  169. .settings :
  170. {
  171. . = ALIGN(4);
  172. FILL(0xFF);
  173. . = ORIGIN(SETTINGS) + LENGTH(SETTINGS) - 1;
  174. BYTE(0xFF)
  175. } >SETTINGS
  176. .ARM.attributes 0 : { *(.ARM.attributes) }
  177. }