treewide: drop context.device (MR 2332)

this turns out to have never been set??? We have config.device anyways,
so let's use that instead.

Tweaked-by: Oliver Smith <ollieparanoid@postmarketos.org>
Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
This commit is contained in:
Caleb Connolly 2024-06-23 21:05:23 +02:00 committed by Oliver Smith
parent 84332cdce0
commit 35eff91564
No known key found for this signature in database
GPG key ID: 5AE7F5513E0885CB
6 changed files with 26 additions and 34 deletions

View file

@ -439,7 +439,7 @@ def ask_for_device(context: Context):
device = f"{vendor}-{codename}"
device_path = pmb.helpers.devices.find_path(device, "deviceinfo")
if device_path is None:
if device == context.device:
if device == context.config.device:
raise RuntimeError(
"This device does not exist anymore, check"
" <https://postmarketos.org/renamed>"

View file

@ -21,11 +21,6 @@ class Context:
# Operate offline
offline: bool = False
# Device we are operating on
# FIXME: should not be in global context, only
# specific actions actually depend on this
device: str = ""
# The pmbootstrap subcommand
command: str = ""

View file

@ -11,7 +11,7 @@ from pmb.core import Chroot, ChrootType
def frontend(args: PmbArgs): # FIXME: ARGS_REFACTOR
context = get_context()
config = get_context().config
# Create the export folder
target = args.export_folder
if not os.path.exists(target):
@ -19,7 +19,7 @@ def frontend(args: PmbArgs): # FIXME: ARGS_REFACTOR
# Rootfs image note
chroot = Chroot.native()
rootfs_dir = chroot / "home/pmos/rootfs" / context.device
rootfs_dir = chroot / "home/pmos/rootfs" / config.device
if not rootfs_dir.glob("*.img"):
logging.info(
"NOTE: To export the rootfs image, run 'pmbootstrap"
@ -27,12 +27,12 @@ def frontend(args: PmbArgs): # FIXME: ARGS_REFACTOR
)
# Rebuild the initramfs, just to make sure (see #69)
flavor = pmb.helpers.frontend._parse_flavor(context.device, args.autoinstall)
flavor = pmb.helpers.frontend._parse_flavor(config.device, args.autoinstall)
if args.autoinstall:
pmb.chroot.initfs.build(flavor, Chroot(ChrootType.ROOTFS, context.device))
pmb.chroot.initfs.build(flavor, Chroot(ChrootType.ROOTFS, config.device))
# Do the export, print all files
logging.info(f"Export symlinks to: {target}")
if args.odin_flashable_tar:
pmb.export.odin(context, flavor, target)
pmb.export.odin(config.device, flavor, target)
pmb.export.symlinks(flavor, target)

View file

@ -1,6 +1,5 @@
# Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
from pmb.core.context import Context
from pmb.helpers import logging
from pathlib import Path
@ -12,15 +11,15 @@ import pmb.helpers.file
from pmb.core import Chroot, ChrootType
def odin(context: Context, flavor, folder: Path):
def odin(device: str, flavor, folder: Path):
"""
Create Odin flashable tar file with kernel and initramfs
for devices configured with the flasher method 'heimdall-isorec'
and with boot.img for devices with 'heimdall-bootimg'
"""
pmb.flasher.init(context.device, "heimdall-isorec")
suffix = Chroot(ChrootType.ROOTFS, context.device)
deviceinfo = pmb.parse.deviceinfo(context.device)
pmb.flasher.init(device, "heimdall-isorec")
suffix = Chroot(ChrootType.ROOTFS, device)
deviceinfo = pmb.parse.deviceinfo(device)
# Backwards compatibility with old mkinitfs (pma#660)
suffix_flavor = f"-{flavor}"
@ -50,12 +49,12 @@ def odin(context: Context, flavor, folder: Path):
# Odin flashable tar generation script
# (because redirecting stdin/stdout is not allowed
# in pmbootstrap's chroot/shell functions for security reasons)
odin_script = Chroot(ChrootType.ROOTFS, context.device) / "tmp/_odin.sh"
odin_script = Chroot(ChrootType.ROOTFS, device) / "tmp/_odin.sh"
with odin_script.open("w") as handle:
odin_kernel_md5 = f"{partition_kernel}.bin.md5"
odin_initfs_md5 = f"{partition_initfs}.bin.md5"
odin_device_tar = f"{context.device}.tar"
odin_device_tar_md5 = f"{context.device}.tar.md5"
odin_device_tar = f"{device}.tar"
odin_device_tar_md5 = f"{device}.tar.md5"
handle.write("#!/bin/sh\n" f"cd {temp_folder}\n")
if method == "heimdall-isorec":
@ -97,7 +96,7 @@ def odin(context: Context, flavor, folder: Path):
pmb.chroot.root(
[
"mv",
f"/mnt/rootfs_{context.device}{temp_folder}" f"/{odin_device_tar_md5}",
f"/mnt/rootfs_{device}{temp_folder}" f"/{odin_device_tar_md5}",
"/home/pmos/rootfs/",
]
),

View file

@ -18,8 +18,8 @@ def symlinks(flavor, folder: Path):
Create convenience symlinks to the rootfs and boot files.
"""
context = get_context()
arch = pmb.parse.deviceinfo(context.device).arch
device = get_context().config.device
arch = pmb.parse.deviceinfo(device).arch
# Backwards compatibility with old mkinitfs (pma#660)
suffix = f"-{flavor}"
@ -38,16 +38,16 @@ def symlinks(flavor, folder: Path):
f"uInitrd{suffix}": "Initramfs, legacy u-boot image format",
f"uImage{suffix}": "Kernel, legacy u-boot image format",
f"vmlinuz{suffix}": "Linux kernel",
f"{context.device}.img": "Rootfs with partitions for /boot and /",
f"{context.device}-boot.img": "Boot partition image",
f"{context.device}-root.img": "Root partition image",
f"pmos-{context.device}.zip": "Android recovery flashable zip",
f"{device}.img": "Rootfs with partitions for /boot and /",
f"{device}-boot.img": "Boot partition image",
f"{device}-root.img": "Root partition image",
f"pmos-{device}.zip": "Android recovery flashable zip",
"lk2nd.img": "Secondary Android bootloader",
}
# Generate a list of patterns
chroot_native = Chroot.native()
path_boot = Chroot(ChrootType.ROOTFS, context.device) / "boot"
path_boot = Chroot(ChrootType.ROOTFS, device) / "boot"
chroot_buildroot = Chroot.buildroot(arch)
files: list[Path] = [
path_boot / f"boot.img{suffix}",
@ -55,12 +55,10 @@ def symlinks(flavor, folder: Path):
path_boot / f"uImage{suffix}",
path_boot / f"vmlinuz{suffix}",
path_boot / "dtbo.img",
chroot_native / "home/pmos/rootfs" / f"{context.device}.img",
chroot_native / "home/pmos/rootfs" / f"{context.device}-boot.img",
chroot_native / "home/pmos/rootfs" / f"{context.device}-root.img",
chroot_buildroot
/ "var/libpostmarketos-android-recovery-installer"
/ f"pmos-{context.device}.zip",
chroot_native / "home/pmos/rootfs" / f"{device}.img",
chroot_native / "home/pmos/rootfs" / f"{device}-boot.img",
chroot_native / "home/pmos/rootfs" / f"{device}-root.img",
chroot_buildroot / "var/libpostmarketos-android-recovery-installer" / f"pmos-{device}.zip",
path_boot / "lk2nd.img",
]

View file

@ -144,7 +144,7 @@ def flash_lk2nd(deviceinfo: Deviceinfo, method: str):
def frontend(args: PmbArgs):
context = get_context()
action = args.action_flasher
device = context.device
device = context.config.device
deviceinfo = pmb.parse.deviceinfo()
method = args.flash_method or deviceinfo.flash_method