Compiling linux driver kernel module on target (iMX7ULP)

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Compiling linux driver kernel module on target (iMX7ULP)

Jump to solution
283 Views
HenrikZ
Contributor III

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?

Labels (3)
0 Kudos
Reply
1 Solution
260 Views
Chavira
NXP TechSupport
NXP TechSupport

Hi @HenrikZ!

 

By default our pre-compiled image doesn't have the proper packages to compile in the target.

 

I recommend to use the Yocto SDK instead to cross compile your drivers in a Linux Host Machine.

 

You can compile and Set up the Yocto SDK by following this guide.

 

Best Regards!

Chavira

View solution in original post

0 Kudos
Reply
2 Replies
261 Views
Chavira
NXP TechSupport
NXP TechSupport

Hi @HenrikZ!

 

By default our pre-compiled image doesn't have the proper packages to compile in the target.

 

I recommend to use the Yocto SDK instead to cross compile your drivers in a Linux Host Machine.

 

You can compile and Set up the Yocto SDK by following this guide.

 

Best Regards!

Chavira

0 Kudos
Reply
243 Views
HenrikZ
Contributor III

Hi @Chavira 

Thanks for you reply.

I had hoped to be able to compile on the target because it would provide a much faster process for programming the drivers, since I would be able to make the changes on the target, apply the kernel module; see the result; make new changes and try again.

If I use the host machine, it is a lot more cumbersome, since I will have to cross compile the drivers on the host machine; copy the drivers to an SD-card for the target board; boot the processor and apply the kernel module and finally see the result. I only have the serial connection to the MCU, which means no possibility of transferring the files through a network.

Is there a way to include to include the necessary packages in the pre-compiled image?

I saw an example for a Raspberry Pi, where the drivers were programmed, compiled and applied all from a terminal in a very smooth process.

 

BTW, it is a very nice page you have written for the knowledge forum (How to compile linux kernel image...)

0 Kudos
Reply