From b992a2a8f9b8dd029319c2b037eee7ad529d06c1 Mon Sep 17 00:00:00 2001 From: Richard Hughes Date: Mon, 9 Mar 2020 20:21:03 +0000 Subject: [PATCH] Add a helper script to add a DFU header This is so simple we can do it in 10 lines of Python. It matches the format of the `add_capsule_header.py` utility. --- contrib/firmware_packager/add_dfu_header.py | 49 +++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100755 contrib/firmware_packager/add_dfu_header.py diff --git a/contrib/firmware_packager/add_dfu_header.py b/contrib/firmware_packager/add_dfu_header.py new file mode 100755 index 000000000..18a1b31ab --- /dev/null +++ b/contrib/firmware_packager/add_dfu_header.py @@ -0,0 +1,49 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- +# +# Copyright (C) 2020 Richard Hughes +# +# SPDX-License-Identifier: LGPL-2.1+ + +import struct +import zlib +import argparse + +def main(bin_fn, dfu_fn, pad, vid, pid, rev): + + # read binary file + with open(bin_fn, 'rb') as f: + blob = f.read() + + # pad blob to a specific size + if pad: + while len(blob) < int(pad, 16): + blob += b'\0' + + # create DFU footer with checksum + blob += struct.pack('