Restructure building images, flashing and booting
This commit is contained in:
parent
4df7e93655
commit
4369df9673
5 changed files with 146 additions and 93 deletions
40
boot.py
40
boot.py
|
@ -1,24 +1,13 @@
|
|||
import os
|
||||
import urllib.request
|
||||
from image import get_device_and_flavour, get_image_name
|
||||
from logger import logging, setup_logging, verbose_option
|
||||
from flash import dump_bootimg, erase_dtbo
|
||||
from image import get_device_and_flavour, get_image_name, dump_bootimg, dump_lk2nd
|
||||
from logger import setup_logging, verbose_option
|
||||
from fastboot import fastboot_boot, fastboot_erase_dtbo
|
||||
from constants import BOOT_STRATEGIES, FASTBOOT, JUMPDRIVE, LK2ND, JUMPDRIVE_VERSION
|
||||
import click
|
||||
import subprocess
|
||||
|
||||
FASTBOOT = 'fastboot'
|
||||
|
||||
JUMPDRIVE = 'jumpdrive'
|
||||
jumpdrive_version = '0.8'
|
||||
|
||||
boot_strategies = {
|
||||
'oneplus-enchilada': FASTBOOT,
|
||||
'xiaomi-beryllium-ebbg': FASTBOOT,
|
||||
'xiaomi-beryllium-tianma': FASTBOOT,
|
||||
}
|
||||
|
||||
|
||||
@click.command(name='boot', help=f'Leave TYPE empty or choose \'{JUMPDRIVE}\'')
|
||||
@click.command(name='boot')
|
||||
@verbose_option
|
||||
@click.argument('type', required=False)
|
||||
def cmd_boot(verbose, type):
|
||||
|
@ -26,23 +15,18 @@ def cmd_boot(verbose, type):
|
|||
|
||||
device, flavour = get_device_and_flavour()
|
||||
image_name = get_image_name(device, flavour)
|
||||
strategy = boot_strategies[device]
|
||||
strategy = BOOT_STRATEGIES[device]
|
||||
|
||||
if strategy == FASTBOOT:
|
||||
if type == JUMPDRIVE:
|
||||
file = f'boot-{device}.img'
|
||||
path = os.path.join('/var/cache/jumpdrive', file)
|
||||
urllib.request.urlretrieve(f'https://github.com/dreemurrs-embedded/Jumpdrive/releases/download/{jumpdrive_version}/{file}', path)
|
||||
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)
|
||||
else:
|
||||
path = dump_bootimg(image_name)
|
||||
|
||||
erase_dtbo()
|
||||
|
||||
result = subprocess.run([
|
||||
'fastboot',
|
||||
'boot',
|
||||
path,
|
||||
])
|
||||
if result.returncode != 0:
|
||||
logging.fatal(f'Failed to boot {path} using fastboot')
|
||||
exit(1)
|
||||
fastboot_erase_dtbo()
|
||||
fastboot_boot(path)
|
||||
|
|
34
constants.py
Normal file
34
constants.py
Normal file
|
@ -0,0 +1,34 @@
|
|||
FASTBOOT = 'fastboot'
|
||||
|
||||
ROOTFS = 'rootfs'
|
||||
BOOTIMG = 'bootimg'
|
||||
LK2ND = 'lk2nd'
|
||||
QHYPSTUB = 'qhypstub'
|
||||
|
||||
EMMC = 'emmc'
|
||||
EMMCFILE = 'emmc-file'
|
||||
MICROSD = 'microsd'
|
||||
LOCATIONS = [EMMC, EMMCFILE, MICROSD]
|
||||
|
||||
JUMPDRIVE = 'jumpdrive'
|
||||
JUMPDRIVE_VERSION = '0.8'
|
||||
|
||||
BOOT_STRATEGIES = {
|
||||
'oneplus-enchilada': FASTBOOT,
|
||||
'xiaomi-beryllium-ebbg': FASTBOOT,
|
||||
'xiaomi-beryllium-tianma': FASTBOOT,
|
||||
'bq-paella': FASTBOOT,
|
||||
}
|
||||
|
||||
DEVICES = {
|
||||
'oneplus-enchilada': ['sdm845-oneplus-enchilada'],
|
||||
'xiaomi-beryllium-ebbg': ['sdm845-xiaomi-beryllium-ebbg'],
|
||||
'xiaomi-beryllium-tianma': ['sdm845-xiaomi-beryllium-tianma'],
|
||||
'bq-paella': ['msm8916-bq-paella'],
|
||||
}
|
||||
|
||||
FLAVOURS = {
|
||||
'barebone': [],
|
||||
'phosh': [],
|
||||
'plasma-mobile': [],
|
||||
}
|
36
fastboot.py
Normal file
36
fastboot.py
Normal file
|
@ -0,0 +1,36 @@
|
|||
import logging
|
||||
import subprocess
|
||||
|
||||
|
||||
def fastboot_erase_dtbo():
|
||||
subprocess.run(
|
||||
[
|
||||
'fastboot',
|
||||
'erase',
|
||||
'dtbo',
|
||||
],
|
||||
capture_output=True,
|
||||
)
|
||||
|
||||
|
||||
def fastboot_flash(partition, file):
|
||||
result = subprocess.run([
|
||||
'fastboot',
|
||||
'flash',
|
||||
partition,
|
||||
file,
|
||||
])
|
||||
if result.returncode != 0:
|
||||
logging.info(f'Failed to flash {file}')
|
||||
exit(1)
|
||||
|
||||
|
||||
def fastboot_boot(file):
|
||||
result = subprocess.run([
|
||||
'fastboot',
|
||||
'boot',
|
||||
file,
|
||||
])
|
||||
if result.returncode != 0:
|
||||
logging.fatal(f'Failed to boot {file} using fastboot')
|
||||
exit(1)
|
59
flash.py
59
flash.py
|
@ -1,47 +1,14 @@
|
|||
import atexit
|
||||
from cmath import log
|
||||
from email.mime import image
|
||||
from constants import BOOTIMG, LK2ND, LOCATIONS, QHYPSTUB, ROOTFS
|
||||
from fastboot import fastboot_flash
|
||||
import shutil
|
||||
from image import get_device_and_flavour, get_image_name
|
||||
from image import dump_bootimg, dump_lk2nd, dump_qhypstub, get_device_and_flavour, get_image_name
|
||||
import os
|
||||
import subprocess
|
||||
import click
|
||||
import tempfile
|
||||
from logger import logging, setup_logging, verbose_option
|
||||
|
||||
ROOTFS = 'rootfs'
|
||||
BOOTIMG = 'bootimg'
|
||||
|
||||
EMMC = 'emmc'
|
||||
EMMCFILE = 'emmc-file'
|
||||
MICROSD = 'microsd'
|
||||
locations = [EMMC, EMMCFILE, MICROSD]
|
||||
|
||||
|
||||
def dump_bootimg(image_name: str) -> str:
|
||||
path = '/tmp/boot.img'
|
||||
result = subprocess.run([
|
||||
'debugfs',
|
||||
image_name,
|
||||
'-R',
|
||||
f'dump /boot/boot.img {path}',
|
||||
])
|
||||
if result.returncode != 0:
|
||||
logging.fatal(f'Faild to dump boot.img')
|
||||
exit(1)
|
||||
return path
|
||||
|
||||
|
||||
def erase_dtbo():
|
||||
result = subprocess.run([
|
||||
'fastboot',
|
||||
'erase',
|
||||
'dtbo',
|
||||
])
|
||||
if result.returncode != 0:
|
||||
logging.info(f'Failed to erase dtbo')
|
||||
exit(1)
|
||||
|
||||
|
||||
@click.command(name='flash')
|
||||
@verbose_option
|
||||
|
@ -57,8 +24,8 @@ def cmd_flash(verbose, what, location):
|
|||
if location == None:
|
||||
logging.info(f'You need to specify a location to flash {what} to')
|
||||
exit(1)
|
||||
if location not in locations:
|
||||
logging.info(f'Invalid location {location}. Choose one of {", ".join(locations)} for location')
|
||||
if location not in LOCATIONS:
|
||||
logging.info(f'Invalid location {location}. Choose one of {", ".join(LOCATIONS)} for location')
|
||||
exit(1)
|
||||
|
||||
path = ''
|
||||
|
@ -168,15 +135,13 @@ def cmd_flash(verbose, what, location):
|
|||
|
||||
elif what == BOOTIMG:
|
||||
path = dump_bootimg(image_name)
|
||||
result = subprocess.run([
|
||||
'fastboot',
|
||||
'flash',
|
||||
'boot',
|
||||
path,
|
||||
])
|
||||
if result.returncode != 0:
|
||||
logging.info(f'Failed to flash boot.img')
|
||||
exit(1)
|
||||
fastboot_flash('boot', path)
|
||||
elif what == LK2ND:
|
||||
path = dump_lk2nd(image_name)
|
||||
fastboot_flash('lk2nd', path)
|
||||
elif what == QHYPSTUB:
|
||||
path = dump_qhypstub(image_name)
|
||||
fastboot_flash('qhypstub', path)
|
||||
else:
|
||||
logging.fatal(f'Unknown what {what}')
|
||||
exit(1)
|
||||
|
|
70
image.py
70
image.py
|
@ -4,18 +4,7 @@ import subprocess
|
|||
import click
|
||||
from logger import logging, setup_logging, verbose_option
|
||||
from chroot import create_chroot, create_chroot_user
|
||||
|
||||
devices = {
|
||||
'oneplus-enchilada': ['sdm845-oneplus-enchilada'],
|
||||
'xiaomi-beryllium-ebbg': ['sdm845-xiaomi-beryllium-ebbg'],
|
||||
'xiaomi-beryllium-tianma': ['sdm845-xiaomi-beryllium-tianma'],
|
||||
}
|
||||
|
||||
flavours = {
|
||||
'barebone': [],
|
||||
'phosh': [],
|
||||
'plasma-mobile': [],
|
||||
}
|
||||
from constants import DEVICES, FLAVOURS
|
||||
|
||||
|
||||
def get_device_and_flavour() -> tuple[str, str]:
|
||||
|
@ -69,6 +58,51 @@ def mount_rootfs_image(path):
|
|||
return rootfs_mount
|
||||
|
||||
|
||||
def dump_bootimg(image_name: str) -> str:
|
||||
path = '/tmp/boot.img'
|
||||
result = subprocess.run([
|
||||
'debugfs',
|
||||
image_name,
|
||||
'-R',
|
||||
f'dump /boot/boot.img {path}',
|
||||
])
|
||||
if result.returncode != 0:
|
||||
logging.fatal(f'Faild to dump boot.img')
|
||||
exit(1)
|
||||
return path
|
||||
|
||||
|
||||
def dump_lk2nd(image_name: str) -> str:
|
||||
"""
|
||||
This doesn't append the image with the appended DTB which is needed for some devices, so it should get added in the future.
|
||||
"""
|
||||
path = '/tmp/lk2nd.img'
|
||||
result = subprocess.run([
|
||||
'debugfs',
|
||||
image_name,
|
||||
'-R',
|
||||
f'dump /boot/lk2nd.img {path}',
|
||||
])
|
||||
if result.returncode != 0:
|
||||
logging.fatal(f'Faild to dump lk2nd.img')
|
||||
exit(1)
|
||||
return path
|
||||
|
||||
|
||||
def dump_qhypstub(image_name: str) -> str:
|
||||
path = '/tmp/qhypstub.bin'
|
||||
result = subprocess.run([
|
||||
'debugfs',
|
||||
image_name,
|
||||
'-R',
|
||||
f'dump /boot/qhypstub.bin {path}',
|
||||
])
|
||||
if result.returncode != 0:
|
||||
logging.fatal(f'Faild to dump qhypstub.bin')
|
||||
exit(1)
|
||||
return path
|
||||
|
||||
|
||||
@click.group(name='image')
|
||||
def cmd_image():
|
||||
pass
|
||||
|
@ -80,13 +114,13 @@ def cmd_image():
|
|||
def cmd_device(verbose, device):
|
||||
setup_logging(verbose)
|
||||
|
||||
for key in devices.keys():
|
||||
for key in DEVICES.keys():
|
||||
if '-'.join(key.split('-')[1:]) == device:
|
||||
device = key
|
||||
break
|
||||
|
||||
if device not in devices:
|
||||
logging.fatal(f'Unknown device {device}. Pick one from:\n{", ".join(devices.keys())}')
|
||||
if device not in DEVICES:
|
||||
logging.fatal(f'Unknown device {device}. Pick one from:\n{", ".join(DEVICES.keys())}')
|
||||
exit(1)
|
||||
|
||||
logging.info(f'Setting device to {device}')
|
||||
|
@ -101,8 +135,8 @@ def cmd_device(verbose, device):
|
|||
def cmd_flavour(verbose, flavour):
|
||||
setup_logging(verbose)
|
||||
|
||||
if flavour not in flavours:
|
||||
logging.fatal(f'Unknown flavour {flavour}. Pick one from:\n{", ".join(flavours.keys())}')
|
||||
if flavour not in FLAVOURS:
|
||||
logging.fatal(f'Unknown flavour {flavour}. Pick one from:\n{", ".join(FLAVOURS.keys())}')
|
||||
exit(1)
|
||||
|
||||
logging.info(f'Setting flavour to {flavour}')
|
||||
|
@ -163,7 +197,7 @@ def cmd_build(verbose):
|
|||
|
||||
create_chroot(
|
||||
rootfs_mount,
|
||||
packages=(['base', 'base-kupfer'] + devices[device] + flavours[flavour]),
|
||||
packages=['base', 'base-kupfer'] + DEVICES[device] + FLAVOURS[flavour],
|
||||
pacman_conf='/app/local/etc/pacman.conf',
|
||||
extra_repos=extra_repos,
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue