public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
* [PATCHv2 0/4] Add support for per-kernel recipe variants
@ 2025-04-11 20:08 chris.larson via isar-users
  2025-04-11 20:08 ` [PATCH 1/4] per-kernel.bbclass: add class chris.larson via isar-users
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: chris.larson via isar-users @ 2025-04-11 20:08 UTC (permalink / raw)
  To: isar-users; +Cc: Cedric Hombourger, Christopher Larson

From: Christopher Larson <chris.larson@siemens.com>

Add support for generation of per-kernel recipe variants. This aids in the
ability for a MACHINE to support multiple kernels, by allowing us to generate
per-kernel packages in recipes like external kernel modules. Enable this
support by default for external kernel modules.

A new variable KERNEL_NAMES will list the kernels for which variants will be
generated. For any kernels listed other than KERNEL_NAME, a variant of the
recipe will be produced, to generate a package or packages for that kernel.
In each variant, the KERNEL_NAME variable will be set to the kernel name for
which the variant is being built, and the `kernel-<kernel_name>` override
will be added, allowing for further metadata customization on a per-kernel
basis.

In a recipe that already uses KERNEL_NAME and appends it to its PN, all you
need to do to use this is to inherit per-kernel, and add any additional kernels
you want to support to KERNEL_NAMES. The second patch in this series
does so for external kernel modules by default, but this will have no effect
on existing recipes unless KERNEL_NAMES is set to something other than
KERNEL_NAME.

A new test is added to verify that the per-kernel support works as expected.

No documentation for the per-kernel class is added, as it's already being enabled
for external kernel modules, which is the main use case, and no other optional
bbclasses are being documented in the user manual today.

Christopher Larson (4):
  per-kernel.bbclass: add class
  linux-module: inherit per-kernel
  testsuite: add 'extra_lines' argument to configure
  testsuite: add a test for per_kernel support

 meta/classes/per-kernel.bbclass             | 35 +++++++++++++++++++++
 meta/recipes-kernel/linux-module/module.inc |  1 +
 testsuite/cibuilder.py                      |  5 +++
 testsuite/citest.py                         | 22 +++++++++++++
 4 files changed, 63 insertions(+)
 create mode 100644 meta/classes/per-kernel.bbclass

-- 
2.47.2

-- 
You received this message because you are subscribed to the Google Groups "isar-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to isar-users+unsubscribe@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/isar-users/20250411200852.51967-1-chris.larson%40siemens.com.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/4] per-kernel.bbclass: add class
  2025-04-11 20:08 [PATCHv2 0/4] Add support for per-kernel recipe variants chris.larson via isar-users
@ 2025-04-11 20:08 ` chris.larson via isar-users
  2025-04-11 20:08 ` [PATCH 2/4] linux-module: inherit per-kernel chris.larson via isar-users
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: chris.larson via isar-users @ 2025-04-11 20:08 UTC (permalink / raw)
  To: isar-users; +Cc: Cedric Hombourger, Christopher Larson

From: Christopher Larson <chris.larson@siemens.com>

Add support for generation of per-kernel recipe variants. This aids in the
ability for a MACHINE to support multiple kernels, by allowing us to generate
per-kernel packages in recipes like external kernel modules.

A new variable KERNEL_NAMES will list the kernels for which variants will be
generated. For any kernels listed other than KERNEL_NAME, a variant of the
recipe will be produced, to generate a package or packages for that kernel.
In each variant, the KERNEL_NAME variable will be set to the kernel name for
which the variant is being built, and the `kernel-<kernel_name>` override
will be added, allowing for further metadata customization on a per-kernel
basis.

Signed-off-by: Christopher Larson <chris.larson@siemens.com>
---
 meta/classes/per-kernel.bbclass | 35 +++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
 create mode 100644 meta/classes/per-kernel.bbclass

diff --git a/meta/classes/per-kernel.bbclass b/meta/classes/per-kernel.bbclass
new file mode 100644
index 00000000..8abe117f
--- /dev/null
+++ b/meta/classes/per-kernel.bbclass
@@ -0,0 +1,35 @@
+# Generate per-kernel recipe variants
+#
+# Recipes which are specific to a specific kernel currently append KERNEL_NAME to the PN,
+# and depend on and target that specific kernel. For a machine which supports and builds
+# multiple kernel images, there is a need to generate a variant of the recipe for each
+# kernel image.
+# 
+# Each variant listed in KERNEL_NAMES will add `kernel-<kernel_name>` to the OVERRIDES variable, and
+# `per-kernel:<kernel_name>` to the BBCLASSEXTEND variable. In addition, KERNEL_NAME will be
+# set to the kernel name for the current variant.
+#
+# Copyright (c) Siemens AG, 2025
+# SPDX-License-Identifier: MIT
+
+OVERRIDES .= ":kernel-${KERNEL_NAME}"
+
+KERNEL_NAMES ?= "${KERNEL_NAME}"
+BBCLASSEXTEND += "${@' '.join(f'per-kernel:{kernel}' for kernel in d.getVar('KERNEL_NAMES').split() if kernel != d.getVar('KERNEL_NAME'))}"
+
+python per_kernel_virtclass_handler() {
+    orig_pn = d.getVar('PN')
+
+    d = e.data
+    extend = d.getVar('BBEXTENDCURR') or ''
+    variant = d.getVar('BBEXTENDVARIANT') or ''
+    if extend != 'per-kernel':
+        return
+    elif variant == '':
+        d.appendVar('PROVIDES', f' {orig_pn}')
+        return
+
+    d.setVar('KERNEL_NAME', variant)
+}
+addhandler per_kernel_virtclass_handler
+per_kernel_virtclass_handler[eventmask] = "bb.event.RecipePreFinalise"
-- 
2.47.2

-- 
You received this message because you are subscribed to the Google Groups "isar-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to isar-users+unsubscribe@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/isar-users/20250411200852.51967-2-chris.larson%40siemens.com.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 2/4] linux-module: inherit per-kernel
  2025-04-11 20:08 [PATCHv2 0/4] Add support for per-kernel recipe variants chris.larson via isar-users
  2025-04-11 20:08 ` [PATCH 1/4] per-kernel.bbclass: add class chris.larson via isar-users
