summaryrefslogtreecommitdiff
path: root/extra/usb_updater
diff options
context:
space:
mode:
authorNick Sanders <nsanders@chromium.org>2017-09-14 16:16:10 -0700
committerchrome-bot <chrome-bot@chromium.org>2017-10-25 01:38:45 -0700
commit28a5ad1646b2994853e310354b604547950a55c0 (patch)
tree066c2af5e0b90f03dc2a92eecfa2d20c32f5bca4 /extra/usb_updater
parentc49d32a265ea76d9af55ccbcbda90e27748de1a3 (diff)
downloadchrome-ec-28a5ad1646b2994853e310354b604547950a55c0.tar.gz
servo: add usb updater
This updater combines console and firmware update commands to update both RO and RW sections of servo_v4 and servo_micro. BRANCH=None BUG=b:37513705 TEST=updated firmware Change-Id: I9f585c90f5849f8dd7c9d2e08111ffbd5770fd54 Signed-off-by: Nick Sanders <nsanders@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/668156 Reviewed-by: Nicolas Boichat <drinkcat@chromium.org>
Diffstat (limited to 'extra/usb_updater')
l---------extra/usb_updater/ecusb1
-rwxr-xr-xextra/usb_updater/fw_update.py34
-rwxr-xr-xextra/usb_updater/servo_updater.py85
3 files changed, 104 insertions, 16 deletions
diff --git a/extra/usb_updater/ecusb b/extra/usb_updater/ecusb
new file mode 120000
index 0000000000..c06ee0f51b
--- /dev/null
+++ b/extra/usb_updater/ecusb
@@ -0,0 +1 @@
+../tigertool/ecusb/ \ No newline at end of file
diff --git a/extra/usb_updater/fw_update.py b/extra/usb_updater/fw_update.py
index 73393c8fb2..367c0cad14 100755
--- a/extra/usb_updater/fw_update.py
+++ b/extra/usb_updater/fw_update.py
@@ -5,6 +5,8 @@
# Upload firmware over USB
+from __future__ import print_function
+
import argparse
import array
import json
@@ -19,10 +21,10 @@ import usb
debug = False
def debuglog(msg):
if debug:
- print msg
+ print(msg)
-def logoutput(msg):
- print msg
+def log(msg):
+ print(msg)
sys.stdout.flush()
@@ -189,7 +191,7 @@ class Supdate(object):
read = self.wr_command(cmd, read_count=4)
if len(read) == 4:
- print "Finished flashing"
+ log("Finished flashing")
return
raise Exception("Update", "Stop failed [%s]" % read)
@@ -212,7 +214,7 @@ class Supdate(object):
region, self._brdcfg['regions'][region][0], offset))
length = self._brdcfg['regions'][region][1]
- print "Sending"
+ log("Sending")
# Go to the correct region in the ec.bin file.
self._binfile.seek(offset)
@@ -246,7 +248,7 @@ class Supdate(object):
self.wr_command(data, read_count=0)
break
except:
- print "Timeout fail"
+ log("Timeout fail")
todo -= packetsize
# Done with this packet, move to the next one.
length -= pagesize
@@ -285,8 +287,8 @@ class Supdate(object):
raise Exception("Update", "Protocol version 0 not supported")
elif len(read) == expected:
base, version = struct.unpack(">II", read)
- print "Update protocol v. %d" % version
- print "Available flash region base: %x" % base
+ log("Update protocol v. %d" % version)
+ log("Available flash region base: %x" % base)
else:
raise Exception("Update", "Start command returned %d bytes" % len(read))
@@ -302,7 +304,7 @@ class Supdate(object):
if (self._offset >= self._brdcfg['regions'][region][0]) and \
(self._offset < (self._brdcfg['regions'][region][0] + \
self._brdcfg['regions'][region][1])):
- print "Active region: %s" % region
+ log("Active region: %s" % region)
self._region = region
@@ -333,26 +335,26 @@ class Supdate(object):
if debug:
pprint(data)
- print "Board is %s" % self._brdcfg['board']
+ log("Board is %s" % self._brdcfg['board'])
# Cast hex strings to int.
self._brdcfg['flash'] = int(self._brdcfg['flash'], 0)
self._brdcfg['vid'] = int(self._brdcfg['vid'], 0)
self._brdcfg['pid'] = int(self._brdcfg['pid'], 0)
- print "Flash Base is %x" % self._brdcfg['flash']
+ log("Flash Base is %x" % self._brdcfg['flash'])
self._flashsize = 0
for region in self._brdcfg['regions']:
base = int(self._brdcfg['regions'][region][0], 0)
length = int(self._brdcfg['regions'][region][1], 0)
- print "region %s\tbase:0x%08x size:0x%08x" % (
- region, base, length)
+ log("region %s\tbase:0x%08x size:0x%08x" % (
+ region, base, length))
self._flashsize += length
# Convert these to int because json doesn't support hex.
self._brdcfg['regions'][region][0] = base
self._brdcfg['regions'][region][1] = length
- print "Flash Size: 0x%x" % self._flashsize
+ log("Flash Size: 0x%x" % self._flashsize)
def load_file(self, binfile):
"""Open and verify size of the target ec.bin file.
@@ -405,11 +407,11 @@ def main():
# Start transfer and erase.
p.start()
# Upload the bin file
- print "Uploading %s" % binfile
+ log("Uploading %s" % binfile)
p.write_file()
# Finalize
- print "Done. Finalizing."
+ log("Done. Finalizing.")
p.stop()
if __name__ == "__main__":
diff --git a/extra/usb_updater/servo_updater.py b/extra/usb_updater/servo_updater.py
new file mode 100755
index 0000000000..0f7d640c39
--- /dev/null
+++ b/extra/usb_updater/servo_updater.py
@@ -0,0 +1,85 @@
+#!/usr/bin/python
+# Copyright 2016 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+from __future__ import print_function
+
+import argparse
+import errno
+import os
+import subprocess
+import time
+
+import json
+import fw_update
+import ecusb.tiny_servo_common as c
+
+
+def flash(brdfile, serialno, binfile):
+ p = fw_update.Supdate()
+ p.load_board(brdfile)
+ p.connect_usb(serialname=serialno)
+ p.load_file(binfile)
+
+ # Start transfer and erase.
+ p.start()
+ # Upload the bin file
+ print("Uploading %s" % binfile)
+ p.write_file()
+
+ # Finalize
+ print("Done. Finalizing.")
+ p.stop()
+
+
+def select(vidpid, serialno, region, debuglog=False):
+ if region not in ["rw", "ro"]:
+ raise Exception("Region must be ro or rw")
+
+ # Make sure device is up
+ c.wait_for_usb(vidpid, serialname=serialno)
+
+ # make a console
+ pty = c.setup_tinyservod(vidpid, 0, serialname=serialno, debuglog=debuglog)
+
+ cmd = "sysjump %s\nreboot" % region
+ pty._issue_cmd(cmd)
+ time.sleep(1)
+ pty.close()
+
+
+def main():
+ parser = argparse.ArgumentParser(description="Image a servo micro device")
+ parser.add_argument('-s', '--serialno', type=str,
+ help="serial number to program", default=None)
+ parser.add_argument('-b', '--board', type=str,
+ help="Board configuration json file", default="servo_v4.json")
+ parser.add_argument('-f', '--file', type=str,
+ help="Complete ec.bin file", default="servo_v4.bin")
+ parser.add_argument('-v', '--verbose', action="store_true",
+ help="Chatty output")
+
+ args = parser.parse_args()
+
+ brdfile = args.board
+ binfile = 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))
+
+ select(vidpid, serialno, "ro", debuglog=debuglog)
+
+ flash(brdfile, serialno, binfile)
+
+ select(vidpid, serialno, "rw", debuglog=debuglog)
+
+ flash(brdfile, serialno, binfile)
+
+if __name__ == "__main__":
+ main()
+