Compiling kernel module results in ERROR
This issue was present when compiling a linux device driver using make on a raspberry pi zero w 2. The below log was printed:
make -C /lib/modules/6.6.31+rpt-rpi-v8/build M=/home/alex/Linux_I2C_LCD_driver2.0 modules make[1]: Entering directory '/usr/src/linux-headers-6.6.31+rpt-rpi-v8'
- ERROR: Kernel configuration is invalid.
- include/generated/autoconf.h or include/config/auto.conf are missing.
- Run 'make oldconfig && make prepare' on kernel src to fix it.
make[2]: *** [/usr/src/linux-headers-6.6.31+rpt-common-rpi/Makefile:817: include/config/auto.conf] Error 1 make[1]: *** [/usr/src/linux-headers-6.6.31+rpt-common-rpi/Makefile:246: __sub-make] Error 2 make[1]: Leaving directory '/usr/src/linux-headers-6.6.31+rpt-rpi-v8' make: *** [Makefile:9: module] Error 2
To correct this re-install the linux-headers using the command:
sudo apt install --reinstall linux-headers-$(uname -r)
Below is a copy of the Makefile used:
obj-m = waveshare_lcd_driver.o
KVERSION = $(shell uname -r)
all: module dt
- echo Builded Device Tree Overlay and kernel module
module:
- make -C /lib/modules/$(KVERSION)/build M=$(PWD) modules
dt: overlay.dts
- dtc -@ -I dts -O dtb -o overlay.dtbo overlay.dts
clean:
- make -C /lib/modules/$(KVERSION)/build M=$(PWD) clean
- rm -rf overlay.dtbo