summaryrefslogtreecommitdiff
path: root/extra/tigertool
diff options
context:
space:
mode:
authorRuben Rodriguez Buchillon <coconutruben@chromium.org>2020-12-08 13:27:46 -0800
committerCommit Bot <commit-bot@chromium.org>2020-12-11 02:57:42 +0000
commite96554d35c8f0e24a02767c1d9b2860c28e6974a (patch)
tree5d146f13a1b42f1de7a917c4f98b2cd97e162e02 /extra/tigertool
parent590ac3bc3f34bb0c9d92f35c853adb5bca252892 (diff)
downloadchrome-ec-e96554d35c8f0e24a02767c1d9b2860c28e6974a.tar.gz
servo_updater: make more robust on resets
long-term, we need to pull this into hdctools, rather than reimplement everything twice. Short term, this is a fine solution. It essentially makes sure that 1. we only keep one pty/stm32uart/stm32usb object around for communication 2. we always reset it properly when it could need a reset e.g. when the stm32 is rebooting, or a new firmware was flashed 3. it expands the timeout for the chip to come back to 2s the tiny_servod will eventually also land in hdctools, though for now it just ensures that we can reset the pyusb communication without larger issues and a larger refactor. BUG=chromium:1152838 BRANCH=None // Timeout before change, runs after change TEST=sudo servo_updater --board servo_micro // Timeout before change, runs after change TEST=sudo servo_updater --board sweetberry // Timeout before change, runs after change TEST=sudo servo_updater --board servo_micro --force // to show the serialname support. This is a fake serial, and it gets stuck waiting TEST=sudo servo_updater -s MICRO-S-2009020022 --board servo_micro // to show the serialname support. This is a real serial and it proceeds TEST=sudo servo_updater -s MICRO-S-2009020022 --board servo_micro Change-Id: I747ca69881c13c1aadd8e90a35badecbf4e6a09e Signed-off-by: Ruben Rodriguez Buchillon <coconutruben@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2580854 Reviewed-by: Otabek Kasimov <otabek@google.com> Reviewed-by: Garry Wang <xianuowang@chromium.org> (cherry picked from commit c1ff0aed409b5ddf03538448e2e4c773b97986f4) Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2585855
Diffstat (limited to 'extra/tigertool')
-rw-r--r--extra/tigertool/ecusb/tiny_servod.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/extra/tigertool/ecusb/tiny_servod.py b/extra/tigertool/ecusb/tiny_servod.py
new file mode 100644
index 0000000000..aec87995a4
--- /dev/null
+++ b/extra/tigertool/ecusb/tiny_servod.py
@@ -0,0 +1,50 @@
+# Copyright 2020 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.
+
+"""Helper class to facilitate communication to servo ec console."""
+
+from ecusb import pty_driver
+from ecusb import stm32uart
+
+
+class TinyServod(object):
+ """Helper class to wrap a pty_driver with interface."""
+
+ def __init__(self, vid, pid, interface, serialname=None, debug=False):
+ """Build the driver and interface.
+
+ Args:
+ vid: servo device vid
+ pid: servo device pid
+ interface: which usb interface the servo console is on
+ serialname: the servo device serial (if available)
+ """
+ self._vid = vid
+ self._pid = pid
+ self._interface = interface
+ self._serial = serialname
+ self._debug = debug
+ self._init()
+
+ def _init(self):
+ self.suart = stm32uart.Suart(vendor=self._vid,
+ product=self._pid,
+ interface=self._interface,
+ serialname=self._serial,
+ debuglog=self._debug)
+ self.suart.run()
+ self.pty = pty_driver.ptyDriver(self.suart, [])
+
+ def reinitialize(self):
+ """Reinitialize the connect after a reset/disconnect/etc."""
+ self.close()
+ self._init()
+
+ def close(self):
+ """Close out the connection and release resources.
+
+ Note: if another TinyServod process or servod itself needs the same device
+ it's necessary to call this to ensure the usb device is available.
+ """
+ self.suart.close()