You-Cheng Syu | f0f4be1 | 2017-12-05 16:33:53 +0800 | [diff] [blame] | 1 | #!/usr/bin/env python |
Jon Salz | e60307f | 2014-08-05 16:20:00 +0800 | [diff] [blame] | 2 | # -*- coding: utf-8 -*- |
| 3 | # Copyright 2014 The Chromium OS Authors. All rights reserved. |
Tammo Spalink | 9a96b8a | 2012-04-03 11:10:41 +0800 | [diff] [blame] | 4 | # Use of this source code is governed by a BSD-style license that can be |
| 5 | # found in the LICENSE file. |
| 6 | |
Jon Salz | e60307f | 2014-08-05 16:20:00 +0800 | [diff] [blame] | 7 | |
Tammo Spalink | 9a96b8a | 2012-04-03 11:10:41 +0800 | [diff] [blame] | 8 | """Google Factory Tool. |
| 9 | |
You-Cheng Syu | 461ec03 | 2017-03-06 15:56:58 +0800 | [diff] [blame] | 10 | This tool is intended to be used on factory assembly lines. It |
Tammo Spalink | 9a96b8a | 2012-04-03 11:10:41 +0800 | [diff] [blame] | 11 | provides all of the Google required test functionality and must be run |
| 12 | on each device as part of the assembly process. |
| 13 | """ |
| 14 | |
Tammo Spalink | 9a96b8a | 2012-04-03 11:10:41 +0800 | [diff] [blame] | 15 | import logging |
| 16 | import os |
Jon Salz | 6526643 | 2012-07-30 19:02:49 +0800 | [diff] [blame] | 17 | import pipes |
Tammo Spalink | 9a96b8a | 2012-04-03 11:10:41 +0800 | [diff] [blame] | 18 | import re |
| 19 | import sys |
Peter Shih | fdf1768 | 2017-05-26 11:38:39 +0800 | [diff] [blame] | 20 | from tempfile import gettempdir |
Cheng-Yi Chiang | 9fc121c | 2014-01-27 11:23:22 +0800 | [diff] [blame] | 21 | import threading |
Hung-Te Lin | 6bd1647 | 2012-06-20 16:26:47 +0800 | [diff] [blame] | 22 | import time |
Jon Salz | a88b83b | 2013-05-27 20:00:35 +0800 | [diff] [blame] | 23 | import xmlrpclib |
Peter Shih | fdf1768 | 2017-05-26 11:38:39 +0800 | [diff] [blame] | 24 | |
Ricky Liang | 7905f27 | 2013-03-16 01:57:10 +0800 | [diff] [blame] | 25 | import yaml |
Tammo Spalink | 9a96b8a | 2012-04-03 11:10:41 +0800 | [diff] [blame] | 26 | |
Peter Shih | fdf1768 | 2017-05-26 11:38:39 +0800 | [diff] [blame] | 27 | import factory_common # pylint: disable=unused-import |
Wei-Han Chen | 0a3320e | 2016-04-23 01:32:07 +0800 | [diff] [blame] | 28 | from cros.factory.gooftool.common import ExecFactoryPar |
Hung-Te Lin | 0e0f936 | 2015-11-18 18:18:05 +0800 | [diff] [blame] | 29 | from cros.factory.gooftool.common import Shell |
Peter Shih | fdf1768 | 2017-05-26 11:38:39 +0800 | [diff] [blame] | 30 | from cros.factory.gooftool.core import Gooftool |
| 31 | from cros.factory.gooftool import crosfw |
| 32 | from cros.factory.gooftool.probe import CalculateFirmwareHashes |
Ting Shen | 129fa6f | 2016-09-02 12:22:24 +0800 | [diff] [blame] | 33 | from cros.factory.gooftool.probe import Probe |
| 34 | from cros.factory.gooftool.probe import ReadRoVpd |
Peter Shih | fdf1768 | 2017-05-26 11:38:39 +0800 | [diff] [blame] | 35 | from cros.factory.gooftool import report_upload |
Hung-Te Lin | 604e0c2 | 2015-11-24 15:17:07 +0800 | [diff] [blame] | 36 | from cros.factory.hwid.v3 import common |
| 37 | from cros.factory.hwid.v3 import hwid_utils |
Wei-Han Chen | 2ebb92d | 2016-01-12 14:51:41 +0800 | [diff] [blame] | 38 | from cros.factory.test.env import paths |
Peter Shih | fdf1768 | 2017-05-26 11:38:39 +0800 | [diff] [blame] | 39 | from cros.factory.test import event_log |
Wei-Han Chen | aff5623 | 2016-04-16 09:17:59 +0800 | [diff] [blame] | 40 | from cros.factory.test.rules import phase |
Hung-Te Lin | 3f09684 | 2016-01-13 17:37:06 +0800 | [diff] [blame] | 41 | from cros.factory.test.rules.privacy import FilterDict |
Peter Shih | fdf1768 | 2017-05-26 11:38:39 +0800 | [diff] [blame] | 42 | from cros.factory.utils import argparse_utils |
Hung-Te Lin | 03bf7ab | 2016-06-16 17:26:19 +0800 | [diff] [blame] | 43 | from cros.factory.utils.argparse_utils import CmdArg |
Hung-Te Lin | 03bf7ab | 2016-06-16 17:26:19 +0800 | [diff] [blame] | 44 | from cros.factory.utils.argparse_utils import ParseCmdline |
| 45 | from cros.factory.utils.argparse_utils import verbosity_cmd_arg |
Peter Shih | fdf1768 | 2017-05-26 11:38:39 +0800 | [diff] [blame] | 46 | from cros.factory.utils.debug_utils import SetupLogging |
Jon Salz | 40b9f82 | 2014-07-25 16:39:55 +0800 | [diff] [blame] | 47 | from cros.factory.utils import file_utils |
Wei-Han Chen | a5c01a0 | 2016-04-23 19:27:19 +0800 | [diff] [blame] | 48 | from cros.factory.utils import sys_utils |
Chun-Ta Lin | 53cbbd5 | 2016-06-08 21:42:19 +0800 | [diff] [blame] | 49 | from cros.factory.utils import time_utils |
Jon Salz | ff88c02 | 2012-11-03 12:19:58 +0800 | [diff] [blame] | 50 | from cros.factory.utils.process_utils import Spawn |
Joel Kitching | d3bc266 | 2014-12-16 16:03:32 -0800 | [diff] [blame] | 51 | from cros.factory.utils.type_utils import Error |
Tammo Spalink | 86a61c6 | 2012-05-25 15:10:35 +0800 | [diff] [blame] | 52 | |
Tammo Spalink | 5c69983 | 2012-07-03 17:50:39 +0800 | [diff] [blame] | 53 | |
Tammo Spalink | 5c69983 | 2012-07-03 17:50:39 +0800 | [diff] [blame] | 54 | # TODO(tammo): Replace calls to sys.exit with raise Exit, and maybe |
| 55 | # treat that specially (as a smoot exit, as opposed to the more |
| 56 | # verbose output for generic Error). |
| 57 | |
Cheng-Yi Chiang | 9fc121c | 2014-01-27 11:23:22 +0800 | [diff] [blame] | 58 | _global_gooftool = None |
| 59 | _gooftool_lock = threading.Lock() |
Tammo Spalink | 5c69983 | 2012-07-03 17:50:39 +0800 | [diff] [blame] | 60 | |
Hung-Te Lin | 56b1840 | 2015-01-16 14:52:30 +0800 | [diff] [blame] | 61 | |
Ricky Liang | a70a120 | 2013-03-15 15:03:17 +0800 | [diff] [blame] | 62 | def GetGooftool(options): |
Peter Shih | fdf1768 | 2017-05-26 11:38:39 +0800 | [diff] [blame] | 63 | global _global_gooftool # pylint: disable=global-statement |
Ricky Liang | a70a120 | 2013-03-15 15:03:17 +0800 | [diff] [blame] | 64 | |
Cheng-Yi Chiang | 9fc121c | 2014-01-27 11:23:22 +0800 | [diff] [blame] | 65 | if _global_gooftool is None: |
| 66 | with _gooftool_lock: |
Shen-En Shih | c5d15d6 | 2017-08-04 13:02:59 +0800 | [diff] [blame] | 67 | if _global_gooftool is None: |
| 68 | project = getattr(options, 'project', None) |
| 69 | hwdb_path = getattr(options, 'hwdb_path', None) |
| 70 | _global_gooftool = Gooftool(hwid_version=3, project=project, |
| 71 | hwdb_path=hwdb_path) |
Cheng-Yi Chiang | 9fc121c | 2014-01-27 11:23:22 +0800 | [diff] [blame] | 72 | |
| 73 | return _global_gooftool |
Ricky Liang | a70a120 | 2013-03-15 15:03:17 +0800 | [diff] [blame] | 74 | |
Hung-Te Lin | 56b1840 | 2015-01-16 14:52:30 +0800 | [diff] [blame] | 75 | |
Ting Shen | 18a0638 | 2016-08-30 16:18:21 +0800 | [diff] [blame] | 76 | def Command(cmd_name, *args, **kwargs): |
| 77 | """ Decorator for commands in gooftool. |
| 78 | |
| 79 | This is similar to argparse_utils.Command, but all gooftool commands |
| 80 | can be waived during `gooftool finalize` or `gooftool verify` using |
Wei-Han Chen | 60c5d33 | 2017-01-05 17:15:10 +0800 | [diff] [blame] | 81 | --waive_list or --skip_list option. |
Ting Shen | 18a0638 | 2016-08-30 16:18:21 +0800 | [diff] [blame] | 82 | """ |
| 83 | def Decorate(fun): |
Wei-Han Chen | 60c5d33 | 2017-01-05 17:15:10 +0800 | [diff] [blame] | 84 | def CommandWithWaiveSkipCheck(options): |
Ting Shen | 18a0638 | 2016-08-30 16:18:21 +0800 | [diff] [blame] | 85 | waive_list = vars(options).get('waive_list', []) |
Wei-Han Chen | 60c5d33 | 2017-01-05 17:15:10 +0800 | [diff] [blame] | 86 | skip_list = vars(options).get('skip_list', []) |
| 87 | if phase.GetPhase() >= phase.PVT_DOGFOOD and ( |
| 88 | waive_list != [] or skip_list != []): |
Ting Shen | 18a0638 | 2016-08-30 16:18:21 +0800 | [diff] [blame] | 89 | raise Error( |
Wei-Han Chen | 60c5d33 | 2017-01-05 17:15:10 +0800 | [diff] [blame] | 90 | 'waive_list and skip_list should be empty for phase %s' % |
| 91 | phase.GetPhase()) |
Ting Shen | 18a0638 | 2016-08-30 16:18:21 +0800 | [diff] [blame] | 92 | |
Wei-Han Chen | 60c5d33 | 2017-01-05 17:15:10 +0800 | [diff] [blame] | 93 | if cmd_name not in skip_list: |
| 94 | try: |
| 95 | fun(options) |
| 96 | except Exception as e: |
| 97 | if cmd_name in waive_list: |
| 98 | logging.exception(e) |
| 99 | else: |
| 100 | raise |
Ting Shen | 18a0638 | 2016-08-30 16:18:21 +0800 | [diff] [blame] | 101 | |
| 102 | return argparse_utils.Command(cmd_name, *args, **kwargs)( |
Wei-Han Chen | 60c5d33 | 2017-01-05 17:15:10 +0800 | [diff] [blame] | 103 | CommandWithWaiveSkipCheck) |
Ting Shen | 18a0638 | 2016-08-30 16:18:21 +0800 | [diff] [blame] | 104 | return Decorate |
| 105 | |
| 106 | |
Tammo Spalink | 9a96b8a | 2012-04-03 11:10:41 +0800 | [diff] [blame] | 107 | @Command('write_hwid', |
| 108 | CmdArg('hwid', metavar='HWID', help='HWID string')) |
Andy Cheng | c92e6f9 | 2012-11-20 16:55:53 +0800 | [diff] [blame] | 109 | def WriteHWID(options): |
Tammo Spalink | 9a96b8a | 2012-04-03 11:10:41 +0800 | [diff] [blame] | 110 | """Write specified HWID value into the system BB.""" |
Andy Cheng | 7a76cb8 | 2012-11-19 18:08:19 +0800 | [diff] [blame] | 111 | |
Tammo Spalink | 95c4373 | 2012-07-25 15:57:14 -0700 | [diff] [blame] | 112 | logging.info('writing hwid string %r', options.hwid) |
Ricky Liang | a70a120 | 2013-03-15 15:03:17 +0800 | [diff] [blame] | 113 | GetGooftool(options).WriteHWID(options.hwid) |
Andy Cheng | 0465d13 | 2013-03-20 12:12:06 +0800 | [diff] [blame] | 114 | event_log.Log('write_hwid', hwid=options.hwid) |
Tammo Spalink | 95c4373 | 2012-07-25 15:57:14 -0700 | [diff] [blame] | 115 | print 'Wrote HWID: %r' % options.hwid |
Tammo Spalink | 9a96b8a | 2012-04-03 11:10:41 +0800 | [diff] [blame] | 116 | |
| 117 | |
Yong Hong | 5408f65 | 2017-07-11 19:20:25 +0800 | [diff] [blame] | 118 | _project_cmd_arg = CmdArg( |
| 119 | '--project', metavar='PROJECT', |
| 120 | default=None, help='Project name to test.') |
Ricky Liang | 5339023 | 2013-03-08 15:37:57 +0800 | [diff] [blame] | 121 | |
Tammo Spalink | 8fab531 | 2012-05-28 18:33:30 +0800 | [diff] [blame] | 122 | _hwdb_path_cmd_arg = CmdArg( |
| 123 | '--hwdb_path', metavar='PATH', |
Ricky Liang | eede792 | 2013-06-19 10:18:41 +0800 | [diff] [blame] | 124 | default=common.DEFAULT_HWID_DATA_PATH, |
Tammo Spalink | 8fab531 | 2012-05-28 18:33:30 +0800 | [diff] [blame] | 125 | help='Path to the HWID database.') |
| 126 | |
Tammo Spalink | 95c4373 | 2012-07-25 15:57:14 -0700 | [diff] [blame] | 127 | _hwid_status_list_cmd_arg = CmdArg( |
Hung-Te Lin | 56b1840 | 2015-01-16 14:52:30 +0800 | [diff] [blame] | 128 | '--status', nargs='*', default=['supported'], |
| 129 | help='allow only HWIDs with these status values') |
Tammo Spalink | 95c4373 | 2012-07-25 15:57:14 -0700 | [diff] [blame] | 130 | |
Jon Salz | ce124fb | 2012-10-02 17:42:03 +0800 | [diff] [blame] | 131 | _probe_results_cmd_arg = CmdArg( |
| 132 | '--probe_results', metavar='RESULTS.yaml', |
Ricky Liang | c662be3 | 2013-12-24 11:50:23 +0800 | [diff] [blame] | 133 | help=('Output from "gooftool probe --include_vpd" (used instead of ' |
Jon Salz | ce124fb | 2012-10-02 17:42:03 +0800 | [diff] [blame] | 134 | 'probing this system).')) |
| 135 | |
Ricky Liang | 5339023 | 2013-03-08 15:37:57 +0800 | [diff] [blame] | 136 | _device_info_cmd_arg = CmdArg( |
Ricky Liang | f89f73a | 2013-03-19 05:00:24 +0800 | [diff] [blame] | 137 | '--device_info', metavar='DEVICE_INFO.yaml', default=None, |
Ricky Liang | 5339023 | 2013-03-08 15:37:57 +0800 | [diff] [blame] | 138 | help='A dict of device info to use instead of fetching from shopfllor ' |
| 139 | 'server.') |
| 140 | |
Jon Salz | ce124fb | 2012-10-02 17:42:03 +0800 | [diff] [blame] | 141 | _hwid_cmd_arg = CmdArg( |
| 142 | '--hwid', metavar='HWID', |
Ricky Liang | a70a120 | 2013-03-15 15:03:17 +0800 | [diff] [blame] | 143 | help='HWID to verify (instead of the currently set HWID of this system).') |
Jon Salz | ce124fb | 2012-10-02 17:42:03 +0800 | [diff] [blame] | 144 | |
Bernie Thompson | 3c11c87 | 2013-07-22 18:22:45 -0700 | [diff] [blame] | 145 | _rma_mode_cmd_arg = CmdArg( |
| 146 | '--rma_mode', action='store_true', |
| 147 | help='Enable RMA mode, do not check for deprecated components.') |
Tammo Spalink | 95c4373 | 2012-07-25 15:57:14 -0700 | [diff] [blame] | 148 | |
Chih-Yu Huang | 714dbc4 | 2015-07-21 16:42:16 +0800 | [diff] [blame] | 149 | _cros_core_cmd_arg = CmdArg( |
| 150 | '--cros_core', action='store_true', |
| 151 | help='Finalize for ChromeOS Core devices (may add or remove few test ' |
Hung-Te Lin | 53c4940 | 2017-07-26 13:10:58 +0800 | [diff] [blame] | 152 | 'items. For example, registration codes or firmware bitmap ' |
Chih-Yu Huang | 714dbc4 | 2015-07-21 16:42:16 +0800 | [diff] [blame] | 153 | 'locale settings).') |
| 154 | |
bowgotsai | 13820f4 | 2015-09-10 23:18:04 +0800 | [diff] [blame] | 155 | _enforced_release_channels_cmd_arg = CmdArg( |
| 156 | '--enforced_release_channels', nargs='*', default=None, |
| 157 | help='Enforced release image channels.') |
| 158 | |
Yilun Lin | 34f5480 | 2017-11-16 11:58:25 +0800 | [diff] [blame] | 159 | _ec_pubkey_path_cmd_arg = CmdArg( |
| 160 | '--ec_pubkey_path', |
| 161 | default=None, |
| 162 | help='Path to public key in vb2 format. Verify EC key with pubkey file.') |
| 163 | |
| 164 | _ec_pubkey_hash_cmd_arg = CmdArg( |
| 165 | '--ec_pubkey_hash', |
| 166 | default=None, |
| 167 | help='A string for public key hash. Verify EC key with the given hash.') |
| 168 | |
Hung-Te Lin | cdb9652 | 2016-04-15 16:51:10 +0800 | [diff] [blame] | 169 | _release_rootfs_cmd_arg = CmdArg( |
| 170 | '--release_rootfs', help='Location of release image rootfs partition.') |
| 171 | |
| 172 | _firmware_path_cmd_arg = CmdArg( |
| 173 | '--firmware_path', help='Location of firmware image partition.') |
Ricky Liang | 43b879b | 2014-02-24 11:36:55 +0800 | [diff] [blame] | 174 | |
Wei-Han Chen | be1355a | 2016-04-24 19:31:03 +0800 | [diff] [blame] | 175 | _shopfloor_url_args_cmd_arg = CmdArg( |
| 176 | '--shopfloor_url', |
Earl Ou | 5118222 | 2016-09-09 12:16:48 +0800 | [diff] [blame] | 177 | help='Shopfloor server url to be informed when wiping is done. ' |
| 178 | 'After wiping, a XML-RPC request will be sent to the ' |
| 179 | 'given url to indicate the completion of wiping.') |
Wei-Han Chen | be1355a | 2016-04-24 19:31:03 +0800 | [diff] [blame] | 180 | |
| 181 | _station_ip_cmd_arg = CmdArg( |
| 182 | '--station_ip', |
| 183 | help='IP of remote station') |
| 184 | |
| 185 | _station_port_cmd_arg = CmdArg( |
| 186 | '--station_port', |
| 187 | help='Port on remote station') |
| 188 | |
| 189 | _wipe_finish_token_cmd_arg = CmdArg( |
| 190 | '--wipe_finish_token', |
| 191 | help='Required token when notifying station after wipe finished') |
| 192 | |
Ting Shen | 18a0638 | 2016-08-30 16:18:21 +0800 | [diff] [blame] | 193 | _waive_list_cmd_arg = CmdArg( |
| 194 | '--waive_list', nargs='*', default=[], metavar='SUBCMD', |
You-Cheng Syu | 461ec03 | 2017-03-06 15:56:58 +0800 | [diff] [blame] | 195 | help='A list of waived checks, separated by whitespace.' |
Ting Shen | 18a0638 | 2016-08-30 16:18:21 +0800 | [diff] [blame] | 196 | 'Each item should be a sub-command of gooftool.' |
| 197 | 'e.g. "gooftool verify --waive_list verify_tpm clear_gbb_flags".') |
| 198 | |
Wei-Han Chen | 60c5d33 | 2017-01-05 17:15:10 +0800 | [diff] [blame] | 199 | _skip_list_cmd_arg = CmdArg( |
| 200 | '--skip_list', nargs='*', default=[], metavar='SUBCMD', |
You-Cheng Syu | 461ec03 | 2017-03-06 15:56:58 +0800 | [diff] [blame] | 201 | help='A list of skipped checks, separated by whitespace.' |
Wei-Han Chen | 60c5d33 | 2017-01-05 17:15:10 +0800 | [diff] [blame] | 202 | 'Each item should be a sub-command of gooftool.' |
| 203 | 'e.g. "gooftool verify --skip_list verify_tpm clear_gbb_flags".') |
| 204 | |
Tammo Spalink | 8fab531 | 2012-05-28 18:33:30 +0800 | [diff] [blame] | 205 | |
Tammo Spalink | 9a96b8a | 2012-04-03 11:10:41 +0800 | [diff] [blame] | 206 | @Command('probe', |
| 207 | CmdArg('--comps', nargs='*', |
| 208 | help='List of keys from the component_db registry.'), |
Ricky Liang | b30da67 | 2013-06-14 12:36:34 +0800 | [diff] [blame] | 209 | CmdArg('--fast_fw_probe', action='store_true', |
| 210 | help='Do a fast probe for EC and main firmware versions only. ' |
| 211 | 'This implies --no_vol and --no_ic.'), |
Tammo Spalink | 9a96b8a | 2012-04-03 11:10:41 +0800 | [diff] [blame] | 212 | CmdArg('--no_vol', action='store_true', |
| 213 | help='Do not probe volatile data.'), |
| 214 | CmdArg('--no_ic', action='store_true', |
Jon Salz | 0f8a684 | 2012-09-25 11:28:22 +0800 | [diff] [blame] | 215 | help='Do not probe initial_config data.'), |
| 216 | CmdArg('--include_vpd', action='store_true', |
| 217 | help='Include VPD data in volatiles.')) |
Tammo Spalink | 9a96b8a | 2012-04-03 11:10:41 +0800 | [diff] [blame] | 218 | def RunProbe(options): |
| 219 | """Print yaml-formatted breakdown of probed device properties.""" |
Ricky Liang | a70a120 | 2013-03-15 15:03:17 +0800 | [diff] [blame] | 220 | print GetGooftool(options).Probe( |
| 221 | target_comp_classes=options.comps, |
Ricky Liang | b30da67 | 2013-06-14 12:36:34 +0800 | [diff] [blame] | 222 | fast_fw_probe=options.fast_fw_probe, |
Ricky Liang | a70a120 | 2013-03-15 15:03:17 +0800 | [diff] [blame] | 223 | probe_volatile=not options.no_vol, |
| 224 | probe_initial_config=not options.no_ic, |
| 225 | probe_vpd=options.include_vpd).Encode() |
Ricky Liang | 5339023 | 2013-03-08 15:37:57 +0800 | [diff] [blame] | 226 | |
Tammo Spalink | 9a96b8a | 2012-04-03 11:10:41 +0800 | [diff] [blame] | 227 | |
Tammo Spalink | 214caf4 | 2012-05-28 10:45:00 +0800 | [diff] [blame] | 228 | @Command('verify_components', |
| 229 | _hwdb_path_cmd_arg, |
Tammo Spalink | 5c69983 | 2012-07-03 17:50:39 +0800 | [diff] [blame] | 230 | CmdArg('target_comps', nargs='*')) |
Tammo Spalink | 214caf4 | 2012-05-28 10:45:00 +0800 | [diff] [blame] | 231 | def VerifyComponents(options): |
Andy Cheng | 8ece738 | 2012-08-22 16:25:42 +0800 | [diff] [blame] | 232 | """Verify that probeable components all match entries in the component_db. |
Tammo Spalink | 214caf4 | 2012-05-28 10:45:00 +0800 | [diff] [blame] | 233 | |
Tammo Spalink | 5c69983 | 2012-07-03 17:50:39 +0800 | [diff] [blame] | 234 | Probe for each component class in the target_comps and verify |
Tammo Spalink | 214caf4 | 2012-05-28 10:45:00 +0800 | [diff] [blame] | 235 | that a corresponding match exists in the component_db -- make sure |
| 236 | that these components are present, that they have been approved, but |
| 237 | do not check against any specific BOM/HWID configurations. |
| 238 | """ |
Andy Cheng | 7a76cb8 | 2012-11-19 18:08:19 +0800 | [diff] [blame] | 239 | |
Andy Cheng | c531e2f | 2012-10-15 19:09:17 +0800 | [diff] [blame] | 240 | try: |
Ricky Liang | a70a120 | 2013-03-15 15:03:17 +0800 | [diff] [blame] | 241 | result = GetGooftool(options).VerifyComponents( |
Andy Cheng | c531e2f | 2012-10-15 19:09:17 +0800 | [diff] [blame] | 242 | options.target_comps) |
| 243 | except ValueError, e: |
| 244 | sys.exit(e) |
| 245 | |
Ricky Liang | 5339023 | 2013-03-08 15:37:57 +0800 | [diff] [blame] | 246 | PrintVerifyComponentsResults(result) |
| 247 | |
| 248 | |
| 249 | def PrintVerifyComponentsResults(result): |
| 250 | """Prints out the results of VerifyComponents method call. |
| 251 | |
| 252 | Groups the results into two groups: 'matches' and 'errors', and prints out |
| 253 | their values. |
| 254 | """ |
Andy Cheng | c531e2f | 2012-10-15 19:09:17 +0800 | [diff] [blame] | 255 | # group by matches and errors |
Tammo Spalink | 214caf4 | 2012-05-28 10:45:00 +0800 | [diff] [blame] | 256 | matches = [] |
Andy Cheng | c531e2f | 2012-10-15 19:09:17 +0800 | [diff] [blame] | 257 | errors = [] |
| 258 | for result_list in result.values(): |
| 259 | for component_name, _, error in result_list: |
| 260 | if component_name: |
| 261 | matches.append(component_name) |
Tammo Spalink | 214caf4 | 2012-05-28 10:45:00 +0800 | [diff] [blame] | 262 | else: |
Andy Cheng | c531e2f | 2012-10-15 19:09:17 +0800 | [diff] [blame] | 263 | errors.append(error) |
| 264 | |
Andy Cheng | 228a8c9 | 2012-08-27 10:53:57 +0800 | [diff] [blame] | 265 | if matches: |
| 266 | print 'found probeable components:\n %s' % '\n '.join(matches) |
Tammo Spalink | 214caf4 | 2012-05-28 10:45:00 +0800 | [diff] [blame] | 267 | if errors: |
Andy Cheng | 228a8c9 | 2012-08-27 10:53:57 +0800 | [diff] [blame] | 268 | print '\nerrors:\n %s' % '\n '.join(errors) |
| 269 | sys.exit('\ncomponent verification FAILURE') |
Tammo Spalink | 214caf4 | 2012-05-28 10:45:00 +0800 | [diff] [blame] | 270 | else: |
Hung-Te Lin | 56b1840 | 2015-01-16 14:52:30 +0800 | [diff] [blame] | 271 | print '\ncomponent verification SUCCESS' |
Tammo Spalink | 214caf4 | 2012-05-28 10:45:00 +0800 | [diff] [blame] | 272 | |
| 273 | |
Yilun Lin | 34f5480 | 2017-11-16 11:58:25 +0800 | [diff] [blame] | 274 | @Command( |
| 275 | 'verify_ec_key', |
| 276 | _ec_pubkey_path_cmd_arg, |
| 277 | _ec_pubkey_hash_cmd_arg) |
| 278 | def VerifyECKey(options): |
| 279 | """Verify EC key.""" |
| 280 | return GetGooftool(options).VerifyECKey( |
| 281 | options.ec_pubkey_path, options.ec_pubkey_hash) |
| 282 | |
| 283 | |
Hung-Te Lin | e1d80f6 | 2016-03-31 14:58:13 +0800 | [diff] [blame] | 284 | @Command('verify_keys', |
Hung-Te Lin | cdb9652 | 2016-04-15 16:51:10 +0800 | [diff] [blame] | 285 | _release_rootfs_cmd_arg, |
| 286 | _firmware_path_cmd_arg) |
Peter Shih | fdf1768 | 2017-05-26 11:38:39 +0800 | [diff] [blame] | 287 | def VerifyKeys(options): |
Tammo Spalink | 9a96b8a | 2012-04-03 11:10:41 +0800 | [diff] [blame] | 288 | """Verify keys in firmware and SSD match.""" |
Hung-Te Lin | e1d80f6 | 2016-03-31 14:58:13 +0800 | [diff] [blame] | 289 | return GetGooftool(options).VerifyKeys( |
Hung-Te Lin | cdb9652 | 2016-04-15 16:51:10 +0800 | [diff] [blame] | 290 | options.release_rootfs, options.firmware_path) |
Tammo Spalink | 9a96b8a | 2012-04-03 11:10:41 +0800 | [diff] [blame] | 291 | |
| 292 | |
| 293 | @Command('set_fw_bitmap_locale') |
Peter Shih | fdf1768 | 2017-05-26 11:38:39 +0800 | [diff] [blame] | 294 | def SetFirmwareBitmapLocale(options): |
Tammo Spalink | 9a96b8a | 2012-04-03 11:10:41 +0800 | [diff] [blame] | 295 | """Use VPD locale value to set firmware bitmap default language.""" |
Andy Cheng | 7a76cb8 | 2012-11-19 18:08:19 +0800 | [diff] [blame] | 296 | |
Ricky Liang | a70a120 | 2013-03-15 15:03:17 +0800 | [diff] [blame] | 297 | (index, locale) = GetGooftool(options).SetFirmwareBitmapLocale() |
Andy Cheng | 2582d29 | 2012-12-04 17:38:28 +0800 | [diff] [blame] | 298 | logging.info('Firmware bitmap initial locale set to %d (%s).', |
| 299 | index, locale) |
Tammo Spalink | 9a96b8a | 2012-04-03 11:10:41 +0800 | [diff] [blame] | 300 | |
| 301 | |
Hung-Te Lin | e1d80f6 | 2016-03-31 14:58:13 +0800 | [diff] [blame] | 302 | @Command('verify_system_time', |
Hung-Te Lin | cdb9652 | 2016-04-15 16:51:10 +0800 | [diff] [blame] | 303 | _release_rootfs_cmd_arg) |
Peter Shih | fdf1768 | 2017-05-26 11:38:39 +0800 | [diff] [blame] | 304 | def VerifySystemTime(options): |
Tammo Spalink | 9a96b8a | 2012-04-03 11:10:41 +0800 | [diff] [blame] | 305 | """Verify system time is later than release filesystem creation time.""" |
Andy Cheng | 7a76cb8 | 2012-11-19 18:08:19 +0800 | [diff] [blame] | 306 | |
Hung-Te Lin | cdb9652 | 2016-04-15 16:51:10 +0800 | [diff] [blame] | 307 | return GetGooftool(options).VerifySystemTime(options.release_rootfs) |
Tammo Spalink | 9a96b8a | 2012-04-03 11:10:41 +0800 | [diff] [blame] | 308 | |
| 309 | |
Hung-Te Lin | e1d80f6 | 2016-03-31 14:58:13 +0800 | [diff] [blame] | 310 | @Command('verify_rootfs', |
Hung-Te Lin | cdb9652 | 2016-04-15 16:51:10 +0800 | [diff] [blame] | 311 | _release_rootfs_cmd_arg) |
Peter Shih | fdf1768 | 2017-05-26 11:38:39 +0800 | [diff] [blame] | 312 | def VerifyRootFs(options): |
Tammo Spalink | 9a96b8a | 2012-04-03 11:10:41 +0800 | [diff] [blame] | 313 | """Verify rootfs on SSD is valid by checking hash.""" |
Andy Cheng | 7a76cb8 | 2012-11-19 18:08:19 +0800 | [diff] [blame] | 314 | |
Hung-Te Lin | e1d80f6 | 2016-03-31 14:58:13 +0800 | [diff] [blame] | 315 | return GetGooftool(options).VerifyRootFs(options.release_rootfs) |
Tammo Spalink | 9a96b8a | 2012-04-03 11:10:41 +0800 | [diff] [blame] | 316 | |
Hung-Te Lin | 56b1840 | 2015-01-16 14:52:30 +0800 | [diff] [blame] | 317 | |
Cheng-Yi Chiang | 676b529 | 2013-06-18 12:05:33 +0800 | [diff] [blame] | 318 | @Command('verify_tpm') |
Peter Shih | fdf1768 | 2017-05-26 11:38:39 +0800 | [diff] [blame] | 319 | def VerifyTPM(options): |
Cheng-Yi Chiang | 676b529 | 2013-06-18 12:05:33 +0800 | [diff] [blame] | 320 | """Verify TPM is cleared.""" |
| 321 | |
| 322 | return GetGooftool(options).VerifyTPM() |
Tammo Spalink | 9a96b8a | 2012-04-03 11:10:41 +0800 | [diff] [blame] | 323 | |
Hung-Te Lin | 56b1840 | 2015-01-16 14:52:30 +0800 | [diff] [blame] | 324 | |
Hung-Te Lin | dd708d4 | 2014-07-11 17:05:01 +0800 | [diff] [blame] | 325 | @Command('verify_me_locked') |
Peter Shih | fdf1768 | 2017-05-26 11:38:39 +0800 | [diff] [blame] | 326 | def VerifyManagementEngineLocked(options): |
You-Cheng Syu | 461ec03 | 2017-03-06 15:56:58 +0800 | [diff] [blame] | 327 | """Verify Management Engine is locked.""" |
Hung-Te Lin | dd708d4 | 2014-07-11 17:05:01 +0800 | [diff] [blame] | 328 | |
| 329 | return GetGooftool(options).VerifyManagementEngineLocked() |
| 330 | |
Hung-Te Lin | 56b1840 | 2015-01-16 14:52:30 +0800 | [diff] [blame] | 331 | |
Tammo Spalink | 9a96b8a | 2012-04-03 11:10:41 +0800 | [diff] [blame] | 332 | @Command('verify_switch_wp') |
Peter Shih | fdf1768 | 2017-05-26 11:38:39 +0800 | [diff] [blame] | 333 | def VerifyWPSwitch(options): |
Tammo Spalink | 9a96b8a | 2012-04-03 11:10:41 +0800 | [diff] [blame] | 334 | """Verify hardware write protection switch is enabled.""" |
Andy Cheng | 7a76cb8 | 2012-11-19 18:08:19 +0800 | [diff] [blame] | 335 | |
Ricky Liang | a70a120 | 2013-03-15 15:03:17 +0800 | [diff] [blame] | 336 | GetGooftool(options).VerifyWPSwitch() |
Tammo Spalink | 9a96b8a | 2012-04-03 11:10:41 +0800 | [diff] [blame] | 337 | |
| 338 | |
| 339 | @Command('verify_switch_dev') |
Peter Shih | fdf1768 | 2017-05-26 11:38:39 +0800 | [diff] [blame] | 340 | def VerifyDevSwitch(options): |
Tammo Spalink | 9a96b8a | 2012-04-03 11:10:41 +0800 | [diff] [blame] | 341 | """Verify developer switch is disabled.""" |
Andy Cheng | 7a76cb8 | 2012-11-19 18:08:19 +0800 | [diff] [blame] | 342 | |
Ricky Liang | a70a120 | 2013-03-15 15:03:17 +0800 | [diff] [blame] | 343 | if GetGooftool(options).CheckDevSwitchForDisabling(): |
Hung-Te Lin | d7d3472 | 2012-07-26 16:48:35 +0800 | [diff] [blame] | 344 | logging.warn('VerifyDevSwitch: No physical switch.') |
Andy Cheng | 0465d13 | 2013-03-20 12:12:06 +0800 | [diff] [blame] | 345 | event_log.Log('switch_dev', type='virtual switch') |
Tammo Spalink | 9a96b8a | 2012-04-03 11:10:41 +0800 | [diff] [blame] | 346 | |
| 347 | |
Hung-Te Lin | 53c4940 | 2017-07-26 13:10:58 +0800 | [diff] [blame] | 348 | @Command('verify_vpd') |
| 349 | def VerifyVPD(options): |
| 350 | """Verify that VPD values are properly set. |
Jon Salz | add90d3 | 2014-04-29 16:16:27 +0800 | [diff] [blame] | 351 | |
Hung-Te Lin | 53c4940 | 2017-07-26 13:10:58 +0800 | [diff] [blame] | 352 | Check if mandatory fields are set, and deprecated fields don't exist. |
Jon Salz | add90d3 | 2014-04-29 16:16:27 +0800 | [diff] [blame] | 353 | """ |
Hung-Te Lin | 53c4940 | 2017-07-26 13:10:58 +0800 | [diff] [blame] | 354 | return GetGooftool(options).VerifyVPD() |
Jon Salz | add90d3 | 2014-04-29 16:16:27 +0800 | [diff] [blame] | 355 | |
| 356 | |
bowgotsai | 13820f4 | 2015-09-10 23:18:04 +0800 | [diff] [blame] | 357 | @Command('verify_release_channel', |
| 358 | _enforced_release_channels_cmd_arg) |
Peter Shih | fdf1768 | 2017-05-26 11:38:39 +0800 | [diff] [blame] | 359 | def VerifyReleaseChannel(options): |
bowgotsai | 529139c | 2015-05-30 01:39:49 +0800 | [diff] [blame] | 360 | """Verify that release image channel is correct. |
| 361 | |
| 362 | ChromeOS has four channels: canary, dev, beta and stable. |
| 363 | The last three channels support image auto-updates, checks |
| 364 | that release image channel is one of them. |
| 365 | """ |
bowgotsai | 13820f4 | 2015-09-10 23:18:04 +0800 | [diff] [blame] | 366 | return GetGooftool(options).VerifyReleaseChannel( |
| 367 | options.enforced_release_channels) |
bowgotsai | 529139c | 2015-05-30 01:39:49 +0800 | [diff] [blame] | 368 | |
| 369 | |
Tammo Spalink | 9a96b8a | 2012-04-03 11:10:41 +0800 | [diff] [blame] | 370 | @Command('write_protect') |
Peter Shih | fdf1768 | 2017-05-26 11:38:39 +0800 | [diff] [blame] | 371 | def EnableFwWp(options): |
Tammo Spalink | 9a96b8a | 2012-04-03 11:10:41 +0800 | [diff] [blame] | 372 | """Enable then verify firmware write protection.""" |
Peter Shih | fdf1768 | 2017-05-26 11:38:39 +0800 | [diff] [blame] | 373 | del options # Unused. |
Tammo Spalink | 9a96b8a | 2012-04-03 11:10:41 +0800 | [diff] [blame] | 374 | |
Yong Hong | dad230a | 2017-08-30 22:25:19 +0800 | [diff] [blame] | 375 | def WriteProtect(fw): |
Tammo Spalink | 9a96b8a | 2012-04-03 11:10:41 +0800 | [diff] [blame] | 376 | """Calculate protection size, then invoke flashrom. |
| 377 | |
Yong Hong | dad230a | 2017-08-30 22:25:19 +0800 | [diff] [blame] | 378 | The region (offset and size) to write protect may be different per chipset |
| 379 | and firmware layout, so we have to read the WP_RO section from FMAP to |
| 380 | decide that. |
Tammo Spalink | 9a96b8a | 2012-04-03 11:10:41 +0800 | [diff] [blame] | 381 | """ |
Hung-Te Lin | 7ea39e8 | 2012-07-31 18:39:33 +0800 | [diff] [blame] | 382 | wp_section = 'WP_RO' |
Hung-Te Lin | 7ea39e8 | 2012-07-31 18:39:33 +0800 | [diff] [blame] | 383 | |
Yong Hong | dad230a | 2017-08-30 22:25:19 +0800 | [diff] [blame] | 384 | fmap_image = fw.GetFirmwareImage( |
| 385 | sections=(['FMAP'] if fw.target == crosfw.TARGET_MAIN else None)) |
| 386 | if not fmap_image.has_section(wp_section): |
| 387 | raise Error('Could not find %s firmware section: %s' % |
| 388 | (fw.target.upper(), wp_section)) |
| 389 | |
| 390 | section_data = fw.GetFirmwareImage( |
| 391 | sections=[wp_section]).get_section_area(wp_section) |
| 392 | ro_offset, ro_size = section_data[0 : 2] |
| 393 | |
| 394 | logging.debug('write protecting %s [off=%x size=%x]', fw.target.upper(), |
Hung-Te Lin | 7ea39e8 | 2012-07-31 18:39:33 +0800 | [diff] [blame] | 395 | ro_offset, ro_size) |
Yong Hong | dad230a | 2017-08-30 22:25:19 +0800 | [diff] [blame] | 396 | crosfw.Flashrom(fw.target).EnableWriteProtection(ro_offset, ro_size) |
Tammo Spalink | 9a96b8a | 2012-04-03 11:10:41 +0800 | [diff] [blame] | 397 | |
Yong Hong | dad230a | 2017-08-30 22:25:19 +0800 | [diff] [blame] | 398 | WriteProtect(crosfw.LoadMainFirmware()) |
Andy Cheng | 0465d13 | 2013-03-20 12:12:06 +0800 | [diff] [blame] | 399 | event_log.Log('wp', fw='main') |
Hung-Te Lin | d3b124c | 2016-10-20 22:22:31 +0800 | [diff] [blame] | 400 | |
| 401 | # Some EC (mostly PD) does not support "RO NOW". Instead they will only set |
| 402 | # "RO_AT_BOOT" when you request to enable RO (These platforms consider |
| 403 | # --wp-range with right range identical to --wp-enable), and requires a |
| 404 | # 'ectool reboot_ec RO at-shutdown; reboot' to let the RO take effect. |
Hung-Te Lin | 0d10b56 | 2016-12-28 10:58:07 +0800 | [diff] [blame] | 405 | # After reboot, "flashrom -p host --wp-status" will return protected range. |
Hung-Te Lin | d3b124c | 2016-10-20 22:22:31 +0800 | [diff] [blame] | 406 | # If you don't reboot, returned range will be (0, 0), and running command |
| 407 | # "ectool flashprotect" will not have RO_NOW. |
| 408 | |
Yong Hong | dad230a | 2017-08-30 22:25:19 +0800 | [diff] [blame] | 409 | for fw in [crosfw.LoadEcFirmware(), crosfw.LoadPDFirmware()]: |
| 410 | if fw.GetChipId() is None: |
Hung-Te Lin | d3b124c | 2016-10-20 22:22:31 +0800 | [diff] [blame] | 411 | logging.warning('%s not write protected (seems there is no %s flash).', |
Yong Hong | dad230a | 2017-08-30 22:25:19 +0800 | [diff] [blame] | 412 | fw.target.upper(), fw.target.upper()) |
Hung-Te Lin | d3b124c | 2016-10-20 22:22:31 +0800 | [diff] [blame] | 413 | continue |
Yong Hong | dad230a | 2017-08-30 22:25:19 +0800 | [diff] [blame] | 414 | WriteProtect(fw) |
| 415 | event_log.Log('wp', fw=fw.target) |
Tammo Spalink | 9a96b8a | 2012-04-03 11:10:41 +0800 | [diff] [blame] | 416 | |
| 417 | |
| 418 | @Command('clear_gbb_flags') |
Peter Shih | fdf1768 | 2017-05-26 11:38:39 +0800 | [diff] [blame] | 419 | def ClearGBBFlags(options): |
Tammo Spalink | 9a96b8a | 2012-04-03 11:10:41 +0800 | [diff] [blame] | 420 | """Zero out the GBB flags, in preparation for transition to release state. |
| 421 | |
| 422 | No GBB flags are set in release/shipping state, but they are useful |
Hung-Te Lin | 879cff4 | 2017-06-19 12:46:37 +0800 | [diff] [blame] | 423 | for factory/development. See "futility gbb --flags" for details. |
Tammo Spalink | 9a96b8a | 2012-04-03 11:10:41 +0800 | [diff] [blame] | 424 | """ |
Andy Cheng | 7a76cb8 | 2012-11-19 18:08:19 +0800 | [diff] [blame] | 425 | |
Ricky Liang | a70a120 | 2013-03-15 15:03:17 +0800 | [diff] [blame] | 426 | GetGooftool(options).ClearGBBFlags() |
Andy Cheng | 0465d13 | 2013-03-20 12:12:06 +0800 | [diff] [blame] | 427 | event_log.Log('clear_gbb_flags') |
Tammo Spalink | 9a96b8a | 2012-04-03 11:10:41 +0800 | [diff] [blame] | 428 | |
| 429 | |
Jon Salz | aa3a30e | 2013-05-15 15:56:28 +0800 | [diff] [blame] | 430 | @Command('clear_factory_vpd_entries') |
Peter Shih | fdf1768 | 2017-05-26 11:38:39 +0800 | [diff] [blame] | 431 | def ClearFactoryVPDEntries(options): |
Jon Salz | aa3a30e | 2013-05-15 15:56:28 +0800 | [diff] [blame] | 432 | """Clears factory.* items in the RW VPD.""" |
| 433 | entries = GetGooftool(options).ClearFactoryVPDEntries() |
| 434 | event_log.Log('clear_factory_vpd_entries', entries=FilterDict(entries)) |
| 435 | |
| 436 | |
Mattias Nissler | cca761b | 2015-04-15 21:53:04 +0200 | [diff] [blame] | 437 | @Command('generate_stable_device_secret') |
Peter Shih | fdf1768 | 2017-05-26 11:38:39 +0800 | [diff] [blame] | 438 | def GenerateStableDeviceSecret(options): |
You-Cheng Syu | 461ec03 | 2017-03-06 15:56:58 +0800 | [diff] [blame] | 439 | """Generates a fresh stable device secret and stores it in the RO VPD.""" |
Mattias Nissler | cca761b | 2015-04-15 21:53:04 +0200 | [diff] [blame] | 440 | GetGooftool(options).GenerateStableDeviceSecret() |
| 441 | event_log.Log('generate_stable_device_secret') |
| 442 | |
Wei-Han Chen | be1355a | 2016-04-24 19:31:03 +0800 | [diff] [blame] | 443 | |
Shen-En Shih | d078a7c | 2017-08-04 13:33:49 +0800 | [diff] [blame] | 444 | @Command('cr50_set_board_id') |
| 445 | def Cr50SetBoardId(options): |
| 446 | """Set the board id and flag in the Cr50 chip.""" |
| 447 | GetGooftool(options).Cr50SetBoardId() |
| 448 | event_log.Log('cr50_set_board_id') |
| 449 | |
| 450 | |
Earl Ou | 564a787 | 2016-10-05 10:22:00 +0800 | [diff] [blame] | 451 | @Command('enable_release_partition', |
| 452 | CmdArg('--release_rootfs', |
| 453 | help=('path to the release rootfs device. If not specified, ' |
| 454 | 'the default (5th) partition will be used.'))) |
| 455 | def EnableReleasePartition(options): |
| 456 | """Enables a release image partition on the disk.""" |
| 457 | GetGooftool(options).EnableReleasePartition(options.release_rootfs) |
| 458 | |
| 459 | |
Shun-Hsing Ou | cdc64e1 | 2015-01-14 22:07:33 +0800 | [diff] [blame] | 460 | @Command('wipe_in_place', |
| 461 | CmdArg('--fast', action='store_true', |
Shun-Hsing Ou | 8d3c40a | 2015-10-08 18:16:08 +0800 | [diff] [blame] | 462 | help='use non-secure but faster wipe method.'), |
Wei-Han Chen | be1355a | 2016-04-24 19:31:03 +0800 | [diff] [blame] | 463 | _shopfloor_url_args_cmd_arg, |
| 464 | _station_ip_cmd_arg, |
| 465 | _station_port_cmd_arg, |
| 466 | _wipe_finish_token_cmd_arg) |
Shun-Hsing Ou | cdc64e1 | 2015-01-14 22:07:33 +0800 | [diff] [blame] | 467 | def WipeInPlace(options): |
| 468 | """Start factory wipe directly without reboot.""" |
| 469 | |
Wei-Han Chen | be1355a | 2016-04-24 19:31:03 +0800 | [diff] [blame] | 470 | GetGooftool(options).WipeInPlace(options.fast, |
Wei-Han Chen | be1355a | 2016-04-24 19:31:03 +0800 | [diff] [blame] | 471 | options.shopfloor_url, |
| 472 | options.station_ip, |
| 473 | options.station_port, |
| 474 | options.wipe_finish_token) |
Mattias Nissler | cca761b | 2015-04-15 21:53:04 +0200 | [diff] [blame] | 475 | |
Wei-Han Chen | 7dc6d13 | 2016-04-06 11:11:53 +0800 | [diff] [blame] | 476 | @Command('wipe_init', |
Wei-Han Chen | 0a3320e | 2016-04-23 01:32:07 +0800 | [diff] [blame] | 477 | CmdArg('--wipe_args', help='arguments for clobber-state'), |
| 478 | CmdArg('--state_dev', help='path to stateful partition device'), |
| 479 | CmdArg('--root_disk', help='path to primary device'), |
| 480 | CmdArg('--old_root', help='path to old root'), |
Wei-Han Chen | 0a3320e | 2016-04-23 01:32:07 +0800 | [diff] [blame] | 481 | _shopfloor_url_args_cmd_arg, |
Wei-Han Chen | be1355a | 2016-04-24 19:31:03 +0800 | [diff] [blame] | 482 | _release_rootfs_cmd_arg, |
| 483 | _station_ip_cmd_arg, |
| 484 | _station_port_cmd_arg, |
| 485 | _wipe_finish_token_cmd_arg) |
Wei-Han Chen | 7dc6d13 | 2016-04-06 11:11:53 +0800 | [diff] [blame] | 486 | def WipeInit(options): |
Wei-Han Chen | 0a3320e | 2016-04-23 01:32:07 +0800 | [diff] [blame] | 487 | GetGooftool(options).WipeInit(options.wipe_args, |
Wei-Han Chen | 0a3320e | 2016-04-23 01:32:07 +0800 | [diff] [blame] | 488 | options.shopfloor_url, |
| 489 | options.state_dev, |
| 490 | options.release_rootfs, |
| 491 | options.root_disk, |
Wei-Han Chen | be1355a | 2016-04-24 19:31:03 +0800 | [diff] [blame] | 492 | options.old_root, |
| 493 | options.station_ip, |
| 494 | options.station_port, |
| 495 | options.wipe_finish_token) |
Wei-Han Chen | 7dc6d13 | 2016-04-06 11:11:53 +0800 | [diff] [blame] | 496 | |
Tammo Spalink | 9a96b8a | 2012-04-03 11:10:41 +0800 | [diff] [blame] | 497 | @Command('verify', |
Hung-Te Lin | 6d82754 | 2012-07-19 11:50:41 +0800 | [diff] [blame] | 498 | CmdArg('--no_write_protect', action='store_true', |
| 499 | help='Do not check write protection switch state.'), |
Tammo Spalink | 95c4373 | 2012-07-25 15:57:14 -0700 | [diff] [blame] | 500 | _hwid_status_list_cmd_arg, |
Jon Salz | ce124fb | 2012-10-02 17:42:03 +0800 | [diff] [blame] | 501 | _hwdb_path_cmd_arg, |
Yong Hong | 5408f65 | 2017-07-11 19:20:25 +0800 | [diff] [blame] | 502 | _project_cmd_arg, |
Jon Salz | ce124fb | 2012-10-02 17:42:03 +0800 | [diff] [blame] | 503 | _probe_results_cmd_arg, |
Cheng-Yi Chiang | 406ad91 | 2013-11-14 16:51:33 +0800 | [diff] [blame] | 504 | _hwid_cmd_arg, |
Chih-Yu Huang | 714dbc4 | 2015-07-21 16:42:16 +0800 | [diff] [blame] | 505 | _rma_mode_cmd_arg, |
bowgotsai | 13820f4 | 2015-09-10 23:18:04 +0800 | [diff] [blame] | 506 | _cros_core_cmd_arg, |
Yilun Lin | 34f5480 | 2017-11-16 11:58:25 +0800 | [diff] [blame] | 507 | _ec_pubkey_path_cmd_arg, |
| 508 | _ec_pubkey_hash_cmd_arg, |
Hung-Te Lin | cdb9652 | 2016-04-15 16:51:10 +0800 | [diff] [blame] | 509 | _release_rootfs_cmd_arg, |
| 510 | _firmware_path_cmd_arg, |
Ting Shen | 18a0638 | 2016-08-30 16:18:21 +0800 | [diff] [blame] | 511 | _enforced_release_channels_cmd_arg, |
Wei-Han Chen | 60c5d33 | 2017-01-05 17:15:10 +0800 | [diff] [blame] | 512 | _waive_list_cmd_arg, |
| 513 | _skip_list_cmd_arg) |
Tammo Spalink | 9a96b8a | 2012-04-03 11:10:41 +0800 | [diff] [blame] | 514 | def Verify(options): |
| 515 | """Verifies if whole factory process is ready for finalization. |
| 516 | |
| 517 | This routine performs all the necessary checks to make sure the |
| 518 | device is ready to be finalized, but does not modify state. These |
| 519 | checks include dev switch, firmware write protection switch, hwid, |
| 520 | system time, keys, and root file system. |
| 521 | """ |
Andy Cheng | 7a76cb8 | 2012-11-19 18:08:19 +0800 | [diff] [blame] | 522 | |
Hung-Te Lin | 6d82754 | 2012-07-19 11:50:41 +0800 | [diff] [blame] | 523 | if not options.no_write_protect: |
Ricky Liang | a70a120 | 2013-03-15 15:03:17 +0800 | [diff] [blame] | 524 | VerifyWPSwitch(options) |
Hung-Te Lin | dd708d4 | 2014-07-11 17:05:01 +0800 | [diff] [blame] | 525 | VerifyManagementEngineLocked(options) |
Ricky Liang | a70a120 | 2013-03-15 15:03:17 +0800 | [diff] [blame] | 526 | VerifyDevSwitch(options) |
Ting Shen | 129fa6f | 2016-09-02 12:22:24 +0800 | [diff] [blame] | 527 | VerifyHWID(options) |
Ricky Liang | a70a120 | 2013-03-15 15:03:17 +0800 | [diff] [blame] | 528 | VerifySystemTime(options) |
Yilun Lin | 34f5480 | 2017-11-16 11:58:25 +0800 | [diff] [blame] | 529 | VerifyECKey(options) |
Ricky Liang | a70a120 | 2013-03-15 15:03:17 +0800 | [diff] [blame] | 530 | VerifyKeys(options) |
| 531 | VerifyRootFs(options) |
Cheng-Yi Chiang | 676b529 | 2013-06-18 12:05:33 +0800 | [diff] [blame] | 532 | VerifyTPM(options) |
Hung-Te Lin | 53c4940 | 2017-07-26 13:10:58 +0800 | [diff] [blame] | 533 | VerifyVPD(options) |
bowgotsai | 529139c | 2015-05-30 01:39:49 +0800 | [diff] [blame] | 534 | VerifyReleaseChannel(options) |
Tammo Spalink | 9a96b8a | 2012-04-03 11:10:41 +0800 | [diff] [blame] | 535 | |
Hung-Te Lin | 56b1840 | 2015-01-16 14:52:30 +0800 | [diff] [blame] | 536 | |
Jon Salz | fe9036f | 2014-01-16 14:11:23 +0800 | [diff] [blame] | 537 | @Command('untar_stateful_files') |
Hung-Te Lin | 388bce2 | 2014-06-03 19:56:40 +0800 | [diff] [blame] | 538 | def UntarStatefulFiles(unused_options): |
Jon Salz | fe9036f | 2014-01-16 14:11:23 +0800 | [diff] [blame] | 539 | """Untars stateful files from stateful_files.tar.xz on stateful partition. |
| 540 | |
| 541 | If that file does not exist (which should only be R30 and earlier), |
| 542 | this is a no-op. |
| 543 | """ |
Hung-Te Lin | 2333f3f | 2016-08-24 17:56:48 +0800 | [diff] [blame] | 544 | # Path to stateful partition on device. |
| 545 | device_stateful_path = '/mnt/stateful_partition' |
| 546 | tar_file = os.path.join(device_stateful_path, 'stateful_files.tar.xz') |
Jon Salz | fe9036f | 2014-01-16 14:11:23 +0800 | [diff] [blame] | 547 | if os.path.exists(tar_file): |
Hung-Te Lin | 2333f3f | 2016-08-24 17:56:48 +0800 | [diff] [blame] | 548 | Spawn(['tar', 'xf', tar_file], cwd=device_stateful_path, |
Jon Salz | fe9036f | 2014-01-16 14:11:23 +0800 | [diff] [blame] | 549 | log=True, check_call=True) |
| 550 | else: |
| 551 | logging.warning('No stateful files at %s', tar_file) |
Tammo Spalink | 9a96b8a | 2012-04-03 11:10:41 +0800 | [diff] [blame] | 552 | |
Jon Salz | 40b9f82 | 2014-07-25 16:39:55 +0800 | [diff] [blame] | 553 | |
| 554 | @Command('log_source_hashes') |
Peter Shih | fdf1768 | 2017-05-26 11:38:39 +0800 | [diff] [blame] | 555 | def LogSourceHashes(options): |
Jon Salz | 40b9f82 | 2014-07-25 16:39:55 +0800 | [diff] [blame] | 556 | """Logs hashes of source files in the factory toolkit.""" |
Peter Shih | fdf1768 | 2017-05-26 11:38:39 +0800 | [diff] [blame] | 557 | del options # Unused. |
Jon Salz | e60307f | 2014-08-05 16:20:00 +0800 | [diff] [blame] | 558 | # WARNING: The following line is necessary to validate the integrity |
| 559 | # of the factory software. Do not remove or modify it. |
| 560 | # |
| 561 | # 警告:此行会验证工厂软件的完整性,禁止删除或修改。 |
Wei-Han Chen | a5c01a0 | 2016-04-23 19:27:19 +0800 | [diff] [blame] | 562 | factory_par = sys_utils.GetRunningFactoryPythonArchivePath() |
| 563 | if factory_par: |
| 564 | event_log.Log( |
| 565 | 'source_hashes', |
| 566 | **file_utils.HashPythonArchive(factory_par)) |
| 567 | else: |
| 568 | event_log.Log( |
| 569 | 'source_hashes', |
Peter Shih | ad16677 | 2017-05-31 11:36:17 +0800 | [diff] [blame] | 570 | **file_utils.HashSourceTree(os.path.join(paths.FACTORY_DIR, 'py'))) |
Jon Salz | 40b9f82 | 2014-07-25 16:39:55 +0800 | [diff] [blame] | 571 | |
| 572 | |
Tammo Spalink | 86a61c6 | 2012-05-25 15:10:35 +0800 | [diff] [blame] | 573 | @Command('log_system_details') |
Peter Shih | fdf1768 | 2017-05-26 11:38:39 +0800 | [diff] [blame] | 574 | def LogSystemDetails(options): |
Tammo Spalink | 86a61c6 | 2012-05-25 15:10:35 +0800 | [diff] [blame] | 575 | """Write miscellaneous system details to the event log.""" |
Andy Cheng | 7a76cb8 | 2012-11-19 18:08:19 +0800 | [diff] [blame] | 576 | |
Ricky Liang | 43b879b | 2014-02-24 11:36:55 +0800 | [diff] [blame] | 577 | event_log.Log('system_details', **GetGooftool(options).GetSystemDetails()) |
Tammo Spalink | 86a61c6 | 2012-05-25 15:10:35 +0800 | [diff] [blame] | 578 | |
| 579 | |
Jon Salz | a88b83b | 2013-05-27 20:00:35 +0800 | [diff] [blame] | 580 | def CreateReportArchiveBlob(*args, **kwargs): |
| 581 | """Creates a report archive and returns it as a blob. |
Tammo Spalink | 9a96b8a | 2012-04-03 11:10:41 +0800 | [diff] [blame] | 582 | |
Jon Salz | a88b83b | 2013-05-27 20:00:35 +0800 | [diff] [blame] | 583 | Args: |
| 584 | See CreateReportArchive. |
Andy Cheng | 7a76cb8 | 2012-11-19 18:08:19 +0800 | [diff] [blame] | 585 | |
Jon Salz | a88b83b | 2013-05-27 20:00:35 +0800 | [diff] [blame] | 586 | Returns: |
| 587 | An xmlrpclib.Binary object containing a .tar.xz file. |
| 588 | """ |
Wei-Han Chen | 4741661 | 2016-09-14 17:41:52 +0800 | [diff] [blame] | 589 | report_archive = CreateReportArchive(*args, **kwargs) |
| 590 | try: |
You-Cheng Syu | f0f4be1 | 2017-12-05 16:33:53 +0800 | [diff] [blame] | 591 | return xmlrpclib.Binary(file_utils.ReadFile(report_archive)) |
Wei-Han Chen | 4741661 | 2016-09-14 17:41:52 +0800 | [diff] [blame] | 592 | finally: |
| 593 | os.unlink(report_archive) |
Jon Salz | a88b83b | 2013-05-27 20:00:35 +0800 | [diff] [blame] | 594 | |
| 595 | |
| 596 | def CreateReportArchive(device_sn=None, add_file=None): |
| 597 | """Creates a report archive in a temporary directory. |
| 598 | |
| 599 | Args: |
| 600 | device_sn: The device serial number (optional). |
| 601 | add_file: A list of files to add (optional). |
| 602 | |
| 603 | Returns: |
| 604 | Path to the archive. |
| 605 | """ |
Hung-Te Lin | 6bd1647 | 2012-06-20 16:26:47 +0800 | [diff] [blame] | 606 | def NormalizeAsFileName(token): |
| 607 | return re.sub(r'\W+', '', token).strip() |
Jon Salz | a88b83b | 2013-05-27 20:00:35 +0800 | [diff] [blame] | 608 | |
| 609 | target_name = '%s%s.tar.xz' % ( |
| 610 | time.strftime('%Y%m%dT%H%M%SZ', |
| 611 | time.gmtime()), |
Hung-Te Lin | 56b1840 | 2015-01-16 14:52:30 +0800 | [diff] [blame] | 612 | ('' if device_sn is None else |
| 613 | '_' + NormalizeAsFileName(device_sn))) |
Tammo Spalink | 86a61c6 | 2012-05-25 15:10:35 +0800 | [diff] [blame] | 614 | target_path = os.path.join(gettempdir(), target_name) |
Jon Salz | a88b83b | 2013-05-27 20:00:35 +0800 | [diff] [blame] | 615 | |
Tammo Spalink | 86a61c6 | 2012-05-25 15:10:35 +0800 | [diff] [blame] | 616 | # Intentionally ignoring dotfiles in EVENT_LOG_DIR. |
Andy Cheng | 0465d13 | 2013-03-20 12:12:06 +0800 | [diff] [blame] | 617 | tar_cmd = 'cd %s ; tar cJf %s *' % (event_log.EVENT_LOG_DIR, target_path) |
Peter Shih | b4e4935 | 2017-05-25 17:35:11 +0800 | [diff] [blame] | 618 | tar_cmd += ' %s' % paths.FACTORY_LOG_PATH |
Jon Salz | a88b83b | 2013-05-27 20:00:35 +0800 | [diff] [blame] | 619 | if add_file: |
| 620 | for f in add_file: |
Jon Salz | 6526643 | 2012-07-30 19:02:49 +0800 | [diff] [blame] | 621 | # Require absolute paths since the tar command may change the |
| 622 | # directory. |
| 623 | if not f.startswith('/'): |
| 624 | raise Error('Not an absolute path: %s' % f) |
| 625 | if not os.path.exists(f): |
| 626 | raise Error('File does not exist: %s' % f) |
Wei-Han Chen | 4b75502 | 2017-01-04 10:51:52 +0800 | [diff] [blame] | 627 | tar_cmd += ' %s' % pipes.quote(f) |
Tammo Spalink | 86a61c6 | 2012-05-25 15:10:35 +0800 | [diff] [blame] | 628 | cmd_result = Shell(tar_cmd) |
Jon Salz | ff88c02 | 2012-11-03 12:19:58 +0800 | [diff] [blame] | 629 | |
| 630 | if ((cmd_result.status == 1) and |
| 631 | all((x == '' or |
| 632 | 'file changed as we read it' in x or |
| 633 | "Removing leading `/' from member names" in x) |
| 634 | for x in cmd_result.stderr.split('\n'))): |
| 635 | # That's OK. Make sure it's valid though. |
Vic Yang | 85199e7 | 2013-01-28 14:33:11 +0800 | [diff] [blame] | 636 | Spawn(['tar', 'tfJ', target_path], check_call=True, log=True, |
Jon Salz | ff88c02 | 2012-11-03 12:19:58 +0800 | [diff] [blame] | 637 | ignore_stdout=True) |
| 638 | elif not cmd_result.success: |
Tammo Spalink | 86a61c6 | 2012-05-25 15:10:35 +0800 | [diff] [blame] | 639 | raise Error('unable to tar event logs, cmd %r failed, stderr: %r' % |
| 640 | (tar_cmd, cmd_result.stderr)) |
Jon Salz | ff88c02 | 2012-11-03 12:19:58 +0800 | [diff] [blame] | 641 | |
Jon Salz | a88b83b | 2013-05-27 20:00:35 +0800 | [diff] [blame] | 642 | return target_path |
| 643 | |
| 644 | _upload_method_cmd_arg = CmdArg( |
| 645 | '--upload_method', metavar='METHOD:PARAM', |
| 646 | help=('How to perform the upload. METHOD should be one of ' |
| 647 | '{ftp, shopfloor, ftps, cpfe}.')) |
| 648 | _add_file_cmd_arg = CmdArg( |
| 649 | '--add_file', metavar='FILE', action='append', |
| 650 | help='Extra file to include in report (must be an absolute path)') |
| 651 | |
Hung-Te Lin | 56b1840 | 2015-01-16 14:52:30 +0800 | [diff] [blame] | 652 | |
Jon Salz | a88b83b | 2013-05-27 20:00:35 +0800 | [diff] [blame] | 653 | @Command('upload_report', |
| 654 | _upload_method_cmd_arg, |
| 655 | _add_file_cmd_arg) |
| 656 | def UploadReport(options): |
| 657 | """Create a report containing key device details.""" |
Hung-Te Lin | 74346d7 | 2016-01-07 22:16:57 +0800 | [diff] [blame] | 658 | ro_vpd = ReadRoVpd() |
Jon Salz | a88b83b | 2013-05-27 20:00:35 +0800 | [diff] [blame] | 659 | device_sn = ro_vpd.get('serial_number', None) |
| 660 | if device_sn is None: |
| 661 | logging.warning('RO_VPD missing device serial number') |
Chun-Ta Lin | 53cbbd5 | 2016-06-08 21:42:19 +0800 | [diff] [blame] | 662 | device_sn = 'MISSING_SN_' + time_utils.TimedUUID() |
Jon Salz | a88b83b | 2013-05-27 20:00:35 +0800 | [diff] [blame] | 663 | target_path = CreateReportArchive(device_sn) |
| 664 | |
Tammo Spalink | 86a61c6 | 2012-05-25 15:10:35 +0800 | [diff] [blame] | 665 | if options.upload_method is None or options.upload_method == 'none': |
| 666 | logging.warning('REPORT UPLOAD SKIPPED (report left at %s)', target_path) |
| 667 | return |
| 668 | method, param = options.upload_method.split(':', 1) |
| 669 | if method == 'shopfloor': |
You-Cheng Syu | f0f4be1 | 2017-12-05 16:33:53 +0800 | [diff] [blame] | 670 | report_upload.ShopFloorUpload( |
| 671 | target_path, param, |
| 672 | 'GRT' if options.command_name == 'finalize' else None) |
Tammo Spalink | 86a61c6 | 2012-05-25 15:10:35 +0800 | [diff] [blame] | 673 | elif method == 'ftp': |
Jay Kim | 360c1dd | 2012-06-25 10:58:11 -0700 | [diff] [blame] | 674 | report_upload.FtpUpload(target_path, 'ftp:' + param) |
Tammo Spalink | 86a61c6 | 2012-05-25 15:10:35 +0800 | [diff] [blame] | 675 | elif method == 'ftps': |
| 676 | report_upload.CurlUrlUpload(target_path, '--ftp-ssl-reqd ftp:%s' % param) |
| 677 | elif method == 'cpfe': |
Shawn Nematbakhsh | 3404a09 | 2013-01-28 16:49:09 -0800 | [diff] [blame] | 678 | report_upload.CpfeUpload(target_path, pipes.quote(param)) |
Tammo Spalink | 86a61c6 | 2012-05-25 15:10:35 +0800 | [diff] [blame] | 679 | else: |
| 680 | raise Error('unknown report upload method %r', method) |
Tammo Spalink | 9a96b8a | 2012-04-03 11:10:41 +0800 | [diff] [blame] | 681 | |
| 682 | |
| 683 | @Command('finalize', |
Hung-Te Lin | 6d82754 | 2012-07-19 11:50:41 +0800 | [diff] [blame] | 684 | CmdArg('--no_write_protect', action='store_true', |
| 685 | help='Do not enable firmware write protection.'), |
Tammo Spalink | 9a96b8a | 2012-04-03 11:10:41 +0800 | [diff] [blame] | 686 | CmdArg('--fast', action='store_true', |
| 687 | help='use non-secure but faster wipe method.'), |
Shun-Hsing Ou | db407d6 | 2015-11-11 11:03:59 +0800 | [diff] [blame] | 688 | _shopfloor_url_args_cmd_arg, |
Tammo Spalink | 9a96b8a | 2012-04-03 11:10:41 +0800 | [diff] [blame] | 689 | _hwdb_path_cmd_arg, |
Tammo Spalink | 95c4373 | 2012-07-25 15:57:14 -0700 | [diff] [blame] | 690 | _hwid_status_list_cmd_arg, |
Jon Salz | 6526643 | 2012-07-30 19:02:49 +0800 | [diff] [blame] | 691 | _upload_method_cmd_arg, |
Jon Salz | ce124fb | 2012-10-02 17:42:03 +0800 | [diff] [blame] | 692 | _add_file_cmd_arg, |
| 693 | _probe_results_cmd_arg, |
Cheng-Yi Chiang | 406ad91 | 2013-11-14 16:51:33 +0800 | [diff] [blame] | 694 | _hwid_cmd_arg, |
Chih-Yu Huang | 714dbc4 | 2015-07-21 16:42:16 +0800 | [diff] [blame] | 695 | _rma_mode_cmd_arg, |
bowgotsai | 13820f4 | 2015-09-10 23:18:04 +0800 | [diff] [blame] | 696 | _cros_core_cmd_arg, |
Yilun Lin | 34f5480 | 2017-11-16 11:58:25 +0800 | [diff] [blame] | 697 | _ec_pubkey_path_cmd_arg, |
| 698 | _ec_pubkey_hash_cmd_arg, |
Hung-Te Lin | cdb9652 | 2016-04-15 16:51:10 +0800 | [diff] [blame] | 699 | _release_rootfs_cmd_arg, |
| 700 | _firmware_path_cmd_arg, |
Wei-Han Chen | be1355a | 2016-04-24 19:31:03 +0800 | [diff] [blame] | 701 | _enforced_release_channels_cmd_arg, |
| 702 | _station_ip_cmd_arg, |
| 703 | _station_port_cmd_arg, |
Ting Shen | 18a0638 | 2016-08-30 16:18:21 +0800 | [diff] [blame] | 704 | _wipe_finish_token_cmd_arg, |
Wei-Han Chen | 60c5d33 | 2017-01-05 17:15:10 +0800 | [diff] [blame] | 705 | _waive_list_cmd_arg, |
| 706 | _skip_list_cmd_arg) |
Tammo Spalink | 9a96b8a | 2012-04-03 11:10:41 +0800 | [diff] [blame] | 707 | def Finalize(options): |
| 708 | """Verify system readiness and trigger transition into release state. |
| 709 | |
Jon Salz | aa3a30e | 2013-05-15 15:56:28 +0800 | [diff] [blame] | 710 | This routine does the following: |
| 711 | - Verifies system state (see verify command) |
Jon Salz | fe9036f | 2014-01-16 14:11:23 +0800 | [diff] [blame] | 712 | - Untars stateful_files.tar.xz, if it exists, in the stateful partition, to |
| 713 | initialize files such as the CRX cache |
Jon Salz | aa3a30e | 2013-05-15 15:56:28 +0800 | [diff] [blame] | 714 | - Modifies firmware bitmaps to match locale |
| 715 | - Clears all factory-friendly flags from the GBB |
| 716 | - Removes factory-specific entries from RW_VPD (factory.*) |
| 717 | - Enables firmware write protection (cannot rollback after this) |
| 718 | - Uploads system logs & reports |
Earl Ou | 5118222 | 2016-09-09 12:16:48 +0800 | [diff] [blame] | 719 | - Wipes the testing kernel, rootfs, and stateful partition |
Tammo Spalink | 9a96b8a | 2012-04-03 11:10:41 +0800 | [diff] [blame] | 720 | """ |
Tammo Spalink | 9a96b8a | 2012-04-03 11:10:41 +0800 | [diff] [blame] | 721 | Verify(options) |
Shen-En Shih | 3e079b2 | 2017-09-11 05:43:09 -0700 | [diff] [blame] | 722 | Cr50SetBoardId(options) |
Jon Salz | 40b9f82 | 2014-07-25 16:39:55 +0800 | [diff] [blame] | 723 | LogSourceHashes(options) |
Jon Salz | fe9036f | 2014-01-16 14:11:23 +0800 | [diff] [blame] | 724 | UntarStatefulFiles(options) |
Chih-Yu Huang | 714dbc4 | 2015-07-21 16:42:16 +0800 | [diff] [blame] | 725 | if options.cros_core: |
| 726 | logging.info('SetFirmwareBitmapLocale is skipped for ChromeOS Core device.') |
| 727 | else: |
| 728 | SetFirmwareBitmapLocale(options) |
Jon Salz | aa3a30e | 2013-05-15 15:56:28 +0800 | [diff] [blame] | 729 | ClearFactoryVPDEntries(options) |
Mattias Nissler | cca761b | 2015-04-15 21:53:04 +0200 | [diff] [blame] | 730 | GenerateStableDeviceSecret(options) |
Shen-En Shih | 3e079b2 | 2017-09-11 05:43:09 -0700 | [diff] [blame] | 731 | ClearGBBFlags(options) |
Hung-Te Lin | 6d82754 | 2012-07-19 11:50:41 +0800 | [diff] [blame] | 732 | if options.no_write_protect: |
| 733 | logging.warn('WARNING: Firmware Write Protection is SKIPPED.') |
Andy Cheng | 0465d13 | 2013-03-20 12:12:06 +0800 | [diff] [blame] | 734 | event_log.Log('wp', fw='both', status='skipped') |
Hung-Te Lin | 6d82754 | 2012-07-19 11:50:41 +0800 | [diff] [blame] | 735 | else: |
Wei-Han Chen | ba21f51 | 2016-10-14 18:52:33 +0800 | [diff] [blame] | 736 | EnableFwWp(options) |
Jon Salz | a0f58e0 | 2012-05-29 19:33:39 +0800 | [diff] [blame] | 737 | LogSystemDetails(options) |
Tammo Spalink | 9a96b8a | 2012-04-03 11:10:41 +0800 | [diff] [blame] | 738 | UploadReport(options) |
Earl Ou | 5118222 | 2016-09-09 12:16:48 +0800 | [diff] [blame] | 739 | |
| 740 | event_log.Log('wipe_in_place') |
| 741 | wipe_args = [] |
Earl Ou | 5118222 | 2016-09-09 12:16:48 +0800 | [diff] [blame] | 742 | if options.shopfloor_url: |
| 743 | wipe_args += ['--shopfloor_url', options.shopfloor_url] |
| 744 | if options.fast: |
| 745 | wipe_args += ['--fast'] |
| 746 | if options.station_ip: |
| 747 | wipe_args += ['--station_ip', options.station_ip] |
| 748 | if options.station_port: |
| 749 | wipe_args += ['--station_port', options.station_port] |
| 750 | if options.wipe_finish_token: |
| 751 | wipe_args += ['--wipe_finish_token', options.wipe_finish_token] |
| 752 | ExecFactoryPar('gooftool', 'wipe_in_place', *wipe_args) |
Tammo Spalink | 9a96b8a | 2012-04-03 11:10:41 +0800 | [diff] [blame] | 753 | |
| 754 | |
Ting Shen | 129fa6f | 2016-09-02 12:22:24 +0800 | [diff] [blame] | 755 | @Command('verify_hwid', |
| 756 | _probe_results_cmd_arg, |
| 757 | _hwdb_path_cmd_arg, |
| 758 | _hwid_cmd_arg, |
| 759 | _rma_mode_cmd_arg) |
| 760 | def VerifyHWID(options): |
Ricky Liang | c662be3 | 2013-12-24 11:50:23 +0800 | [diff] [blame] | 761 | """A simple wrapper that calls out to HWID utils to verify version 3 HWID. |
Ricky Liang | 5339023 | 2013-03-08 15:37:57 +0800 | [diff] [blame] | 762 | |
Ricky Liang | c662be3 | 2013-12-24 11:50:23 +0800 | [diff] [blame] | 763 | This is mainly for Gooftool to verify v3 HWID during finalize. For testing |
| 764 | and development purposes, please use `hwid` command. |
Ricky Liang | 5339023 | 2013-03-08 15:37:57 +0800 | [diff] [blame] | 765 | """ |
Ricky Liang | c662be3 | 2013-12-24 11:50:23 +0800 | [diff] [blame] | 766 | db = GetGooftool(options).db |
| 767 | encoded_string = options.hwid or hwid_utils.GetHWIDString() |
Ricky Liang | 7905f27 | 2013-03-16 01:57:10 +0800 | [diff] [blame] | 768 | if options.probe_results: |
You-Cheng Syu | f0f4be1 | 2017-12-05 16:33:53 +0800 | [diff] [blame] | 769 | probed_results = yaml.load(file_utils.ReadFile(options.probe_results)) |
Ricky Liang | 7905f27 | 2013-03-16 01:57:10 +0800 | [diff] [blame] | 770 | else: |
Ricky Liang | c662be3 | 2013-12-24 11:50:23 +0800 | [diff] [blame] | 771 | probed_results = yaml.load(Probe(probe_vpd=True).Encode()) |
| 772 | vpd = hwid_utils.GetVPD(probed_results) |
Ricky Liang | 5339023 | 2013-03-08 15:37:57 +0800 | [diff] [blame] | 773 | |
Hung-Te Lin | 1105295 | 2015-03-18 13:48:59 +0800 | [diff] [blame] | 774 | event_log.Log('probed_results', probed_results=FilterDict(probed_results)) |
| 775 | event_log.Log('vpd', vpd=FilterDict(vpd)) |
Ricky Liang | 5339023 | 2013-03-08 15:37:57 +0800 | [diff] [blame] | 776 | |
Ricky Liang | c662be3 | 2013-12-24 11:50:23 +0800 | [diff] [blame] | 777 | hwid_utils.VerifyHWID(db, encoded_string, probed_results, vpd, |
Hung-Te Lin | 56b1840 | 2015-01-16 14:52:30 +0800 | [diff] [blame] | 778 | rma_mode=options.rma_mode) |
Ricky Liang | 5339023 | 2013-03-08 15:37:57 +0800 | [diff] [blame] | 779 | |
Ricky Liang | c662be3 | 2013-12-24 11:50:23 +0800 | [diff] [blame] | 780 | event_log.Log('verified_hwid', hwid=encoded_string) |
Ricky Liang | 5339023 | 2013-03-08 15:37:57 +0800 | [diff] [blame] | 781 | |
| 782 | |
henryhsu | 44d793a | 2013-07-20 00:07:38 +0800 | [diff] [blame] | 783 | @Command('get_firmware_hash', |
| 784 | CmdArg('--file', metavar='FILE', help='Firmware File.')) |
| 785 | def GetFirmwareHash(options): |
henryhsu | f6f835c | 2013-07-20 20:49:25 +0800 | [diff] [blame] | 786 | """Get firmware hash from a file""" |
henryhsu | 44d793a | 2013-07-20 00:07:38 +0800 | [diff] [blame] | 787 | if os.path.exists(options.file): |
| 788 | hashes = CalculateFirmwareHashes(options.file) |
| 789 | for section, value_dict in hashes.iteritems(): |
Hung-Te Lin | 56b1840 | 2015-01-16 14:52:30 +0800 | [diff] [blame] | 790 | print '%s:' % section |
henryhsu | 44d793a | 2013-07-20 00:07:38 +0800 | [diff] [blame] | 791 | for key, value in value_dict.iteritems(): |
Hung-Te Lin | 56b1840 | 2015-01-16 14:52:30 +0800 | [diff] [blame] | 792 | print ' %s: %s' % (key, value) |
henryhsu | 44d793a | 2013-07-20 00:07:38 +0800 | [diff] [blame] | 793 | else: |
| 794 | raise Error('File does not exist: %s' % options.file) |
| 795 | |
henryhsu | f6f835c | 2013-07-20 20:49:25 +0800 | [diff] [blame] | 796 | |
Peter Shih | fdf1768 | 2017-05-26 11:38:39 +0800 | [diff] [blame] | 797 | def main(): |
Tammo Spalink | 9a96b8a | 2012-04-03 11:10:41 +0800 | [diff] [blame] | 798 | """Run sub-command specified by the command line args.""" |
Andy Cheng | 7a76cb8 | 2012-11-19 18:08:19 +0800 | [diff] [blame] | 799 | |
Tammo Spalink | 9a96b8a | 2012-04-03 11:10:41 +0800 | [diff] [blame] | 800 | options = ParseCmdline( |
Ting Shen | 129fa6f | 2016-09-02 12:22:24 +0800 | [diff] [blame] | 801 | 'Perform Google required factory tests.', |
Tammo Spalink | 9a96b8a | 2012-04-03 11:10:41 +0800 | [diff] [blame] | 802 | CmdArg('-l', '--log', metavar='PATH', |
| 803 | help='Write logs to this file.'), |
Jon Salz | a4bea38 | 2012-10-29 13:00:34 +0800 | [diff] [blame] | 804 | CmdArg('--suppress-event-logs', action='store_true', |
| 805 | help='Suppress event logging.'), |
Wei-Han Chen | aff5623 | 2016-04-16 09:17:59 +0800 | [diff] [blame] | 806 | CmdArg('--phase', default=None, |
| 807 | help=('override phase for phase checking (defaults to the current ' |
| 808 | 'as returned by the "factory phase" command)')), |
Tammo Spalink | 8fab531 | 2012-05-28 18:33:30 +0800 | [diff] [blame] | 809 | verbosity_cmd_arg) |
Tammo Spalink | 9a96b8a | 2012-04-03 11:10:41 +0800 | [diff] [blame] | 810 | SetupLogging(options.verbosity, options.log) |
Andy Cheng | 0465d13 | 2013-03-20 12:12:06 +0800 | [diff] [blame] | 811 | event_log.SetGlobalLoggerDefaultPrefix('gooftool') |
| 812 | event_log.GetGlobalLogger().suppress = options.suppress_event_logs |
Tammo Spalink | 9a96b8a | 2012-04-03 11:10:41 +0800 | [diff] [blame] | 813 | logging.debug('gooftool options: %s', repr(options)) |
Wei-Han Chen | aff5623 | 2016-04-16 09:17:59 +0800 | [diff] [blame] | 814 | |
| 815 | phase.OverridePhase(options.phase) |
Tammo Spalink | 9a96b8a | 2012-04-03 11:10:41 +0800 | [diff] [blame] | 816 | try: |
| 817 | logging.debug('GOOFTOOL command %r', options.command_name) |
| 818 | options.command(options) |
| 819 | logging.info('GOOFTOOL command %r SUCCESS', options.command_name) |
| 820 | except Error, e: |
| 821 | logging.exception(e) |
| 822 | sys.exit('GOOFTOOL command %r ERROR: %s' % (options.command_name, e)) |
| 823 | except Exception, e: |
| 824 | logging.exception(e) |
| 825 | sys.exit('UNCAUGHT RUNTIME EXCEPTION %s' % e) |
| 826 | |
| 827 | |
| 828 | if __name__ == '__main__': |
Peter Shih | fdf1768 | 2017-05-26 11:38:39 +0800 | [diff] [blame] | 829 | main() |