@ 2025-04-11 20:08 ` chris.larson via isar-users
  2025-04-11 20:08 ` [PATCH 3/4] testsuite: add 'extra_lines' argument to configure chris.larson via isar-users
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: chris.larson via isar-users @ 2025-04-11 20:08 UTC (permalink / raw)
  To: isar-users; +Cc: Cedric Hombourger, Christopher Larson

From: Christopher Larson <chris.larson@siemens.com>

This ensures that it's possible to build the kernel module for all kernels which
are supported by the current MACHINE. This will have no effect unless the
KERNEL_NAMES variable is adjusted to add more than just KERNEL_NAME.

Signed-off-by: Christopher Larson <chris.larson@siemens.com>
---
 meta/recipes-kernel/linux-module/module.inc | 1 +
 1 file changed, 1 insertion(+)

diff --git a/meta/recipes-kernel/linux-module/module.inc b/meta/recipes-kernel/linux-module/module.inc
index 3b0ceae7..6f877115 100644
--- a/meta/recipes-kernel/linux-module/module.inc
+++ b/meta/recipes-kernel/linux-module/module.inc
@@ -43,6 +43,7 @@ python() {
 }
 
 inherit dpkg
+inherit per-kernel
 
 TEMPLATE_FILES = "debian/control.tmpl \
                   debian/rules.tmpl"
-- 
2.47.2

