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