linux-module: Support emulated module build with cross-compiled kernel

Message ID 20240430131058.2574127-1-stefan-koch@siemens.com
State Superseded, archived
Headers show
Series linux-module: Support emulated module build with cross-compiled kernel | expand

Commit Message

Koch, Stefan April 30, 2024, 1:10 p.m. UTC
Signed-off-by: Stefan Koch <stefan-koch@siemens.com>
---
 meta/recipes-kernel/linux-module/module.inc | 9 ++++++++-
 meta/recipes-kernel/linux/linux-custom.inc  | 2 +-
 meta/recipes-kernel/linux/linux-distro.bb   | 1 +
 3 files changed, 10 insertions(+), 2 deletions(-)

Comments

Jan Kiszka April 30, 2024, 1:44 p.m. UTC | #1
Why?

Jan

On 30.04.24 15:10, Stefan Koch wrote:
> Signed-off-by: Stefan Koch <stefan-koch@siemens.com>
> ---
>  meta/recipes-kernel/linux-module/module.inc | 9 ++++++++-
>  meta/recipes-kernel/linux/linux-custom.inc  | 2 +-
>  meta/recipes-kernel/linux/linux-distro.bb   | 1 +
>  3 files changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/meta/recipes-kernel/linux-module/module.inc b/meta/recipes-kernel/linux-module/module.inc
> index eddbf177..eaf086eb 100644
> --- a/meta/recipes-kernel/linux-module/module.inc
> +++ b/meta/recipes-kernel/linux-module/module.inc
> @@ -17,7 +17,6 @@ PN .= "-${KERNEL_NAME}"
>  
>  KERNEL_IMAGE_PKG ??= "linux-image-${KERNEL_NAME}"
>  KERNEL_HEADERS_PKG ??= "linux-headers-${KERNEL_NAME}"
> -DEPENDS += "${KERNEL_HEADERS_PKG}"
>  DEBIAN_BUILD_DEPENDS = "${KERNEL_HEADERS_PKG}"
>  
>  SIGNATURE_KEYFILE ??= ""
> @@ -36,8 +35,16 @@ AUTOLOAD ?= ""
>  python() {
>      if d.getVar('KERNEL_NAME') in d.getVar('DISTRO_KERNELS').split():
>          d.setVar('ISAR_CROSS_COMPILE', '0')
> +
> +    if d.getVar("DISTRO_ARCH") != d.getVar("HOST_ARCH") and bb.utils.to_boolean(d.getVar("ISAR_CROSS_COMPILE")):
> +        d.appendVar("OVERRIDES", ":cross-profile")
>  }
>  
> +DEFAULT_KERNEL_KBUILD_PKG = "linux-kbuild-${KERNEL_NAME}"
> +DEFAULT_KERNEL_KBUILD_PKG:cross-profile = "linux-kbuild-${KERNEL_NAME}-native"
> +KERNEL_KBUILD_PKG ??= "${DEFAULT_KERNEL_KBUILD_PKG}"
> +DEPENDS += "${KERNEL_HEADERS_PKG} ${KERNEL_KBUILD_PKG}"
> +
>  inherit dpkg
>  
>  TEMPLATE_FILES = "debian/control.tmpl \
> diff --git a/meta/recipes-kernel/linux/linux-custom.inc b/meta/recipes-kernel/linux/linux-custom.inc
> index 0d222332..16e65d7a 100644
> --- a/meta/recipes-kernel/linux/linux-custom.inc
> +++ b/meta/recipes-kernel/linux/linux-custom.inc
> @@ -97,7 +97,7 @@ KERNEL_NAME_PROVIDED ?= "${@ d.getVar('BPN').partition('linux-')[2]}"
>  
>  # Determine cross-profile override
>  python() {
> -    if d.getVar("DISTRO_ARCH") != d.getVar("HOST_ARCH") and d.getVar("ISAR_CROSS_COMPILE", True) == "1" and "class-native" not in d.getVar("OVERRIDES", True).split(":"):
> +    if d.getVar("DISTRO_ARCH") != d.getVar("HOST_ARCH") and bb.utils.to_boolean(d.getVar("ISAR_CROSS_COMPILE")) and "class-native" not in d.getVar("OVERRIDES", True).split(":"):
>          d.appendVar("OVERRIDES", ":cross-profile")
>  }
>  
> diff --git a/meta/recipes-kernel/linux/linux-distro.bb b/meta/recipes-kernel/linux/linux-distro.bb
> index bc43528c..13b8dc7e 100644
> --- a/meta/recipes-kernel/linux/linux-distro.bb
> +++ b/meta/recipes-kernel/linux/linux-distro.bb
> @@ -10,6 +10,7 @@ python() {
>      for kernel in distro_kernels.split():
>          d.appendVar('PROVIDES', ' linux-image-' + kernel)
>          d.appendVar('PROVIDES', ' linux-headers-' + kernel)
> +        d.appendVar('PROVIDES', ' linux-kbuild-' + kernel)
>      if d.getVar('KERNEL_IMAGE_PKG'):
>          d.appendVar('PROVIDES', ' ' + d.getVar('KERNEL_IMAGE_PKG'))
>      if d.getVar('KERNEL_HEADERS_PKG'):
Koch, Stefan April 30, 2024, 4:52 p.m. UTC | #2
This patch fixes an issue e. g. when building a emulated module built
(using qemu) with a non-emulated cross-built kernel.

On Tue, 2024-04-30 at 15:44 +0200, Jan Kiszka wrote:
> Why?
> 
> Jan
> 
> On 30.04.24 15:10, Stefan Koch wrote:
> > Signed-off-by: Stefan Koch <stefan-koch@siemens.com>
> > ---
> >  meta/recipes-kernel/linux-module/module.inc | 9 ++++++++-
> >  meta/recipes-kernel/linux/linux-custom.inc  | 2 +-
> >  meta/recipes-kernel/linux/linux-distro.bb   | 1 +
> >  3 files changed, 10 insertions(+), 2 deletions(-)
> > 
> > diff --git a/meta/recipes-kernel/linux-module/module.inc
> > b/meta/recipes-kernel/linux-module/module.inc
> > index eddbf177..eaf086eb 100644
> > --- a/meta/recipes-kernel/linux-module/module.inc
> > +++ b/meta/recipes-kernel/linux-module/module.inc
> > @@ -17,7 +17,6 @@ PN .= "-${KERNEL_NAME}"
> >  
> >  KERNEL_IMAGE_PKG ??= "linux-image-${KERNEL_NAME}"
> >  KERNEL_HEADERS_PKG ??= "linux-headers-${KERNEL_NAME}"
> > -DEPENDS += "${KERNEL_HEADERS_PKG}"
> >  DEBIAN_BUILD_DEPENDS = "${KERNEL_HEADERS_PKG}"
> >  
> >  SIGNATURE_KEYFILE ??= ""
> > @@ -36,8 +35,16 @@ AUTOLOAD ?= ""
> >  python() {
> >      if d.getVar('KERNEL_NAME') in
> > d.getVar('DISTRO_KERNELS').split():
> >          d.setVar('ISAR_CROSS_COMPILE', '0')
> > +
> > +    if d.getVar("DISTRO_ARCH") != d.getVar("HOST_ARCH") and
> > bb.utils.to_boolean(d.getVar("ISAR_CROSS_COMPILE")):
> > +        d.appendVar("OVERRIDES", ":cross-profile")
> >  }
> >  
> > +DEFAULT_KERNEL_KBUILD_PKG = "linux-kbuild-${KERNEL_NAME}"
> > +DEFAULT_KERNEL_KBUILD_PKG:cross-profile = "linux-kbuild-
> > ${KERNEL_NAME}-native"
> > +KERNEL_KBUILD_PKG ??= "${DEFAULT_KERNEL_KBUILD_PKG}"
> > +DEPENDS += "${KERNEL_HEADERS_PKG} ${KERNEL_KBUILD_PKG}"
> > +
> >  inherit dpkg
> >  
> >  TEMPLATE_FILES = "debian/control.tmpl \
> > diff --git a/meta/recipes-kernel/linux/linux-custom.inc
> > b/meta/recipes-kernel/linux/linux-custom.inc
> > index 0d222332..16e65d7a 100644
> > --- a/meta/recipes-kernel/linux/linux-custom.inc
> > +++ b/meta/recipes-kernel/linux/linux-custom.inc
> > @@ -97,7 +97,7 @@ KERNEL_NAME_PROVIDED ?= "${@
> > d.getVar('BPN').partition('linux-')[2]}"
> >  
> >  # Determine cross-profile override
> >  python() {
> > -    if d.getVar("DISTRO_ARCH") != d.getVar("HOST_ARCH") and
> > d.getVar("ISAR_CROSS_COMPILE", True) == "1" and "class-native" not
> > in d.getVar("OVERRIDES", True).split(":"):
> > +    if d.getVar("DISTRO_ARCH") != d.getVar("HOST_ARCH") and
> > bb.utils.to_boolean(d.getVar("ISAR_CROSS_COMPILE")) and "class-
> > native" not in d.getVar("OVERRIDES", True).split(":"):
> >          d.appendVar("OVERRIDES", ":cross-profile")
> >  }
> >  
> > diff --git a/meta/recipes-kernel/linux/linux-distro.bb
> > b/meta/recipes-kernel/linux/linux-distro.bb
> > index bc43528c..13b8dc7e 100644
> > --- a/meta/recipes-kernel/linux/linux-distro.bb
> > +++ b/meta/recipes-kernel/linux/linux-distro.bb
> > @@ -10,6 +10,7 @@ python() {
> >      for kernel in distro_kernels.split():
> >          d.appendVar('PROVIDES', ' linux-image-' + kernel)
> >          d.appendVar('PROVIDES', ' linux-headers-' + kernel)
> > +        d.appendVar('PROVIDES', ' linux-kbuild-' + kernel)
> >      if d.getVar('KERNEL_IMAGE_PKG'):
> >          d.appendVar('PROVIDES', ' ' +
> > d.getVar('KERNEL_IMAGE_PKG'))
> >      if d.getVar('KERNEL_HEADERS_PKG'):
>

Patch

diff --git a/meta/recipes-kernel/linux-module/module.inc b/meta/recipes-kernel/linux-module/module.inc
index eddbf177..eaf086eb 100644
--- a/meta/recipes-kernel/linux-module/module.inc
+++ b/meta/recipes-kernel/linux-module/module.inc
@@ -17,7 +17,6 @@  PN .= "-${KERNEL_NAME}"
 
 KERNEL_IMAGE_PKG ??= "linux-image-${KERNEL_NAME}"
 KERNEL_HEADERS_PKG ??= "linux-headers-${KERNEL_NAME}"
-DEPENDS += "${KERNEL_HEADERS_PKG}"
 DEBIAN_BUILD_DEPENDS = "${KERNEL_HEADERS_PKG}"
 
 SIGNATURE_KEYFILE ??= ""
@@ -36,8 +35,16 @@  AUTOLOAD ?= ""
 python() {
     if d.getVar('KERNEL_NAME') in d.getVar('DISTRO_KERNELS').split():
         d.setVar('ISAR_CROSS_COMPILE', '0')
+
+    if d.getVar("DISTRO_ARCH") != d.getVar("HOST_ARCH") and bb.utils.to_boolean(d.getVar("ISAR_CROSS_COMPILE")):
+        d.appendVar("OVERRIDES", ":cross-profile")
 }
 
+DEFAULT_KERNEL_KBUILD_PKG = "linux-kbuild-${KERNEL_NAME}"
+DEFAULT_KERNEL_KBUILD_PKG:cross-profile = "linux-kbuild-${KERNEL_NAME}-native"
+KERNEL_KBUILD_PKG ??= "${DEFAULT_KERNEL_KBUILD_PKG}"
+DEPENDS += "${KERNEL_HEADERS_PKG} ${KERNEL_KBUILD_PKG}"
+
 inherit dpkg
 
 TEMPLATE_FILES = "debian/control.tmpl \
diff --git a/meta/recipes-kernel/linux/linux-custom.inc b/meta/recipes-kernel/linux/linux-custom.inc
index 0d222332..16e65d7a 100644
--- a/meta/recipes-kernel/linux/linux-custom.inc
+++ b/meta/recipes-kernel/linux/linux-custom.inc
@@ -97,7 +97,7 @@  KERNEL_NAME_PROVIDED ?= "${@ d.getVar('BPN').partition('linux-')[2]}"
 
 # Determine cross-profile override
 python() {
-    if d.getVar("DISTRO_ARCH") != d.getVar("HOST_ARCH") and d.getVar("ISAR_CROSS_COMPILE", True) == "1" and "class-native" not in d.getVar("OVERRIDES", True).split(":"):
+    if d.getVar("DISTRO_ARCH") != d.getVar("HOST_ARCH") and bb.utils.to_boolean(d.getVar("ISAR_CROSS_COMPILE")) and "class-native" not in d.getVar("OVERRIDES", True).split(":"):
         d.appendVar("OVERRIDES", ":cross-profile")
 }
 
diff --git a/meta/recipes-kernel/linux/linux-distro.bb b/meta/recipes-kernel/linux/linux-distro.bb
index bc43528c..13b8dc7e 100644
--- a/meta/recipes-kernel/linux/linux-distro.bb
+++ b/meta/recipes-kernel/linux/linux-distro.bb
@@ -10,6 +10,7 @@  python() {
     for kernel in distro_kernels.split():
         d.appendVar('PROVIDES', ' linux-image-' + kernel)
         d.appendVar('PROVIDES', ' linux-headers-' + kernel)
+        d.appendVar('PROVIDES', ' linux-kbuild-' + kernel)
     if d.getVar('KERNEL_IMAGE_PKG'):
         d.appendVar('PROVIDES', ' ' + d.getVar('KERNEL_IMAGE_PKG'))
     if d.getVar('KERNEL_HEADERS_PKG'):