link.lds 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /* Linker script to configure memory regions. */
  2. MEMORY {
  3. FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 256K
  4. SRAM (rwx) : ORIGIN = 0x20000000, LENGTH = 96K
  5. }
  6. SECTIONS {
  7. .text :
  8. {
  9. _text = .;
  10. KEEP(*(.isr_vector))
  11. *(.text*) /* program code */
  12. *(.rodata*) /* read-only data: "const" */
  13. KEEP(*(.init))
  14. KEEP(*(.fini))
  15. /* C++ Exception handling */
  16. KEEP(*(.eh_frame*))
  17. /* section information for finsh shell */
  18. . = ALIGN(4);
  19. __fsymtab_start = .;
  20. KEEP(*(FSymTab))
  21. __fsymtab_end = .;
  22. . = ALIGN(4);
  23. __vsymtab_start = .;
  24. KEEP(*(VSymTab))
  25. __vsymtab_end = .;
  26. /* section information for initial. */
  27. . = ALIGN(4);
  28. __rt_init_start = .;
  29. KEEP(*(SORT(.rti_fn*)))
  30. __rt_init_end = .;
  31. . = ALIGN(4);
  32. PROVIDE(__ctors_start__ = .);
  33. KEEP (*(SORT(.init_array.*)))
  34. KEEP (*(.init_array))
  35. PROVIDE(__ctors_end__ = .);
  36. . = ALIGN(4);
  37. _etext = .;
  38. } > FLASH
  39. /* it's used for C++ exception handling */
  40. /* we need to keep this to avoid overlapping */
  41. .ARM.exidx :
  42. {
  43. __exidx_start = .;
  44. *(.ARM.exidx*)
  45. __exidx_end = .;
  46. } > FLASH
  47. .data :
  48. {
  49. _data = ALIGN(., 4);
  50. *(.data*) /*read-write initialized data: initialized global variable*/
  51. *(.spix_config*) /* SPIX configuration functions need to be run from SRAM */
  52. /* These array sections are used by __libc_init_array to call static C++ constructors */
  53. . = ALIGN(4);
  54. /* preinit data */
  55. PROVIDE_HIDDEN (__preinit_array_start = .);
  56. KEEP(*(.preinit_array))
  57. PROVIDE_HIDDEN (__preinit_array_end = .);
  58. . = ALIGN(4);
  59. /* init data */
  60. PROVIDE_HIDDEN (__init_array_start = .);
  61. KEEP(*(SORT(.init_array.*)))
  62. KEEP(*(.init_array))
  63. PROVIDE_HIDDEN (__init_array_end = .);
  64. . = ALIGN(4);
  65. /* finit data */
  66. PROVIDE_HIDDEN (__fini_array_start = .);
  67. KEEP(*(SORT(.fini_array.*)))
  68. KEEP(*(.fini_array))
  69. PROVIDE_HIDDEN (__fini_array_end = .);
  70. _edata = ALIGN(., 4);
  71. } > SRAM AT>FLASH
  72. __load_data = LOADADDR(.data);
  73. .bss :
  74. {
  75. . = ALIGN(4);
  76. _bss = .;
  77. *(.bss*) /*read-write zero initialized data: uninitialzed global variable*/
  78. *(COMMON)
  79. _ebss = ALIGN(., 4);
  80. } > SRAM
  81. /* Set stack top to end of RAM, and stack limit move down by
  82. * size of stack_dummy section */
  83. __StackTop = ORIGIN(SRAM) + LENGTH(SRAM);
  84. __StackLimit = __StackTop - SIZEOF(.stack_dummy);
  85. /* .stack_dummy section doesn't contains any symbols. It is only
  86. * used for linker to calculate size of stack sections, and assign
  87. * values to stack symbols later */
  88. .stack_dummy (COPY):
  89. {
  90. *(.stack*)
  91. } > SRAM
  92. .heap (COPY):
  93. {
  94. . = ALIGN(4);
  95. *(.heap*)
  96. __HeapLimit = ABSOLUTE(__StackLimit);
  97. } > SRAM
  98. PROVIDE(__stack = __StackTop);
  99. /* Check if data + heap + stack exceeds RAM limit */
  100. ASSERT(__StackLimit >= _ebss, "region RAM overflowed with stack")
  101. }