i.MX 8 getting started: create your kernel module
The normal way that using yocto to do kernel development is really painful… Maybe try out-of-tree build is a better choice.
Create and add your layer
1 | $ bitbake-layers create-layer --example-recipe-name alexkernel meta-alexkernel |
1 | $ bitbake-layers add-layer ../sources/meta-alexkernel/ |
Or you can use exist layer instead, just create recipe files under your layer.
Add your source code and Makefile
alex_module.c:
1 | #include <linux/module.h> |
Makefile:
1 | obj-m := alex_module.o |
Modify recipe files and conf file
alexkernel_0.1.bb:
1 | SUMMARY = "kernel module example" |
Notice: bitbake support inheritance. Inherit from a exist bbclass will be much easier than rewrite one all by yourself. Take a look at openembedded github to check how did they implement a base bbclass. BTW cmake.bbclass might be useful if you trying to support cmake.
layer.conf:
1 | # We have a conf and classes directory, add to BBPATH |
Notice: Module will automatically get loaded when system booting up if KERNEL_MODULE_AUTOLOAD was set.
We should have a folder tree as below:
1 | . |
rebuild your rootfs and image
1 | bitbake fsl-image-qt5-validation-imx |
Check your environment variables by bitbake -e
bitbake -e is a very useful command when you trying to debug build problem.
i.e. Check the rootfs folder of your image:
1 | bitbake -e <image> | grep ^IMAGE_ROOTFS= |
Check the ${WORKDIR} of your recipe:
1 | bitbake -e <recipe> | grep ^WORKDIR= |