ilbers / isar

Integration System for Automated Root filesystem generation
Other
188 stars 73 forks source link

Installing the linux-kbuild package for cross-builds in the SDK's rootfs #109

Open masami256 opened 2 days ago

masami256 commented 2 days ago

In revision "b7e3c78766c3b95198b7fbe5307e0fdad672b0cd" of isar, I was able to install the linux-kbuild-${KERNEL_NAME}-native package in the SDK's rootfs by adding the following configuration to local.conf.

ISAR_CROSS_COMPILE ?= "1"
PREFERRED_VERSION_linux-mainline ?= "6.6.%"
DISTRO_KERNELS:append = " linux-mainline"
KERNEL_NAME="mainline"
SDK_INSTALL:append = " linux-kbuild-${KERNEL_NAME}-native linux-headers-${KERNEL_NAME}"

The SDK build was done with the following command line.

bitbake mc:qemuarm64-bookworm:isar-image-base -c do_populate_sdk

When I check the fixdep command, it is an x86-64 binary.

$ sudo tar xf ./tmp/deploy/images/qemuarm64/isar-image-base-sdk-debian-bookworm-qemuarm64.tar.xz -C sdktest
$ file sdktest/isar-image-base-sdk-debian-bookworm-qemuarm64/usr/lib/linux-kbuild-6.6.11-isar/scripts/basic/fixdep
sdktest/isar-image-base-sdk-debian-bookworm-qemuarm64/usr/lib/linux-kbuild-6.6.11-isar/scripts/basic/fixdep: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=e9c478fa01a04f2d4e7ac96f081ea8a800278e94, for GNU/Linux 3.2.0, stripped

However, in revision 735dc16c1e3d2a66f27504d0ceec8e28a38ab96f, the following error occurred.

| Building dependency tree...
| Package linux-kbuild-mainline is not available, but is referred to by another package.
| This may mean that the package is missing, has been obsoleted, or
| is only available from another source
| 
| E: Package 'linux-kbuild-mainline' has no installation candidate
| WARNING: exit code 100 from a shell command.
| DEBUG: Executing shell function rootfs_do_umounts
| DEBUG: Shell function rootfs_do_umounts finished
| DEBUG: Python function do_rootfs_install finished
ERROR: Task (mc:qemuarm64-bookworm:virtual:sdk:/home/build/work/isar/isar/meta-isar/recipes-core/images/isar-image-base.bb:do_rootfs_install) failed with exit code '1'
NOTE: Tasks Summary: Attempted 78 tasks of which 0 didn't need to be rerun and 1 failed.

I added linux-kbuild-${KERNEL_NAME}-${DISTRO_ARCH}-cross to SDK_INSTALL instead of linux-kbuild-${KERNEL_NAME}-native, but the following error occurred.

ERROR: Nothing PROVIDES 'linux-kbuild-mainline-arm64-cross' (but mc:qemuarm64-bookworm:virtual:sdk:/home/build/work/isar/isar/meta-isar/recipes-core/images/isar-image-base.bb DEPENDS on or otherwise requires it). Close matches:
  linux-kbuild-mainline
  linux-kbuild-mainline-native
  linux-libc-dev-arm64-cross
ERROR: Required build target 'isar-image-base' has no buildable providers.
Missing or unbuildable dependency chain was: ['isar-image-base', 'isar-image-base-sdk', 'linux-kbuild-mainline-arm64-cross']

Summary: There were 2 ERROR messages, returning a non-zero exit code.

In the case of linux-kbuild-${KERNEL_NAME}, I was able to include it in the SDK's rootfs, but the binary is for the target.

build@b08825922409:~/work/isar/build$ file sdktest/isar-image-base-sdk-debian-bookworm-qemuarm64/usr/lib/linux-kbuild-6.6.11-isar/scripts/basic/fixdep
sdktest/isar-image-base-sdk-debian-bookworm-qemuarm64/usr/lib/linux-kbuild-6.6.11-isar/scripts/basic/fixdep: ELF 64-bit LSB pie executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, BuildID[sha1]=50c639f1ed9acdcba3e5f4ed32dc293502eec42c, for GNU/Linux 3.7.0, stripped

How can I install the linux-kbuild package for cross-builds in the SDK's rootfs, as in revision b7e3c78766?

jan-kiszka commented 2 days ago

linux-kbuild-${KERNEL_NAME} alone won't give you enough useful packages for building kernel modules. You want linux-headers-${KERNEL_NAME}. This is also what we install in meta-iot2050, both on the target now (https://github.com/siemens/meta-iot2050/blob/088f2a9adec5f0da68c20846e81cf26fd4059949/recipes-core/images/iot2050-image-example.bb#L45) as well as in the SDK (https://github.com/siemens/meta-iot2050/blob/088f2a9adec5f0da68c20846e81cf26fd4059949/conf/distro/iot2050-debian.conf#L27).

masami256 commented 1 day ago

@jan-kiszka Thank you for the answer.

linux-kbuild-${KERNEL_NAME} alone won't give you enough useful packages for building kernel modules.

Yes. I added linux-kbuild-${KERNEL_NAME} as well.

I wrote simple kernel module and built it in the SDK's chroot environment. Then I got following error.

root@testpc:/test-module# make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- V=1
make -C /usr/src/linux-headers-6.6.11-isar/ M=/test-module KBUILD_VERBOSE=0 modules
make[1]: Entering directory '/usr/src/linux-headers-6.6.11-isar'
warning: the compiler differs from the one used to build the kernel
  The kernel was built by: aarch64-linux-gnu-gcc (Debian 12.2.0-14) 12.2.0
  You are using:           aarch64-linux-gnu-gcc-12.bin (Debian 12.2.0-14) 12.2.0
  CC [M]  /test-module/hello.o
/bin/sh: 1: scripts/basic/fixdep: Exec format error
make[3]: *** [scripts/Makefile.build:243: /test-module/hello.o] Error 126
make[3]: *** Deleting file '/test-module/hello.o'
make[2]: *** [/usr/src/linux-headers-6.6.11-isar/Makefile:1913: /test-module] Error 2
make[1]: *** [Makefile:234: __sub-make] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-6.6.11-isar'
make: *** [Makefile:9: all] Error 2

The fixdep command is aarch64 binary so it won't execute on x86-64 host if binfmt_misc is not enabled on the host.

root@testpc:/test-module# file /usr/src/linux-headers-6.6.11-isar/scripts/basic/fixdep
/usr/src/linux-headers-6.6.11-isar/scripts/basic/fixdep: ELF 64-bit LSB pie executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, BuildID[sha1]=50c639f1ed9acdcba3e5f4ed32dc293502eec42c, for GNU/Linux 3.7.0, stripped

So, I wanted to install native linux-kbuild package in SDK. Am I missing something?

jan-kiszka commented 1 day ago

As I wrote, only use SDK_INSTALL:append = " linux-headers-${KERNEL_NAME}", isar takes care of the right kbuild dependency.

Then, do not touch DISTRO_KERNELS, linux-mainline is and remains a custom kernel. I suspect now, changing that variable causes your problems. I cannot reproduce them when adding linux-headers only.

masami256 commented 1 day ago

@jan-kiszka Understood. I’ll look into it. Thank you.