This topic shows how to make permanent changes to the kernel source tree and build it using Digi Embedded Yocto. Use one of the following workflows:

  • Repository-based: Use your own fork of the Linux kernel repository to track your changes as separate commits.

  • Patch-based: Create patches to apply on top of Digi Linux kernel repository.

Workflow 1: Repository-based

This workflow consists of creating a separate git repository (a fork of the Linux repo) and using it to make changes to the kernel and/or device tree.

Pros and cons

  • Pros

    • You have full control of the repository, where you can create your own branches and tags.

    • Digi Embedded Yocto handles the build.

    • Changes are permanent and applied to any images built with Digi Embedded Yocto.

    • You don’t need to modify the kernel recipe.

  • Cons

    • Fixes released by Digi to the Linux kernel on GitHub are not automatically applied. You must manually check for released changes to merge into (or rebase) your forked repository.

Instructions

  1. Clone the Linux kernel repository in a directory of your choice and specify the appropriate branch to check out:

    $ cd <your-chosen-path>
    $ git clone git@github.com:digi-embedded/linux.git -b v5.4/dey-3.2/maint
  2. Configure your Digi Embedded Yocto project to build the linux-dey recipe from an external source by adding the following to your project conf/local.conf file:

    conf/local.conf
    1 2 3
    # Build linux kernel from external source INHERIT += "externalsrc" EXTERNALSRC_pn-linux-dey = "<your-chosen-path>/linux"

You can now modify the kernel source code and commit your work to your branch and repository on your development machine. To change the kernel configuration, see Change the Linux kernel configuration.

Workflow 2: Patch-based workflow

This workflow consists of creating custom patches to apply on top of the source code downloaded by the recipe. This is the typical way to modify source code in any Yocto recipe.

Pros and cons

  • Pros

    • You will remain in sync with the original code tree (and any future patches released by Digi) while still applying modifications to suit your needs.

    • Digi Embedded Yocto handles the build.

    • Changes are permanent and applied to any images built with Digi Embedded Yocto.

  • Cons

    • You have to generate the changes as patch files and modify the linux-dey recipe to apply them.

    • You have to keep the patches in sync with Digi repository and may need to update them when the code in GitHub has changed in the sections affected by the patches.

Instructions

For this approach, you can generate the patches from a standalone/external build or the Yocto devshell.

  1. Clone the Linux kernel repository in a directory of your choice and specify the appropriate branch to check out:

    $ cd <your-chosen-path>
    $ git clone git@github.com:digi-embedded/linux.git -b v5.4/dey-3.2/maint
  2. Make your changes in the source code.

  3. Commit them with git:

    $ git add <changed files>
    $ git commit -s -m 'This is a test patch'
  4. Keep making changes and commits as needed.

  5. Create the patches for the number of commits you have made and put them inside the kernel’s recipe folder. For example, if you have made five commits:

    $ git format-patch -5 -o /path/to/dey/sources/meta-digi/meta-digi-arm/recipes-kernel/linux/linux-dey-5.4/ccimx6ulsbc
  6. Edit the kernel recipe (linux-dey_5.4.bb) and add the patches to the sources. Follow the same example as above:

    SRC_URI_append_ccimx6ulsbc = " \
        file://0001-this-is-patch1.patch \
        file://0002-now-patch2.patch \
        file://0003-another-patch.patch \
        file://0004-yet-another-patch.patch \
        file://0005-this-is-the-final-patch.patch \
    "
  7. Go to your Digi Embedded Yocto project and source the environment:

    $ source dey-setup-environment
  8. Rebuild the kernel:

    $ bitbake -c cleanall virtual/kernel
    $ bitbake virtual/kernel

With this method, every time you do a repo sync, you will get the latest fixes released by Digi from GitHub, and your patches will be applied on top.

Change the Linux kernel configuration

Generate a custom kernel configuration file

Digi Embedded Yocto uses a default configuration for the Linux kernel saved in file arch/arm/configs/ccimx6ul_defconfig on the Linux source tree. You can create a custom defconfig file from your current configuration:

When using an external repository

If you are using an external repository (as seen in Workflow 1: Repository-based):

  1. Go to the kernel source tree and run:

    $ make menuconfig
  2. Make your configuration changes, save, and quit the configuration tool.

  3. Generate a defconfig file with your changes by running:

    $ make savedefconfig

    This generates a defconfig file in the root directory of your kernel source tree.

When not using an external repository

If you are not using a external repository (as seen in Workflow 2: Patch-based workflow):

  1. Run this command from your Digi Embedded Yocto project:

    $ bitbake -c menuconfig virtual/kernel
  2. Make your configuration changes, save, and quit the configuration tool.

  3. Generate a defconfig file with your changes by running:

    $ bitbake -c savedefconfig virtual/kernel

    This generates a defconfig file in the root directory of your project’s kernel source tree.

Use a custom kernel configuration file

To make Digi Embedded Yocto use your custom configuration file, set the Yocto variable KERNEL_DEFCONFIG in your project’s conf/local.conf to one of the following:

  • the relative path to the defconfig file inside the kernel repository.

    conf/local.conf
    KERNEL_DEFCONFIG = "arch/arm/configs/my_custom_defconfig"
  • the absolute path to the defconfig file in your workstation.

    conf/local.conf
    KERNEL_DEFCONFIG = "/path/to/my_custom_defconfig"
  • nothing, then copy the defconfig file (it must be named defconfig) inside a folder named ccimx6ulsbc under the linux-dey recipe folder.

    conf/local.conf
    KERNEL_DEFCONFIG = ""
    $ mkdir <path-to-dey>/sources/meta-digi/meta-digi-arm/recipes-kernel/linux/linux-dey-5.4/ccimx6ulsbc
    $ cp <custom-path>/my_custom_defconfig <path-to-dey>/sources/meta-digi/meta-digi-arm/recipes-kernel/linux/linux-dey-5.4/ccimx6ulsbc/defconfig

Deploy the kernel on your target

After you build your kernel and device tree, proceed to deploy them. See Deploy the kernel on your target.