Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions tools/targets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,12 +386,9 @@ class TEENSY3_1Code(object):
@staticmethod
def binary_hook(t_self, resources, elf, binf):
"""Hook that is run after elf is generated"""
from intelhex import IntelHex
binh = IntelHex()
binh.loadbin(binf, offset=0)

with open(binf.replace(".bin", ".hex"), "w") as file_desc:
binh.tofile(file_desc, format='hex')
# This function is referenced by old versions of targets.json and should
# be kept for backwards compatibility.
pass

class MTSCode(object):
"""Generic MTS code"""
Expand Down Expand Up @@ -475,7 +472,11 @@ def binary_hook(t_self, resources, _, binf):
# Merge user code with softdevice
from intelhex import IntelHex
binh = IntelHex()
binh.loadbin(binf, offset=softdevice_and_offset_entry['offset'])
_, ext = os.path.splitext(binf)
if ext == ".hex":
binh.loadhex(binf)
elif ext == ".bin":
binh.loadbin(binf, softdevice_and_offset_entry['offset'])

if t_self.target.MERGE_SOFT_DEVICE is True:
t_self.debug("Merge SoftDevice file %s"
Expand Down
4 changes: 2 additions & 2 deletions tools/toolchains/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1003,7 +1003,7 @@ def link_program(self, r, tmp_path, name):

filename = name+'.'+ext
elf = join(tmp_path, name + '.elf')
bin = join(tmp_path, filename)
bin = None if ext is 'elf' else join(tmp_path, filename)
map = join(tmp_path, name + '.map')

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

if self.need_update(bin, [elf]):
if bin and self.need_update(bin, [elf]):
needed_update = True
self.progress("elf2bin", name)
self.binary(r, elf, bin)
Expand Down
4 changes: 3 additions & 1 deletion tools/toolchains/arm.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,10 @@ def archive(self, objects, lib_path):

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

# Call cmdline hook
cmd = self.hook.get_cmdline_binary(cmd)
Expand Down
4 changes: 3 additions & 1 deletion tools/toolchains/gcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,9 @@ def archive(self, objects, lib_path):
@hook_tool
def binary(self, resources, elf, bin):
# Build binary command
cmd = [self.elf2bin, "-O", "binary", elf, bin]
_, fmt = splitext(bin)
bin_arg = {'.bin': 'binary', '.hex': 'ihex'}[fmt]
cmd = [self.elf2bin, "-O", bin_arg, elf, bin]

# Call cmdline hook
cmd = self.hook.get_cmdline_binary(cmd)
Expand Down
4 changes: 3 additions & 1 deletion tools/toolchains/iar.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,10 @@ def archive(self, objects, lib_path):

@hook_tool
def binary(self, resources, elf, bin):
_, fmt = splitext(bin)
bin_arg = {".bin": "--bin", ".hex": "--ihex"}[fmt]
# Build binary command
cmd = [self.elf2bin, "--bin", elf, bin]
cmd = [self.elf2bin, bin_arg, elf, bin]

# Call cmdline hook
cmd = self.hook.get_cmdline_binary(cmd)
Expand Down