blob: c3924488f90c476395682b9cd2e5439cd51fd05f [file] [log] [blame]
Kuang-che Wu2ea804f2017-11-28 17:11:41 +08001#!/usr/bin/env python2
Kuang-che Wu6e4beca2018-06-27 17:45:02 +08002# -*- coding: utf-8 -*-
Kuang-che Wu2ea804f2017-11-28 17:11:41 +08003# 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
8from __future__ import print_function
9import argparse
10import logging
11import os
Kuang-che Wu44278142019-03-04 11:33:57 +080012import sys
Kuang-che Wu2ea804f2017-11-28 17:11:41 +080013
14from bisect_kit import cli
15from bisect_kit import common
16from bisect_kit import configure
17from bisect_kit import cros_util
18
19logger = logging.getLogger(__name__)
20
21
22def 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 Wu86fbde52019-01-18 15:41:00 +080045 '--clobber_stateful',
Kuang-che Wu2ea804f2017-11-28 17:11:41 +080046 action='store_true',
47 help='Clobber stateful partition when performing update')
48 parser.add_argument(
49 '--no-disable-rootfs-verification',
Kuang-che Wu86fbde52019-01-18 15:41:00 +080050 '--no_disable_rootfs_verification',
Kuang-che Wu2ea804f2017-11-28 17:11:41 +080051 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 Wu927231f2018-07-24 14:21:56 +080058 os.path.expanduser('~/chromiumos')),
Kuang-che Wu2ea804f2017-11-28 17:11:41 +080059 help='Default chromeos tree to run "cros flash" (default: %(default)s)')
60
61 return parser
62
63
64def 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 Wu44278142019-03-04 11:33:57 +080070 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 Wu2ea804f2017-11-28 17:11:41 +080073 board = opts.board or cros_util.query_dut_board(opts.dut)
74
Kuang-che Wubfc4a642018-04-19 11:54:08 +080075 # TODO(kcwu): clear cache of cros flash
76 image_path = cros_util.prepare_prebuilt_image(board, opts.version)
Kuang-che Wu44278142019-03-04 11:33:57 +080077 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 Wu2ea804f2017-11-28 17:11:41 +080090
91
92if __name__ == '__main__':
93 main()