15
15
limitations under the License.
16
16
"""
17
17
import re
18
+ from copy import copy
18
19
from os .path import join , dirname , splitext , basename , exists
19
20
from os import makedirs , write
20
21
from tempfile import mkstemp
@@ -31,6 +32,7 @@ class ARM(mbedToolchain):
31
32
DIAGNOSTIC_PATTERN = re .compile ('"(?P<file>[^"]+)", line (?P<line>\d+)( \(column (?P<column>\d+)\)|): (?P<severity>Warning|Error|Fatal error): (?P<message>.+)' )
32
33
INDEX_PATTERN = re .compile ('(?P<col>\s*)\^' )
33
34
DEP_PATTERN = re .compile ('\S+:\s(?P<file>.+)\n ' )
35
+ SHEBANG = "#! armcc -E"
34
36
35
37
@staticmethod
36
38
def check_executable ():
@@ -175,32 +177,52 @@ def compile_c(self, source, object, includes):
175
177
def compile_cpp (self , source , object , includes ):
176
178
return self .compile (self .cppc , source , object , includes )
177
179
178
- @hook_tool
179
- def link (self , output , objects , libraries , lib_dirs , mem_map ):
180
- map_file = splitext (output )[0 ] + ".map"
181
- if len (lib_dirs ):
182
- args = ["-o" , output , "--userlibpath" , "," .join (lib_dirs ), "--info=totals" , "--map" , "--list=%s" % map_file ]
183
- else :
184
- args = ["-o" , output , "--info=totals" , "--map" , "--list=%s" % map_file ]
185
-
186
- args .extend (self .flags ['ld' ])
180
+ def correct_scatter_shebang (self , scatter_file ):
181
+ """Correct the shebang at the top of a scatter file.
182
+
183
+ Positional arguments:
184
+ scatter_file -- the scatter file to correct
185
+
186
+ Return:
187
+ The location of the correct scatter file
188
+
189
+ Side Effects:
190
+ This method MAY write a new scatter file to disk
191
+ """
192
+ with open (scatter_file , "rb" ) as input :
193
+ lines = input .readlines ()
194
+ if lines [0 ].startswith (self .SHEBANG ):
195
+ return scatter_file
196
+ else :
197
+ new_scatter = join (self .build_dir , ".link_script.sct" )
198
+ if self .need_update (new_scatter , [scatter_file ]):
199
+ with open (new_scatter , "wb" ) as out :
200
+ out .write (self .SHEBANG )
201
+ out .write ("\n " )
202
+ out .write ("" .join (lines [1 :]))
203
+ return new_scatter
187
204
188
- if mem_map :
189
- args .extend (["--scatter" , mem_map ])
190
-
191
- # Build linker command
192
- cmd = self .ld + args + objects + libraries + self .sys_libs
193
-
194
- # Call cmdline hook
195
- cmd = self .hook .get_cmdline_linker (cmd )
205
+ @hook_tool
206
+ def link (self , output , objects , libraries , lib_dirs , scatter_file ):
207
+ base , _ = splitext (output )
208
+ map_file = base + ".map"
209
+ args = ["-o" , output , "--info=totals" , "--map" , "--list=%s" % map_file ]
210
+ args .extend (objects )
211
+ args .extend (libraries )
212
+ if lib_dirs :
213
+ args .extend (["--userlibpath" , "," .join (lib_dirs )])
214
+ if scatter_file :
215
+ new_scatter = self .correct_scatter_shebang (scatter_file )
216
+ args .extend (["--scatter" , new_scatter ])
217
+
218
+ cmd_pre = self .ld + args
219
+ cmd = self .hook .get_cmdline_linker (cmd_pre )
196
220
197
221
if self .RESPONSE_FILES :
198
- # Split link command to linker executable + response file
199
222
cmd_linker = cmd [0 ]
200
223
link_files = self .get_link_file (cmd [1 :])
201
224
cmd = [cmd_linker , '--via' , link_files ]
202
225
203
- # Exec command
204
226
self .cc_verbose ("Link: %s" % ' ' .join (cmd ))
205
227
self .default_cmd (cmd )
206
228
@@ -210,21 +232,14 @@ def archive(self, objects, lib_path):
210
232
param = ['--via' , self .get_arch_file (objects )]
211
233
else :
212
234
param = objects
213
-
214
- # Exec command
215
235
self .default_cmd ([self .ar , '-r' , lib_path ] + param )
216
236
217
237
@hook_tool
218
238
def binary (self , resources , elf , bin ):
219
239
_ , fmt = splitext (bin )
220
240
bin_arg = {".bin" : "--bin" , ".hex" : "--i32" }[fmt ]
221
- # Build binary command
222
241
cmd = [self .elf2bin , bin_arg , '-o' , bin , elf ]
223
-
224
- # Call cmdline hook
225
242
cmd = self .hook .get_cmdline_binary (cmd )
226
-
227
- # Exec command
228
243
self .cc_verbose ("FromELF: %s" % ' ' .join (cmd ))
229
244
self .default_cmd (cmd )
230
245
@@ -248,6 +263,89 @@ def redirect_symbol(source, sync, build_dir):
248
263
class ARM_STD (ARM ):
249
264
pass
250
265
251
-
252
266
class ARM_MICRO (ARM ):
253
267
PATCHED_LIBRARY = False
268
+
269
+ class ARMC6 (ARM_STD ):
270
+ SHEBANG = "#! armclang -E --target=arm-arm-none-eabi -x c"
271
+ @staticmethod
272
+ def check_executable ():
273
+ return mbedToolchain .generic_check_executable ("ARMC6" , "armclang" , 1 )
274
+
275
+ def __init__ (self , target , * args , ** kwargs ):
276
+ mbedToolchain .__init__ (self , target , * args , ** kwargs )
277
+
278
+ if target .core .lower ().endswith ("fd" ):
279
+ self .flags ['common' ].append ("-mcpu=%s" % target .core .lower ()[:- 2 ])
280
+ self .flags ['ld' ].append ("--cpu=%s" % target .core .lower ()[:- 2 ])
281
+ elif target .core .lower ().endswith ("f" ):
282
+ self .flags ['common' ].append ("-mcpu=%s" % target .core .lower ()[:- 1 ])
283
+ self .flags ['ld' ].append ("--cpu=%s" % target .core .lower ()[:- 1 ])
284
+ else :
285
+ self .flags ['common' ].append ("-mcpu=%s" % target .core .lower ())
286
+ self .flags ['ld' ].append ("--cpu=%s" % target .core .lower ())
287
+
288
+ if target .core == "Cortex-M4F" :
289
+ self .flags ['common' ].append ("-mfpu=fpv4-sp-d16" )
290
+ self .flags ['common' ].append ("-mfloat-abi=hard" )
291
+ elif target .core == "Cortex-M7F" :
292
+ self .flags ['common' ].append ("-mfpu=fpv5-sp-d16" )
293
+ self .flags ['common' ].append ("-mfloat-abi=softfp" )
294
+ elif target .core == "Cortex-M7FD" :
295
+ self .flags ['common' ].append ("-mfpu=fpv5-d16" )
296
+ self .flags ['common' ].append ("-mfloat-abi=softfp" )
297
+
298
+ asm_cpu = {
299
+ "Cortex-M0+" : "Cortex-M0" ,
300
+ "Cortex-M4F" : "Cortex-M4.fp" ,
301
+ "Cortex-M7F" : "Cortex-M7.fp.sp" ,
302
+ "Cortex-M7FD" : "Cortex-M7.fp.dp" }.get (target .core , target .core )
303
+
304
+ self .flags ['asm' ].append ("--cpu=%s" % asm_cpu )
305
+
306
+ self .cc = ([join (TOOLCHAIN_PATHS ["ARMC6" ], "armclang" )] +
307
+ self .flags ['common' ] + self .flags ['c' ])
308
+ self .cppc = ([join (TOOLCHAIN_PATHS ["ARMC6" ], "armclang" )] +
309
+ self .flags ['common' ] + self .flags ['cxx' ])
310
+ self .asm = [join (TOOLCHAIN_PATHS ["ARMC6" ], "armasm" )] + self .flags ['asm' ]
311
+ self .ld = [join (TOOLCHAIN_PATHS ["ARMC6" ], "armlink" )] + self .flags ['ld' ]
312
+ self .ar = [join (TOOLCHAIN_PATHS ["ARMC6" ], "armar" )]
313
+ self .elf2bin = join (TOOLCHAIN_PATHS ["ARMC6" ], "fromelf" )
314
+
315
+
316
+ def parse_dependencies (self , dep_path ):
317
+ return []
318
+
319
+ def parse_output (self , output ):
320
+ pass
321
+
322
+ def get_config_option (self , config_header ):
323
+ return ["-include" , config_header ]
324
+
325
+ def get_compile_options (self , defines , includes , for_asm = False ):
326
+ opts = ['-D%s' % d for d in defines ]
327
+ opts .extend (["-I%s" % i for i in includes ])
328
+ if for_asm :
329
+ return ["--cpreproc" ,
330
+ "--cpreproc_opts=%s" % "," .join (self .flags ['common' ] + opts )]
331
+ else :
332
+ config_header = self .get_config_header ()
333
+ if config_header :
334
+ opts .extend (self .get_config_option (config_header ))
335
+ return opts
336
+
337
+ @hook_tool
338
+ def assemble (self , source , object , includes ):
339
+ cmd_pre = copy (self .asm )
340
+ cmd_pre .extend (self .get_compile_options (
341
+ self .get_symbols (True ), includes , for_asm = True ))
342
+ cmd_pre .extend (["-o" , object , source ])
343
+ return [self .hook .get_cmdline_assembler (cmd_pre )]
344
+
345
+ @hook_tool
346
+ def compile (self , cc , source , object , includes ):
347
+ cmd = copy (cc )
348
+ cmd .extend (self .get_compile_options (self .get_symbols (), includes ))
349
+ cmd .extend (["-o" , object , source ])
350
+ cmd = self .hook .get_cmdline_compiler (cmd )
351
+ return [cmd ]
0 commit comments