Enable Kernel Modules in Toradex Yocto Build

There are multiple descriptions of how to add kernel modules to the kernel configuration in the Yocto build. These don’t work in the Toradex 3.0 BSP layer, which is what we are using at the time of this writing.

The examples here use a custom layer named meta-example for demonstraton purposes.

Location of default defconfig

For the linux-toradex 4.14-2.0.x branch, the default defconfig is in the meta-toradex-nxp layer. The configs are located in the kernel recipe under directories named after the "machine" used in the build.

recipes-kernel/
|-- kernel-modules
|   `-- kernel-module-imx-gpu-viv_6.2.4.p1.8.bbappend
`-- linux
    |-- linux-imx
    |   `-- 0001-uapi-Add-ion.h-to-userspace.patch
    |-- linux-imx-headers_4.9.123.bbappend
    |-- linux-toradex-4.14-2.3.x
    |   |-- apalis-imx6
    |   |   `-- defconfig
    |   |-- colibri-imx6
    |   |   `-- defconfig
    |   |-- colibri-imx6ull
    |   |   `-- defconfig
    |   |-- mx7
    |   |   `-- defconfig
    |   `-- mx8
    |       `-- defconfig
    |-- linux-toradex_4.14-2.3.x.bb

A new defconfig must be created based on these defaults. The new file is then included in our custom layer.

  1. Create the new file, by either:
    • Copy the default defconfig, then add the appropriate config line
    • Use the menuconfig for the kernel to select the appropriate module, using the result as the basis for creating the defconfig file
  2. Place the defconfig in a similar directory structure within our custom meta-example layer.
  3. As long as the defconfig file is in the right place, it is picked up automatically by the build process. Do not add the new file to the SRC_URI in our .bbappend file.

Create the new defconfig

As an example, we will add the CH341 USB serial driver to the build.

Manually add the appropriate config

If you are familiar with the kernel module Kconfig files, find the right line and manually add it to the file copied from the Toradex tree. The line we want is:

CONFIG_USB_SERIAL_CH341=m

You can add it anywhere, but for consistency add it near the other CONFIG_USB_SERIAL... options.

You can also create a patch to enable the kernel module with a .patch file that is applied during the build.

Use the menuconfig system

The devshell is probably easiest, but this can also be done using bitbake commands.

The devshell method:

bitbake -c devshell linux-toradex

This will put you into a the OpenEmbedded devshell.

make menuconfig
# select appropriate module(s)
make savedefconfig

The output will be in the build directory, not the current source directory. Access the build directory using the $KBUILD_OUTPUT environment variable.

cp $KBUILD_OUTPUT/defconfig <some new location>

Then exit the devshell as you would exit any other shell (exit command or Ctrl-D).

Add new defconfig to your custom layer

The structure of the recipes-kernel section of the meta-example custom layer should look something like:

recipes-kernel/
`-- linux
    |-- linux-toradex
    |   |-- colibri-imx6
    |   |   |-- defconfig
    `-- linux-toradex_4.14-2.3.x.bbappend

Note all our files are in the linux-toradex directory. This is the directory specified in our .bbappend file, in the line:

FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"

The THISDIR variable expands to the directory containing the recipe (recipes-kernel/linux) and the PN variable expands to the package name (linux-toradex).

The base Toradex recipe uses

FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}-${PV}:"

which includes the package version (PV). We would ideally like to have our changes applied even if the base Toradex recipe is upgraded, so we omit the package version in our .bbappend recipe.

Build

Build the image and the new module(s) should be included. First clean the saved state of the kernel to make sure our changes are picked up.

bitbake -c cleansstate linux-toradex
bitbake <target image>

To test the updated module config is found before starting the lengthy build process:

  • Clean the saved state of the kernel: bitbake -c cleansstate linux-toradex
  • Configure the kernel: bitbake -c configure linux-toradex
  • Enter the devshell: bitbake -c devshell linux-toradex (easier for me than remembering the build path)
  • Examine the .config file that will be used: less $KBUILD_OUTPUT/.config
  • Exit the devshell

Notes

  • Key Toradex community post used for reference: How to use customized defconfig in Apalis ixm6 – works for Colibri modules even though the question asks about Apalis
  • One can also remove modules from the build using this process, which we might be helpful in streamlining the image.

Leave a Reply

Your email address will not be published.