2021-08-17 20:57:31 +02:00
|
|
|
import logging
|
|
|
|
|
2023-01-06 04:37:23 +01:00
|
|
|
from exec.cmd import run_cmd, CompletedProcess
|
2023-01-06 04:22:46 +01:00
|
|
|
from typing import Optional
|
|
|
|
|
2021-08-17 20:57:31 +02:00
|
|
|
|
|
|
|
def fastboot_erase_dtbo():
|
2022-02-20 19:23:28 +01:00
|
|
|
logging.info("Fastboot: Erasing DTBO")
|
2023-01-06 04:37:23 +01:00
|
|
|
run_cmd(
|
2021-08-17 20:57:31 +02:00
|
|
|
[
|
|
|
|
'fastboot',
|
|
|
|
'erase',
|
|
|
|
'dtbo',
|
|
|
|
],
|
|
|
|
capture_output=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-01-06 04:22:46 +01:00
|
|
|
def fastboot_flash(partition: str, file: str, sparse_size: Optional[str] = None):
|
2021-10-26 06:02:55 +02:00
|
|
|
logging.info(f"Fastboot: Flashing {file} to {partition}")
|
2023-01-06 04:37:23 +01:00
|
|
|
result = run_cmd([
|
2021-08-17 20:57:31 +02:00
|
|
|
'fastboot',
|
2023-01-06 04:22:46 +01:00
|
|
|
*(['-S', sparse_size] if sparse_size is not None else []),
|
2021-08-17 20:57:31 +02:00
|
|
|
'flash',
|
|
|
|
partition,
|
|
|
|
file,
|
|
|
|
])
|
2023-01-06 04:37:23 +01:00
|
|
|
assert isinstance(result, CompletedProcess)
|
2021-08-17 20:57:31 +02:00
|
|
|
if result.returncode != 0:
|
2022-09-27 03:55:16 +02:00
|
|
|
raise Exception(f'Failed to flash {file}')
|
2021-08-17 20:57:31 +02:00
|
|
|
|
|
|
|
|
|
|
|
def fastboot_boot(file):
|
2021-10-26 06:02:55 +02:00
|
|
|
logging.info(f"Fastboot: booting {file}")
|
2023-01-06 04:37:23 +01:00
|
|
|
result = run_cmd([
|
2021-08-17 20:57:31 +02:00
|
|
|
'fastboot',
|
|
|
|
'boot',
|
|
|
|
file,
|
|
|
|
])
|
2023-01-06 04:37:23 +01:00
|
|
|
assert isinstance(result, CompletedProcess)
|
2021-08-17 20:57:31 +02:00
|
|
|
if result.returncode != 0:
|
2022-09-27 03:55:16 +02:00
|
|
|
raise Exception(f'Failed to boot {file} using fastboot')
|