2021-08-05 20:26:48 +02:00
|
|
|
import os
|
|
|
|
import urllib.request
|
|
|
|
import click
|
2021-10-25 17:42:31 +02:00
|
|
|
|
|
|
|
from config import config
|
|
|
|
from constants import BOOT_STRATEGIES, FLASH_PARTS, FASTBOOT, JUMPDRIVE, JUMPDRIVE_VERSION
|
2022-08-16 02:14:19 +02:00
|
|
|
from exec.file import makedir
|
2021-10-25 17:42:31 +02:00
|
|
|
from fastboot import fastboot_boot, fastboot_erase_dtbo
|
2022-02-06 20:36:11 +01:00
|
|
|
from image import get_device_and_flavour, losetup_rootfs_image, get_image_path, dump_aboot, dump_lk2nd
|
2021-09-29 23:18:12 +02:00
|
|
|
from wrapper import enforce_wrap
|
2021-09-29 02:00:59 +02:00
|
|
|
|
|
|
|
LK2ND = FLASH_PARTS['LK2ND']
|
2022-02-06 20:36:11 +01:00
|
|
|
ABOOT = FLASH_PARTS['ABOOT']
|
2021-09-29 02:00:59 +02:00
|
|
|
|
2022-02-06 20:36:11 +01:00
|
|
|
TYPES = [LK2ND, JUMPDRIVE, ABOOT]
|
2021-08-05 20:26:48 +02:00
|
|
|
|
|
|
|
|
2021-08-17 20:57:31 +02:00
|
|
|
@click.command(name='boot')
|
2022-02-06 20:36:11 +01:00
|
|
|
@click.argument('type', required=False, default=ABOOT, type=click.Choice(TYPES))
|
2021-09-09 20:23:23 +02:00
|
|
|
def cmd_boot(type):
|
2022-02-13 19:57:04 +01:00
|
|
|
"""Boot JumpDrive or the Kupfer aboot image. Erases Android DTBO in the process."""
|
2021-09-29 23:18:12 +02:00
|
|
|
enforce_wrap()
|
2021-08-05 20:26:48 +02:00
|
|
|
device, flavour = get_device_and_flavour()
|
2021-10-26 06:03:31 +02:00
|
|
|
# TODO: parse arch and sector size
|
|
|
|
sector_size = 4096
|
2022-02-13 20:00:59 +01:00
|
|
|
image_path = get_image_path(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'
|
2021-10-25 17:42:31 +02:00
|
|
|
path = os.path.join(config.get_path('jumpdrive'), file)
|
2022-08-16 02:14:19 +02:00
|
|
|
makedir(os.path.dirname(path))
|
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)
|
2021-09-29 02:00:59 +02:00
|
|
|
else:
|
2022-02-13 20:00:59 +01:00
|
|
|
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}')
|
2021-08-17 20:57:31 +02:00
|
|
|
fastboot_erase_dtbo()
|
|
|
|
fastboot_boot(path)
|