forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
boot_device.py
44 lines (36 loc) · 1.55 KB
/
boot_device.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# Copyright 2023 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Functionalities to reliably reboot the device."""
import enum
from typing import Optional
class BootMode(enum.Enum):
"""Specifies boot mode for device."""
REGULAR = enum.auto()
RECOVERY = enum.auto()
BOOTLOADER = enum.auto()
class StateTransitionError(Exception):
"""Raised when target does not transition to desired state."""
def boot_device(target_id: Optional[str],
mode: BootMode,
serial_num: Optional[str] = None,
must_boot: bool = False) -> None:
"""Boot device into desired mode.
Args:
target_id: Optional target_id of device.
mode: Desired boot mode.
must_boot: Forces device to boot, regardless of current state.
Raises:
StateTransitionError: When final state of device is not desired.
"""
# Avoid cycle dependency.
# This file will be replaced with serial_boot_device quite soon, later one
# should be much more reliable comparing to ffx target list and ssh. So
# changing the file structure is not necessary in the current situation.
# pylint: disable=cyclic-import, import-outside-toplevel
# pylint: disable=wrong-import-position
import serial_boot_device
if not serial_boot_device.boot_device(target_id, serial_num, mode,
must_boot):
raise StateTransitionError(
f'Could not get device to desired state {mode}.')