I'm trying to write a driver kernel module for the hardware (e.g. I2C and GPIO) that are exposed through the Device Tree Source. It would be convenient to able to compile and deploy the kernel module directly on target to speed up the process - but I'm having trouble compiling the kernel modules.
The Linux image is bitbaked using yocto "imx-image-full" and the latest version 6.6.52.
I have written a tiny kernel module that is writing a message in the kernel log when started and stopped - just to have simple program to compile. The Makefile is as follows:
obj-m += hellokernel.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
When I run the make command, I get the following error:
make -C /lib/modules/6.6.52-lts-next-ge0f9e2afd4cf/build M=/home/01_helloKernel modules
make[1]: Entering directory '/home/01_helloKernel'
make[1]: *** /lib/modules/6.6.52-lts-next-ge0f9e2afd4cf/build: No such file or directory. Stop.
make[1]: Leaving directory '/home/01_helloKernel'
make: *** [Makefile:4: all] Error 2
It seems that the compiler is missing something in the build folder, and actually it turns out that the build folder is missing entirely. As far as I can figure out, the folder should contain "kernel headers", which is available from the yocto build in the folder:
<build-folder>/tmp/work-shared/imx7ulpevk/kernel-source/
This folder contains 1.4GB data, thus it could be the reason it is not included in the image, but have to be handled separately after the image has been transferred to the SD card. However it is possible to reduce the size by removing components that is not going to be used. I copied the files to the SD card at the location:
/usr/src/linux-headers-$(uname -r)
Which translates into /usr/src/linux-headers-6.6.52-lts-next-ge0f9e2afd4cf and afterwards linked the headers to the build folder:
ln -sf /usr/src/linux-headers-$(uname -r) /lib/modules/$(uname -r)/build
This changed the error and now it is no longer the build folder that is missing, but the auto.conf file.
make -C /lib/modules/6.6.52-lts-next-ge0f9e2afd4cf/build M=/home/01_helloKernel modules
make[1]: Entering directory '/usr/src/linux-headers-6.6.52-lts-next-ge0f9e2afd4cf'
/usr/src/linux-headers-6.6.52-lts-next-ge0f9e2afd4cf/Makefile:741: include/config/auto.conf: No such file or directory
make[1]: *** [Makefile:234: __sub-make] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-6.6.52-lts-next-ge0f9e2afd4cf'
make: *** [Makefile:4: all] Error 2
The error is referring to a folder "config" that doesn't exist:
/usr/src/linux-headers-6.6.52-lts-next-ge0f9e2afd4cf/include/config/
How do I add that folder and its content?
It seems that I am chasing the rabbit further and further down the hole - or am I doing something wrong? Is there an easier solution to compile Linux kernel modules directly on target?