Clone of official tools
Diff: utils.py
- Revision:
- 36:96847d42f010
- Parent:
- 31:8ea194f6145b
- Child:
- 43:2a7da56ebd24
--- a/utils.py Wed Feb 15 13:53:18 2017 -0600 +++ b/utils.py Thu Jun 22 11:12:28 2017 -0500 @@ -28,6 +28,7 @@ import json from collections import OrderedDict import logging +from intelhex import IntelHex def remove_if_in(lst, thing): if thing in lst: @@ -510,7 +511,21 @@ for string_part in range(num_parts): start_index = string_part * string_limit if string_part == num_parts - 1: - print large_string[start_index:] + sys.stdout.write(large_string[start_index:]) else: - end_index = ((string_part + 1) * string_limit) - 1 - print large_string[start_index:end_index], + sys.stdout.write(large_string[start_index: + start_index + string_limit]) + sys.stdout.write("\n") + +def intelhex_offset(filename, offset): + """Load a hex or bin file at a particular offset""" + _, inteltype = splitext(filename) + ih = IntelHex() + if inteltype == ".bin": + ih.loadbin(filename, offset=offset) + elif inteltype == ".hex": + ih.loadhex(filename) + else: + raise ToolException("File %s does not have a known binary file type" + % filename) + return ih