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 # tcsd already shutdown by test framework. 47 48 # Should return 1 4c 57 52 47 1 0 1 0 0 0 0 0 49 command = 'tpmc read 0x1008 0x0d' 50 self.dut_run_cmd(command) 51 52 self.dut_run_cmd('crossystem kernkey_vfy dev_boot_usb') 53 # Boot CrOS from USB 54 self.faft_client.system.set_dev_boot_usb(1) 55 self.switcher.mode_aware_reboot(wait_for_dut_up=False) 56 self.switcher.bypass_dev_boot_usb() 57 self.switcher.wait_for_client() 58 59 # Check that DUT is booted from USB. 60 self.check_state((self.checkers.crossystem_checker, 61 {'kernkey_vfy': 'hash'})) 62 63 out = self.dut_run_cmd('crossystem tpm_kernver tpm_fwver') 64 (kernver, fwver) = out[0].split(' ') 65 logging.info('tpm_kernver=%s tpm_fwver=%s', kernver, fwver) 66 assert kernver != '0xFFFFFFFF' 67 assert fwver != '0xFFFFFFFF' 68