Kuang-che Wu | 2ea804f | 2017-11-28 17:11:41 +0800 | [diff] [blame] | 1 | #!/usr/bin/env python2 |
Kuang-che Wu | 6e4beca | 2018-06-27 17:45:02 +0800 | [diff] [blame] | 2 | # -*- coding: utf-8 -*- |
Kuang-che Wu | 2ea804f | 2017-11-28 17:11:41 +0800 | [diff] [blame] | 3 | # Copyright 2017 The Chromium OS Authors. All rights reserved. |
| 4 | # Use of this source code is governed by a BSD-style license that can be |
| 5 | # found in the LICENSE file. |
| 6 | """Switcher for ChromeOS prebuilt""" |
| 7 | |
| 8 | from __future__ import print_function |
| 9 | import argparse |
| 10 | import logging |
| 11 | import os |
Kuang-che Wu | 4427814 | 2019-03-04 11:33:57 +0800 | [diff] [blame^] | 12 | import sys |
Kuang-che Wu | 2ea804f | 2017-11-28 17:11:41 +0800 | [diff] [blame] | 13 | |
| 14 | from bisect_kit import cli |
| 15 | from bisect_kit import common |
| 16 | from bisect_kit import configure |
| 17 | from bisect_kit import cros_util |
| 18 | |
| 19 | logger = logging.getLogger(__name__) |
| 20 | |
| 21 | |
| 22 | def create_argument_parser(): |
| 23 | parser = argparse.ArgumentParser(description=__doc__) |
| 24 | common.add_common_arguments(parser) |
| 25 | parser.add_argument( |
| 26 | 'dut', |
| 27 | nargs='?', |
| 28 | type=cli.argtype_notempty, |
| 29 | metavar='DUT', |
| 30 | default=configure.get('DUT', '')) |
| 31 | parser.add_argument( |
| 32 | 'version', |
| 33 | nargs='?', |
| 34 | type=cros_util.argtype_cros_version, |
| 35 | metavar='CROS_VERSION', |
| 36 | default=configure.get('CROS_VERSION', ''), |
| 37 | help='ChromeOS version number, short (10162.0.0) or full (R64-10162.0.0)') |
| 38 | parser.add_argument( |
| 39 | '--board', |
| 40 | metavar='BOARD', |
| 41 | default=configure.get('BOARD', ''), |
| 42 | help='ChromeOS board name') |
| 43 | parser.add_argument( |
| 44 | '--clobber-stateful', |
Kuang-che Wu | 86fbde5 | 2019-01-18 15:41:00 +0800 | [diff] [blame] | 45 | '--clobber_stateful', |
Kuang-che Wu | 2ea804f | 2017-11-28 17:11:41 +0800 | [diff] [blame] | 46 | action='store_true', |
| 47 | help='Clobber stateful partition when performing update') |
| 48 | parser.add_argument( |
| 49 | '--no-disable-rootfs-verification', |
Kuang-che Wu | 86fbde5 | 2019-01-18 15:41:00 +0800 | [diff] [blame] | 50 | '--no_disable_rootfs_verification', |
Kuang-che Wu | 2ea804f | 2017-11-28 17:11:41 +0800 | [diff] [blame] | 51 | dest='disable_rootfs_verification', |
| 52 | action='store_false', |
| 53 | help="Don't disable rootfs verification after update is completed") |
| 54 | parser.add_argument( |
| 55 | '--default_chromeos_root', |
| 56 | type=cli.argtype_dir_path, |
| 57 | default=configure.get('DEFAULT_CHROMEOS_ROOT', |
Kuang-che Wu | 927231f | 2018-07-24 14:21:56 +0800 | [diff] [blame] | 58 | os.path.expanduser('~/chromiumos')), |
Kuang-che Wu | 2ea804f | 2017-11-28 17:11:41 +0800 | [diff] [blame] | 59 | help='Default chromeos tree to run "cros flash" (default: %(default)s)') |
| 60 | |
| 61 | return parser |
| 62 | |
| 63 | |
| 64 | def main(args=None): |
| 65 | common.init() |
| 66 | parser = create_argument_parser() |
| 67 | opts = parser.parse_args(args) |
| 68 | common.config_logging(opts) |
| 69 | |
Kuang-che Wu | 4427814 | 2019-03-04 11:33:57 +0800 | [diff] [blame^] | 70 | if not cros_util.is_good_dut(opts.dut): |
| 71 | logger.error('%r is not a good DUT', opts.dut) |
| 72 | sys.exit(126) # fatal, bisect should stop |
Kuang-che Wu | 2ea804f | 2017-11-28 17:11:41 +0800 | [diff] [blame] | 73 | board = opts.board or cros_util.query_dut_board(opts.dut) |
| 74 | |
Kuang-che Wu | bfc4a64 | 2018-04-19 11:54:08 +0800 | [diff] [blame] | 75 | # TODO(kcwu): clear cache of cros flash |
| 76 | image_path = cros_util.prepare_prebuilt_image(board, opts.version) |
Kuang-che Wu | 4427814 | 2019-03-04 11:33:57 +0800 | [diff] [blame^] | 77 | try: |
| 78 | cros_util.cros_flash( |
| 79 | opts.default_chromeos_root, |
| 80 | opts.dut, |
| 81 | board, |
| 82 | image_path, |
| 83 | version=opts.version, |
| 84 | clobber_stateful=opts.clobber_stateful, |
| 85 | disable_rootfs_verification=opts.disable_rootfs_verification) |
| 86 | except Exception: |
| 87 | if not cros_util.is_good_dut(opts.dut): |
| 88 | sys.exit(126) # fatal, bisect should stop |
| 89 | raise |
Kuang-che Wu | 2ea804f | 2017-11-28 17:11:41 +0800 | [diff] [blame] | 90 | |
| 91 | |
| 92 | if __name__ == '__main__': |
| 93 | main() |