Yocto add a custom layer for simple small change in an intree kernel module

Here is another thread on the topic of rpmsg and how do I increase the buffer size.
I have set up a YOCTO build environment and I can create a Torizon OS BSP that behaves on the module in the same way as a BSP provided directly by Toradex.
Now I want to edit 2 source files. I am aware that there are several approaches to this.

However, I now want to use the approach via a meta-custom layer, as partially described here:

meta-customer/
|-- COPYING.MIT
|-- README
|-- conf
|   `-- layer.conf
`-- recipes-kernel
    `-- linux
        |-- linux-toradex
        |   `-- rpmsg_char.patch
        |   `-- virtio_rpmsg_bus.patch
        `-- linux-toradex%.bbappend

But what does the /.bbappend file have to look like?

And what is still missing?

The examples above are already too complex for my case.
I need a very simple example that works.

In my last approach, the source files were patched, but the change did not arrive in the finished image. I suspect that they were not recompiled.

Best regards
Gerald

Hi, I’m the Toradex AI Assistant. I’m in early beta, and I would appreciate your feedback.
The Toradex Support team will follow up with you shortly!

Did you like my answer?

:+1: :-1:


Hello Gerald,

To create a custom layer for a simple change in an in-tree kernel module using Yocto, and ensure your changes are compiled and included in the final image, your .bbappend file should instruct Yocto to apply your patches and possibly force a recompilation of the affected modules. Here’s a simplified approach:

  1. Create the .bbappend File: This file should append the necessary tasks to apply your patches. Assuming you’re modifying the rpmsg module in the Linux kernel provided by Toradex, your linux-toradex_%.bbappend might look something like this:
FILESEXTRAPATHS_prepend := "${THISDIR}/linux-toradex:"

SRC_URI += " \
    file://rpmsg_char.patch \
    file://virtio_rpmsg_bus.patch \
"

# Force a recompilation of the kernel to ensure your changes are applied
do_configure:append() {
    oe_runmake oldconfig
}
  1. Ensure Patches Are Correctly Formatted: Your patches (rpmsg_char.patch and virtio_rpmsg_bus.patch) need to be correctly formatted diff files. They should be created based on the differences between the original and modified source files. Use the diff -u command to generate these patches if you haven’t already.

  2. Place the Patches in the Correct Directory: As per your directory structure, place your patches in the recipes-kernel/linux/linux-toradex directory. Ensure the path in SRC_URI correctly points to these patch files.

  3. Force Kernel Recompilation (If Needed): The do_configure:append() function with oe_runmake oldconfig is a simple way to ensure the kernel is reconfigured. This step might be necessary if your patches alter configuration options. However, if your patches only modify source files and don’t require changes to the kernel configuration, this step might not be strictly necessary. Yocto should detect the changes and rebuild the affected modules automatically.

  4. Layer Configuration: Ensure your layer.conf in the meta-customer/conf directory is correctly set up to include your custom layer in the build. It should look something like this:

BBPATH .= ":${LAYERDIR}"
BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
            ${LAYERDIR}/recipes-*/*/*.bbappend"

BBFILE_COLLECTIONS += "meta
		

Please, also check if these links can help you solve your problem:

https://developer.toradex.com/software/linux-resources/linux-features/enabling-spread-spectrum-clocking-on-ddr-interface
https://developer.toradex.com/linux-bsp/os-development/build-yocto/custom-meta-layers-recipes-and-images-in-yocto-project-hello-world-examples.

that seems to help

Hello @gerko,

The do_configure:append() should not really be needed for this case.

What may have done the trick is to add the *.patch files to the SRC_URI.
We have a similar example of this here: Custom meta layers, recipes and images in Yocto Project (hello-world examples) | Toradex Developer Center

Best Regards,
Bruno

I had done that. Otherwise the patch would probably not have been applied. As I said, you could see under

/home/gerko/build-torizon/tmp/work-shared/apalis-imx8/kernel-source/drivers/rpmsg

that the patch had worked.

However, I was able to see from a changed message in linux/drivers/rpmsg/virtio_rpmsg_bus.c:724:

dev_warn(dev, "inbound msg is too big: (%d, %d)\n", len, msg_len);

that this part was not recompiled. With the addition: do_configure:append() ...
will definitely be recompiled.
In my case, however, this takes about 1/4 hour.

Greetings

Hello @gerko,

Thanks for sharing this information.

Best Regards,
Bruno

I think I have gained a little more certainty.
Whether recompilation is decided based on the local git repository. If there is a valid commit that contains all the required files, it is also recompiled.

I think with git commit -a you are on the safe side

And whether it is also appended may decide whether to use *.bbappend or just *.bb ???

I have to test it all again …

Greetings
Gerald

Hello @gerko,

Thanks for the update.

Just to clarify this point, .bbappend files should be used when modifying an existing recipe, which is the case for the Linux kernel, while .bb files should be used when declaring new recipes, which will likely be the case when adding a custom application, for example.

Best Regards,
Bruno