Message ID | 20240502140917.1365786-1-stefan-koch@siemens.com |
---|---|
State | Superseded, archived |
Headers | show |
Series | linux-module: Support emulated module build with cross-compiled kernel | expand |
On 02.05.24 16:09, Stefan Koch wrote: > The dependency to linux-kbuild is modeled using bitbake dependencies as > well as downstream users need to individually select the headers and kbuild > packages - for different architectures in the cross build case. > > So, the linux-kbuild package must be explicitly installed within > host arch to build a cross-module. Bitbake must be able to resolve the > dependencies for distro kernels (emulated build), too. > > Since distro kernels do not support cross-build kernel modules, > for these kernels an emulated module build is automatically selected. > This is still not making it fully clear that this fixes the non-cross build of kernel modules against custom cross-built kernels, and only that. That's a corner case that hopefully no one has to use (the proper solution in such cases is making the module cross-built compatible in first place), but that would be no excuse for leaving this combination broken. > 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}" Why does the logic in multiarch.bbclass fail to help us in this case? Jan > + > 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(":"): This does not change the logic, it only cleans up (to_boolean() instead of == "1"). Please provide separately. > 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) This almost looks like a separate fix, needed for this to work but also valid without. > if d.getVar('KERNEL_IMAGE_PKG'): > d.appendVar('PROVIDES', ' ' + d.getVar('KERNEL_IMAGE_PKG')) > if d.getVar('KERNEL_HEADERS_PKG'): Jan
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'):
The dependency to linux-kbuild is modeled using bitbake dependencies as well as downstream users need to individually select the headers and kbuild packages - for different architectures in the cross build case. So, the linux-kbuild package must be explicitly installed within host arch to build a cross-module. Bitbake must be able to resolve the dependencies for distro kernels (emulated build), too. Since distro kernels do not support cross-build kernel modules, for these kernels an emulated module build is automatically selected. 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(-)