# Yocto support

Source: [https://docs.qualcomm.com/doc/80-70014-3/topic/yocto-kernel-support.html](https://docs.qualcomm.com/doc/80-70014-3/topic/yocto-kernel-support.html)

Qualcomm Linux `meta-qcom-hwe` layer supports
            `linux-kernel-qcom` recipe that fetches and builds the Linux kernel for
        supported machine.

For more information on available recipes, see [Build the Yocto image recipes and kernel configurations](https://docs.qualcomm.com/doc/80-70014-3/topic/getting_started_chapter2.html#kernel-configuration1).

## Kernel source

Source: [https://docs.qualcomm.com/doc/80-70014-3/topic/yocto-kernel-support.html](https://docs.qualcomm.com/doc/80-70014-3/topic/yocto-kernel-support.html)

Kernel source can be fetched from the Codelinaro repository as a part of BitBake
        builds.

**Yocto kernel**

    $ MACHINE=qcm6490 DISTRO=qcom-wayland source setup-environment
    $ bitbake qcom-console-image
     
    # kernel source is downloaded under following location
    $ ls build-qcom-wayland/tmp-glibc/work-shared/qcm6490/kernel-source/
    arch     Documentation  ipc       MAINTAINERS  samples   virt
    block    drivers        Kbuild    Makefile     scripts
    certs    fs             Kconfig   mm           security
    COPYING  include        kernel    net          sound
    CREDITS  init           lib       README       tools
    crypto   io_uring       LICENSES  rust         usrCopy to clipboard

For more information on the setup and obtaining a source, see the [Qualcomm Linux Build Guide](bundle/publicresource/topics/80-70014-254).

## Kernel recipe

Source: [https://docs.qualcomm.com/doc/80-70014-3/topic/yocto-kernel-support.html](https://docs.qualcomm.com/doc/80-70014-3/topic/yocto-kernel-support.html)

Qualcomm Linux maintains `meta-qcom-hwe` layer and hosts kernel recipe
        at ` meta-qcom-hwe/recipes-kernel/linux/linux-kernel-qcom_6.6.bb`
        file.

The `PREFERRED_PROVIDER_virtual/kernel` is defined as
                `linux-kernel-qcom` in the
                `meta-qcom-hwe/conf/machine/include/qti-common.inc` file. All
            references to `virtual/kernel` point to
                `linux-kernel-qcom` recipe file.

For the kernel recipe, run the following
            commands:

    $ MACHINE=qcm6490 DISTRO=qcom-wayland source setup-environment
    $ bitbake qcom-console-image
     
    # kernel recipe location
    $ ls -l meta-qcom-hwe/recipes-kernel/linux/
     linux-kernel-headers-install_6.6.bb
     linux-kernel-qcom
     linux-kernel-qcom_6.6.bb
     linux-kernel-qcom-headers_6.6.bbCopy to clipboard

## Unpack kernel source

Source: [https://docs.qualcomm.com/doc/80-70014-3/topic/yocto-kernel-support.html](https://docs.qualcomm.com/doc/80-70014-3/topic/yocto-kernel-support.html)

The kernel source can be unpacked for development and customization after cloning the
        meta layer.

The following set of commands are used to unpack the source
            code:

    # unpack kernel
    $  devtool modify linux-kernel-qcom
    # Fetch and set up kernel repository at build-qcom-wayland/workspace/sources/linux-kernel-qcom
    # Creates a bbappend recipe at build-qcom-wayland/workspace/appends/linux-kernel-qcom_6.6.bbappend
    # and also adds build-qcom-wayland/workspace to conf/bblayers.conf
    $ ls build-qcom-wayland/workspace/
    appends/      conf/         .devtool_md5  README        sources/
     
    $ ls build-qcom-wayland/workspace/appends
    linux-kernel-qcom_6.6.bbappend
     
    $ ls build-qcom-wayland/workspace/conf
    layer.conf
     
    # kernel source repository
    $ ls build-qcom-wayland/workspace/sources/
    linux-kernel-qcomCopy to clipboard

When the commands are run, BitBake picks the kernel from the workspace and applies the
                `bbappend` recipe.

## Make kernel changes

Source: [https://docs.qualcomm.com/doc/80-70014-3/topic/yocto-kernel-support.html](https://docs.qualcomm.com/doc/80-70014-3/topic/yocto-kernel-support.html)

Kernel changes or customizations are done in the
            `build-qcom-wayland/workspace/sources/linux-kernel-qcom`
        workspace.

To modify the kernel configuration, use the following
            commands:

    # Modify sources in build-qcom-wayland/workspace/sources/linux-kernel-qcom, or update kernel configuration by running makemenufonfig
    $ devtool menuconfig linux-kernel-qcom
     
    # config fragment is updated in following location
    $ ls build-qcom-wayland/workspace/sources/linux-kernel-qcom/oe-local-files/devtool-fragment.cfg
    devtool-fragment.cfg
     
    # you may do other changes to kernel and commitCopy to clipboard

## Commit kernel changes

Source: [https://docs.qualcomm.com/doc/80-70014-3/topic/yocto-kernel-support.html](https://docs.qualcomm.com/doc/80-70014-3/topic/yocto-kernel-support.html)

Use the following Git commands to commit your changes:

$ cd build-qcom-wayland/workspace/sources/linux-kernel-qcom
    $ git add .
    $ git commit -s -m "my changes"Copy to clipboard

## Build kernel image

Source: [https://docs.qualcomm.com/doc/80-70014-3/topic/yocto-kernel-support.html](https://docs.qualcomm.com/doc/80-70014-3/topic/yocto-kernel-support.html)

After the changes are done, use the following procedures to build the kernel and the
        image:

# to build kernel use
    $ devtool build linux-kernel-qcom
     
    # and following to build the image
    $ devtool build-image qcom-console-image
     
    # built images are produced in standard location
    $ ls build-qcom-wayland/tmp-glibc/deploy/images/qcm6490/Copy to clipboard

## Maintain kernel changes

Source: [https://docs.qualcomm.com/doc/80-70014-3/topic/yocto-kernel-support.html](https://docs.qualcomm.com/doc/80-70014-3/topic/yocto-kernel-support.html)

Use Devtool to develop and export the patch and create an append file in the
            `meta-mylayer` layer. To create your own layer, first add it to the host
        kernel `bbappend` files and make changes.

Run the following commands to create and append kernel patches in the meta
            layer:

    # create your own layer first and add it to host kernel bbappend and changes
    $ bitbake-layers create-layer ~/meta-mylayer
    # mkdir -p ~/meta-mylayer/recipes-kernel/linux/linux-kernel-qcom
    $ bitbake-layers add-layer ~/meta-mylayer
     
    # following would update the meta-mylayer recipe and the change
    $ devtool finish linux-kernel-qcom ~/meta-mylayer
     
    # devtool finish shall populate the meta-mylayer recipes along with patches,
     
    $ ls -R meta-mylayer/recipes-kernel/
    meta-mylayer/recipes-kernel/:
    linux
     
    meta-mylayer/recipes-kernel/linux:
    linux-kernel-qcom  linux-kernel-qcom_%.bbappend
     
    meta-mylayer/recipes-kernel/linux/linux-kernel-qcom:
    0001-my-patch.patch  devtool-fragment.cfg
     
    $ less meta-mylayer/recipes-kernel/linux/linux-kernel-qcom_%.bbappend
    FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"
     
    SRC_URI += "file://devtool-fragment.cfg \
                file://0001-my-patch.patch"Copy to clipboard

After executing, `devtool finish` command, the
                `~/meta-mylayer` layer is updated with the following:

- Corresponding kernel changes hosted as patches in
                    `meta-mylayer/recipes-kernel/linux/linux-kernel-qcom/*.patch`.
- Add and update
                    `meta-mylayer/recipes-kernel/linux/linux-kernel-qcom_%.bbappend SRC_URI
                ` with these patches.
- `build-qcom-wayland/workspace` can be removed after development is
                completed.

## Clean up the workspace

Source: [https://docs.qualcomm.com/doc/80-70014-3/topic/yocto-kernel-support.html](https://docs.qualcomm.com/doc/80-70014-3/topic/yocto-kernel-support.html)

Use the following Devtool and BitBake commands to clean up the workspace:

# to remove layer
    $ bitbake-layers remove-layer ~/meta-mylayer
    
    # to clean complete work space
    $ bitbake -c cleanall recipe
    
    # reset using Devtool
    $ devtool reset linux-kernel-qcom
    
    # manually delete the workspace directory
    $ rm -rf build-qcom-wayland/workspace/sources/linux-kernel-qcom   Copy to clipboard

Last Published: Jul 15, 2024

[Previous Topic
Features](https://docs.qualcomm.com/bundle/publicresource/80-70014-3/topics/features.md) [Next Topic
Customize](https://docs.qualcomm.com/bundle/publicresource/80-70014-3/topics/customize.md)