Skip to content

Commit 7f97575

Browse files
committed
scripts: build: mergehex: Add --output-bin parameter
The optional --output-bin parameter instructs the IntelHex class to save the content as a binary file instead of the Intel Hex format. Signed-off-by: BUDKE Gerson Fernando <[email protected]>
1 parent 0e380ec commit 7f97575

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

scripts/build/mergehex.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import argparse
1414

1515

16-
def merge_hex_files(output, input_hex_files, overlap):
16+
def merge_hex_files(output, input_hex_files, overlap, output_bin):
1717
ih = IntelHex()
1818

1919
for hex_file_path in input_hex_files:
@@ -29,27 +29,29 @@ def merge_hex_files(output, input_hex_files, overlap):
2929
except AddressOverlapError:
3030
raise AddressOverlapError("{} has merge issues".format(hex_file_path))
3131

32-
ih.write_hex_file(output)
32+
output_format = "bin" if output_bin else "hex"
33+
ih.tofile(output, format=output_format)
3334

3435

3536
def parse_args():
3637
parser = argparse.ArgumentParser(
3738
description="Merge hex files.",
3839
formatter_class=argparse.RawDescriptionHelpFormatter, allow_abbrev=False)
3940
parser.add_argument("-o", "--output", required=False, default="merged.hex",
40-
type=argparse.FileType('w', encoding='UTF-8'),
4141
help="Output file name.")
4242
parser.add_argument("--overlap", default="error",
4343
help="What to do when files overlap (error, ignore, replace). "
4444
"See IntelHex.merge() for more info.")
45+
parser.add_argument("--output-bin", default=False,
46+
help="Save the merged content as binary file.")
4547
parser.add_argument("input_files", nargs='*')
4648
return parser.parse_args()
4749

4850

4951
def main():
5052
args = parse_args()
5153

52-
merge_hex_files(args.output, args.input_files, args.overlap)
54+
merge_hex_files(args.output, args.input_files, args.overlap, args.output_bin)
5355

5456

5557
if __name__ == "__main__":

0 commit comments

Comments
 (0)