openMSP430之Custom linker script

  The use of the -mmcu switch is of course NOT mandatory. It is simply a convenient way to use the pre-existing linker scripts provided with the MSPGCC4 toolchain. However, if the peripheral address space is larger than the standard 512B of the original MSP430 (see the Advanced System Configuration section), a customized linker script MUST be provided.


  To create a custom linker script, the simplest way is to start from an existing one:
  • The MSPGCC(4) toolchain provides a wide range of examples for all supported MSP430 models (see “msp430/lib/ldscripts/” sub-directory in the MSPGCC(4) installation directory).


  • The openMSP430 project also provide a simple linker script example:
    ldscript_example.x


From there, the script can be modified to match YOUR openMSP430 configuration:

  • In the text (rx) section definition, update the ORIGIN and LENGTH fields to match the PROGRAM MEMORY configuration.
  • In the data (rwx) section definition, update the ORIGIN field to match the PERIPHERAL SPACE configuration and the LENGTH field to match the DATA MEMORY configuration.

 

ldscript_example.x

  1 /* Default linker script, for normal executables */

  2 OUTPUT_FORMAT("elf32-msp430")

  3 OUTPUT_ARCH("msp430")

  4 MEMORY

  5 {

  6   data    (rwx)      : ORIGIN = 0x0200,     LENGTH = 0x0080

  7   text    (rx)       : ORIGIN = 0xf800,      LENGTH = 0x0800-0x20

  8   vectors (rw)      : ORIGIN = 0xffe0,      LENGTH = 0x20

  9 }

 10 REGION_ALIAS("REGION_TEXT", text);

 11 REGION_ALIAS("REGION_DATA", data);

 12 __WDTCTL = 0x0120;

 13 __MPY    = 0x0130;

 14 __MPYS   = 0x0132;

 15 __MAC    = 0x0134;

 16 __MACS   = 0x0136;

 17 __OP2    = 0x0138;

 18 __RESLO  = 0x013A;

 19 __RESHI  = 0x013C;

 20 __SUMEXT = 0x013E;

 21 

 22 SECTIONS

 23 {

 24   /* Read-only sections, merged into text segment.  */

 25   .hash          : { *(.hash)             }

 26   .dynsym        : { *(.dynsym)           }

 27   .dynstr        : { *(.dynstr)           }

 28   .gnu.version   : { *(.gnu.version)      }

 29   .gnu.version_d   : { *(.gnu.version_d)  }

 30   .gnu.version_r   : { *(.gnu.version_r)  }

 31   .rel.init      : { *(.rel.init) }

 32   .rela.init     : { *(.rela.init) }

 33   .rel.text      :

 34     {

 35       *(.rel.text)

 36       *(.rel.text.*)

 37       *(.rel.gnu.linkonce.t*)

 38     }

 39   .rela.text     :

 40     {

 41       *(.rela.text)

 42       *(.rela.text.*)

 43       *(.rela.gnu.linkonce.t*)

 44     }

 45   .rel.fini      : { *(.rel.fini) }

 46   .rela.fini     : { *(.rela.fini) }

 47   .rel.rodata    :

 48     {

 49       *(.rel.rodata)

 50       *(.rel.rodata.*)

 51       *(.rel.gnu.linkonce.r*)

 52     }

 53   .rela.rodata   :

 54     {

 55       *(.rela.rodata)

 56       *(.rela.rodata.*)

 57       *(.rela.gnu.linkonce.r*)

 58     }

 59   .rel.data      :

 60     {

 61       *(.rel.data)

 62       *(.rel.data.*)

 63       *(.rel.gnu.linkonce.d*)

 64     }

 65   .rela.data     :

 66     {

 67       *(.rela.data)

 68       *(.rela.data.*)

 69       *(.rela.gnu.linkonce.d*)

 70     }

 71   .rel.ctors     : { *(.rel.ctors)        }

 72   .rela.ctors    : { *(.rela.ctors)       }

 73   .rel.dtors     : { *(.rel.dtors)        }

 74   .rela.dtors    : { *(.rela.dtors)       }

 75   .rel.got       : { *(.rel.got)          }

 76   .rela.got      : { *(.rela.got)         }

 77   .rel.bss       : { *(.rel.bss)          }

 78   .rela.bss      : { *(.rela.bss)         }

 79   .rel.plt       : { *(.rel.plt)          }

 80   .rela.plt      : { *(.rela.plt)         }

 81   /* Internal text space.  */

 82   .text :

 83   {

 84     . = ALIGN(2);

 85     *(.init)

 86     *(.init0)  /* Start here after reset.  */

 87     *(.init1)

 88     *(.init2)  /* Copy data loop  */

 89     *(.init3)

 90     *(.init4)  /* Clear bss  */

 91     *(.init5)

 92     *(.init6)  /* C++ constructors.  */

 93     *(.init7)

 94     *(.init8)

 95     *(.init9)  /* Call main().  */

 96      __ctors_start = . ;

 97      *(.ctors)

 98      __ctors_end = . ;

 99      __dtors_start = . ;

100      *(.dtors)

101      __dtors_end = . ;

102     . = ALIGN(2);

103     *(.text)

104     . = ALIGN(2);

105     *(.text.*)

106     . = ALIGN(2);

107     *(.fini9)  /*   */

108     *(.fini8)

109     *(.fini7)

110     *(.fini6)  /* C++ destructors.  */

111     *(.fini5)

112     *(.fini4)

113     *(.fini3)

114     *(.fini2)

115     *(.fini1)

116     *(.fini0)  /* Infinite loop after program termination.  */

117     *(.fini)

118   }  > text

119   .rodata   :

120   {

121      . = ALIGN(2);

122     *(.rodata .rodata.* .gnu.linkonce.r.*)

123      . = ALIGN(2);

124   }  > text

125    _etext = .; /* Past last read-only (loadable) segment */

126   .data   : AT (ADDR (.text) + SIZEOF (.text) + SIZEOF (.rodata) )

127   {

128      PROVIDE (__data_start = .) ;

129     . = ALIGN(2);

130     *(.data)

131     . = ALIGN(2);

132     *(.gnu.linkonce.d*)

133     . = ALIGN(2);

134      _edata = . ;

135   }  > data

136    PROVIDE (__data_load_start = LOADADDR(.data) );

137    PROVIDE (__data_size = SIZEOF(.data) );

138   .bss  SIZEOF(.data) + ADDR(.data) :

139   {

140      PROVIDE (__bss_start = .) ;

141     *(.bss)

142     *(COMMON)

143      PROVIDE (__bss_end = .) ;

144      _end = . ;

145   }  > data

146    PROVIDE (__bss_size = SIZEOF(.bss) );

147   .noinit  SIZEOF(.bss) + ADDR(.bss) :

148   {

149      PROVIDE (__noinit_start = .) ;

150     *(.noinit)

151     *(COMMON)

152      PROVIDE (__noinit_end = .) ;

153      _end = . ;

154   }  > data

155   .vectors  :

156   {

157      PROVIDE (__vectors_start = .) ;

158     *(.vectors*)

159      _vectors_end = . ;

160   }  > vectors

161   /* Stabs for profiling information*/

162   .profiler 0 : { *(.profiler) }

163   /* Stabs debugging sections.  */

164   .stab 0 : { *(.stab) }

165   .stabstr 0 : { *(.stabstr) }

166   .stab.excl 0 : { *(.stab.excl) }

167   .stab.exclstr 0 : { *(.stab.exclstr) }

168   .stab.index 0 : { *(.stab.index) }

169   .stab.indexstr 0 : { *(.stab.indexstr) }

170   .comment 0 : { *(.comment) }

171   /* DWARF debug sections.

172      Symbols in the DWARF debugging sections are relative to the beginning

173      of the section so we begin them at 0.  */

174   /* DWARF 1 */

175   .debug          0 : { *(.debug) }

176   .line           0 : { *(.line) }

177   /* GNU DWARF 1 extensions */

178   .debug_srcinfo  0 : { *(.debug_srcinfo) }

179   .debug_sfnames  0 : { *(.debug_sfnames) }

180   /* DWARF 1.1 and DWARF 2 */

181   .debug_aranges  0 : { *(.debug_aranges) }

182   .debug_pubnames 0 : { *(.debug_pubnames) }

183   /* DWARF 2 */

184   .debug_info     0 : { *(.debug_info) *(.gnu.linkonce.wi.*) }

185   .debug_abbrev   0 : { *(.debug_abbrev) }

186   .debug_line     0 : { *(.debug_line) }

187   .debug_frame    0 : { *(.debug_frame) }

188   .debug_str      0 : { *(.debug_str) }

189   .debug_loc      0 : { *(.debug_loc) }

190   .debug_macinfo  0 : { *(.debug_macinfo) }

191   PROVIDE (__stack = ORIGIN(data) + LENGTH(data));

192   PROVIDE (__data_start_rom = _etext) ;

193   PROVIDE (__data_end_rom   = _etext + SIZEOF (.data)) ;

194 }

 

你可能感兴趣的:(script)