summaryrefslogtreecommitdiff
path: root/extra/usb_updater/servo_updater.py
diff options
context:
space:
mode:
Diffstat (limited to 'extra/usb_updater/servo_updater.py')
-rwxr-xr-xextra/usb_updater/servo_updater.py86
1 files changed, 38 insertions, 48 deletions
diff --git a/extra/usb_updater/servo_updater.py b/extra/usb_updater/servo_updater.py
index 80a63636d8..e093f55422 100755
--- a/extra/usb_updater/servo_updater.py
+++ b/extra/usb_updater/servo_updater.py
@@ -19,7 +19,7 @@ import json
import fw_update
import ecusb.tiny_servo_common as c
-
+from ecusb import tiny_servod
class ServoUpdaterException(Exception):
"""Raised on exceptions generated by servo_updater."""
@@ -82,48 +82,25 @@ def flash2(vidpid, serialno, binfile):
else:
raise ServoUpdaterException("%s exit with res = %d" % (cmd, res))
-def connect(vidpid, iface, serialno, debuglog=False):
- """Connect to console.
-
- Args:
- vidpid: vidpid of desired device.
- iface: interface to connect.
- serialno: serial number, to differentiate multiple devices.
- debuglog: do chatty log.
-
- Returns:
- a connected pty object.
- """
- # Make sure device is up.
- c.wait_for_usb(vidpid, serialname=serialno)
-
- # make a console.
- pty = c.setup_tinyservod(vidpid, iface,
- serialname=serialno, debuglog=debuglog)
-
- return pty
-
-def select(vidpid, iface, serialno, region, debuglog=False):
+def select(tinys, region):
"""Ensure the servo is in the expected ro/rw partition."""
if region not in ["rw", "ro"]:
raise Exception("Region must be ro or rw")
- pty = connect(vidpid, iface, serialno)
-
if region is "ro":
cmd = "reboot"
else:
cmd = "sysjump %s" % region
- pty._issue_cmd(cmd)
- time.sleep(1)
- pty.close()
+ tinys.pty._issue_cmd(cmd)
+ time.sleep(2)
+ tinys.reinitialize()
-def do_version(vidpid, iface, serialno):
+def do_version(tinys):
"""Check version via ec console 'pty'.
Args:
- see connect()
+ tinys: TinyServod object
Returns:
detected version number
@@ -133,26 +110,23 @@ def do_version(vidpid, iface, serialno):
# ...
# Build: tigertail_v1.1.6749-74d1a312e
"""
- pty = connect(vidpid, iface, serialno)
-
cmd = '\r\nversion\r\n'
regex = 'Build:\s+(\S+)[\r\n]+'
- results = pty._issue_cmd_get_results(cmd, [regex])[0]
- pty.close()
+ results = tinys.pty._issue_cmd_get_results(cmd, [regex])[0]
return results[1].strip(' \t\r\n\0')
-def do_updater_version(vidpid, iface, serialno):
+def do_updater_version(tinys):
"""Check whether this uses python updater or c++ updater
Args:
- see connect()
+ tinys: TinyServod object
Returns:
updater version number. 2 or 6.
"""
- vers = do_version(vidpid, iface, serialno)
+ vers = do_version(tinys)
# Servo versions below 58 are from servo-9040.B. Versions starting with _v2
# are newer than anything _v1, no need to check the exact number. Updater
@@ -270,17 +244,22 @@ def main():
brdfile, binfile = findfiles(args.board, args.file)
serialno = args.serialno
- debuglog = (args.verbose is True)
with open(brdfile) as data_file:
data = json.load(data_file)
-
- vidpid = "%04x:%04x" % (int(data['vid'], 0), int(data['pid'], 0))
+ vid, pid = int(data['vid'], 0), int(data['pid'], 0)
+ vidpid = "%04x:%04x" % (vid, pid)
iface = int(data['console'], 0)
boardname = data['board']
+
+ # Make sure device is up.
+ c.wait_for_usb(vidpid, serialname=serialno)
+ # We need a tiny_servod to query some information. Set it up first.
+ tinys = tiny_servod.TinyServod(vid, pid, iface, serialno, args.verbose)
+
if not args.force:
- vers = do_version(vidpid, iface, serialno)
+ vers = do_version(tinys)
print("Current %s version is %s" % (boardname, vers))
newvers = find_available_version(boardname, binfile)
@@ -288,16 +267,20 @@ def main():
if newvers == vers:
print("No version update needed")
- if args.reboot is True:
- select(vidpid, iface, serialno, "ro", debuglog=debuglog)
+ if args.reboot:
+ select(tinys, 'ro')
return
else:
print("Updating to recommended version.")
- select(vidpid, iface, serialno, "ro", debuglog=debuglog)
+ # Make sure the servo MCU is in RO
+ select(tinys, 'ro')
- vers = do_updater_version(vidpid, iface, serialno)
+ vers = do_updater_version(tinys)
+ # To make sure that the tiny_servod here does not interfere with other
+ # processes, close it out.
+ tinys.close()
if vers == 2:
flash(brdfile, serialno, binfile)
elif vers == 6:
@@ -305,9 +288,15 @@ def main():
else:
raise ServoUpdaterException("Can't detect updater version")
- select(vidpid, iface, serialno, "rw", debuglog=debuglog)
+ # Make sure device is up.
+ c.wait_for_usb(vidpid, serialname=serialno)
+ # After we have made sure that it's back/available, reconnect the tiny servod.
+ tinys.reinitialize()
+
+ # Make sure the servo MCU is in RW
+ select(tinys, 'rw')
- vers = do_updater_version(vidpid, iface, serialno)
+ vers = do_updater_version(tinys)
if vers == 2:
flash(brdfile, serialno, binfile)
elif vers == 6:
@@ -315,7 +304,8 @@ def main():
else:
raise ServoUpdaterException("Can't detect updater version")
- select(vidpid, iface, serialno, "ro", debuglog=debuglog)
+ # Make sure the servo MCU is in RO
+ select(tinys, 'ro')
if __name__ == "__main__":
main()