-- 
You received this message because you are subscribed to the Google Groups "isar-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to isar-users+unsubscribe@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/isar-users/20250411200852.51967-3-chris.larson%40siemens.com.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 3/4] testsuite: add 'extra_lines' argument to configure
  2025-04-11 20:08 [PATCHv2 0/4] Add support for per-kernel recipe variants chris.larson via isar-users
  2025-04-11 20:08 ` [PATCH 1/4] per-kernel.bbclass: add class chris.larson via isar-users
  2025-04-11 20:08 ` [PATCH 2/4] linux-module: inherit per-kernel chris.larson via isar-users
@ 2025-04-11 20:08 ` chris.larson via isar-users
  2025-04-11 20:08 ` [PATCH 4/4] testsuite: add a test for per_kernel support chris.larson via isar-users
  2025-04-11 20:10 ` [PATCHv2 0/4] Add support for per-kernel recipe variants 'Larson, Chris' via isar-users
  4 siblings, 0 replies; 6+ messages in thread
From: chris.larson via isar-users @ 2025-04-11 20:08 UTC (permalink / raw)
  To: isar-users; +Cc: Cedric Hombourger, Christopher Larson

From: Christopher Larson <chris.larson@siemens.com>

This allows us to add extra lines to the configuration file, which is generally
useful, and will ease future creation of tests by avoiding the need to add new
arguments to the configure function for each configuration needed.

Signed-off-by: Christopher Larson <chris.larson@siemens.com>
---
 testsuite/cibuilder.py | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/testsuite/cibuilder.py b/testsuite/cibuilder.py
index e726ba87..f47d6a77 100755
--- a/testsuite/cibuilder.py
+++ b/testsuite/cibuilder.py
@@ -114,6 +114,7 @@ def configure(
         installer_distro=None,
         installer_device=None,
         customizations=None,
+        lines=None,
         **kwargs,
     ):
         # write configuration file and set bitbake_args
@@ -142,6 +143,7 @@ def configure(
         distro_apt_premir = os.getenv('DISTRO_APT_PREMIRRORS')
         fail_on_cleanup = os.getenv('ISAR_FAIL_ON_CLEANUP')
 
+        strlines = None if lines is None else '\\n'.join(lines)
         self.log.info(
             f"===================================================\n"
             f"Configuring build_dir {self.build_dir}\n"
@@ -162,6 +164,7 @@ def configure(
             f"  image_install = {image_install}\n"
             f"  installer_image = {installer_image}\n"
             f"  customizations = {customizations}\n"
+            f"  lines = {strlines}\n"
             f"==================================================="
         )
 
@@ -248,6 +251,8 @@ def configure(
                 f.write('CUSTOMIZATION_VARS:append = " ${IMAGE}"\n')
                 f.write('CUSTOMIZATION_FOR_IMAGES:append = " isar-image-ci"\n')
                 f.write('HOSTNAME:isar-image-ci = "isar-ci"\n')
+            if lines is not None:
+                f.writelines((line + '\n' if not line.endswith('\n') else line) for line in lines)
 
         # include ci_build.conf in local.conf
         with open(self.build_dir + '/conf/local.conf', 'r+') as f:
-- 
2.47.2

-- 
You received this message because you are subscribed to the Google Groups "isar-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to isar-users+unsubscribe@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/isar-users/20250411200852.51967-4-chris.larson%40siemens.com.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 4/4] testsuite: add a test for per_kernel support
  2025-04-11 20:08 [PATCHv2 0/4] Add support for per-kernel recipe variants chris.larson via isar-users
                   ` (2 preceding siblings ...)
  2025-04-11 20:08 ` [PATCH 3/4] testsuite: add 'extra_lines' argument to configure chris.larson via isar-users
@ 2025-04-11 20:08 ` chris.larson via isar-users
  2025-04-11 20:10 ` [PATCHv2 0/4] Add support for per-kernel recipe variants 'Larson, Chris' via isar-users
  4 siblings, 0 replies; 6+ messages in thread
From: chris.larson via isar-users @ 2025-04-11 20:08 UTC (permalink / raw)
  To: isar-users; +Cc: Cedric Hombourger, Christopher Larson

From: Christopher Larson <chris.larson@siemens.com>

This is a build test for the per-kernel support. It will build a kernel module for
multiple kernels, and install all of the kernel modules in the test image.

Signed-off-by: Christopher Larson <chris.larson@siemens.com>
---
 testsuite/citest.py | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/testsuite/citest.py b/testsuite/citest.py
index a5661eac..4b32b849 100755
--- a/testsuite/citest.py
+++ b/testsuite/citest.py
@@ -205,6 +205,28 @@ def test_cross_rpi(self):
         self.perform_build_test(targets)
 
 
+class KernelTests(CIBaseTest):
+    """
+    Tests associated with kernel builds and development.
+    :avocado: tags=kernel,full
+    """
+
+    def test_per_kernel(self):
+        """Test per-kernel recipe variants for external kernel modules."""
+
+        targets = ['mc:qemuarm64-bookworm:isar-image-ci']
+        kernel_names = self.params.get('kernel_names', default='mainline')
+        kernel_names = [k.strip() for k in kernel_names.split(',') if k.strip()]
+        modules = [f"example-module-{k}" for k in kernel_names]
+        modules.append('example-module-${KERNEL_NAME}')
+        kernel_names = ' '.join(sorted(kernel_names))
+        lines = [
+            f"KERNEL_NAMES:append = ' {kernel_names}'",
+        ]
+        self.init()
+        self.perform_build_test(targets, image_install=' '.join(modules), lines=lines)
+
+
 class WicTest(CIBaseTest):
 
     """
-- 
2.47.2

-- 
You received this message because you are subscribed to the Google Groups "isar-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to isar-users+unsubscribe@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/isar-users/20250411200852.51967-5-chris.larson%40siemens.com.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCHv2 0/4] Add support for per-kernel recipe variants
  2025-04-11 20:08 [PATCHv2 0/4] Add support for per-kernel recipe variants chris.larson via isar-users
                   ` (3 preceding siblings ...)
  2025-04-11 20:08 ` [PATCH 4/4] testsuite: add a test for per_kernel support chris.larson via isar-users
@ 2025-04-11 20:10 ` 'Larson, Chris' via isar-users
  4 siblings, 0 replies; 6+ messages in thread
