Kernel module compiling

Hi, I recently got my hands on a VisionFive V2 board and am playing around with it.

I currently have Ubuntu booted from an SD card and the uname is as follows:
Linux starfive 5.15.0-starfive #1 SMP Sun Mar 26 12:29:48 EDT 2023 riscv64 GNU/Linux

In this case I am trying to compile a hello_world kernel module to observe the behavior, but I am having several problems. It seems that all the linux 5.15.0 headers are missing:

root@starfive$ gcc -I/usr/src/linux-headers-$(uname -r)/include/ -E hello_world.c -o hello_world.i
In file included from /usr/src/linux-headers-5.15.0-starfive/include/linux/kcsan-checks.h:13,
                 from /usr/src/linux-headers-5.15.0-starfive/include/asm/rwonce.h:27,
                 from /usr/src/linux-headers-5.15.0-starfive/include/linux/compiler.h:266,
                 from /usr/src/linux-headers-5.15.0-starfive/include/linux/kernel.h:11,
                 from /usr/src/linux-headers-5.15.0-starfive/include/linux/list.h:9,
                 from /usr/src/linux-headers-5.15.0-starfive/include/linux/module.h:12,
                 from hello_world.c:12:
/usr/src/linux-headers-5.15.0-starfive/include/linux/compiler_attributes.h:45: warning: "__always_inline" redefined
   45 | #define __always_inline                 inline __attribute__((__always_inline__))
      | 
In file included from /usr/src/linux-headers-5.15.0-starfive/include/linux/stddef.h:5,
                 from /usr/include/linux/posix_types.h:5,
                 from /usr/src/linux-headers-5.15.0-starfive/include/uapi/linux/types.h:14,
                 from /usr/src/linux-headers-5.15.0-starfive/include/linux/types.h:6,
                 from /usr/src/linux-headers-5.15.0-starfive/include/linux/list.h:5:
/usr/src/linux-headers-5.15.0-starfive/include/uapi/linux/stddef.h:5: note: this is the location of the previous definition
    5 | #define __always_inline inline
      | 
In file included from /usr/src/linux-headers-5.15.0-starfive/include/linux/time32.h:13,
                 from /usr/src/linux-headers-5.15.0-starfive/include/linux/time.h:60,
                 from /usr/src/linux-headers-5.15.0-starfive/include/linux/stat.h:19,
                 from /usr/src/linux-headers-5.15.0-starfive/include/linux/module.h:13:
/usr/src/linux-headers-5.15.0-starfive/include/linux/timex.h:59: warning: "ADJ_OFFSET_SINGLESHOT" redefined
   59 | #define ADJ_OFFSET_SINGLESHOT   0x0001  /* old-fashioned adjtime */
      | 
In file included from /usr/src/linux-headers-5.15.0-starfive/include/linux/timex.h:56:
/usr/src/linux-headers-5.15.0-starfive/include/uapi/linux/timex.h:152: note: this is the location of the previous definition
  152 | #define ADJ_OFFSET_SINGLESHOT   0x8001  /* old-fashioned adjtime */
      | 
In file included from /usr/src/linux-headers-5.15.0-starfive/include/asm/preempt.h:5,
                 from /usr/src/linux-headers-5.15.0-starfive/include/linux/preempt.h:78,
                 from /usr/src/linux-headers-5.15.0-starfive/include/linux/spinlock.h:55,
                 from /usr/src/linux-headers-5.15.0-starfive/include/linux/mm_types.h:9,
                 from /usr/src/linux-headers-5.15.0-starfive/include/linux/buildid.h:5,
                 from /usr/src/linux-headers-5.15.0-starfive/include/linux/module.h:14:
/usr/src/linux-headers-5.15.0-starfive/include/linux/thread_info.h:60:10: fatal error: asm/thread_info.h: No such file or directory
   60 | #include <asm/thread_info.h>
      |          ^~~~~~~~~~~~~~~~~~~
compilation terminated.

Is there any way to get all headers or any explained procedure to do it in this version of the kernel or device?

Thank you.

To compile a kernel module I had to compile the kernel from source code and use those files (binaries. headers, etc) to compile the kernel module. The Linux kernel will not load kernel modules that don’t match it’s exact version.

Have a look at this topic to see some examples of compiling kernel modules:

which tag did you use to compile the headers? because with the 5.15.0 still the same problem

My SD card used Image_69 for the kernel/filesystem/etc.
https://debian.starfivetech.com/

The kernel tag is:
git@github.com:starfive-tech/VisionFive2.git
commit 5729916a27ae69d7ae3eb066d168e6295208a308 (HEAD → JH7110_VisionFive2_devel, tag: VF2_v2.8.0, origin/JH7110_VisionFive2_devel, origin/HEAD)
Author: Andy Hu andy.hu@starfivetech.com
Date: Thu Jan 19 00:38:20 2023 +0800