Yocto Recipe for automatically loading Out of Tree Linux Device Drivers on Start

We can instruct Yocto to automatically start our own Linux Kernel Module on Start.

Steps:

1. Create a folder 'recipes-kernel' in your own custom meta layer if it doesn't exist
$ mkdir recipes-kernel
2. Inside 'recipes-kernel', create a folder 'my-module' for storing recipe and device driver files
$ cd recipes-kernel; mkdir my-module
3. Inside 'my-module', create 'files' folder and copy your device driver files
$ cd my-module; mkdir files
4. Copy this Makefile in the 'files' directory

obj-m := mymod.o
SRC := $(shell pwd)
all:
$(MAKE) -C $(KERNEL_SRC) M=$(SRC)
modules_install:
$(MAKE) -C $(KERNEL_SRC) M=$(SRC) modules_install
clean:
rm -f *.o *~ core .depend .*.cmd *.ko *.mod.c
rm -f Module.markers Module.symvers modules.order
rm -rf .tmp_versions Modules.symvers
view raw Makefile hosted with ❤ by GitHub
5. Come back to the parent folder (i.e., my-module) and create a recipe for building the module
$ cd .. ; touch my-module_0.1.bb

You should have the following tree after this step.

SUMMARY = "My Module"
LICENSE = "GPLv2"
inherit module
SRC_URI = "file://Makefile \
file://mymod.c \
"
S = "${WORKDIR}"
# The inherit of module.bbclass will automatically name module packages with
# "kernel-module-" prefix as required by the oe-core build environment.
RPROVIDES_${PN} += "kernel-module-mymod"
6. Add this module into your configuration file (local.conf file or machine.conf)
MACHINE_ESSENTIAL_EXTRA_RDEPENDS += "kernel-module-mymod"
KERNEL_MODULE_AUTOLOAD += "mymod"

MACHINE_ESSENTIAL_EXTRA_RDEPENDS tells yocto to build this module and include it in the build image 
KERNEL_MODULE_AUTOLOAD is to load the module automatically on start

Comments

Popular posts from this blog

bb.utils.contains yocto

Difference between RDEPENDS and DEPENDS in Yocto

PR, PN and PV Variable in Yocto