kupferbootstrap/image/fastboot.py

40 lines
933 B
Python

import logging
import subprocess
from typing import Optional
def fastboot_erase_dtbo():
logging.info("Fastboot: Erasing DTBO")
subprocess.run(
[
'fastboot',
'erase',
'dtbo',
],
capture_output=True,
)
def fastboot_flash(partition: str, file: str, sparse_size: Optional[str] = None):
logging.info(f"Fastboot: Flashing {file} to {partition}")
result = subprocess.run([
'fastboot',
*(['-S', sparse_size] if sparse_size is not None else []),
'flash',
partition,
file,
])
if result.returncode != 0:
raise Exception(f'Failed to flash {file}')
def fastboot_boot(file):
logging.info(f"Fastboot: booting {file}")
result = subprocess.run([
'fastboot',
'boot',
file,
])
if result.returncode != 0:
raise Exception(f'Failed to boot {file} using fastboot')