blob: 4dde88017ce4f536030da2c478b032f605ee66f6 [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
12
13from bisect_kit import cli
14from bisect_kit import common
15from bisect_kit import configure
16from bisect_kit import cros_util
17
18logger = logging.getLogger(__name__)
19
20
21def 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 Wu86fbde52019-01-18 15:41:00 +080044 '--clobber_stateful',
Kuang-che Wu2ea804f2017-11-28 17:11:41 +080045 action='store_true',
46 help='Clobber stateful partition when performing update')
47 parser.add_argument(
48 '--no-disable-rootfs-verification',
Kuang-che Wu86fbde52019-01-18 15:41:00 +080049 '--no_disable_rootfs_verification',
Kuang-che Wu2ea804f2017-11-28 17:11:41 +080050 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 Wu927231f2018-07-24 14:21:56 +080057 os.path.expanduser('~/chromiumos')),
Kuang-che Wu2ea804f2017-11-28 17:11:41 +080058 help='Default chromeos tree to run "cros flash" (default: %(default)s)')
59
60 return parser
61
62
63def 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 Wubfc4a642018-04-19 11:54:08 +080072 # TODO(kcwu): clear cache of cros flash
73 image_path = cros_util.prepare_prebuilt_image(board, opts.version)
Kuang-che Wu2ea804f2017-11-28 17:11:41 +080074 cros_util.cros_flash(
75 opts.default_chromeos_root,
76 opts.dut,
77 board,
Kuang-che Wubfc4a642018-04-19 11:54:08 +080078 image_path,
79 version=opts.version,
Kuang-che Wu2ea804f2017-11-28 17:11:41 +080080 clobber_stateful=opts.clobber_stateful,
81 disable_rootfs_verification=opts.disable_rootfs_verification)
82
83
84if __name__ == '__main__':
85 main()