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):
# 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"

View File

@ -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"):

View File

@ -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):

View File

@ -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-<manufacturer>-<device/chip>", 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):

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
# 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)

View File

@ -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