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?
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.