Building a LKM

Hello all,

I’m trying to write a LKM for my module. Till thus this far I think I managed to build .ko file with the following makefile:

export ARCH:=arm
export CROSS_COMPILE:=~/gcc-linaro-5.2-2015.11-2-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-

obj-m+=hello.o

all:
	make -C ~/linux-toradex/ M=$(PWD) modules
clean:
	make -C ~/linux-toradex/ M=$(PWD) clean

The LKM is very simple, it just announces that it is loaded and not more (yet). However when I try to load the module I get the error that is an invalid format. I guess this is because the kernel is 4.1.35 and the module is compiled against version 4.1.41.

Because there is a difference, the kernel will not accept the module. I tried several way to compile the module to the correct version or updating the kernel to the same version. However none worked so far. I guess this is just a missing rule somewhere on my side, only I cant find the solution to this.

I’m able to bitbake a new image with openembedded and to make an .dtb with the linux-toradex kernel. I think there are two solutions, only I don’t know how to do this:

  • Link the local linux-toradex kernel to the open embedded bitbake process. Thus the kernel source is the same to which I compile my LKM against.
  • To make sure that the correct version are “downloaded”.

Can someone point me in the right direction to solve this problem of mine.

Build a kernel using instructions available:

then build your module against that kernel and deploy both to the board.

Dear Remcovh ,

Along with valuable inputs from dominik , you can try below mentioned approach if it can help you.

I faced similar problem when tried to compile the driver module externally.
As an simple workaround i added the module in linud/driver folder and tried to compile as part of bsp.

Below are steps which might help :-

  1. Create an folder say “helloworld” in drivers folder

    cd drivers

    mkdir helloword

  2. Add below mentioned line in Kconfig just before end

    source “drivers/helloworld/Kconfig”

  3. Add below mentioned line in Makefile at the end of file

    #drivers added by ashish

    obj-$(CONFIG_HELLOWORLD) += helloworld/

  4. Traverse to the newly created folder

    cd helloworld

  5. Create an Makefile here

    obj-$(CONFIG_HELLOWORLD) += helloworld.o

    helloworld-objs := hello_base.o

  6. Create an Kconfig here

    config HELLOWORLD

     tristate "HELLO-WORLD-MENUCONFIG-LABEL"
    
     help
    
    		 This is help statement
    
  7. Create an hello_base.c

    This will have your driver code

  8. You can make this functionality as part of kernel or separately as an module by using make menuconfig option

Hope this helps

Thank You,

Ashish Kumar Mishra