forked from Mirror/pmbootstrap
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:
parent
84332cdce0
commit
35eff91564
6 changed files with 26 additions and 34 deletions
|
@ -439,7 +439,7 @@ def ask_for_device(context: Context):
|
||||||
device = f"{vendor}-{codename}"
|
device = f"{vendor}-{codename}"
|
||||||
device_path = pmb.helpers.devices.find_path(device, "deviceinfo")
|
device_path = pmb.helpers.devices.find_path(device, "deviceinfo")
|
||||||
if device_path is None:
|
if device_path is None:
|
||||||
if device == context.device:
|
if device == context.config.device:
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
"This device does not exist anymore, check"
|
"This device does not exist anymore, check"
|
||||||
" <https://postmarketos.org/renamed>"
|
" <https://postmarketos.org/renamed>"
|
||||||
|
|
|
@ -21,11 +21,6 @@ class Context:
|
||||||
# Operate offline
|
# Operate offline
|
||||||
offline: bool = False
|
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
|
# The pmbootstrap subcommand
|
||||||
command: str = ""
|
command: str = ""
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ from pmb.core import Chroot, ChrootType
|
||||||
|
|
||||||
|
|
||||||
def frontend(args: PmbArgs): # FIXME: ARGS_REFACTOR
|
def frontend(args: PmbArgs): # FIXME: ARGS_REFACTOR
|
||||||
context = get_context()
|
config = get_context().config
|
||||||
# Create the export folder
|
# Create the export folder
|
||||||
target = args.export_folder
|
target = args.export_folder
|
||||||
if not os.path.exists(target):
|
if not os.path.exists(target):
|
||||||
|
@ -19,7 +19,7 @@ def frontend(args: PmbArgs): # FIXME: ARGS_REFACTOR
|
||||||
|
|
||||||
# Rootfs image note
|
# Rootfs image note
|
||||||
chroot = Chroot.native()
|
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"):
|
if not rootfs_dir.glob("*.img"):
|
||||||
logging.info(
|
logging.info(
|
||||||
"NOTE: To export the rootfs image, run 'pmbootstrap"
|
"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)
|
# 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:
|
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
|
# Do the export, print all files
|
||||||
logging.info(f"Export symlinks to: {target}")
|
logging.info(f"Export symlinks to: {target}")
|
||||||
if args.odin_flashable_tar:
|
if args.odin_flashable_tar:
|
||||||
pmb.export.odin(context, flavor, target)
|
pmb.export.odin(config.device, flavor, target)
|
||||||
pmb.export.symlinks(flavor, target)
|
pmb.export.symlinks(flavor, target)
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
# Copyright 2023 Oliver Smith
|
# Copyright 2023 Oliver Smith
|
||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
from pmb.core.context import Context
|
|
||||||
from pmb.helpers import logging
|
from pmb.helpers import logging
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
@ -12,15 +11,15 @@ import pmb.helpers.file
|
||||||
from pmb.core import Chroot, ChrootType
|
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
|
Create Odin flashable tar file with kernel and initramfs
|
||||||
for devices configured with the flasher method 'heimdall-isorec'
|
for devices configured with the flasher method 'heimdall-isorec'
|
||||||
and with boot.img for devices with 'heimdall-bootimg'
|
and with boot.img for devices with 'heimdall-bootimg'
|
||||||
"""
|
"""
|
||||||
pmb.flasher.init(context.device, "heimdall-isorec")
|
pmb.flasher.init(device, "heimdall-isorec")
|
||||||
suffix = Chroot(ChrootType.ROOTFS, context.device)
|
suffix = Chroot(ChrootType.ROOTFS, device)
|
||||||
deviceinfo = pmb.parse.deviceinfo(context.device)
|
deviceinfo = pmb.parse.deviceinfo(device)
|
||||||
|
|
||||||
# Backwards compatibility with old mkinitfs (pma#660)
|
# Backwards compatibility with old mkinitfs (pma#660)
|
||||||
suffix_flavor = f"-{flavor}"
|
suffix_flavor = f"-{flavor}"
|
||||||
|
@ -50,12 +49,12 @@ def odin(context: Context, flavor, folder: Path):
|
||||||
# Odin flashable tar generation script
|
# Odin flashable tar generation script
|
||||||
# (because redirecting stdin/stdout is not allowed
|
# (because redirecting stdin/stdout is not allowed
|
||||||
# in pmbootstrap's chroot/shell functions for security reasons)
|
# 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:
|
with odin_script.open("w") as handle:
|
||||||
odin_kernel_md5 = f"{partition_kernel}.bin.md5"
|
odin_kernel_md5 = f"{partition_kernel}.bin.md5"
|
||||||
odin_initfs_md5 = f"{partition_initfs}.bin.md5"
|
odin_initfs_md5 = f"{partition_initfs}.bin.md5"
|
||||||
odin_device_tar = f"{context.device}.tar"
|
odin_device_tar = f"{device}.tar"
|
||||||
odin_device_tar_md5 = f"{context.device}.tar.md5"
|
odin_device_tar_md5 = f"{device}.tar.md5"
|
||||||
|
|
||||||
handle.write("#!/bin/sh\n" f"cd {temp_folder}\n")
|
handle.write("#!/bin/sh\n" f"cd {temp_folder}\n")
|
||||||
if method == "heimdall-isorec":
|
if method == "heimdall-isorec":
|
||||||
|
@ -97,7 +96,7 @@ def odin(context: Context, flavor, folder: Path):
|
||||||
pmb.chroot.root(
|
pmb.chroot.root(
|
||||||
[
|
[
|
||||||
"mv",
|
"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/",
|
"/home/pmos/rootfs/",
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
|
|
|
@ -18,8 +18,8 @@ def symlinks(flavor, folder: Path):
|
||||||
Create convenience symlinks to the rootfs and boot files.
|
Create convenience symlinks to the rootfs and boot files.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
context = get_context()
|
device = get_context().config.device
|
||||||
arch = pmb.parse.deviceinfo(context.device).arch
|
arch = pmb.parse.deviceinfo(device).arch
|
||||||
|
|
||||||
# Backwards compatibility with old mkinitfs (pma#660)
|
# Backwards compatibility with old mkinitfs (pma#660)
|
||||||
suffix = f"-{flavor}"
|
suffix = f"-{flavor}"
|
||||||
|
@ -38,16 +38,16 @@ def symlinks(flavor, folder: Path):
|
||||||
f"uInitrd{suffix}": "Initramfs, legacy u-boot image format",
|
f"uInitrd{suffix}": "Initramfs, legacy u-boot image format",
|
||||||
f"uImage{suffix}": "Kernel, legacy u-boot image format",
|
f"uImage{suffix}": "Kernel, legacy u-boot image format",
|
||||||
f"vmlinuz{suffix}": "Linux kernel",
|
f"vmlinuz{suffix}": "Linux kernel",
|
||||||
f"{context.device}.img": "Rootfs with partitions for /boot and /",
|
f"{device}.img": "Rootfs with partitions for /boot and /",
|
||||||
f"{context.device}-boot.img": "Boot partition image",
|
f"{device}-boot.img": "Boot partition image",
|
||||||
f"{context.device}-root.img": "Root partition image",
|
f"{device}-root.img": "Root partition image",
|
||||||
f"pmos-{context.device}.zip": "Android recovery flashable zip",
|
f"pmos-{device}.zip": "Android recovery flashable zip",
|
||||||
"lk2nd.img": "Secondary Android bootloader",
|
"lk2nd.img": "Secondary Android bootloader",
|
||||||
}
|
}
|
||||||
|
|
||||||
# Generate a list of patterns
|
# Generate a list of patterns
|
||||||
chroot_native = Chroot.native()
|
chroot_native = Chroot.native()
|
||||||
path_boot = Chroot(ChrootType.ROOTFS, context.device) / "boot"
|
path_boot = Chroot(ChrootType.ROOTFS, device) / "boot"
|
||||||
chroot_buildroot = Chroot.buildroot(arch)
|
chroot_buildroot = Chroot.buildroot(arch)
|
||||||
files: list[Path] = [
|
files: list[Path] = [
|
||||||
path_boot / f"boot.img{suffix}",
|
path_boot / f"boot.img{suffix}",
|
||||||
|
@ -55,12 +55,10 @@ def symlinks(flavor, folder: Path):
|
||||||
path_boot / f"uImage{suffix}",
|
path_boot / f"uImage{suffix}",
|
||||||
path_boot / f"vmlinuz{suffix}",
|
path_boot / f"vmlinuz{suffix}",
|
||||||
path_boot / "dtbo.img",
|
path_boot / "dtbo.img",
|
||||||
chroot_native / "home/pmos/rootfs" / f"{context.device}.img",
|
chroot_native / "home/pmos/rootfs" / f"{device}.img",
|
||||||
chroot_native / "home/pmos/rootfs" / f"{context.device}-boot.img",
|
chroot_native / "home/pmos/rootfs" / f"{device}-boot.img",
|
||||||
chroot_native / "home/pmos/rootfs" / f"{context.device}-root.img",
|
chroot_native / "home/pmos/rootfs" / f"{device}-root.img",
|
||||||
chroot_buildroot
|
chroot_buildroot / "var/libpostmarketos-android-recovery-installer" / f"pmos-{device}.zip",
|
||||||
/ "var/libpostmarketos-android-recovery-installer"
|
|
||||||
/ f"pmos-{context.device}.zip",
|
|
||||||
path_boot / "lk2nd.img",
|
path_boot / "lk2nd.img",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -144,7 +144,7 @@ def flash_lk2nd(deviceinfo: Deviceinfo, method: str):
|
||||||
def frontend(args: PmbArgs):
|
def frontend(args: PmbArgs):
|
||||||
context = get_context()
|
context = get_context()
|
||||||
action = args.action_flasher
|
action = args.action_flasher
|
||||||
device = context.device
|
device = context.config.device
|
||||||
deviceinfo = pmb.parse.deviceinfo()
|
deviceinfo = pmb.parse.deviceinfo()
|
||||||
method = args.flash_method or deviceinfo.flash_method
|
method = args.flash_method or deviceinfo.flash_method
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue