Yocto Customizing Linux kernel AM62

From Variscite Wiki
Warning: This page is designed to be used with a 'release' URL parameter.

This page is using the default release am62-yocto-kirkstone-6.1.46_09.01.00.08-v1.0.
To view this page for a specific Variscite SoM and software release, please follow these steps:

  1. Visit variwiki.com
  2. Select your SoM
  3. Select the software release
VAR-SOM-AM62 - Yocto Customize from source code



After customizing the Linux kernel by following the below instructions, you can either bitbake your complete image (e.g. var-default-image) and the updated kernel that will be used, or you can bitbake the kernel alone by running MACHINE=am62x-var-som bitbake virtual/kernel (see the Build Yocto from source code page for the initial setup and for more info on using bitbake).

Configuring the kernel

The default kernel configuration file used by Yocto is part of the kernel source tree and is located at:

arch/arm64/configs/am62x_var_defconfig


To configure the kernel using Yocto:

  • Follow steps 1-3 of the Build Yocto from source code page.
  • Run the script to set up the environment (stop after that - don't build any image). E.g.: 
$ cd ~/var-ti-yocto/build
$ . conf/setenv


  • Run menuconfig and configure the kernel:
$ MACHINE=am62x-var-som bitbake -c menuconfig virtual/kernel

When finished, save and exit.

The .config file is saved to ~/var-ti-yocto/build/arago-tmp-default-glibc/work/am62x_var_som-oe-linux/linux-variscite/<kernel-version>/build/.config

  • At this point, you can continue following the rest of step 4 of the Build Yocto from source code page to build your image with the newly configured kernel, or just build the kernel by running MACHINE=am62x-var-som bitbake virtual/kernel, or, you can follow the next steps to use this configuration permanently.


To save the configuration in a defconfig format:

$ MACHINE=am62x-var-som bitbake -c savedefconfig virtual/kernel

The defconfig file is saved to ~/var-ti-yocto/build/arago-tmp-default-glibc/work/am62x_var_som-oe-linux/linux-variscite/<kernel-version>/build/defconfig

To make the kernel recipe use this configuration permanently, you can do either of the following:

  • Use any of the three methods described in the Making changes in the source code section below to overwrite the default configuration file in the source tree, arch/arm/configs/am62x_var_defconfig, and replace it with the above defconfig.
  • Make the kernel recipe use the defconfig from outside of the source tree:

Copy your defconfig:

$ cd ~/var-ti-yocto/sources/meta-variscite-bsp-ti/recipes-kernel/linux/
$ mkdir -p files
$ cp ~/var-ti-yocto/build/arago-tmp-default-glibc/work/am62x_var_som-oe-linux/linux-variscite/<kernel-version>/build/defconfig files/defconfig

Create a linux-variscite_%.bbappend file:

$ vim linux-variscite_%.bbappend

and append the following to it:  

SRC_URI += "file://defconfig"
KBUILD_DEFCONFIG:am62x-var-som = ""

Making changes in the source code

Choose one of the following three methods to customize the Linux kernel and build it using Yocto:

Add your own patches on top of our source code

Using this method Yocto will take the source code from our default remote repository, and apply your patches to it before building it:

Setup Yocto:
To configure the kernel using Yocto:

  • Follow steps 1-3 of the Build Yocto from source code page.
  • Run the script to set up the environment (stop after that - don't build any image). E.g.: 
$ cd ~/var-ti-yocto/build
$ . conf/setenv


Get the source code:

$ MACHINE=am62x-var-som bitbake -c patch virtual/kernel
$ mkdir -p ../local_repos/ti-linux-kernel
$ cp -a arago-tmp-default-glibc/work-shared/am62x-var-som/kernel-source/. ../local_repos/ti-linux-kernel
$ cd ../local_repos/ti-linux-kernel
$ git reset --hard
$ git clean -fdx


Make your changes in the source code and create a patch:
You can use either diff or patch file types.
For example:

$ cd ~/var-ti-yocto/local_repos/ti-linux-kernel
$ vim arch/arm64/boot/dts/ti/k3-am625-var-som-symphony.dts
edit and save

$ git diff > my_device_tree_changes.patch


Update the recipes to use your patch:
Copy your patch:

$ cd ~/var-ti-yocto/sources/meta-variscite-bsp-ti/recipes-kernel/linux/
$ mkdir -p files
$ cp ~/var-ti-yocto/local_repos/ti-linux-kernel/my_device_tree_changes.patch  files/

Create a linux-variscite_%.bbappend file:

$ vim linux-variscite_%.bbappend

and append the following line to it:

SRC_URI += "file://my_device_tree_changes.patch"

Use a local repository

Using this method Yocto will take the kernel source from a local repository instead of our remote ones on GitHub:

Setup Yocto:
To configure the kernel using Yocto:

  • Follow steps 1-3 of the Build Yocto from source code page.
  • Run the script to set up the environment (stop after that - don't build any image). E.g.: 
$ cd ~/var-ti-yocto/build
$ . conf/setenv


Get the source code:

$ MACHINE=am62x-var-som bitbake -c patch virtual/kernel
$ mkdir -p ../local_repos/ti-linux-kernel
$ cp -a arago-tmp-default-glibc/work-shared/am62x-var-som/kernel-source/. ../local_repos/ti-linux-kernel
$ cd ../local_repos/ti-linux-kernel
$ git reset --hard
$ git clean -fdx


Make your changes in the source code and commit them:
After making changes in the source code you need to commit them.
For example:

$ cd ~/var-ti-yocto/local_repos/ti-linux-kernel
$ vim arch/arm64/boot/dts/ti/k3-am625-var-som-symphony.dts
edit and save

$ git commit -a -m "my device tree changes"
To list all of the commits:
$ git log
Get the latest commit id:
$ git rev-parse HEAD


Update the recipes to use the local repository instead of the default one:

$ cd ~/var-ti-yocto/sources/meta-variscite-bsp-ti/recipes-kernel/linux/

Create a linux-variscite_%.bbappend file:

$ vim linux-variscite_%.bbappend

and append the following lines to it (see the previous section for listing the commits or getting the latest commit ID):

KERNEL_SRC = "git://<var-ti-yocto_directory>/local_repos/ti-linux-kernel;protocol=file"
SRCBRANCH:am62x-var-som = "ti-linux-6.1.y_var01" (or your own created branch)
SRCREV:am62x-var-som = "The commit id you'd like to use"


For the SRCREV value you can also use "${AUTOREV}" during development to get the latest commit of the branch
(If you do so, make sure to run "MACHINE=am62x-var-som bitbake -c cleansstate virtual/kernel" before rebuilding the kernel)

Use your own remote repository on GitHub

Using this method Yocto will take the source code from your own remote repository on GitHub:

Create your own GitHub account and upload your proprietary kernel to a new repository:
For example, you can fork our repository to your own account by visiting the following link and clicking on "Fork" at the top right of the screen.
Alternatively, you can clone our repository to your local machine, and push it later to your own account.

https://github.com/varigit/ti-linux-kernel/tree/ti-linux-6.1.y_var01


Update the recipes to use your remote repository instead of the default one:

$ cd ~/var-ti-yocto/sources/meta-variscite-bsp-ti/recipes-kernel/linux/

Create a linux-variscite_%.bbappend file:

$ vim linux-variscite_%.bbappend

and append the following lines to it (see the previous section for listing the commits or getting the latest commit id):

KERNEL_SRC = "git://github.com/your_account/ti-linux-kernel.git;protocol=git"
SRCBRANCH = "ti-linux-6.1.y_var01" (or your own created branch)
SRCREV = "The commit id you'd like to use"


For the SRCREV value you can also use "${AUTOREV}" during development to get the latest commit of the branch
(If you do so, make sure to run "MACHINE=am62x-var-som bitbake -c cleansstate virtual/kernel" before rebuilding the kernel)