diff --git a/magboot.py b/magboot.py index 376facd..1db3e5c 100755 --- a/magboot.py +++ b/magboot.py @@ -45,47 +45,50 @@ def usage(*args): sys.stdout = sys.stderr - print __doc__ + print(__doc__) for msg in args: - print msg + print(msg) sys.exit(2) -def do_cmd(str, expect_reply=True): - ser.write(str) +def do_cmd(val, expect_reply=True): + if isinstance(val, str): + val = val.encode('latin1') + ser.write(val) if not expect_reply: - print "> OK" + print("> OK") return reply = ser.read() if (len(reply) == 0): - print "> FAILED (TIMEOUT)" + print("> FAILED (TIMEOUT)") sys.exit(1) - + reply = reply.decode() if (reply == 'Y'): - print "> OK" + print("> OK") return if (reply == 'N'): - print "> FAILED" + print("> FAILED") else: - print "> FAILED (UNKNOWN):" + print("> FAILED (UNKNOWN):") while (len(reply) == 1): - print reply + print(reply) reply = ser.read() sys.exit(1) def cmd_device_id(): - print "ID" + print("ID") do_cmd('I' + dev['signature']) def cmd_load_addr(addr): - print "LOAD_ADDR" + print("LOAD_ADDR") # Little-endian, 16-bit uint load address load_addr = pack('