1# Copyright 2014 The Chromium OS Authors. All rights reserved. 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5import logging 6 7from autotest_lib.server.cros.faft.firmware_test import FirmwareTest 8 9 10class firmware_TPMKernelVersion(FirmwareTest): 11 """Dev mode will not corrupt kernel and firmware version stored in the TPM. 12 13 Automate 1.2.4 Check Kernel version in TPM is not corrupted. 14 """ 15 version = 1 16 17 def initialize(self, host, cmdline_args): 18 super(firmware_TPMKernelVersion, self).initialize(host, cmdline_args) 19 self.switcher.setup_mode('dev') 20 self.setup_usbkey(usbkey=True, host=False) 21 self.original_dev_boot_usb = self.faft_client.system.get_dev_boot_usb() 22 logging.info('Original dev_boot_usb value: %s', 23 str(self.original_dev_boot_usb)) 24 25 26 def dut_run_cmd(self, command): 27 """Execute command on DUT. 28 29 @param command: shell command to be executed on DUT. 30 @returns command output. 31 """ 32 logging.info('Execute %s', command) 33 output = self.faft_client.system.run_shell_command_get_output(command) 34 logging.info('Output %s', output) 35 return output 36 37 def cleanup(self): 38 """Reboot device from SSD.""" 39 if self.faft_client.system.is_removable_device_boot(): 40 logging.info('Reboot into internal disk...') 41 self.faft_client.system.set_dev_boot_usb(self.original_dev_boot_usb) 42 self.switcher.mode_aware_reboot() 43 super(firmware_TPMKernelVersion, self).cleanup() 44 45 def run_once(self): 46 # Get the kernel version and its datakey version. 47 # TODO(twreid): Verify the results. 48 version = self.faft_client.tpm.get_kernel_version() 49 logging.info('Kernel version: %d', version) 50 version = self.faft_client.tpm.get_kernel_datakey_version() 51 logging.info('Kernel datakey version: %d', version) 52 53 self.dut_run_cmd('crossystem kernkey_vfy dev_boot_usb') 54 # Boot CrOS from USB 55 self.faft_client.system.set_dev_boot_usb(1) 56 self.switcher.simple_reboot() 57 self.switcher.bypass_dev_boot_usb() 58 self.switcher.wait_for_client() 59 60 # Check that DUT is booted from USB. 61 self.check_state((self.checkers.crossystem_checker, 62 {'kernkey_vfy': 'hash'})) 63 64 out = self.dut_run_cmd('crossystem tpm_kernver tpm_fwver') 65 (kernver, fwver) = out[0].split(' ') 66 logging.info('tpm_kernver=%s tpm_fwver=%s', kernver, fwver) 67 assert kernver != '0xFFFFFFFF' 68 assert fwver != '0xFFFFFFFF' 69