From 2082d4b85c2abf74b030f12345913ae6f8bfb056 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Wed, 10 Jul 2013 21:43:35 +0000 Subject: upgraded pic downloader git-svn-id: https://svn.spreadspace.org/mur.sat@808 7de4ea59-55d0-425e-a1af-a3118ea81d4c --- software/pic.bootloader/downloader.py | 57 ++++++++++++++++++++++++++++++----- 1 file changed, 49 insertions(+), 8 deletions(-) (limited to 'software') diff --git a/software/pic.bootloader/downloader.py b/software/pic.bootloader/downloader.py index 27b15c3..8ca2b1b 100755 --- a/software/pic.bootloader/downloader.py +++ b/software/pic.bootloader/downloader.py @@ -179,7 +179,7 @@ def cmd_identify(dev, name): print >> sys.stderr, " right device?" sys.exit(4) - print >> sys.stderr, "connected with Bootloader '%s' Version %d.%d, (ID=%04X, %d words Flash, FSS=%d, %d bytes EEPROM, MESS=%d)" % \ + print >> sys.stderr, "connected with Bootloader '%s' Version %d.%d,\n (ID=%04X, %d words Flash, FSS=%d, %d bytes EEPROM, MESS=%d)" % \ (id['name'], id['ver_maj'], id['ver_min'], id['devid'], id['fs'], id['fss'], id['es'], id['mess']) return id @@ -216,32 +216,72 @@ def cmd_write_config(dev, id, nr, word): ### commands +class progressbar(object): + def __init__(self, total, name): + self._name = name + self._cnt = 0 + self._total = float(total) + self._point = total / 100.0 + self._increment = total / 50.0 + self._update() + + def _update(self): + sys.stderr.write("\r %13s" % self._name) + sys.stderr.write(" [" + "=" * int(self._cnt / self._increment) + " " * int((self._total - self._cnt)/ self._increment) + "]") +# sys.stderr.write(" " + str(self._cnt / self._point) + "%") + sys.stderr.write(" ( %d / %d )" % (self._cnt, self._total)) + sys.stderr.flush() + + def increment(self): + self._cnt += 1 + self._update() + + def end(self): + self._cnt = self._total + self._update() + sys.stderr.write("\n") + + + def boot(dev, id, file): cmd_boot(dev) def write_flash(dev, id, file): hexdata = load_hex(file) - for segment in create_flash_segments(hexdata, id['fs'], id['fss']): -# print >> sys.stderr, "%05X: %s" % (segment[0], ''.join('%04X '%i for i in segment[1])) + flashsegments = list(create_flash_segments(hexdata, id['fs'], id['fss'])) + print >> sys.stderr, "" + bar = progressbar(len(flashsegments), "write flash") + for segment in flashsegments: cmd_write_flash_segment(dev, id, segment[0], segment[1]) + bar.increment() + bar.end() + print >> sys.stderr, "" def read_flash(dev, id, file): codedata = {} + print >> sys.stderr, "" + bar = progressbar(float(id['fs'])/float(id['fss']), "read flash") for addr in xrange(0, id['fs'], id['fss']): data = cmd_read_flash_segment(dev, id, addr) -# print >> sys.stderr, "%05X: %s" % (addr, ''.join('%04X '%i for i in data)) + bar.increment() a = addr for d in data: if d != 0x3FFF: codedata[a] = d a += 1 + bar.end() write_hex(file, codedata) + print >> sys.stderr, "" def verify_flash(dev, id, file): hexdata = load_hex(file) err = 0 - for segment in create_flash_segments(hexdata, id['fs'], id['fss']): + flashsegments = list(create_flash_segments(hexdata, id['fs'], id['fss'])) + print >> sys.stderr, "" + bar = progressbar(len(flashsegments), "verify flash") + for segment in flashsegments: flashdata = cmd_read_flash_segment(dev, id, segment[0]) + bar.increment() for file,flash in zip(segment[1] , flashdata): if flash == 0x3FFF: flash = 0xFFFF @@ -251,12 +291,13 @@ def verify_flash(dev, id, file): if err !=0: break - + bar.end() + print >> sys.stderr, "" if err != 0: - print >> sys.stderr, "ERROR: verify failed!" + print >> sys.stderr, " ********* verify failed! ********" sys.exit(-1) else: - print >> sys.stderr, "verify ok!" + print >> sys.stderr, " *********** verify ok! **********" sys.exit(0) commands = { -- cgit v1.2.3