From c3b0fa04a663fe233765b83d3be41a42aa08c25d Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Mon, 3 May 2021 08:21:10 +0100 Subject: Initial import for public release --- tools/bin2h.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100755 tools/bin2h.py (limited to 'tools/bin2h.py') diff --git a/tools/bin2h.py b/tools/bin2h.py new file mode 100755 index 0000000..c430538 --- /dev/null +++ b/tools/bin2h.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python + +from argparse import ArgumentParser + +__version__ = "1.0" + +def main(): + + parser = ArgumentParser(description="Bin to H converter", + epilog="Copyright (C) 2014 Juan J Martinez ", + ) + + parser.add_argument("--version", action="version", version="%(prog)s " + __version__) + parser.add_argument("file", help="file to convert") + parser.add_argument("id", help="variable to use") + + args = parser.parse_args() + + with open(args.file, "rb") as fd: + data = bytearray(fd.read()) + + data_out = "" + for part in range(0, len(data), 8): + if data_out: + data_out += ",\n" + data_out += ', '.join(["0x%02x" % b for b in data[part: part + 8]]) + + print("/* file: %s */" % args.file) + print("#define %s_LEN %d\n" % (args.id.upper(), len(data))) + print("const unsigned char %s[] = {\n%s\n};\n" % (args.id, data_out)) + +if __name__ == "__main__": + main() + -- cgit v1.2.3