mirror of
https://gitlab.postmarketos.org/postmarketOS/pmbootstrap.git
synced 2025-07-13 03:19:47 +03:00
pmb.flasher: Remove use of args (MR 2441)
Also adapt pmb/install/recovery.py to new API for variables.py. [ci:skip-build]: already built successfully in CI
This commit is contained in:
parent
2305cc5db6
commit
37ec73c07c
9 changed files with 140 additions and 56 deletions
|
@ -20,6 +20,14 @@ pmb.commands.base module
|
||||||
:undoc-members:
|
:undoc-members:
|
||||||
:show-inheritance:
|
:show-inheritance:
|
||||||
|
|
||||||
|
pmb.commands.flasher module
|
||||||
|
---------------------------
|
||||||
|
|
||||||
|
.. automodule:: pmb.commands.flasher
|
||||||
|
:members:
|
||||||
|
:undoc-members:
|
||||||
|
:show-inheritance:
|
||||||
|
|
||||||
pmb.commands.index module
|
pmb.commands.index module
|
||||||
-------------------------
|
-------------------------
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@ from pmb.helpers import frontend
|
||||||
|
|
||||||
from .base import Command
|
from .base import Command
|
||||||
from .aportgen import Aportgen
|
from .aportgen import Aportgen
|
||||||
|
from .flasher import Flasher
|
||||||
from .log import Log
|
from .log import Log
|
||||||
from .index import Index
|
from .index import Index
|
||||||
from .repo_bootstrap import RepoBootstrap
|
from .repo_bootstrap import RepoBootstrap
|
||||||
|
@ -31,7 +32,6 @@ unmigrated_commands = [
|
||||||
"export",
|
"export",
|
||||||
"sideload",
|
"sideload",
|
||||||
"netboot",
|
"netboot",
|
||||||
"flasher",
|
|
||||||
"initfs",
|
"initfs",
|
||||||
"qemu",
|
"qemu",
|
||||||
"aportupgrade",
|
"aportupgrade",
|
||||||
|
@ -65,6 +65,16 @@ def run_command(args: PmbArgs):
|
||||||
match args.action:
|
match args.action:
|
||||||
case "aportgen":
|
case "aportgen":
|
||||||
command = Aportgen(args.packages, args.fork_alpine, args.fork_alpine_retain_branch)
|
command = Aportgen(args.packages, args.fork_alpine, args.fork_alpine_retain_branch)
|
||||||
|
case "flasher":
|
||||||
|
command = Flasher(
|
||||||
|
args.action_flasher,
|
||||||
|
args.autoinstall,
|
||||||
|
getattr(args, "cmdline", None),
|
||||||
|
args.flash_method,
|
||||||
|
getattr(args, "no_reboot", None),
|
||||||
|
getattr(args, "partition", None),
|
||||||
|
getattr(args, "resume", None),
|
||||||
|
)
|
||||||
case "log":
|
case "log":
|
||||||
command = Log(args.clear_log, args.lines)
|
command = Log(args.clear_log, args.lines)
|
||||||
case "index":
|
case "index":
|
||||||
|
|
83
pmb/commands/flasher.py
Normal file
83
pmb/commands/flasher.py
Normal file
|
@ -0,0 +1,83 @@
|
||||||
|
# Copyright 2023 Oliver Smith
|
||||||
|
# Copyright 2024 Stefan Hansson
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
import pmb.parse.deviceinfo
|
||||||
|
from pmb import commands
|
||||||
|
from pmb.core.context import get_context
|
||||||
|
from pmb.flasher.frontend import flash_lk2nd, kernel, list_flavors, rootfs, sideload
|
||||||
|
from pmb.helpers import logging
|
||||||
|
|
||||||
|
|
||||||
|
class Flasher(commands.Command):
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
action_flasher: str,
|
||||||
|
autoinstall: bool,
|
||||||
|
cmdline: str | None,
|
||||||
|
flash_method: str,
|
||||||
|
no_reboot: bool | None,
|
||||||
|
partition: str | None,
|
||||||
|
resume: bool | None,
|
||||||
|
) -> None:
|
||||||
|
self.action_flasher = action_flasher
|
||||||
|
self.autoinstall = autoinstall
|
||||||
|
self.cmdline = cmdline
|
||||||
|
self.flash_method = flash_method
|
||||||
|
self.no_reboot = no_reboot
|
||||||
|
self.partition = partition
|
||||||
|
self.resume = resume
|
||||||
|
|
||||||
|
def run(self) -> None:
|
||||||
|
context = get_context()
|
||||||
|
action = self.action_flasher
|
||||||
|
device = context.config.device
|
||||||
|
deviceinfo = pmb.parse.deviceinfo()
|
||||||
|
method = self.flash_method or deviceinfo.flash_method
|
||||||
|
|
||||||
|
if method == "none" and action in ["boot", "flash_kernel", "flash_rootfs", "flash_lk2nd"]:
|
||||||
|
logging.info("This device doesn't support any flash method.")
|
||||||
|
return
|
||||||
|
|
||||||
|
if action in ["boot", "flash_kernel"]:
|
||||||
|
kernel(deviceinfo, method, action == "boot", self.autoinstall)
|
||||||
|
elif action == "flash_rootfs":
|
||||||
|
rootfs(deviceinfo, method)
|
||||||
|
elif action == "flash_vbmeta":
|
||||||
|
logging.info("(native) flash vbmeta.img with verity disabled flag")
|
||||||
|
pmb.flasher.run(
|
||||||
|
deviceinfo,
|
||||||
|
method,
|
||||||
|
"flash_vbmeta",
|
||||||
|
cmdline=self.cmdline,
|
||||||
|
no_reboot=self.no_reboot,
|
||||||
|
partition=self.partition,
|
||||||
|
resume=self.resume,
|
||||||
|
)
|
||||||
|
elif action == "flash_dtbo":
|
||||||
|
logging.info("(native) flash dtbo image")
|
||||||
|
pmb.flasher.run(
|
||||||
|
deviceinfo,
|
||||||
|
method,
|
||||||
|
"flash_dtbo",
|
||||||
|
cmdline=self.cmdline,
|
||||||
|
no_reboot=self.no_reboot,
|
||||||
|
partition=self.partition,
|
||||||
|
resume=self.resume,
|
||||||
|
)
|
||||||
|
elif action == "flash_lk2nd":
|
||||||
|
flash_lk2nd(deviceinfo, method)
|
||||||
|
elif action == "list_flavors":
|
||||||
|
list_flavors(device)
|
||||||
|
elif action == "list_devices":
|
||||||
|
pmb.flasher.run(
|
||||||
|
deviceinfo,
|
||||||
|
method,
|
||||||
|
"list_devices",
|
||||||
|
cmdline=self.cmdline,
|
||||||
|
no_reboot=self.no_reboot,
|
||||||
|
partition=self.partition,
|
||||||
|
resume=self.resume,
|
||||||
|
)
|
||||||
|
elif action == "sideload":
|
||||||
|
sideload(deviceinfo, method)
|
|
@ -5,4 +5,3 @@ from pmb.flasher.init import install_depends
|
||||||
from pmb.flasher.run import run
|
from pmb.flasher.run import run
|
||||||
from pmb.flasher.run import check_partition_blacklist
|
from pmb.flasher.run import check_partition_blacklist
|
||||||
from pmb.flasher.variables import variables
|
from pmb.flasher.variables import variables
|
||||||
from pmb.flasher.frontend import frontend
|
|
||||||
|
|
|
@ -7,7 +7,6 @@ from pmb.helpers import logging
|
||||||
|
|
||||||
import pmb.config
|
import pmb.config
|
||||||
from pmb.parse.deviceinfo import Deviceinfo
|
from pmb.parse.deviceinfo import Deviceinfo
|
||||||
from pmb.types import PmbArgs
|
|
||||||
import pmb.flasher
|
import pmb.flasher
|
||||||
import pmb.install
|
import pmb.install
|
||||||
import pmb.chroot.apk
|
import pmb.chroot.apk
|
||||||
|
@ -146,34 +145,3 @@ def flash_lk2nd(deviceinfo: Deviceinfo, method: str) -> None:
|
||||||
|
|
||||||
logging.info("(native) flash lk2nd image")
|
logging.info("(native) flash lk2nd image")
|
||||||
pmb.flasher.run(deviceinfo, method, "flash_lk2nd")
|
pmb.flasher.run(deviceinfo, method, "flash_lk2nd")
|
||||||
|
|
||||||
|
|
||||||
def frontend(args: PmbArgs) -> None:
|
|
||||||
context = get_context()
|
|
||||||
action = args.action_flasher
|
|
||||||
device = context.config.device
|
|
||||||
deviceinfo = pmb.parse.deviceinfo()
|
|
||||||
method = args.flash_method or deviceinfo.flash_method
|
|
||||||
|
|
||||||
if method == "none" and action in ["boot", "flash_kernel", "flash_rootfs", "flash_lk2nd"]:
|
|
||||||
logging.info("This device doesn't support any flash method.")
|
|
||||||
return
|
|
||||||
|
|
||||||
if action in ["boot", "flash_kernel"]:
|
|
||||||
kernel(deviceinfo, method, action == "boot", args.autoinstall)
|
|
||||||
elif action == "flash_rootfs":
|
|
||||||
rootfs(deviceinfo, method)
|
|
||||||
elif action == "flash_vbmeta":
|
|
||||||
logging.info("(native) flash vbmeta.img with verity disabled flag")
|
|
||||||
pmb.flasher.run(deviceinfo, method, "flash_vbmeta")
|
|
||||||
elif action == "flash_dtbo":
|
|
||||||
logging.info("(native) flash dtbo image")
|
|
||||||
pmb.flasher.run(deviceinfo, method, "flash_dtbo")
|
|
||||||
elif action == "flash_lk2nd":
|
|
||||||
flash_lk2nd(deviceinfo, method)
|
|
||||||
elif action == "list_flavors":
|
|
||||||
list_flavors(device)
|
|
||||||
elif action == "list_devices":
|
|
||||||
pmb.flasher.run(deviceinfo, method, "list_devices")
|
|
||||||
elif action == "sideload":
|
|
||||||
sideload(deviceinfo, method)
|
|
||||||
|
|
|
@ -24,7 +24,16 @@ def check_partition_blacklist(deviceinfo: Deviceinfo, key, value):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def run(deviceinfo: Deviceinfo, method: str, action: str, flavor=None):
|
def run(
|
||||||
|
deviceinfo: Deviceinfo,
|
||||||
|
method: str,
|
||||||
|
action: str,
|
||||||
|
flavor: str | None = None,
|
||||||
|
cmdline: str | None = None,
|
||||||
|
no_reboot: bool | None = None,
|
||||||
|
partition: str | None = None,
|
||||||
|
resume: bool | None = None,
|
||||||
|
) -> None:
|
||||||
pmb.flasher.init(deviceinfo.codename, method)
|
pmb.flasher.init(deviceinfo.codename, method)
|
||||||
|
|
||||||
# Verify action
|
# Verify action
|
||||||
|
@ -42,9 +51,7 @@ def run(deviceinfo: Deviceinfo, method: str, action: str, flavor=None):
|
||||||
)
|
)
|
||||||
|
|
||||||
# Variable setup
|
# Variable setup
|
||||||
# FIXME: handle argparsing and pass in only the args we need.
|
fvars = pmb.flasher.variables(flavor, method, cmdline, no_reboot, partition, resume)
|
||||||
args = pmb.helpers.args.please_i_really_need_args()
|
|
||||||
fvars = pmb.flasher.variables(args, flavor, method)
|
|
||||||
|
|
||||||
# vbmeta flasher requires vbmeta partition to be explicitly specified
|
# vbmeta flasher requires vbmeta partition to be explicitly specified
|
||||||
if action == "flash_vbmeta" and not fvars["$PARTITION_VBMETA"]:
|
if action == "flash_vbmeta" and not fvars["$PARTITION_VBMETA"]:
|
||||||
|
@ -69,12 +76,12 @@ def run(deviceinfo: Deviceinfo, method: str, action: str, flavor=None):
|
||||||
"Deviceinfo_reference>"
|
"Deviceinfo_reference>"
|
||||||
)
|
)
|
||||||
|
|
||||||
if args.no_reboot and ("flash" not in action or method != "heimdall-bootimg"):
|
if no_reboot and ("flash" not in action or method != "heimdall-bootimg"):
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
"The '--no-reboot' option is only" " supported when flashing with heimall-bootimg."
|
"The '--no-reboot' option is only" " supported when flashing with heimall-bootimg."
|
||||||
)
|
)
|
||||||
|
|
||||||
if args.resume and ("flash" not in action or method != "heimdall-bootimg"):
|
if resume and ("flash" not in action or method != "heimdall-bootimg"):
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
"The '--resume' option is only" " supported when flashing with heimall-bootimg."
|
"The '--resume' option is only" " supported when flashing with heimall-bootimg."
|
||||||
)
|
)
|
||||||
|
|
|
@ -3,15 +3,21 @@
|
||||||
import pmb.config.pmaports
|
import pmb.config.pmaports
|
||||||
from pmb.core.chroot import Chroot
|
from pmb.core.chroot import Chroot
|
||||||
from pmb.core.context import get_context
|
from pmb.core.context import get_context
|
||||||
from pmb.types import PmbArgs
|
|
||||||
|
|
||||||
|
|
||||||
def variables(args: PmbArgs, flavor: str, method: str):
|
def variables(
|
||||||
|
flavor: str | None,
|
||||||
|
method: str,
|
||||||
|
cmdline: str | None,
|
||||||
|
no_reboot: bool | None,
|
||||||
|
partition: str | None,
|
||||||
|
resume: bool | None,
|
||||||
|
) -> dict[str, str]:
|
||||||
device = get_context().config.device
|
device = get_context().config.device
|
||||||
deviceinfo = pmb.parse.deviceinfo()
|
deviceinfo = pmb.parse.deviceinfo()
|
||||||
_cmdline = deviceinfo.kernel_cmdline or ""
|
_cmdline = deviceinfo.kernel_cmdline or ""
|
||||||
if "cmdline" in args and args.cmdline:
|
if cmdline:
|
||||||
_cmdline = args.cmdline
|
_cmdline = cmdline
|
||||||
|
|
||||||
flash_pagesize = deviceinfo.flash_pagesize
|
flash_pagesize = deviceinfo.flash_pagesize
|
||||||
|
|
||||||
|
@ -54,22 +60,22 @@ def variables(args: PmbArgs, flavor: str, method: str):
|
||||||
_partition_vbmeta = deviceinfo.flash_heimdall_partition_vbmeta or None
|
_partition_vbmeta = deviceinfo.flash_heimdall_partition_vbmeta or None
|
||||||
_partition_dtbo = deviceinfo.flash_heimdall_partition_dtbo or None
|
_partition_dtbo = deviceinfo.flash_heimdall_partition_dtbo or None
|
||||||
|
|
||||||
if "partition" in args and args.partition:
|
if partition:
|
||||||
# Only one operation is done at same time so it doesn't matter
|
# Only one operation is done at same time so it doesn't matter
|
||||||
# sharing the arg
|
# sharing the arg
|
||||||
_partition_kernel = args.partition
|
_partition_kernel = partition
|
||||||
_partition_rootfs = args.partition
|
_partition_rootfs = partition
|
||||||
_partition_vbmeta = args.partition
|
_partition_vbmeta = partition
|
||||||
_partition_dtbo = args.partition
|
_partition_dtbo = partition
|
||||||
|
|
||||||
_dtb = deviceinfo.dtb + ".dtb"
|
_dtb = deviceinfo.dtb + ".dtb"
|
||||||
|
|
||||||
_no_reboot = ""
|
_no_reboot = ""
|
||||||
if getattr(args, "no_reboot", False):
|
if no_reboot:
|
||||||
_no_reboot = "--no-reboot"
|
_no_reboot = "--no-reboot"
|
||||||
|
|
||||||
_resume = ""
|
_resume = ""
|
||||||
if getattr(args, "resume", False):
|
if resume:
|
||||||
_resume = "--resume"
|
_resume = "--resume"
|
||||||
|
|
||||||
fvars = {
|
fvars = {
|
||||||
|
|
|
@ -403,10 +403,6 @@ def install(args: PmbArgs) -> None:
|
||||||
pmb.install.install(args)
|
pmb.install.install(args)
|
||||||
|
|
||||||
|
|
||||||
def flasher(args: PmbArgs) -> None:
|
|
||||||
pmb.flasher.frontend(args)
|
|
||||||
|
|
||||||
|
|
||||||
def export(args: PmbArgs) -> None:
|
def export(args: PmbArgs) -> None:
|
||||||
pmb.export.frontend(args)
|
pmb.export.frontend(args)
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,14 @@ def create_zip(args: PmbArgs, chroot: Chroot, device: str):
|
||||||
flavor = pmb.helpers.frontend._parse_flavor(device)
|
flavor = pmb.helpers.frontend._parse_flavor(device)
|
||||||
deviceinfo = pmb.parse.deviceinfo()
|
deviceinfo = pmb.parse.deviceinfo()
|
||||||
method = deviceinfo.flash_method
|
method = deviceinfo.flash_method
|
||||||
fvars = pmb.flasher.variables(args, flavor, method)
|
fvars = pmb.flasher.variables(
|
||||||
|
flavor,
|
||||||
|
method,
|
||||||
|
getattr(args, "cmdline", None),
|
||||||
|
getattr(args, "no_reboot", None),
|
||||||
|
getattr(args, "partition", None),
|
||||||
|
getattr(args, "resume", None),
|
||||||
|
)
|
||||||
|
|
||||||
# Install recovery installer package in buildroot
|
# Install recovery installer package in buildroot
|
||||||
pmb.chroot.apk.install(["postmarketos-android-recovery-installer"], chroot)
|
pmb.chroot.apk.install(["postmarketos-android-recovery-installer"], chroot)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue