Skip to main content
Most Qualcomm® Linux drivers are compiled directly from the kernel source tree. Some drivers are maintained outside that tree—called out-of-tree or Dynamically Loadable Kernel Module (DLKM) drivers—and are built separately using either a standalone Makefile or the Yocto build system. The Qualcomm kernel graphics support layer (KGSL) GPU driver is an example: its recipe at recipes-graphics/kgsl-dlkm/kgsl-dlkm_git.bb builds and installs the driver as an out-of-tree module.

Build and autoload modules

Standalone Makefile

Create a Makefile that delegates to the kernel build system via $(MAKE) -C:
Set KERNEL_SRC to the path of the configured kernel source tree before invoking make.

Yocto recipe

Integrate an out-of-tree module into the Yocto build by inheriting the module class. The class handles make modules and make modules_install automatically.
The KERNEL_MODULE_AUTOLOAD variable writes the module name into /etc/modules-load.d/ in the target rootfs, causing systemd-modules-load to insert it on every boot.

Real-world example: KGSL

The KGSL recipe illustrates a production out-of-tree module:
Note the blacklist msm_kgsl entry: it prevents the upstream in-tree stub from loading when the out-of-tree KGSL module is present. For more information about out-of-tree modules in Yocto, see Working with Out-of-Tree Modules.

Module versioning strategy

Kernel symbol versioning (MODVERSIONS)

When CONFIG_MODVERSIONS=y is set in the kernel configuration, the kernel embeds a CRC checksum for each exported symbol. A module is loaded only when its per-symbol CRCs match those of the running kernel, preventing silently binary-incompatible modules from being inserted. To verify whether MODVERSIONS is active on the target:
A module built against a different kernel tree or a different defconfig will produce a load-time error if any CRC mismatches:

vermagic compatibility

Every .ko file embeds a vermagic string that encodes the kernel version, SMP flag, and compiler version used at build time. The running kernel rejects any module whose vermagic does not match exactly. Inspect a module’s vermagic before deployment:
Table: vermagic fields

Version-pinning in Yocto

To ensure an out-of-tree module is always built against the same kernel version as the running image, set DEPENDS and RDEPENDS to the kernel recipe in the module’s .bb file:
The Yocto module class automatically sets KERNEL_SRC and KERNELRELEASE to values from the selected kernel recipe, so the module Makefile picks up the correct headers and symbol tables without any manual configuration.