-
Notifications
You must be signed in to change notification settings - Fork 2
/
boot.py
44 lines (38 loc) · 1.66 KB
/
boot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import os
import urllib.request
import click
from config import config
from constants import BOOT_STRATEGIES, FLASH_PARTS, FASTBOOT, JUMPDRIVE, JUMPDRIVE_VERSION
from fastboot import fastboot_boot, fastboot_erase_dtbo
from image import get_device_and_flavour, losetup_rootfs_image, get_image_path, dump_aboot, dump_lk2nd
from wrapper import enforce_wrap
LK2ND = FLASH_PARTS['LK2ND']
ABOOT = FLASH_PARTS['ABOOT']
TYPES = [LK2ND, JUMPDRIVE, ABOOT]
@click.command(name='boot')
@click.argument('type', required=False, default=ABOOT, type=click.Choice(TYPES))
def cmd_boot(type):
"""Boot JumpDrive or the Kupfer aboot image. Erases Android DTBO in the process."""
enforce_wrap()
device, flavour = get_device_and_flavour()
# TODO: parse arch and sector size
sector_size = 4096
image_path = get_image_path(device, flavour)
strategy = BOOT_STRATEGIES[device]
if strategy == FASTBOOT:
if type == JUMPDRIVE:
file = f'boot-{device}.img'
path = os.path.join(config.get_path('jumpdrive'), file)
os.makedirs(os.path.dirname(path), exist_ok=True)
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)