bootloader.lds 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /* Copyright (c) 2020 StarFiveTech, Inc */
  3. OUTPUT_ARCH( "riscv" )
  4. ENTRY( _start )
  5. MEMORY
  6. {
  7. rom (rxai!w) : ORIGIN = 0x18000000, LENGTH = 32K
  8. ram (wxa!ri) : ORIGIN = 0x18008000, LENGTH = 32K
  9. }
  10. PHDRS
  11. {
  12. rom PT_LOAD;
  13. ram_init PT_LOAD;
  14. ram PT_NULL;
  15. }
  16. SECTIONS
  17. {
  18. __stack_size = DEFINED(__stack_size) ? __stack_size : 2K;
  19. .init :
  20. {
  21. KEEP (*(SORT_NONE(.init)))
  22. } >rom AT>rom :rom
  23. .text :
  24. {
  25. *(.text.unlikely .text.unlikely.*)
  26. *(.text.startup .text.startup.*)
  27. *(.text .text.*)
  28. *(.gnu.linkonce.t.*)
  29. } >rom AT>rom :rom
  30. .fini :
  31. {
  32. KEEP (*(SORT_NONE(.fini)))
  33. } >rom AT>rom :rom
  34. PROVIDE (__etext = .);
  35. PROVIDE (_etext = .);
  36. PROVIDE (etext = .);
  37. .rodata :
  38. {
  39. *(.rdata)
  40. *(.rodata .rodata.*)
  41. *(.gnu.linkonce.r.*)
  42. } >rom AT>rom :rom
  43. . = ALIGN(4);
  44. .preinit_array :
  45. {
  46. PROVIDE_HIDDEN (__preinit_array_start = .);
  47. KEEP (*(.preinit_array))
  48. PROVIDE_HIDDEN (__preinit_array_end = .);
  49. } >rom AT>rom :rom
  50. .init_array :
  51. {
  52. PROVIDE_HIDDEN (__init_array_start = .);
  53. KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
  54. KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors))
  55. PROVIDE_HIDDEN (__init_array_end = .);
  56. } >rom AT>rom :rom
  57. .fini_array :
  58. {
  59. PROVIDE_HIDDEN (__fini_array_start = .);
  60. KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))
  61. KEEP (*(.fini_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .dtors))
  62. PROVIDE_HIDDEN (__fini_array_end = .);
  63. } >rom AT>rom :rom
  64. .ctors :
  65. {
  66. /* gcc uses crtbegin.o to find the start of
  67. the constructors, so we make sure it is
  68. first. Because this is a wildcard, it
  69. doesn't matter if the user does not
  70. actually link against crtbegin.o; the
  71. linker won't look for a file to match a
  72. wildcard. The wildcard also means that it
  73. doesn't matter which directory crtbegin.o
  74. is in. */
  75. KEEP (*crtbegin.o(.ctors))
  76. KEEP (*crtbegin?.o(.ctors))
  77. /* We don't want to include the .ctor section from
  78. the crtend.o file until after the sorted ctors.
  79. The .ctor section from the crtend file contains the
  80. end of ctors marker and it must be last */
  81. KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors))
  82. KEEP (*(SORT(.ctors.*)))
  83. KEEP (*(.ctors))
  84. } >rom AT>rom :rom
  85. .dtors :
  86. {
  87. KEEP (*crtbegin.o(.dtors))
  88. KEEP (*crtbegin?.o(.dtors))
  89. KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))
  90. KEEP (*(SORT(.dtors.*)))
  91. KEEP (*(.dtors))
  92. } >rom AT>rom :rom
  93. .lalign :
  94. {
  95. . = ALIGN(4);
  96. PROVIDE( _data_lma = . );
  97. } >ram AT>rom :rom
  98. .dalign :
  99. {
  100. . = ALIGN(4);
  101. PROVIDE( _data = . );
  102. } >ram AT>rom :rom
  103. .data :
  104. {
  105. *(.data .data.*)
  106. *(.gnu.linkonce.d.*)
  107. . = ALIGN(8);
  108. PROVIDE( __global_pointer$ = . + 0x800 );
  109. *(.sdata .sdata.*)
  110. *(.gnu.linkonce.s.*)
  111. . = ALIGN(8);
  112. *(.srodata.cst16)
  113. *(.srodata.cst8)
  114. *(.srodata.cst4)
  115. *(.srodata.cst2)
  116. *(.srodata .srodata.*)
  117. } >ram AT>rom :ram_init
  118. . = ALIGN(4);
  119. PROVIDE( _edata = . );
  120. PROVIDE( edata = . );
  121. PROVIDE( _fbss = . );
  122. PROVIDE( __bss_start = . );
  123. .bss :
  124. {
  125. *(.sbss*)
  126. *(.gnu.linkonce.sb.*)
  127. *(.bss .bss.*)
  128. *(.gnu.linkonce.b.*)
  129. *(COMMON)
  130. . = ALIGN(4);
  131. } >ram AT>ram :ram
  132. . = ALIGN(8);
  133. PROVIDE( _end = . );
  134. PROVIDE( end = . );
  135. .stack ORIGIN(ram) + LENGTH(ram) - __stack_size :
  136. {
  137. PROVIDE( _heap_end = . );
  138. . = __stack_size;
  139. PROVIDE( _sp = . );
  140. } >ram AT>ram :ram
  141. }