FAFT: Initialize the TPM handler only on TPM related methods
Initializing the TPM handler stops tcsd/trunksd and affects other
systems which depend on them. Moving the initializing step to TPM
related methods by reusing the LazyInitHandlerProxy class.
Also restarted tcsd/trunksd when done.
FAFT running on Android system will not run the TPM related tests.
So don't care about the Android system.
CQ-DEPEND=CL:436245
BUG=chrome-os-partner:62150
TEST=Ran a FAFT test and called the TPM related methods manually.
Change-Id: Ifcf0ee858281a7d561ff39a28061832fb22d1217
Reviewed-on: https://chromium-review.googlesource.com/435888
Commit-Ready: Wai-Hong Tam <waihong@google.com>
Tested-by: Wai-Hong Tam <waihong@google.com>
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Reviewed-by: Andrey Pronin <apronin@chromium.org>
diff --git a/client/cros/faft/rpc_functions.py b/client/cros/faft/rpc_functions.py
index f07def6..47d2df6 100755
--- a/client/cros/faft/rpc_functions.py
+++ b/client/cros/faft/rpc_functions.py
@@ -41,19 +41,19 @@
return wrapper
-class LazyFlashromHandlerProxy:
- """Proxy of FlashromHandler for lazy initialization."""
+class LazyInitHandlerProxy:
+ """Proxy of a given handler_class for lazy initialization."""
_loaded = False
_obj = None
- def __init__(self, *args, **kargs):
+ def __init__(self, handler_class, *args, **kargs):
+ self._handler_class = handler_class
self._args = args
self._kargs = kargs
def _load(self):
- self._obj = flashrom_handler.FlashromHandler()
+ self._obj = self._handler_class()
self._obj.init(*self._args, **self._kargs)
- self._obj.new_image()
self._loaded = True
def __getattr__(self, name):
@@ -100,21 +100,23 @@
self._os_if.init(state_dir, log_file=self._log_file)
os.chdir(state_dir)
- self._bios_handler = LazyFlashromHandlerProxy(
- saft_flashrom_util,
- self._os_if,
- None,
- '/usr/share/vboot/devkeys',
- 'bios')
+ self._bios_handler = LazyInitHandlerProxy(
+ flashrom_handler.FlashromHandler,
+ saft_flashrom_util,
+ self._os_if,
+ None,
+ '/usr/share/vboot/devkeys',
+ 'bios')
self._ec_handler = None
if self._os_if.run_shell_command_get_status('mosys ec info') == 0:
- self._ec_handler = LazyFlashromHandlerProxy(
- saft_flashrom_util,
- self._os_if,
- 'ec_root_key.vpubk',
- '/usr/share/vboot/devkeys',
- 'ec')
+ self._ec_handler = LazyInitHandlerProxy(
+ flashrom_handler.FlashromHandler,
+ saft_flashrom_util,
+ self._os_if,
+ 'ec_root_key.vpubk',
+ '/usr/share/vboot/devkeys',
+ 'ec')
else:
self._os_if.log('No EC is reported by mosys.')
@@ -123,12 +125,9 @@
dev_key_path='/usr/share/vboot/devkeys',
internal_disk=True)
- # FIXME(waihong): Add back the TPM support.
- if not self._os_if.is_android:
- self._tpm_handler = tpm_handler.TpmHandler()
- self._tpm_handler.init(self._os_if)
- else:
- self._tpm_handler = None
+ self._tpm_handler = LazyInitHandlerProxy(
+ tpm_handler.TpmHandler,
+ self._os_if)
self._cgpt_handler = cgpt_handler.CgptHandler(self._os_if)
diff --git a/client/cros/faft/utils/flashrom_handler.py b/client/cros/faft/utils/flashrom_handler.py
index 3bbaa40..6a1f85a 100644
--- a/client/cros/faft/utils/flashrom_handler.py
+++ b/client/cros/faft/utils/flashrom_handler.py
@@ -132,6 +132,7 @@
self.os_if = os_if
self.pub_key_file = pub_key_file
self.dev_key_path = dev_key_path
+ self.new_image()
def new_image(self, image_file=None):
"""Parse the full flashrom image and store sections into files.
diff --git a/client/cros/faft/utils/tpm_handler.py b/client/cros/faft/utils/tpm_handler.py
index 83d76e7..1334e4b 100644
--- a/client/cros/faft/utils/tpm_handler.py
+++ b/client/cros/faft/utils/tpm_handler.py
@@ -77,19 +77,26 @@
def init(self, os_if):
self.os_if = os_if
- status = self.os_if.run_shell_command_get_output(
- 'initctl status tcsd') or ['']
- if status[0].startswith('tcsd start/running'):
- self.os_if.run_shell_command('stop tcsd')
-
- status = self.os_if.run_shell_command_get_output(
- 'initctl status trunksd') or ['']
- if status[0].startswith('trunksd start/running'):
+ cmd = 'initctl status tcsd || initctl status trunksd'
+ status = self.os_if.run_shell_command_get_output(cmd) or ['']
+ # Expected status is like ['trunksd start/running, process 2375']
+ trunksd_started = status[0].startswith('trunksd start/running')
+ if trunksd_started:
self.os_if.run_shell_command('stop trunksd')
+ else:
+ tcsd_started = status[0].startswith('tcsd start/running')
+ if tcsd_started:
+ self.os_if.run_shell_command('stop tcsd')
for nvram in self.nvrams.itervalues():
nvram.init(self.os_if)
+ # Restart the daemon
+ if trunksd_started:
+ self.os_if.run_shell_command('start trunksd')
+ elif tcsd_started:
+ self.os_if.run_shell_command('start tcsd')
+
def get_fw_version(self):
return self.nvrams['bios'].get_body_version()