Skip to content

Commit fdf1ed6

Browse files
authored
Merge pull request #3994 from theotherjimmy/fix-output-ext
Use OUTPUT_EXT to pick binary type
2 parents 067fe9b + 74998d6 commit fdf1ed6

File tree

5 files changed

+19
-12
lines changed

5 files changed

+19
-12
lines changed

tools/targets/__init__.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -386,12 +386,9 @@ class TEENSY3_1Code(object):
386386
@staticmethod
387387
def binary_hook(t_self, resources, elf, binf):
388388
"""Hook that is run after elf is generated"""
389-
from intelhex import IntelHex
390-
binh = IntelHex()
391-
binh.loadbin(binf, offset=0)
392-
393-
with open(binf.replace(".bin", ".hex"), "w") as file_desc:
394-
binh.tofile(file_desc, format='hex')
389+
# This function is referenced by old versions of targets.json and should
390+
# be kept for backwards compatibility.
391+
pass
395392

396393
class MTSCode(object):
397394
"""Generic MTS code"""
@@ -475,7 +472,11 @@ def binary_hook(t_self, resources, _, binf):
475472
# Merge user code with softdevice
476473
from intelhex import IntelHex
477474
binh = IntelHex()
478-
binh.loadbin(binf, offset=softdevice_and_offset_entry['offset'])
475+
_, ext = os.path.splitext(binf)
476+
if ext == ".hex":
477+
binh.loadhex(binf)
478+
elif ext == ".bin":
479+
binh.loadbin(binf, softdevice_and_offset_entry['offset'])
479480

480481
if t_self.target.MERGE_SOFT_DEVICE is True:
481482
t_self.debug("Merge SoftDevice file %s"

tools/toolchains/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,7 @@ def link_program(self, r, tmp_path, name):
10031003

10041004
filename = name+'.'+ext
10051005
elf = join(tmp_path, name + '.elf')
1006-
bin = join(tmp_path, filename)
1006+
bin = None if ext is 'elf' else join(tmp_path, filename)
10071007
map = join(tmp_path, name + '.map')
10081008

10091009
r.objects = sorted(set(r.objects))
@@ -1012,7 +1012,7 @@ def link_program(self, r, tmp_path, name):
10121012
self.progress("link", name)
10131013
self.link(elf, r.objects, r.libraries, r.lib_dirs, r.linker_script)
10141014

1015-
if self.need_update(bin, [elf]):
1015+
if bin and self.need_update(bin, [elf]):
10161016
needed_update = True
10171017
self.progress("elf2bin", name)
10181018
self.binary(r, elf, bin)

tools/toolchains/arm.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,10 @@ def archive(self, objects, lib_path):
216216

217217
@hook_tool
218218
def binary(self, resources, elf, bin):
219+
_, fmt = splitext(bin)
220+
bin_arg = {".bin": "--bin", ".hex": "--i32"}[fmt]
219221
# Build binary command
220-
cmd = [self.elf2bin, '--bin', '-o', bin, elf]
222+
cmd = [self.elf2bin, bin_arg, '-o', bin, elf]
221223

222224
# Call cmdline hook
223225
cmd = self.hook.get_cmdline_binary(cmd)

tools/toolchains/gcc.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,9 @@ def archive(self, objects, lib_path):
261261
@hook_tool
262262
def binary(self, resources, elf, bin):
263263
# Build binary command
264-
cmd = [self.elf2bin, "-O", "binary", elf, bin]
264+
_, fmt = splitext(bin)
265+
bin_arg = {'.bin': 'binary', '.hex': 'ihex'}[fmt]
266+
cmd = [self.elf2bin, "-O", bin_arg, elf, bin]
265267

266268
# Call cmdline hook
267269
cmd = self.hook.get_cmdline_binary(cmd)

tools/toolchains/iar.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,10 @@ def archive(self, objects, lib_path):
224224

225225
@hook_tool
226226
def binary(self, resources, elf, bin):
227+
_, fmt = splitext(bin)
228+
bin_arg = {".bin": "--bin", ".hex": "--ihex"}[fmt]
227229
# Build binary command
228-
cmd = [self.elf2bin, "--bin", elf, bin]
230+
cmd = [self.elf2bin, bin_arg, elf, bin]
229231

230232
# Call cmdline hook
231233
cmd = self.hook.get_cmdline_binary(cmd)

0 commit comments

Comments
 (0)