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 |
| 12 | |
| 13 | from bisect_kit import cli |
| 14 | from bisect_kit import common |
| 15 | from bisect_kit import configure |
| 16 | from bisect_kit import cros_util |
| 17 | |
| 18 | logger = logging.getLogger(__name__) |
| 19 | |
| 20 | |
| 21 | def create_argument_parser(): |
| 22 | parser = argparse.ArgumentParser(description=__doc__) |
| 23 | common.add_common_arguments(parser) |
| 24 | parser.add_argument( |
| 25 | 'dut', |
| 26 | nargs='?', |
| 27 | type=cli.argtype_notempty, |
| 28 | metavar='DUT', |
| 29 | default=configure.get('DUT', '')) |
| 30 | parser.add_argument( |
| 31 | 'version', |
| 32 | nargs='?', |
| 33 | type=cros_util.argtype_cros_version, |
| 34 | metavar='CROS_VERSION', |
| 35 | default=configure.get('CROS_VERSION', ''), |
| 36 | help='ChromeOS version number, short (10162.0.0) or full (R64-10162.0.0)') |
| 37 | parser.add_argument( |
| 38 | '--board', |
| 39 | metavar='BOARD', |
| 40 | default=configure.get('BOARD', ''), |
| 41 | help='ChromeOS board name') |
| 42 | parser.add_argument( |
| 43 | '--clobber-stateful', |
Kuang-che Wu | 86fbde5 | 2019-01-18 15:41:00 +0800 | [diff] [blame] | 44 | '--clobber_stateful', |
Kuang-che Wu | 2ea804f | 2017-11-28 17:11:41 +0800 | [diff] [blame] | 45 | action='store_true', |
| 46 | help='Clobber stateful partition when performing update') |
| 47 | parser.add_argument( |
| 48 | '--no-disable-rootfs-verification', |
Kuang-che Wu | 86fbde5 | 2019-01-18 15:41:00 +0800 | [diff] [blame] | 49 | '--no_disable_rootfs_verification', |
Kuang-che Wu | 2ea804f | 2017-11-28 17:11:41 +0800 | [diff] [blame] | 50 | dest='disable_rootfs_verification', |
| 51 | action='store_false', |
| 52 | help="Don't disable rootfs verification after update is completed") |
| 53 | parser.add_argument( |
| 54 | '--default_chromeos_root', |
| 55 | type=cli.argtype_dir_path, |
| 56 | default=configure.get('DEFAULT_CHROMEOS_ROOT', |
Kuang-che Wu | 927231f | 2018-07-24 14:21:56 +0800 | [diff] [blame] | 57 | os.path.expanduser('~/chromiumos')), |
Kuang-che Wu | 2ea804f | 2017-11-28 17:11:41 +0800 | [diff] [blame] | 58 | help='Default chromeos tree to run "cros flash" (default: %(default)s)') |
| 59 | |
| 60 | return parser |
| 61 | |
| 62 | |
| 63 | def main(args=None): |
| 64 | common.init() |
| 65 | parser = create_argument_parser() |
| 66 | opts = parser.parse_args(args) |
| 67 | common.config_logging(opts) |
| 68 | |
| 69 | assert cros_util.is_dut(opts.dut) |
| 70 | board = opts.board or cros_util.query_dut_board(opts.dut) |
| 71 | |
Kuang-che Wu | bfc4a64 | 2018-04-19 11:54:08 +0800 | [diff] [blame] | 72 | # TODO(kcwu): clear cache of cros flash |
| 73 | image_path = cros_util.prepare_prebuilt_image(board, opts.version) |
Kuang-che Wu | 2ea804f | 2017-11-28 17:11:41 +0800 | [diff] [blame] | 74 | cros_util.cros_flash( |
| 75 | opts.default_chromeos_root, |
| 76 | opts.dut, |
| 77 | board, |
Kuang-che Wu | bfc4a64 | 2018-04-19 11:54:08 +0800 | [diff] [blame] | 78 | image_path, |
| 79 | version=opts.version, |
Kuang-che Wu | 2ea804f | 2017-11-28 17:11:41 +0800 | [diff] [blame] | 80 | clobber_stateful=opts.clobber_stateful, |
| 81 | disable_rootfs_verification=opts.disable_rootfs_verification) |
| 82 | |
| 83 | |
| 84 | if __name__ == '__main__': |
| 85 | main() |