I am currently writing a linux kernel module that needs to include a file from the linux driver source code. The particular file I am trying to include is: https://elixir.bootlin.com/linux/latest/source/drivers/nvme/host/nvme.h
But the /lib/modules/$(shell uname -r)/build
directory does not contain the drivers
folder. I tried doing sudo apt-get install linux-headers-$(shell uname -r)
but that also does not include the driver header files. My Makefile looks like this:
obj-m += hello_world.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
I then tried to get a full kernel checkout of the kernel version closest to my kernel version (I couldn't find the exact source code for my kernel version.) I pointed my Makefile to use that version but then when I try to insert the kernel module, it throws Invalid module format
error and dmesg
shows no symbol version for module layout
. My source directory does contain the Module.symvers
file but it still throws this error. I believe this error could be resolved if I somehow use my current linux source.
So, what's the best way to get the driver header files and use them in a kernel module. Any help would be appreciated.