Kernel Patch Not Reflected in Final Image

Issue: Kernel Patch Not Reflected in Final Image

Hi all,

I’m working with a custom Yocto build for the Apalis iMX8 using the linux-toradex kernel recipe. I’ve followed the recommended method of adding kernel patches and configuration fragments via a custom layer (meta-custom). Below is a summary of what I’ve done and the issue I’m facing:

Setup:

  • Custom layer structure:
meta-custom/
└── recipes-kernel/
    └── linux/
        ├── linux-toradex/
        │   ├── 0001-my-device-driver-with-fps-fix.patch
        │   └── linux-toradex_%.bbappend
        └── device-tree-overlays/
            ├── custom_overlay.dts
            └── device-tree-overlay_%.bbappend
  • linux-toradex_%.bbappend:
FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"
SRC_URI += "file://devtool-fragment.cfg \
            file://0001-my-device-driver-with-fps-fix.patch"
  • devtool-fragment.cfg contains:
CONFIG_LOCALVERSION="-6.8.2-devel"
CONFIG_LOCALVERSION_AUTO=y
# CONFIG_MXC_GPU_VIV is not set
CONFIG_VIDEO_my-device=y
  • The patch adds support for a new V4L2 camera sensor (CONFIG_VIDEO_my-device), along with changes to defconfig, Kconfig, Makefile, and source code under drivers/media/i2c/.

What Works:

  • Kernel patch and configuration are correctly applied in the build workspace:
    • Changes are visible under build/tmp/work-shared/apalis-imx8/kernel-source.
    • Overlay DTS is compiled and deployed correctly.

The Problem:

After flashing the built image to the board and booting:

zcat /proc/config.gz | grep VIDEO_my-device
# CONFIG_VIDEO_my-device is not set

zcat /proc/config.gz | grep VIDEO_OV5640
CONFIG_VIDEO_OV5640=y

So despite the patch and fragment being applied in the workspace, the final kernel on the target does not reflect the expected configuration (CONFIG_VIDEO_my-device=y). The newly added driver file also doesn’t appear to be included.

What I’m Looking For:

  • Why might the kernel in the image not reflect the changes applied via patch and config fragment?
  • Is there any step I’m missing that ensures the patched kernel is actually the one getting built into the final image?
  • Could this be due to mismatch or override in defconfig, or some caching issue?

Any insights or pointers would be greatly appreciated. Thanks!

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: :-1:


Hello! Thank you for the detailed description of your setup and the issue—this is very helpful.

Based on what you’ve described, the most likely causes are either a caching/build artifact issue or a problem in how the kernel configuration is finalized and applied to the image. Here are the most common root causes and how to address them:

1. Kernel Build and Caching Issues

When you modify patches or kernel config fragments, old build outputs or cached configurations can persist, causing your changes not to be reflected in the final kernel. To ensure your new patch and configuration are actually used:

  1. Clean the Kernel Build:
    Clean your kernel build to remove previously built artifacts:

    bitbake -c clean linux-toradex
    
  2. Rebuild the Kernel:
    Then rebuild the kernel (and, if necessary, the image itself):

    bitbake virtual/kernel
    bitbake <your-image-name>
    

    Ref: Patching the Kernel in OpenEmbedded

2. Patch and Config Fragment Application

  • Patch Inclusion:
    Ensure your patch is in the correct directory and properly referenced by SRC_URI. From your bbappend it looks good, but double-check that the patch applies cleanly in the build log (you should see a message about the patch being applied).

  • Config Fragment Inclusion:
    Your devtool-fragment.cfg is being included, but verify there are no typos and that the config options do not get overridden by other fragments or the main defconfig. The config option should be present in the final .config file used just before kernel build.

    Use:

    bitbake -c menuconfig virtual/kernel
    

    to inspect the working kernel config in the Yocto build environment.

3. Defconfig Overrides

If another layer or machine configuration provides its own defconfig, it can override your fragment. Ensure there is no other config fragment setting CONFIG_VIDEO_my-device to n.

  • You can also inspect the kernel logs in build/tmp/work/<machine>/linux-toradex/<version>/temp/log.do_configure for how fragments are applied and for any conflicts or rejections.

4. Kernel Image Deployment

  • Sometimes, when you rebuild just the kernel and do not rebuild the full image, the old kernel image may still be present in the deploy directory and flashed onto the board.
  • Make sure you are copying (or flashing) the new kernel image and device tree to the board after the new build:
    • Kernel image and device tree files are typically in build/tmp/deploy/images/<machine>/

5. Additional Check

  • Confirm the driver source and built module (if compiled as module) is present in the root filesystem or in /lib/modules/$(uname -r)/kernel/.
  • Check for build errors or warnings relating to your patch or config fragment.

Summary of Recommended Steps:

  1. Run:
    bitbake -c clean linux-toradex
    bitbake virtual/kernel
    bitbake <your-image-name>
    
  2. Flash the newly built image and ensure no old images are used.
  3. Check zcat /proc/config.gz | grep VIDEO_my-device on the target after flashing.
  4. Inspect the build log.do_configure for config fragment and patch application.

Further reference: https://www.toradex.com/blog/patching-kernel-in-openembedded

If you still experience issues, please review the logs for errors/warnings during kernel configure/build, specifically for patch application and .config generation.

Best regards,
Toradex AI Assistant.

  • The most common cause is persistent build artifacts from previous builds. Please try to clean the kernel build explicitly as AI suggested.

  • Your devtool-fragment.cfg might be overridden by another layer or the base defconfig.

Inspect the kernel's final `.config` during build:

`bitbake -c menuconfig virtual/kernel`

Navigate to `VIDEO_my-device` to confirm its state.
  • Confirm the patch applies cleanly by checking the build logs .
  • The deployed kernel might be outdated. After rebuilding, verify the timestamps of the kernel image