forked from SonicPotions/Penrose
-
Notifications
You must be signed in to change notification settings - Fork 0
/
merge-hex.py
executable file
·44 lines (34 loc) · 1.04 KB
/
merge-hex.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env python3
import argparse
import sys
try:
from intelhex import IntelHex
except ImportError:
sys.exit('Error: IntelHex module not found '
'<https://pypi.org/project/IntelHex/>')
class MergeHex:
def __init__(self, *args):
self._ihex = IntelHex()
for ihex in args:
self.add(ihex)
def add(self, ihex):
self._ihex.merge(ihex, overlap='replace')
def merged(self):
return self._ihex
def main():
parser = argparse.ArgumentParser()
parser.add_argument('-o', dest='output_file', default='-',
help='Output hex file (default stdout)')
parser.add_argument('-i', dest='input_file', required=True, nargs='+',
help='Input hex files')
args = parser.parse_args()
if args.output_file == '-':
args.output_file = sys.stdout
ihex = map(IntelHex, args.input_file)
ihex = MergeHex(*ihex).merged()
try:
ihex.write_hex_file(args.output_file, False)
except BrokenPipeError:
pass
if __name__ == '__main__':
main()