I have written a kernel module for a study research project that is a driver for seven segment displays connected to a Raspberry Pi (I am pretty new to kernel development). I would like to permanently install the module and load it at boot time when it is compiled, so I added the install target to my Makefile which allows the user to directly compile and install it.
I found out that all kernel modules are located somewhere inside /lib/modules/<kernel version>/kernel, so I thought I just had to copy the compiled module into a subdirectory and list the module in the modules.order and modules.dep files. However, this approach did not work and since I could not find any resources to that topic, I am a little desperate.
This is what my Makefile currently looks like:
# All source files are inside the src directory
obj-m := src/sevenseg.o
all:
make -C /lib/modules/$(shell uname -r)/build EXTRA_CFLAGS=-I$(PWD)/src M=$(PWD) modules
mv src/sevenseg.ko .
install:
make -C /lib/modules/$(shell uname -r)/build EXTRA_CFLAGS=-I$(PWD)/src M=$(PWD) modules
mkdir -p /lib/modules/$(shell uname -r)/kernel/drivers/sevenseg
cp src/sevenseg.ko /lib/modules/$(shell uname -r)/kernel/drivers/sevenseg
echo "kernel/drivers/sevenseg/sevenseg.ko:" >> /lib/modules/$(shell uname -r)/modules.dep
echo "kernel/drivers/sevenseg/sevenseg.ko" >> /lib/modules/$(shell uname -r)/modules.order
insmod src/sevenseg.ko
make clean
clean:
rm -rf src
How do I tell the kernel that it should load the module sevenseg.ko at boot time?