Hi, I’m the Toradex AI Assistant.
I might make mistakes. Our support team will step in if needed. If I answered your question, please tick the “Solution” checkbox. For follow-up questions to me, please use @ToradexAI in your post.
Did you like my answer?

(1), (2), (3), (4)
Creating an Out-of-Tree Kernel Module for LAN9252
To add your custom LAN9252 driver to a Yocto build for the Verdin AM62, you’ll need to create a custom meta layer and recipe for your kernel module.
1. Create a Custom Meta Layer and Recipe
First, create a custom meta layer if you don’t have one already (1):
# Run `. export` or `source setup-environment` when building Torizon OS
$ . export # will take you to the `build` directory
$ bitbake-layers create-layer ../layers/meta-customer # inside the build directory
(1)
Next, create the directory structure for your kernel module recipe (1):
$ cd ../layers/meta-customer/
$ mkdir -p recipes-kernel/lan9252-driver/files
2. Create the Kernel Module Recipe
Create a recipe file recipes-kernel/lan9252-driver/lan9252-driver_1.0.bb (1):
SUMMARY = "LAN9252 SPI Kernel Driver"
LICENSE = "GPL-2.0"
LIC_FILES_CHKSUM = "file://COPYING;md5=12f884d2ae1ff87c09e5b7ccc2c4ca7e"
inherit module
SRC_URI = "file://lan9252.c \
file://Makefile \
file://COPYING \
"
S = "${WORKDIR}"
# The inherit of module.bbclass will automatically name module packages with
# kernel-module-* prefix as required by the oe-core build environment.
(1)
3. Create the Makefile
Create recipes-kernel/lan9252-driver/files/Makefile:
obj-m := lan9252.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
(1)
Place your lan9252.c driver file in recipes-kernel/lan9252-driver/files/lan9252.c and add a COPYING file with the GPL-2.0 license text.
4. Add the Module to Your Image
Add the kernel module to your image by appending it to the IMAGE_INSTALL variable in your build/conf/local.conf file (1):
IMAGE_INSTALL:append = " kernel-module-lan9252"
(1)
5. Create a Device Tree Overlay
For the Verdin AM62, create a device tree overlay to disable spidev and enable your LAN9252 device. The overlay structure should follow this pattern (2):
/dts-v1/;
/plugin/;
#include <dt-bindings/gpio/gpio.h>
#include "k3-pinctrl.h"
/ {
compatible = "toradex,verdin-am62";
};
&main_spi1 {
status = "okay";
#address-cells = <1>;
#size-cells = <0>;
lan9252@0 {
compatible = "microchip,lan9252";
reg = <0>;
spi-max-frequency = <25000000>;
status = "okay";
};
};
(2)
6. Integrate the Overlay into Yocto
To add your overlay to the Yocto build, you can create a bbappend for the device tree overlays recipe. The approach depends on whether you’re using upstream or downstream images (4):
Create recipes-kernel/linux/device-tree-overlays_git.bbappend:
FILESEXTRAPATHS:prepend := "${THISDIR}/device-tree-overlays:"
CUSTOM_OVERLAYS_SOURCE = " \
lan9252-verdin-am62_overlay.dts \
"
CUSTOM_OVERLAYS_BINARY = " \
lan9252-verdin-am62_overlay.dtbo \
"
SRC_URI += " \
file://lan9252-verdin-am62_overlay.dts \
"
TEZI_EXTERNAL_KERNEL_DEVICETREE += " \
${CUSTOM_OVERLAYS_BINARY} \
"
TEZI_EXTERNAL_KERNEL_DEVICETREE_BOOT = " \
${CUSTOM_OVERLAYS_BINARY} \
"
do_collect_overlays:prepend() {
for DTS in ${CUSTOM_OVERLAYS_SOURCE}; do
cp ${WORKDIR}/${DTS} ${S}
done
}
(4)
7. Enable Automatic Loading
To ensure your driver loads automatically at boot, you can:
- Add module loading to your recipe by creating a configuration file
- Use device tree compatible matching - if your driver properly implements
of_device_id matching, it will load automatically when the device tree node is present
Create recipes-kernel/lan9252-driver/files/lan9252.conf:
lan9252
And modify your recipe to install this configuration:
do_install:append() {
install -d ${D}${sysconfdir}/modules-load.d
install -m 0644 ${WORKDIR}/lan9252.conf ${D}${sysconfdir}/modules-load.d/
}
FILES:${PN} += "${sysconfdir}/modules-load.d/lan9252.conf"
8. Build Your Custom Image
After setting up the recipe and overlay, build your image (1):
$ bitbake <your-image>
(1)
This approach will properly integrate your LAN9252 driver into the Yocto build system, compile it as a kernel module, apply the necessary device tree changes, and ensure it loads automatically at boot.
Best regards, Toradex AI Assistant.