image: create new module from {image,boot,fastboot,flash}.py
This commit is contained in:
parent
afca099ede
commit
50bcd0de63
9 changed files with 18 additions and 16 deletions
59
image/boot.py
Normal file
59
image/boot.py
Normal file
|
@ -0,0 +1,59 @@
|
|||
import os
|
||||
import urllib.request
|
||||
import click
|
||||
|
||||
from typing import Optional
|
||||
|
||||
from config.state import config
|
||||
from constants import FLASH_PARTS, FASTBOOT, JUMPDRIVE, JUMPDRIVE_VERSION
|
||||
from exec.file import makedir
|
||||
from devices.device import get_profile_device
|
||||
from flavours.flavour import get_profile_flavour
|
||||
from flavours.cli import profile_option
|
||||
from wrapper import enforce_wrap
|
||||
|
||||
from .fastboot import fastboot_boot, fastboot_erase_dtbo
|
||||
from .image import get_device_name, losetup_rootfs_image, get_image_path, dump_aboot, dump_lk2nd
|
||||
|
||||
LK2ND = FLASH_PARTS['LK2ND']
|
||||
ABOOT = FLASH_PARTS['ABOOT']
|
||||
|
||||
TYPES = [LK2ND, JUMPDRIVE, ABOOT]
|
||||
|
||||
|
||||
@click.command(name='boot')
|
||||
@profile_option
|
||||
@click.argument('type', required=False, default=ABOOT, type=click.Choice(TYPES))
|
||||
def cmd_boot(type: str, profile: Optional[str] = None):
|
||||
"""Boot JumpDrive or the Kupfer aboot image. Erases Android DTBO in the process."""
|
||||
enforce_wrap()
|
||||
device = get_profile_device(profile)
|
||||
flavour = get_profile_flavour(profile).name
|
||||
deviceinfo = device.parse_deviceinfo()
|
||||
sector_size = deviceinfo.flash_pagesize
|
||||
if not sector_size:
|
||||
raise Exception(f"Device {device.name} has no flash_pagesize specified")
|
||||
image_path = get_image_path(device, flavour)
|
||||
strategy = deviceinfo.flash_method
|
||||
if not strategy:
|
||||
raise Exception(f"Device {device.name} has no flash strategy defined")
|
||||
|
||||
if strategy == FASTBOOT:
|
||||
if type == JUMPDRIVE:
|
||||
file = f'boot-{get_device_name(device)}.img'
|
||||
path = os.path.join(config.get_path('jumpdrive'), file)
|
||||
makedir(os.path.dirname(path))
|
||||
if not os.path.exists(path):
|
||||
urllib.request.urlretrieve(f'https://github.com/dreemurrs-embedded/Jumpdrive/releases/download/{JUMPDRIVE_VERSION}/{file}', path)
|
||||
else:
|
||||
loop_device = losetup_rootfs_image(image_path, sector_size)
|
||||
if type == LK2ND:
|
||||
path = dump_lk2nd(loop_device + 'p1')
|
||||
elif type == ABOOT:
|
||||
path = dump_aboot(loop_device + 'p1')
|
||||
else:
|
||||
raise Exception(f'Unknown boot image type {type}')
|
||||
fastboot_erase_dtbo()
|
||||
fastboot_boot(path)
|
||||
else:
|
||||
raise Exception(f"Unknown flash strategy {strategy} for device {device.name}")
|
Loading…
Add table
Add a link
Reference in a new issue