2021-08-05 20:26:48 +02:00
|
|
|
import os
|
|
|
|
import urllib.request
|
2021-08-17 20:57:31 +02:00
|
|
|
from image import get_device_and_flavour, get_image_name, dump_bootimg, dump_lk2nd
|
|
|
|
from fastboot import fastboot_boot, fastboot_erase_dtbo
|
2021-09-29 02:00:59 +02:00
|
|
|
from constants import BOOT_STRATEGIES, FLASH_PARTS, FASTBOOT, JUMPDRIVE, JUMPDRIVE_VERSION
|
2021-08-05 20:26:48 +02:00
|
|
|
import click
|
2021-09-29 02:00:59 +02:00
|
|
|
|
|
|
|
LK2ND = FLASH_PARTS['LK2ND']
|
|
|
|
BOOTIMG = FLASH_PARTS['BOOTIMG']
|
|
|
|
|
|
|
|
TYPES = [LK2ND, JUMPDRIVE, BOOTIMG]
|
2021-08-05 20:26:48 +02:00
|
|
|
|
|
|
|
|
2021-08-17 20:57:31 +02:00
|
|
|
@click.command(name='boot')
|
2021-09-29 02:00:59 +02:00
|
|
|
@click.argument('type', required=False, default=BOOTIMG)
|
2021-09-09 20:23:23 +02:00
|
|
|
def cmd_boot(type):
|
2021-09-29 02:00:59 +02:00
|
|
|
f"""Flash one of {', '.join(TYPES)}"""
|
2021-08-05 20:26:48 +02:00
|
|
|
device, flavour = get_device_and_flavour()
|
|
|
|
image_name = get_image_name(device, flavour)
|
2021-08-17 20:57:31 +02:00
|
|
|
strategy = BOOT_STRATEGIES[device]
|
2021-08-05 20:26:48 +02:00
|
|
|
|
|
|
|
if strategy == FASTBOOT:
|
|
|
|
if type == JUMPDRIVE:
|
|
|
|
file = f'boot-{device}.img'
|
|
|
|
path = os.path.join('/var/cache/jumpdrive', file)
|
2021-08-17 20:57:31 +02:00
|
|
|
if not os.path.exists(path):
|
|
|
|
urllib.request.urlretrieve(f'https://github.com/dreemurrs-embedded/Jumpdrive/releases/download/{JUMPDRIVE_VERSION}/{file}', path)
|
|
|
|
elif type == LK2ND:
|
|
|
|
path = dump_lk2nd(image_name)
|
2021-09-29 02:00:59 +02:00
|
|
|
elif type == BOOTIMG:
|
2021-08-05 20:26:48 +02:00
|
|
|
path = dump_bootimg(image_name)
|
2021-09-29 02:00:59 +02:00
|
|
|
else:
|
|
|
|
raise Exception(f'Unknown boot image type {type}')
|
2021-08-17 20:57:31 +02:00
|
|
|
fastboot_erase_dtbo()
|
|
|
|
fastboot_boot(path)
|