All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Zoltan Boszormenyi" <zboszor@pr.hu>
To: openembedded-core@lists.openembedded.org
Cc: "Zoltán Böszörményi" <zboszor@gmail.com>,
	"Bruce Ashfield" <bruce.ashfield@gmail.com>,
	"Richard Purdie" <richard.purdie@linuxfoundation.org>,
	"Khem Raj" <raj.khem@gmail.com>
Subject: [PATCH v2 2/2] kernel.bbclass: Allow using update-alternatives for the kernel image
Date: Wed, 29 Sep 2021 07:33:53 +0200	[thread overview]
Message-ID: <20210929053353.600644-3-zboszor@pr.hu> (raw)
In-Reply-To: <20210929053353.600644-1-zboszor@pr.hu>

From: Zoltán Böszörményi <zboszor@gmail.com>

When using dnf to install new kernel versions and installonly_limit
is reached, dnf automatically removes the oldest kernel version.

For the dnf.conf documentation on installonlypkgs, installonly_limit
and others settings, see:
https://dnf.readthedocs.io/en/latest/conf_ref.html

However, the /boot/bzImage symlink (or whatever image type is used)
is removed unconditionally.

Allow using the alternative symlink machinery so the highest
kernel version takes precedence and the symlink stays in place.

Signed-off-by: Zoltán Böszörményi <zboszor@gmail.com>
---
v2: Mention dnf.conf documentation link
    Protect against "IndexError: list index out of range"

 meta/classes/kernel.bbclass | 27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)

diff --git a/meta/classes/kernel.bbclass b/meta/classes/kernel.bbclass
index 882858e22e..47a78f0dd2 100644
--- a/meta/classes/kernel.bbclass
+++ b/meta/classes/kernel.bbclass
@@ -43,9 +43,23 @@ KERNEL_VERSION_PKG_NAME = "${@legitimize_package_name(d.getVar('KERNEL_VERSION')
 KERNEL_VERSION_PKG_NAME[vardepvalue] = "${LINUX_VERSION}"
 
 python __anonymous () {
+    import re
     pn = d.getVar("PN")
     kpn = d.getVar("KERNEL_PACKAGE_NAME")
 
+    # KERNEL_VERSION cannot be used here as it would cause
+    # "basehash value changed" issues.
+    kver =  d.getVar("PV")
+    kverp = re.compile('[\.-]')
+    kvparts = kverp.split(kver)
+    # It seems PV is unset or empty for early recipe parsing
+    # but __anonymous functions are run nevertheless.
+    # Protect against "IndexError: list index out of range".
+    if len(kvparts) >= 3:
+        kverstr = str(kvparts[0])+str(kvparts[1]).zfill(2)+str(kvparts[2]).zfill(3)
+    else:
+        kverstr = '000000'
+
     # XXX Remove this after bug 11905 is resolved
     #  FILES:${KERNEL_PACKAGE_NAME}-dev doesn't expand correctly
     if kpn == pn:
@@ -117,6 +131,9 @@ python __anonymous () {
         d.setVar('PKG:%s-image-%s' % (kname,typelower), '%s-image-%s-${KERNEL_VERSION_PKG_NAME}' % (kname, typelower))
         d.setVar('ALLOW_EMPTY:%s-image-%s' % (kname, typelower), '1')
         d.setVar('pkg_postinst:%s-image-%s' % (kname,typelower), """set +e
+if [ "${KERNEL_IMAGEDEST_USE_UPDATE_ALTERNATIVES}" != "0" ]; then
+    update-alternatives --install ${KERNEL_IMAGEDEST}/%s %s %s-${KERNEL_VERSION_NAME} %s
+else
 if [ -n "$D" ]; then
     ln -sf %s-${KERNEL_VERSION} $D/${KERNEL_IMAGEDEST}/%s > /dev/null 2>&1
 else
@@ -126,14 +143,19 @@ else
         install -m 0644 ${KERNEL_IMAGEDEST}/%s-${KERNEL_VERSION} ${KERNEL_IMAGEDEST}/%s
     fi
 fi
+fi
 set -e
-""" % (type, type, type, type, type, type, type))
+""" % (type, type, type, kverstr, type, type, type, type, type, type, type))
         d.setVar('pkg_postrm:%s-image-%s' % (kname,typelower), """set +e
+if [ "${KERNEL_IMAGEDEST_USE_UPDATE_ALTERNATIVES}" != "0" ]; then
+    update-alternatives --remove %s %s-${KERNEL_VERSION_NAME}
+else
 if [ -f "${KERNEL_IMAGEDEST}/%s" -o -L "${KERNEL_IMAGEDEST}/%s" ]; then
     rm -f ${KERNEL_IMAGEDEST}/%s  > /dev/null 2>&1
 fi
+fi
 set -e
-""" % (type, type, type))
+""" % (type, type, type, type, type))
 
 
     image = d.getVar('INITRAMFS_IMAGE')
@@ -214,6 +236,7 @@ KERNEL_RELEASE ?= "${KERNEL_VERSION}"
 # The directory where built kernel lies in the kernel tree
 KERNEL_OUTPUT_DIR ?= "arch/${ARCH}/boot"
 KERNEL_IMAGEDEST ?= "boot"
+KERNEL_IMAGEDEST_USE_UPDATE_ALTERNATIVES ?= "0"
 
 #
 # configuration
-- 
2.31.1


  parent reply	other threads:[~2021-09-29  5:33 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-29  5:33 RFC [v2]: Make kernel upgrades via dnf work like on Red Hat Zoltan Boszormenyi
2021-09-29  5:33 ` [PATCH v2 1/2] kernel.bbclass: Add runtime dependency to subpackages on main package Zoltan Boszormenyi
2021-09-29  5:33 ` Zoltan Boszormenyi [this message]
2021-09-29 16:07   ` [PATCH v2 2/2] kernel.bbclass: Allow using update-alternatives for the kernel image Bruce Ashfield
2021-09-29 17:46     ` Zoltan Boszormenyi
2021-09-29 16:06 ` RFC [v2]: Make kernel upgrades via dnf work like on Red Hat Bruce Ashfield
2021-09-29 17:29   ` Zoltan Boszormenyi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210929053353.600644-3-zboszor@pr.hu \
    --to=zboszor@pr.hu \
    --cc=bruce.ashfield@gmail.com \
    --cc=openembedded-core@lists.openembedded.org \
    --cc=raj.khem@gmail.com \
    --cc=richard.purdie@linuxfoundation.org \
    --cc=zboszor@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.