1

I have an ARM-based board, which I used with factory kernel (5.10.110).

To manually build a kernel module, I needed the kernel-header package. To install this package it was explained in the documentation:

sudo dpkg -i /opt/linux-headers-*.deb

This created the below structure:

/lib/modules/5.10.110$ ls -la
total 1584
drwxr-xr-x 1 root root   4096 Apr 29 15:13 .
drwxr-xr-x 1 root root   4096 Jul 10 21:36 ..
lrwxrwxrwx 1 root root     31 Feb 20 07:05 build -> /usr/src/linux-headers-5.10.110
drwxr-xr-x 2 root root   4096 Feb 20 13:29 extra
drwxr-xr-x 1 root root   4096 Feb 20 13:29 kernel
-rw-r--r-- 1 root root 327270 Apr 29 15:13 modules.alias
-rw-r--r-- 1 root root 346627 Apr 29 15:13 modules.alias.bin
-rw-r--r-- 1 root root  28645 Feb 20 13:29 modules.builtin
-rw-r--r-- 1 root root      0 Apr 29 15:13 modules.builtin.alias.bin
-rw-r--r-- 1 root root  30656 Apr 29 15:13 modules.builtin.bin
-rw-r--r-- 1 root root 164216 Feb 20 13:29 modules.builtin.modinfo
-rw-r--r-- 1 root root  95077 Apr 29 15:13 modules.dep
-rw-r--r-- 1 root root 153551 Apr 29 15:13 modules.dep.bin
-rw-r--r-- 1 root root    140 Apr 29 15:13 modules.devname
-rw-r--r-- 1 root root  51432 Feb 20 13:29 modules.order
-rw-r--r-- 1 root root    468 Apr 29 15:13 modules.softdep
-rw-r--r-- 1 root root 163120 Apr 29 15:13 modules.symbols
-rw-r--r-- 1 root root 206275 Apr 29 15:13 modules.symbols.bin

Now I had to recompile the whole kernel and version is increased from 5.10.110 to 5.10.160.

So now, when I try to compile a kernel module it is not finding the required headers.

Build folder contains these files in 5.10.110:

/lib/modules/5.10.110/build$ ls -la
total 1364
drwxr-xr-x  5 root root    4096 Apr 29 15:03 .
drwxr-xr-x  1 root root    4096 Jul 10 22:35 ..
-rw-r--r--  1 root root  220133 Feb 20 07:05 .config
-rw-r--r--  1 root root   68886 Dec  1  2022 Makefile
-rw-r--r--  1 root root 1075160 Feb 20 07:02 Module.symvers
drwxr-xr-x  3 root root    4096 Apr 29 15:03 arch
drwxr-xr-x 31 root root    4096 Apr 29 15:03 include
drwxr-xr-x 17 root root   12288 Apr 29 15:03 scripts

How can I recreate these headers for building custom kernel modules against my new kernel of version 5.10.160?

I made various trials: copying these folders from my computer where I cross-compiled the kernel: not working, as "scripts" folder contains machine code (x86_64) which is not executing on aarch64.

Then I copied "scripts" folder from 5.10.110, but I'm unsure if it's okay, or will cause harm or unwanted results.

So how could I cross-compile the environment for building custom kernel modules?

2
  • 2
    "I needed the kernel-header package-- You have an ARM-based board, but you are probably using an Intel-based PC host to perform this module building with a cross-compiler/toolchain. Your dpkg command fetched and installed the headers of the Linux distro installed for your PC host. But you need the headers for the kernel used by your ARM-based board. You seem to be making a mess by co-mingling code.
    – sawdust
    Jul 11, 2023 at 6:02
  • Yes, so that the question is about how can I create the kernel headers for ARM on X86?
    – Daniel
    Jul 11, 2023 at 9:21

1 Answer 1

2

I have an ARM-based board, which I used with factory kernel (5.10.110).

To manually build a kernel module, I needed the kernel-header package.

You have an ARM-based board, but you are probably using an Intel-based PC host to perform this module building with a cross-compiler/toolchain. Your dpkg command fetched and installed the headers of the Linux distro installed for your PC host. But you need the headers for the kernel version used by your ARM-based board.


First you need to download the tarball of the specific kernel version, i.e. 5.10.110. You neglect to mention if this is a mainline version of the Linux kernel, or a version with modifications by a chip or board manufacturer.

Source code for the mainline versions of the Linux kernel are available from the Linux Kernel Archives. The tarball of mainline version 5.10.110 is here (in gzip compression).

Regardless, obtain/download the appropriate source code.
Unarchive and install this source tree completely separate from your PC's distro installation. Suggest you use a development directory under /home for your cross compilation tasks.


Once you have the required version of the kernel source in a subdirectory, you will be able to export that kernel's header files using the make headers_install command from the shell.
Refer to this guide:

Exporting kernel headers for use by userspace
=============================================

The "make headers_install" command exports the kernel's header files in a
form suitable for use by userspace programs.
...

The "make headers_install" command can be run in the top level directory of the
kernel source code (or using a standard out-of-tree build).  It takes two
optional arguments:

  make headers_install ARCH=i386 INSTALL_HDR_PATH=/usr 

Again, I suggest that you install these headers that are unrelated to your host system and used for cross-compiling somewhere more local, such as a development directory under /home (i.e. do not blindly use the above example).

1
  • Are you sure this will compile the binaries in "scripts" folder ?
    – Daniel
    Jul 13, 2023 at 5:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .