link_optiboot.ld 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /* Customized Linker script for Optiboot */
  2. /* Copyright (C) 2014-2015 Free Software Foundation, Inc.
  3. Copyright (C) 2021 by William Westfield
  4. Copying and distribution of this script, with or without modification,
  5. are permitted in any medium without royalty provided the copyright
  6. notice and this notice are preserved.
  7. */
  8. /*
  9. * this is based off of the default ATmega328 linker script, but it
  10. * has been generalized (since optiboot makes little use of the standard
  11. * chip-specific values), and also specialized to based start addresses
  12. * of the code on symbols passed from the C program, instead of needing
  13. * --section-start commands in the linker command line.
  14. * (The C program does this by using asm() statements to define absolute
  15. * symbols that the linker can see.
  16. * The .data and .bss segments are removed, since the bootloader must not
  17. * use them (and does its own memory management) (this has the added
  18. * "benefit" of spitting out error messages if the code DOES try to
  19. * use data or bss variables.
  20. */
  21. OUTPUT_FORMAT("elf32-avr","elf32-avr","elf32-avr")
  22. __FUSE_REGION_LENGTH__ = DEFINED(__FUSE_REGION_LENGTH__) ? __FUSE_REGION_LENGTH__ : 1K;
  23. /* This makes the disassembly listings prettier */
  24. __RAM__ = 0x800000;
  25. MEMORY
  26. {
  27. text (rx) : ORIGIN = __BOOT_START__, LENGTH = __BOOT_SIZE__
  28. version (rx) : ORIGIN = __VERSION_START__, LENGTH = 2
  29. fuse (rw!x) : ORIGIN = 0x820000, LENGTH = __FUSE_REGION_LENGTH__
  30. }
  31. SECTIONS
  32. {
  33. /* Read-only sections, merged into text segment: */
  34. /* Internal text space or external memory. */
  35. .text :
  36. {
  37. *(.vectors)
  38. KEEP(*(.vectors))
  39. /* For data that needs to reside in the lower 64k of progmem. */
  40. *(.progmem.gcc*)
  41. /* PR 13812: Placing the trampolines here gives a better chance
  42. that they will be in range of the code that uses them. */
  43. . = ALIGN(2);
  44. *(.init0) /* Start here after reset. */
  45. KEEP (*(.init0))
  46. *(.init1)
  47. KEEP (*(.init1))
  48. *(.init2) /* Clear __zero_reg__, set up stack pointer. */
  49. KEEP (*(.init2))
  50. *(.init3)
  51. KEEP (*(.init3))
  52. *(.init4) /* Initialize data and BSS. */
  53. KEEP (*(.init4))
  54. *(.init5)
  55. KEEP (*(.init5))
  56. *(.init6) /* C++ constructors. */
  57. KEEP (*(.init6))
  58. *(.init7)
  59. KEEP (*(.init7))
  60. *(.init8)
  61. KEEP (*(.init8))
  62. *(.init9) /* Call main(). */
  63. KEEP (*(.init9))
  64. *(.text)
  65. . = ALIGN(2);
  66. *(.text.*)
  67. . = ALIGN(2);
  68. *(.fini9) /* _exit() starts here. */
  69. KEEP (*(.fini9))
  70. *(.fini8)
  71. KEEP (*(.fini8))
  72. *(.fini7)
  73. KEEP (*(.fini7))
  74. *(.fini6) /* C++ destructors. */
  75. KEEP (*(.fini6))
  76. *(.fini5)
  77. KEEP (*(.fini5))
  78. *(.fini4)
  79. KEEP (*(.fini4))
  80. *(.fini3)
  81. KEEP (*(.fini3))
  82. *(.fini2)
  83. KEEP (*(.fini2))
  84. *(.fini1)
  85. KEEP (*(.fini1))
  86. *(.fini0) /* Infinite loop after program termination. */
  87. KEEP (*(.fini0))
  88. _etext = . ;
  89. } > text
  90. .version __VERSION_START__ :
  91. {
  92. *(.version)
  93. } > text
  94. .fuse :
  95. {
  96. KEEP(*(.fuse))
  97. KEEP(*(.lfuse))
  98. KEEP(*(.hfuse))
  99. KEEP(*(.efuse))
  100. } > fuse
  101. /* Stabs debugging sections. */
  102. .stab 0 : { *(.stab) }
  103. .stabstr 0 : { *(.stabstr) }
  104. .stab.excl 0 : { *(.stab.excl) }
  105. .stab.exclstr 0 : { *(.stab.exclstr) }
  106. .stab.index 0 : { *(.stab.index) }
  107. .stab.indexstr 0 : { *(.stab.indexstr) }
  108. .comment 0 : { *(.comment) }
  109. .note.gnu.build-id : { *(.note.gnu.build-id) }
  110. /* DWARF debug sections.
  111. Symbols in the DWARF debugging sections are relative to the beginning
  112. of the section so we begin them at 0. */
  113. /* DWARF 1 */
  114. .debug 0 : { *(.debug) }
  115. .line 0 : { *(.line) }
  116. /* GNU DWARF 1 extensions */
  117. .debug_srcinfo 0 : { *(.debug_srcinfo) }
  118. .debug_sfnames 0 : { *(.debug_sfnames) }
  119. /* DWARF 1.1 and DWARF 2 */
  120. .debug_aranges 0 : { *(.debug_aranges) }
  121. .debug_pubnames 0 : { *(.debug_pubnames) }
  122. /* DWARF 2 */
  123. .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }
  124. .debug_abbrev 0 : { *(.debug_abbrev) }
  125. .debug_line 0 : { *(.debug_line .debug_line.* .debug_line_end ) }
  126. .debug_frame 0 : { *(.debug_frame) }
  127. .debug_str 0 : { *(.debug_str) }
  128. .debug_loc 0 : { *(.debug_loc) }
  129. .debug_macinfo 0 : { *(.debug_macinfo) }
  130. /* SGI/MIPS DWARF 2 extensions */
  131. .debug_weaknames 0 : { *(.debug_weaknames) }
  132. .debug_funcnames 0 : { *(.debug_funcnames) }
  133. .debug_typenames 0 : { *(.debug_typenames) }
  134. .debug_varnames 0 : { *(.debug_varnames) }
  135. /* DWARF 3 */
  136. .debug_pubtypes 0 : { *(.debug_pubtypes) }
  137. .debug_ranges 0 : { *(.debug_ranges) }
  138. /* DWARF Extension. */
  139. .debug_macro 0 : { *(.debug_macro) }
  140. }