diff options
-rwxr-xr-x | downloader/downloader.py | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/downloader/downloader.py b/downloader/downloader.py index c918357..8f3fc3b 100755 --- a/downloader/downloader.py +++ b/downloader/downloader.py @@ -125,22 +125,21 @@ def exec_command(dev, cmd, answer): 3: "not implemented", 4: "flash write error", 5: "address invalid", 6: "address prohibited" } - answer = '<cB' + answer + 'B' - answer_len = struct.calcsize(answer) + answer = '<' + answer + 'B' + answer_len = struct.calcsize(answer) + 2 cstr = cmd + calc_csum(cmd) os.write(dev, cstr) astr = b'' - while len(astr) < answer_len: + while len(astr) < 2: astr += os.read(dev, answer_len - len(astr)) - data = list(struct.unpack(answer, astr)) - code = data.pop(0) - ret = data.pop(1) - checksum = data.pop() - if code != cmd[0]: + + if astr[0] != cmd[0]: print "ERROR: bootloader returned wrong command code" sys.exit(4) + + ret = ord(astr[1]) if ret != 0: rstr = "invalid return code" try: @@ -149,6 +148,11 @@ def exec_command(dev, cmd, answer): pass print "ERROR: bootloader returned %d: %s" % (ret, rstr) sys.exit(4) + + while len(astr) < answer_len: + astr += os.read(dev, answer_len - len(astr)) + + data = struct.unpack_from(answer, astr, 2) if 0 != calc_csum(astr): print "ERROR: checksum error" sys.exit(4) |