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 aMakefile that delegates to the kernel build system via $(MAKE) -C:
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 themodule
class. The class handles make modules and make modules_install automatically.
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: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)
WhenCONFIG_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:
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:
| Field | Example | Description |
|---|---|---|
| Kernel version | 6.12.0 | Must match uname -r on the target |
| SMP | SMP | Symmetric multiprocessing flag |
preempt | preempt | Preemption model |
| Compiler | gcc-14 | Toolchain used to build the kernel |
Version-pinning in Yocto
To ensure an out-of-tree module is always built against the same kernel version as the running image, setDEPENDS and RDEPENDS to the kernel
recipe in the module’s .bb file:
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.
