diff --git a/pmb/chroot/initfs.py b/pmb/chroot/initfs.py index ebacf87f..181d08f1 100644 --- a/pmb/chroot/initfs.py +++ b/pmb/chroot/initfs.py @@ -80,8 +80,7 @@ def ls(args, flavor, suffix, extra=False): def frontend(args): # Find the appropriate kernel flavor suffix = f"rootfs_{args.device}" - flavors = pmb.chroot.other.kernel_flavors_installed(args, suffix) - flavor = flavors[0] + flavor = pmb.chroot.other.kernel_flavor_installed(args, suffix) # Handle initfs actions action = args.action_initfs @@ -107,9 +106,8 @@ def frontend(args): elif action == "hook_del": pmb.chroot.initfs_hooks.delete(args, args.hook, suffix) - # Rebuild the initfs for all kernels after adding/removing a hook - for flavor in flavors: - build(args, flavor, suffix) + # Rebuild the initfs after adding/removing a hook + build(args, flavor, suffix) if action in ["ls", "extract"]: link = "https://wiki.postmarketos.org/wiki/Initramfs_development" diff --git a/pmb/chroot/other.py b/pmb/chroot/other.py index 40550869..377519ba 100644 --- a/pmb/chroot/other.py +++ b/pmb/chroot/other.py @@ -7,33 +7,28 @@ import pmb.chroot.apk import pmb.install -def kernel_flavors_installed(args, suffix, autoinstall=True): +def kernel_flavor_installed(args, suffix, autoinstall=True): """ - Get all installed kernel flavors and make sure that there's at least one + Get installed kernel flavor. Optionally install the device's kernel + beforehand. :param suffix: the chroot suffix, e.g. "native" or "rootfs_qemu-amd64" - :param autoinstall: make sure that at least one kernel flavor is installed - :returns: list of installed kernel flavors, e.g. ["postmarketos-mainline"] + :param autoinstall: install the device's kernel if it is not installed + :returns: * string with the installed kernel flavor, + e.g. ["postmarketos-qcom-sdm845"] + * None if no kernel is installed """ # Automatically install the selected kernel if autoinstall: - packages = (["device-" + args.device] + + packages = ([f"device-{args.device}"] + pmb.install.get_kernel_package(args, args.device)) pmb.chroot.apk.install(args, packages, suffix) - # Find all kernels in /boot - prefix = "vmlinuz-" - prefix_len = len(prefix) - pattern = args.work + "/chroot_" + suffix + "/boot/" + prefix + "*" - ret = [] - for file in glob.glob(pattern): - flavor = os.path.basename(file)[prefix_len:] - if flavor[-4:] == "-dtb" or flavor[-4:] == "-mtk": - flavor = flavor[:-4] - ret.append(flavor) + pattern = f"{args.work}/chroot_{suffix}/usr/share/kernel/*" + glob_result = glob.glob(pattern) - # Return without duplicates - return list(set(ret)) + # There should be only one directory here + return os.path.basename(glob_result[0]) if glob_result else None def tempfolder(args, path, suffix="native"): diff --git a/pmb/flasher/frontend.py b/pmb/flasher/frontend.py index aef03275..75175df2 100644 --- a/pmb/flasher/frontend.py +++ b/pmb/flasher/frontend.py @@ -42,8 +42,7 @@ def kernel(args): def list_flavors(args): suffix = "rootfs_" + args.device logging.info("(" + suffix + ") installed kernel flavors:") - for flavor in pmb.chroot.other.kernel_flavors_installed(args, suffix): - logging.info("* " + flavor) + logging.info("* " + pmb.chroot.other.kernel_flavor_installed(args, suffix)) def rootfs(args): diff --git a/pmb/helpers/frontend.py b/pmb/helpers/frontend.py index 65dd5012..64093a5d 100644 --- a/pmb/helpers/frontend.py +++ b/pmb/helpers/frontend.py @@ -38,17 +38,19 @@ def _parse_flavor(args, autoinstall=True): Verify the flavor argument if specified, or return a default value. :param autoinstall: make sure that at least one kernel flavor is installed """ - # Install at least one kernel and get installed flavors + # Install a kernel and get its "flavor", where flavor is a pmOS-specific + # identifier that is typically in the form + # "postmarketos--", e.g. + # "postmarketos-qcom-sdm845" suffix = "rootfs_" + args.device - flavors = pmb.chroot.other.kernel_flavors_installed( + flavor = pmb.chroot.other.kernel_flavor_installed( args, suffix, autoinstall) - # Parse and verify flavor - if not len(flavors): + if not flavor: raise RuntimeError( "No kernel flavors installed in chroot " + suffix + "! Please let" " your device package depend on a package starting with 'linux-'.") - return flavors[0] + return flavor def _parse_suffix(args): diff --git a/pmb/install/_install.py b/pmb/install/_install.py index c50f7002..f08c4216 100644 --- a/pmb/install/_install.py +++ b/pmb/install/_install.py @@ -846,8 +846,8 @@ def create_device_rootfs(args, step, steps): # because that doesn't always happen automatically yet, e.g. when the user # installed a hook without pmbootstrap - see #69 for more info) pmb.chroot.apk.install(args, install_packages, suffix) - for flavor in pmb.chroot.other.kernel_flavors_installed(args, suffix): - pmb.chroot.initfs.build(args, flavor, suffix) + flavor = pmb.chroot.other.kernel_flavor_installed(args, suffix) + pmb.chroot.initfs.build(args, flavor, suffix) # Set the user password setup_login(args, suffix) diff --git a/pmb/qemu/run.py b/pmb/qemu/run.py index 6837fb43..ec511244 100644 --- a/pmb/qemu/run.py +++ b/pmb/qemu/run.py @@ -96,7 +96,7 @@ def command_qemu(args, arch, img_path, img_path_2nd=None): suffix = "rootfs_" + args.device rootfs = args.work + "/chroot_" + suffix - flavor = pmb.chroot.other.kernel_flavors_installed(args, suffix)[0] + flavor = pmb.chroot.other.kernel_flavor_installed(args, suffix) ncpus = os.cpu_count() # QEMU mach-virt's max CPU count is 8, limit it so it will work correctly