From: 'Larson, Chris' via isar-users @ 2025-04-11 20:10 UTC (permalink / raw)
  To: isar-users; +Cc: cedric.hombourger


________________________________________
From: Larson, Chris (FT FDS CES LX MEL) <chris.larson@siemens.com>
Sent: Friday, April 11, 2025 1:08 PM
To: isar-users@googlegroups.com
Cc: Hombourger, Cedric (FT FDS CES LX); Larson, Chris (FT FDS CES LX MEL)
Subject: [PATCHv2 0/4] Add support for per-kernel recipe variants

Apologies, missed the subject line change to v2 on the individual patches.

--
Christopher Larson
Siemens AG
www.siemens.com

-- 
You received this message because you are subscribed to the Google Groups "isar-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to isar-users+unsubscribe@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/isar-users/BN0PR07MB8375B017E80B4A5BC6478D9A9FB62%40BN0PR07MB8375.namprd07.prod.outlook.com.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-04-11 20:10 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-04-11 20:08 [PATCHv2 0/4] Add support for per-kernel recipe variants chris.larson via isar-users
2025-04-11 20:08 ` [PATCH 1/4] per-kernel.bbclass: add class chris.larson via isar-users
2025-04-11 20:08 ` [PATCH 2/4] linux-module: inherit per-kernel chris.larson via isar-users
2025-04-11 20:08 ` [PATCH 3/4] testsuite: add 'extra_lines' argument to configure chris.larson via isar-users
2025-04-11 20:08 ` [PATCH 4/4] testsuite: add a test for per_kernel support chris.larson via isar-users
2025-04-11 20:10 ` [PATCHv2 0/4] Add support for per-kernel recipe variants 'Larson, Chris' via isar-users

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox