From: Bert Vermeulen Date: Mon, 18 Jun 2012 01:14:55 +0000 (+0200) Subject: add hantek-dso-extract tool. X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=683fe750793df2f56a205ddb3294ddf339b658a6;p=sigrok-util.git add hantek-dso-extract tool. --- diff --git a/firmware/README.hantek-dso-extract b/firmware/README.hantek-dso-extract new file mode 100644 index 0000000..f0a765a --- /dev/null +++ b/firmware/README.hantek-dso-extract @@ -0,0 +1,10 @@ +The hantek-dso-extract.py tool extracts firmware from the driver that comes +with the Hantek DSO-2xxx/52xx series USB oscilloscopes. Find the 32-bit +driver installed on the windows system -- typically called DSOxxxx1.sys or +DsoxxxxX861.sys, where xxxx is your device's model. Use it like this: + +$ ./hantek-dso-extract.py Dso2090X861.sys +saved 4730 bytes to hantek-dso-2090.fw + +Copy the resulting file over to the location where sigrok installed its +firmware files. By default this is /usr/local/share/sigrok-firmware diff --git a/firmware/hantek-dso-extract.py b/firmware/hantek-dso-extract.py new file mode 100755 index 0000000..e99236b --- /dev/null +++ b/firmware/hantek-dso-extract.py @@ -0,0 +1,93 @@ +#!/usr/bin/python3 +## +## This file is part of the sigrok project. +## +## Copyright (C) 2012 Bert Vermeulen +## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 3 of the License, or +## (at your option) any later version. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; if not, see . +## + +import sys +import os +import re +import struct +from array import array + +import parsepe + + +def find_model(filename): + filename = os.path.split(filename)[-1] + m = re.search('^dso([a-z0-9]+)1.sys$', filename, re.I) + if m: + model = m.group(1).upper() + model = model.replace('X86', '').replace('AMD64', '').replace('IA64', '') + if model == '520A': + model = '5200A' + else: + model = 'unknown' + + return model + + +def unsparse(data): + p = 0 + maxaddr = 0 + blob = array('B', [0] * 0x4000) + while p <= len(data) and data[p+4] == 0: + num_bytes = struct.unpack(" 0x4000: + # the FX2 only has 16K RAM. other writes are to registers + # in the 0xe000 region, skip those + continue + + blob[address:address+num_bytes] = chunk + + if address + num_bytes > maxaddr: + maxaddr = address + num_bytes + + return blob[:maxaddr].tostring() + + +def usage(): + print("hantek-dso-extract.py ") + sys.exit() + + +# +# main +# + +if len(sys.argv) != 2: + usage() + +try: + filename = sys.argv[1] + binihx = parsepe.extract_symbol(filename, '_firmware') + if binihx is None: + raise Exception("no firmware found") + blob = unsparse(binihx) + outfile = 'hantek-dso-' + find_model(filename) + '.fw' + open(outfile, 'wb').write(blob) + print("saved %d bytes to %s" % (len(blob), outfile)) +except Exception as e: + print("Error: %s" % str(e)) + + +