summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2013-07-10 21:37:51 (GMT)
committerChristian Pointner <equinox@spreadspace.org>2013-07-10 21:37:51 (GMT)
commita10148f232c36e6e43471017da26ee016c43e9c4 (patch)
treef85093385d7019165a5668efad5a8c86d346d631
parentcc4ffd25829e22c122aec269184688ce6bd36865 (diff)
nicer output with progressbar
git-svn-id: https://svn.spreadspace.org/pic/trunk@70 a09c6847-51d9-44de-8ef2-e725cf50f3c7
-rwxr-xr-xbootloader/downloader.py51
1 files changed, 46 insertions, 5 deletions
diff --git a/bootloader/downloader.py b/bootloader/downloader.py
index 27b15c3..ab063b8 100755
--- a/bootloader/downloader.py
+++ b/bootloader/downloader.py
@@ -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 %15s" % 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,7 +291,8 @@ def verify_flash(dev, id, file):
if err !=0:
break
-
+ bar.end()
+ print >> sys.stderr, ""
if err != 0:
print >> sys.stderr, "ERROR: verify failed!"
sys.exit(-1)