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
//========hello_module.c====
#include <linux/init.h>
#include <linux/module.h>
MODULE_LICENSE("Dual BSD/GPL");
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");
}
module_init(hello_init);
module_exit(hello_exit);
#=====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
-Shawn
P.S.
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
./build_imx6ulevk/tmp/work-shared/imx6ulevk/kernel-source/include/linux/module.h
./build_imx6ulevk/tmp/work/cortexa7hf-neon-poky-linux-gnueabi/linux-libc-headers/4.1-r0/linux-4.1/include/linux/module.h
./build_imx6ulevk/tmp/work/x86_64-nativesdk-pokysdk-linux/nativesdk-linux-libc-headers/4.4-r0/linux-4.4/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 fsl-setup-release.sh -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/
>./fsl-imx-x11-glibc-x86_64-meta-toolchain-cortexa7hf-neon-toolchain-4.1.15-2.1.0.sh -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
Solved! Go to Solution.
thanks for pointing on the direction. The correct command to make a out-of-tree module is this:
commands to make a out-of tree module |
---|
#source sdk to setup cross-compile environment. (sdk is generated from "bitbake meta-toolchain") source /home/dev/IMX/toolchain/opt/fsl-imx-x11/4.1.15-2.1.0/environment-setup-cortexa7hf-neon-poky-linux-gnueabi # make module |
P.S. how did I find the path for -C $(KERNEL_SRC)
dev@dev-vm:~/IMX/fsl-release-bsp/build_imx6ulevk$ find -name Module.symvers
./tmp/work-shared/imx6ulevk/kernel-build-artifacts/Module.symvers
./tmp/work/imx6ulevk-poky-linux-gnueabi/linux-imx/4.1.15-r0/build/Module.symvers
./tmp/work/imx6ulevk-poky-linux-gnueabi/lttng-modules/2.7.1+gitAUTOINC+45e0ebd91f-r0/git/Module.symvers
./tmp/work/imx6ulevk-poky-linux-gnueabi/cryptodev-module/1.8-r0/cryptodev-linux-1.8/Module.symvers
dev@dev-vm:~/IMX/fsl-release-bsp/build_imx6ulevk$ find -name .config
./tmp/sysroots/imx6ulevk/usr/lib/busybox/ptest/.config
./tmp/work-shared/imx6ulevk/kernel-build-artifacts/.config
./tmp/work/cortexa7hf-neon-poky-linux-gnueabi/wpa-supplicant/2.5-r0/wpa_supplicant-2.5/wpa_supplicant/.config
./tmp/work/cortexa7hf-neon-poky-linux-gnueabi/linux-libc-headers/4.1-r0/linux-4.1/.config
./tmp/work/cortexa7hf-neon-poky-linux-gnueabi/busybox/1.24.1-r0/image/usr/lib/busybox/ptest/.config
./tmp/work/cortexa7hf-neon-poky-linux-gnueabi/busybox/1.24.1-r0/packages-split/busybox-ptest/usr/lib/busybox/ptest/.config
./tmp/work/cortexa7hf-neon-poky-linux-gnueabi/busybox/1.24.1-r0/package/usr/lib/busybox/ptest/.config
./tmp/work/cortexa7hf-neon-poky-linux-gnueabi/busybox/1.24.1-r0/busybox-1.24.1/.config
./tmp/work/cortexa7hf-neon-poky-linux-gnueabi/busybox/1.24.1-r0/sysroot-destdir/usr/lib/busybox/ptest/.config
./tmp/work/imx6ulevk-poky-linux-gnueabi/linux-imx/4.1.15-r0/build/.config
./tmp/work/imx6ulevk-poky-linux-gnueabi/u-boot-imx/2016.03-r0/git/mx6ul_14x14_evk_config/.config
./tmp/work/x86_64-linux/perl-native/5.22.1-r0/perl-5.22.1/.config
I think above is a generic way of making out-of-tree module, without changing yocto source code. This also can workaround the concern that Yocto doesn't see a modified file, if implementations can be done with out-of-tree module.
Best Regards
-Shawn
Hello Shawn Li,
There is some information on how to incorporate modules on the Yocto Kernel Development Manual that may be of help. Check section 2.5.2 for what I think covers what you want to do. (This document changes slightly between Yocto versions, this is for 2.1, but the basics have not changed much in a while)
http://www.yoctoproject.org/docs/2.1/kernel-dev/kernel-dev.html
Just as an aside, I would recommend working outside of Yocto for the development of any modules and integrating it to Yocto once it’s ready for distribution. This because Yocto is not designed for development so much as for distribution and for example Yocto does not check if a file has been changed so it can be hard to track how your changes in the code get reflected on the final build.
Regards,
thanks for pointing on the direction. The correct command to make a out-of-tree module is this:
commands to make a out-of tree module |
---|
#source sdk to setup cross-compile environment. (sdk is generated from "bitbake meta-toolchain") source /home/dev/IMX/toolchain/opt/fsl-imx-x11/4.1.15-2.1.0/environment-setup-cortexa7hf-neon-poky-linux-gnueabi # make module |
P.S. how did I find the path for -C $(KERNEL_SRC)
dev@dev-vm:~/IMX/fsl-release-bsp/build_imx6ulevk$ find -name Module.symvers
./tmp/work-shared/imx6ulevk/kernel-build-artifacts/Module.symvers
./tmp/work/imx6ulevk-poky-linux-gnueabi/linux-imx/4.1.15-r0/build/Module.symvers
./tmp/work/imx6ulevk-poky-linux-gnueabi/lttng-modules/2.7.1+gitAUTOINC+45e0ebd91f-r0/git/Module.symvers
./tmp/work/imx6ulevk-poky-linux-gnueabi/cryptodev-module/1.8-r0/cryptodev-linux-1.8/Module.symvers
dev@dev-vm:~/IMX/fsl-release-bsp/build_imx6ulevk$ find -name .config
./tmp/sysroots/imx6ulevk/usr/lib/busybox/ptest/.config
./tmp/work-shared/imx6ulevk/kernel-build-artifacts/.config
./tmp/work/cortexa7hf-neon-poky-linux-gnueabi/wpa-supplicant/2.5-r0/wpa_supplicant-2.5/wpa_supplicant/.config
./tmp/work/cortexa7hf-neon-poky-linux-gnueabi/linux-libc-headers/4.1-r0/linux-4.1/.config
./tmp/work/cortexa7hf-neon-poky-linux-gnueabi/busybox/1.24.1-r0/image/usr/lib/busybox/ptest/.config
./tmp/work/cortexa7hf-neon-poky-linux-gnueabi/busybox/1.24.1-r0/packages-split/busybox-ptest/usr/lib/busybox/ptest/.config
./tmp/work/cortexa7hf-neon-poky-linux-gnueabi/busybox/1.24.1-r0/package/usr/lib/busybox/ptest/.config
./tmp/work/cortexa7hf-neon-poky-linux-gnueabi/busybox/1.24.1-r0/busybox-1.24.1/.config
./tmp/work/cortexa7hf-neon-poky-linux-gnueabi/busybox/1.24.1-r0/sysroot-destdir/usr/lib/busybox/ptest/.config
./tmp/work/imx6ulevk-poky-linux-gnueabi/linux-imx/4.1.15-r0/build/.config
./tmp/work/imx6ulevk-poky-linux-gnueabi/u-boot-imx/2016.03-r0/git/mx6ul_14x14_evk_config/.config
./tmp/work/x86_64-linux/perl-native/5.22.1-r0/perl-5.22.1/.config
I think above is a generic way of making out-of-tree module, without changing yocto source code. This also can workaround the concern that Yocto doesn't see a modified file, if implementations can be done with out-of-tree module.
Best Regards
-Shawn
Hi Gusarambula,
Regarding your last remark, i use yocto to develop for a few weeks and i find it very cumbersome. Namely, my main criticism is that yocto doesn't see a modified file and that the whole kernel has to be recompiled at each time.
What do you propose as alternative solution for developping: ltib ? Buildroot ? Other ?
Rgds,
Christophe