I am looking into cross compiling a kernel module for an ARM linux.
The kernel version on my host is 3.13.0-24generic while on the target it's 3.10.17-r0

Now what kernel sources or headers do I actually need to download and install, and where? I downloaded linux-3.10.17tar.bz2 from kernel.org and extracted it. In drivers there's a Makefile and according to this site I need to append these lines to it, then run make:

ARCH=arm
CROSS_COMPILE=arm-poky-linux-gnueabi-gcc
KDIR := /lib/modules/'uname -r'/build

obj-m +=test5.o
all : 
    make -C ${KDIR}/build M=$(PWD) modules 

clean   : 
    make -C ${KDIR}/build M=$(PWD) clean 

But what do i have to replace uname -r with? Cause this would give me my host's kernel version. But my target version is different. Where is the /lib/modules/3.6.9 folder? CROSS_COMPILE and ARCH is both set.

  • Link to site from which you got the above instructions, please? – schaiba Jan 25 '17 at 15:44

In order to cross-compile the Linux kernel module, the Makefile should be aware of the Linux kernel on the target machine, which in your case is 'KDIR'. Configure KDIR to the address where the Linux kernel of the target machine is stored.

The second thing the Makefile needs to be aware of is the CROSS_COMPILER and ARCH. You don't need to configure these in the Makefile. Just pass them as arguments when running make:

make CROSS_COMPILE=arm-poky-linux-gnueabi-  ARCH=arm

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.