[servod] Add command to update servo firmware
BUG=b:192605416
Change-Id: I8da8aa94996d51a6b482cc5c6f991824cc50150b
diff --git a/src/dockerfiles/servod/Dockerfile b/src/dockerfiles/servod/Dockerfile
index fa62117..736bddd 100644
--- a/src/dockerfiles/servod/Dockerfile
+++ b/src/dockerfiles/servod/Dockerfile
@@ -133,4 +133,5 @@
ENV UDEV 1
ENV WARN_ONLY_ON_UNKNOWN_ENV="SERVO_FW_ALL_CHANNEL_OK"
+COPY update_servo_firmware.py /
COPY start_servod.sh stop_servod.sh /
diff --git a/src/dockerfiles/servod/update_servo_firmware.py b/src/dockerfiles/servod/update_servo_firmware.py
new file mode 100644
index 0000000..19d1533
--- /dev/null
+++ b/src/dockerfiles/servod/update_servo_firmware.py
@@ -0,0 +1,26 @@
+# Copyright 2021 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.
+
+import logging
+import subprocess
+import sys
+
+
+if __name__ == "__main__":
+ # Start udev service.
+ try:
+ subprocess.check_call(['service', 'udev', 'start'])
+ except subprocess.CalledProcessError as e:
+ logging.exception('Fail to start udev service.')
+ raise e
+
+ # Invoke servo_updater.
+ try:
+ servo_update_command = ['servo_updater'] + sys.argv[1:]
+ logging.debug('Updating firmware using: {}'.format(' '.join(servo_update_command)))
+ subprocess.check_call(['servo_updater'] + sys.argv[1:])
+ except subprocess.CalledProcessError as e:
+ logging.exception('Fail to update firmware.')
+ logging.info('Update firmware fails if servod is running.')
+ raise e