chroot/other/kernel_flavor_installed: support generic kernel name (MR 2093)

kernel is named /boot/vmlinuz now, looking at the filename will no
longer tell us what flavor it is. This now will look at
/usr/share/kernel, which has always contained the kernel 'flavor', and
since we currently only install 1 kernel these days, guarding this with
pmaports.cfg should be unnecessary. In the worst case (if there are
multiple kernel 'flavors' installed), it'll just grab the first one and
return it.
This commit is contained in:
Clayton Craft 2021-08-18 16:31:59 -07:00
parent 184ac91ec5
commit 09794ef832
No known key found for this signature in database
GPG Key ID: 5AE7F5513E0885CB
6 changed files with 26 additions and 32 deletions

View File

@ -80,8 +80,7 @@ def ls(args, flavor, suffix, extra=False):
def frontend(args): def frontend(args):
# Find the appropriate kernel flavor # Find the appropriate kernel flavor
suffix = f"rootfs_{args.device}" suffix = f"rootfs_{args.device}"
flavors = pmb.chroot.other.kernel_flavors_installed(args, suffix) flavor = pmb.chroot.other.kernel_flavor_installed(args, suffix)
flavor = flavors[0]
# Handle initfs actions # Handle initfs actions
action = args.action_initfs action = args.action_initfs
@ -107,9 +106,8 @@ def frontend(args):
elif action == "hook_del": elif action == "hook_del":
pmb.chroot.initfs_hooks.delete(args, args.hook, suffix) pmb.chroot.initfs_hooks.delete(args, args.hook, suffix)
# Rebuild the initfs for all kernels after adding/removing a hook # Rebuild the initfs after adding/removing a hook
for flavor in flavors: build(args, flavor, suffix)
build(args, flavor, suffix)
if action in ["ls", "extract"]: if action in ["ls", "extract"]:
link = "https://wiki.postmarketos.org/wiki/Initramfs_development" link = "https://wiki.postmarketos.org/wiki/Initramfs_development"

View File

@ -7,33 +7,28 @@ import pmb.chroot.apk
import pmb.install 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 suffix: the chroot suffix, e.g. "native" or "rootfs_qemu-amd64"
:param autoinstall: make sure that at least one kernel flavor is installed :param autoinstall: install the device's kernel if it is not installed
:returns: list of installed kernel flavors, e.g. ["postmarketos-mainline"] :returns: * string with the installed kernel flavor,
e.g. ["postmarketos-qcom-sdm845"]
* None if no kernel is installed
""" """
# Automatically install the selected kernel # Automatically install the selected kernel
if autoinstall: if autoinstall:
packages = (["device-" + args.device] + packages = ([f"device-{args.device}"] +
pmb.install.get_kernel_package(args, args.device)) pmb.install.get_kernel_package(args, args.device))
pmb.chroot.apk.install(args, packages, suffix) pmb.chroot.apk.install(args, packages, suffix)
# Find all kernels in /boot pattern = f"{args.work}/chroot_{suffix}/usr/share/kernel/*"
prefix = "vmlinuz-" glob_result = glob.glob(pattern)
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)
# Return without duplicates # There should be only one directory here
return list(set(ret)) return os.path.basename(glob_result[0]) if glob_result else None
def tempfolder(args, path, suffix="native"): def tempfolder(args, path, suffix="native"):

View File

@ -42,8 +42,7 @@ def kernel(args):
def list_flavors(args): def list_flavors(args):
suffix = "rootfs_" + args.device suffix = "rootfs_" + args.device
logging.info("(" + suffix + ") installed kernel flavors:") logging.info("(" + suffix + ") installed kernel flavors:")
for flavor in pmb.chroot.other.kernel_flavors_installed(args, suffix): logging.info("* " + pmb.chroot.other.kernel_flavor_installed(args, suffix))
logging.info("* " + flavor)
def rootfs(args): def rootfs(args):

View File

@ -38,17 +38,19 @@ def _parse_flavor(args, autoinstall=True):
Verify the flavor argument if specified, or return a default value. Verify the flavor argument if specified, or return a default value.
:param autoinstall: make sure that at least one kernel flavor is installed :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-<manufacturer>-<device/chip>", e.g.
# "postmarketos-qcom-sdm845"
suffix = "rootfs_" + args.device suffix = "rootfs_" + args.device
flavors = pmb.chroot.other.kernel_flavors_installed( flavor = pmb.chroot.other.kernel_flavor_installed(
args, suffix, autoinstall) args, suffix, autoinstall)
# Parse and verify flavor if not flavor:
if not len(flavors):
raise RuntimeError( raise RuntimeError(
"No kernel flavors installed in chroot " + suffix + "! Please let" "No kernel flavors installed in chroot " + suffix + "! Please let"
" your device package depend on a package starting with 'linux-'.") " your device package depend on a package starting with 'linux-'.")
return flavors[0] return flavor
def _parse_suffix(args): def _parse_suffix(args):

View File

@ -846,8 +846,8 @@ def create_device_rootfs(args, step, steps):
# because that doesn't always happen automatically yet, e.g. when the user # because that doesn't always happen automatically yet, e.g. when the user
# installed a hook without pmbootstrap - see #69 for more info) # installed a hook without pmbootstrap - see #69 for more info)
pmb.chroot.apk.install(args, install_packages, suffix) pmb.chroot.apk.install(args, install_packages, suffix)
for flavor in pmb.chroot.other.kernel_flavors_installed(args, suffix): flavor = pmb.chroot.other.kernel_flavor_installed(args, suffix)
pmb.chroot.initfs.build(args, flavor, suffix) pmb.chroot.initfs.build(args, flavor, suffix)
# Set the user password # Set the user password
setup_login(args, suffix) setup_login(args, suffix)

View File

@ -96,7 +96,7 @@ def command_qemu(args, arch, img_path, img_path_2nd=None):
suffix = "rootfs_" + args.device suffix = "rootfs_" + args.device
rootfs = args.work + "/chroot_" + suffix 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() ncpus = os.cpu_count()
# QEMU mach-virt's max CPU count is 8, limit it so it will work correctly # QEMU mach-virt's max CPU count is 8, limit it so it will work correctly