AnsweredAssumed Answered

how to cross-compile a external module based on imx yocto files?

Question asked by Shawn Li on Jul 20, 2017
Latest reply on Jul 26, 2017 by Shawn Li

I want to cross-compile a loadable simple hello world module on imx6ulevk target, by using make command directly. Could anyone tell me how to set the $(KERNEL_SRC) properly? I searched a lot articles on internet  and also read module.txt in kernel document, but didn't get a solution...


I have two files hello_module.c, and single line Makefile, as shown below


#include <linux/init.h>
#include <linux/module.h>
static int hello_init(void){
        printk(KERN_ALERT "Hello, world\n");
        return 0;

static void hello_exit(void){
        printk(KERN_ALERT "Goodbye, cruel world\n");



#=====test above code in ubuntu_14.04: PASS ===
>sudo apt-get install build-essential linux-headers-$(uname -r)
>echo 'obj-m += hello_module.o' > Makefile   #<=== single line Makefile
>make -C /lib/modules/$(uname -r)/build M=`pwd` #specify make parameter on the fly
>sudo insmod hello_module.ko
>rmmod hello_module
>dmesg | tail -3


#=====prepare cross-compile environment parameters=====

>source  ~/IMX/toolchain/opt/fsl-imx-x11/4.1.15-2.1.0/environment-setup-cortexa7hf-neon-poky-linux-gnueabi

>echo $CC
arm-poky-linux-gnueabi-gcc -march=armv7ve -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a7 --sysroot=/home/dev/IMX/toolchain/opt/fsl-imx-x11/4.1.15-2.1.0/sysroots/cortexa7hf-neon-poky-linux-gnueabi

now how to prepare KERNEL_SRC below to let cross-compile success?

make  M=`pwd` -C <KERNEL_SRC>


Many thanks




here are are all linux/module.h that can be found in fsl-release-bsp

dev@dev-vm:~/IMX/fsl-release-bsp$ find -name module.h | grep /include/linux/module.h





### below are operations I did to build corss-compile toolchain ###
>cd /home/dev/IMX/fsl-release-bsp
>DISTRO=fsl-imx-x11 MACHINE=imx6ulevk source -b build_imx6ulevk
>bitbake fsl-image-gui   #<==build image
>bitbake meta-toolchain   #<==build sdk
>cd /home/dev/IMX/fsl-release-bsp/build_imx6ulevk/tmp/deploy/sdk/
>./ -d /home/dev/IMX/toolchain/opt/fsl-imx-x11/4.1.15-2.1.0  #<===install sdk
>source /home/dev/IMX/toolchain/opt/fsl-imx-x11/4.1.15-2.1.0/environment-setup-cortexa7hf-neon-poky-linux-gnueabi