# Develop the kernel

The Qualcomm Linux kernel can be developed using either the Yocto build workflow or a standalone workflow.

## Use Yocto to develop kernel

The Qualcomm Linux `meta-qcom` layer supports `linux-qcom-next.bb`
and `linux-qcom_6.18.bb` recipes that fetch and build the Qualcomm
Linux kernel mainline or LTS versions for the supported machines.

To develop kernel using Yocto development workflow, refer following sections.
For more information about Yocto provisions, host patches, and how to apply
them, see [Yocto Project Linux Kernel
Development](https://docs.yoctoproject.org/1.5/kernel-dev/kernel-dev.html#applying-patches).

## Retrieve the kernel source

Fetch the kernel source from the GitHub repository using `meta-qcom` KAS build.

**Yocto kernel**

To fetch kernel source for Yocto kernel using KAS build, run the following command:

kas build meta-qcom/ci/rb3gen2-core-kit.yml:meta-qcom/ci/linux-qcom-6.18.yml:meta-qcom/ci/qcom-distro.yml:meta-qcom/ci/lock.yml
    Copy to clipboard

The kernel source is present at the following location:

ls tmp/work-shared/rb3gen2-core-kit/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         usr
    Copy to clipboard

Note

`meta-qcom` build uses KAS to build different machines and build configurations
that are present in `meta-qcom/ci/` directory.

Note

For information on why `lock.yml` is required and how to obtain it, see
[Build a BSP image](https://docs.qualcomm.com/doc/80-80020-254/topic/build_from_source_github_intro.html#build-a-bsp-image).

For more information about the setup and obtaining a source, see the
[Qualcomm Linux Build Guide](doc/80-80022-254).

## Retrieve the kernel recipe

Qualcomm Linux maintains the `meta-qcom` layer and hosts kernel recipe files at the following locations:

- Linux kernel LTS BSP: `meta-qcom/recipes-kernel/linux/linux-qcom_6.18.bb` file.
- Linux kernel mainline BSP: `meta-qcom/recipes-kernel/linux/linux-qcom-next_git.bb` file.

`PREFERRED_PROVIDER_virtual/kernel` is defined as `linux-qcom-next` for
mainline and `linux-qcom` for LTS in `meta-qcom kas` configuration file.

For example, see `meta-qcom/ci/linux-qcom-6.18.yml` in the following example:

PREFERRED_PROVIDER_virtual/kernel ?= "linux-qcom"
    PREFERRED_VERSION_virtual/kernel = "6.18%"
    Copy to clipboard

To get the list of all supported kernel recipes, run the following command:

# kernel recipe location
       ls -l meta-qcom/recipes-kernel/linux/
       linux-qcom-next-rt_git.bb
       linux-qcom-next_git.bb
       linux-qcom-rt_6.18.bb
       linux-qcom_6.18.bb
    Copy to clipboard

## Unpack the kernel source

Use Yocto-provided devtool for kernel development. After cloning the meta layer, unpack the kernel source for development and customization.

To unpack the source code, run the following commands:

1. To clone `meta-qcom`, run the following command:

> 
> 
> git clone https://github.com/qualcomm-linux/meta-qcom.git -b master
>     Copy to clipboard

2. To build the kernel using KAS configuration for one of the supported boards, run the following command:

> 
> 
> devtool build linux-qcom
>     Copy to clipboard

3. To ensure that you are in the KAS shell, run the following command:

> 
> 
> kas shell meta-qcom/ci/rb3gen2-core-kit.yml:meta-qcom/ci/linux-qcom-6.18.yml:meta-qcom/ci/qcom-distro.yml
>     Copy to clipboard

4. To modify the kernel source within the KAS shell by using devtool to fetch and prepare it for the change, run the following command:

> 
> 
> devtool modify linux-qcom
>     Copy to clipboard

Note

This checks out the kernel source corresponding to linux-qcom in
`build/workspace/sources/linux-qcom`.

For the mainline BSP version, use `linux-qcom-next`. You can update
`PREFERRED_PROVIDER_virtual/kernel` variable in the `conf/local.conf` before the kernel source is checkout.

> 
> 
> `PREFERRED_PROVIDER_virtual/kernel = "linux-qcom-next"`

## Make kernel changes

Do the kernel changes or customization in the
`build/workspace/sources/linux-qcom` workspace.

Modify the kernel configuration using the following commands:

1. To ensure that you are in the KAS shell, run the following command:

> 
> 
> kas shell meta-qcom/ci/rb3gen2-core-kit.yml:meta-qcom/ci/linux-qcom-6.18.yml:meta-qcom/ci/qcom-distro.yml
>     Copy to clipboard

2. To modify the sources in `build/workspace/sources/linux-qcom`, or update the kernel configuration, run the  following command:

> 
> 
> makemenuconfig
>       devtool menuconfig linux-qcom
>     Copy to clipboard

3. The configuration fragment is updated in following location:

> 
> 
> ls build/workspace/sources/linux-qcom/oe-local-files/devtool-fragment.cfg
>     devtool-fragment.cfg
>     Copy to clipboard

Note

For the mainline kernel, use `linux-qcom-next`.

## Commit the kernel changes

To commit your changes, run the following Git commands:

1. To move into the local kernel source (workspace) directory where the Yocto/Devtool system has unpacked the Qualcomm Linux kernel, run the following command:

> 
> 
> cd build/workspace/sources/linux-qcom
>     Copy to clipboard

2. To add the updated topics for commit, run the following command:

> 
> 
> git add .
>     Copy to clipboard

3. To create a commit, add a commit message, and submit the code changes to the GitHub, run the following command:

> 
> 
> git commit -s -m "my changes"
>     Copy to clipboard

## Build the kernel image

After the changes are done, to build the kernel and the image, run the following commands:

1. To ensure that you are in the KAS shell, run the following command:

> 
> 
> kas shell meta-qcom/ci/rb3gen2-core-kit.yml:meta-qcom/ci/linux-qcom-6.18.yml:meta-qcom/ci/qcom-distro.yml
>     Copy to clipboard

2. To build the kernel, run the following command:

> 
> 
> devtool build linux-qcom
>     Copy to clipboard

3. To build the image, run the following command:

> 
> 
> devtool build-image qcom-multimedia-image
>     Copy to clipboard

The built images are present in the following location:

ls build/tmp/deploy/images/<Machine>/
    Copy to clipboard

Note

To compile the mainline kernel version, use `devtool build linux-qcom-next`.

## Maintain kernel changes

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.

To create and append kernel patches in the meta layer, run the following commands:

1. To ensure that you are in the KAS shell, run the following command:

> 
> 
> kas shell meta-qcom/ci/rb3gen2-core-kit.yml:meta-qcom/ci/linux-qcom-6.18.yml:meta-qcom/ci/qcom-distro.yml
>     Copy to clipboard

2. To create the layer first and add it to the host kernel bbappend and changes, run the following command:

> 
> 
> bitbake-layers create-layer ~/meta-<mylayer>
>     Copy to clipboard

3. To create the directory structure for your custom Yocto layer, specifically for adding or modifying kernel recipes, run the following command:

mkdir -p ~/meta-<mylayer>/recipes-kernel/linux/linux-qcom
        bitbake-layers add-layer ~/meta-<mylayer>
        Copy to clipboard
4. To update the meta-&lt;mylayer&gt; recipe and the change, run the following command:

> 
> 
> devtool finish linux-qcom ~/meta-<mylayer>
>     Copy to clipboard

5. The `devtool finish` command shows the meta-&lt;mylayer&gt; recipes with patches:

> 
> 
> ls -R meta-<mylayer>/recipes-kernel/
>         meta-<mylayer>/recipes-kernel/:
>         linux
>     
>         meta-<mylayer>/recipes-kernel/linux:
>         linux-qcom  linux-qcom_6.18 linux-qcom%.bbappend
>     
>         meta-<mylayer>/recipes-kernel/linux/linux-qcom:
>         0001-<my-patch>.patch  devtool-fragment.cfg
>     Copy to clipboard

6. The patches are present in the following bbappend recipe:

> 
> 
> less meta-<mylayer>/recipes-kernel/linux/linux-qcom-base%.bbappend
>       FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"
>     
>       SRC_URI += "file://devtool-fragment.cfg \
>                   file://0001-my-patch.patch"
>     Copy to clipboard

After running the `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-qcom/*.patch`.
- Adds and updates
`meta-<mylayer>/recipes-kernel/linux/linux-qcom_%.bbappend SRC_URI`
with these patches.
- Removes `build/workspace` after the development is
completed.

## Clean up the workspace

To clean up the workspace, use the following Devtool and BitBake commands:

1. To ensure that you are in the KAS shell, run the following command:

> 
> 
> kas shell meta-qcom/ci/rb3gen2-core-kit.yml:meta-qcom/ci/linux-qcom-6.18.yml:meta-qcom/ci/qcom-distro.yml
>     Copy to clipboard

2. To remove the BitBake layer, run the following command:

> 
> 
> bitbake-layers remove-layer ~/meta-<mylayer>
>     Copy to clipboard

3. To clean the complete workspace, run the following command:

> 
> 
> devtool reset linux-qcom
>     Copy to clipboard

4. To manually delete the workspace directory, run the following command:

> 
> 
> rm -rf build/workspace/sources/linux-qcom
>     Copy to clipboard

## Configure the kernel

The Yocto build system is used for modifying the kernel configuration, while
invoking `menuconfig`.

To modify the kernel configuration, run the following commands:

1. To ensure that you are in the KAS shell, run the following command:

> 
> 
> kas shell meta-qcom/ci/rb3gen2-core-kit.yml:meta-qcom/ci/linux-qcom-6.18.yml:meta-qcom/ci/qcom-distro.yml
>     
>     bitbake linux-qcom -c menuconfig
>     Copy to clipboard

2. The previous command updates the `.config` file in the kernel build directory in `build/tmp/work/<SoC>-<board>-<variant>/linux-qcom/*/build/`.
3. Create a configuration fragment for modifications using the following command:

> 
> 
> bitbake linux-qcom -c diffconfig
>     Copy to clipboard

4. The previous command creates `fragment.cfg` in the build directory `build/tmp/work/<SoC>-<board>-<variant>/linux-qcom/*/fragment.cfg`.

Alternatively, use the Devtool to modify the kernel configuration:

devtool modify linux-qcom
     devtool menuconfig linux-qcom
     devtool finish linux-qcom ~/meta-<mylayer>
    
    # this creates a config fragment as a patch and update in your meta layer
    Copy to clipboard

Note

For the mainline Linux kernel version, use `linux-qcom-next`.

For more information about Yocto-related details on kernel configuration, see
[Configuring the
Kernel](https://docs.yoctoproject.org/4.3.1/kernel-dev/common.html#configuring-the-kernel).

The `recipes-kernel/linux/linux-qcom_6.18.bb` kernel recipe file uses the following configuration fragments to build the images:

KBUILD_DEFCONFIG ?= "defconfig"
    KBUILD_DEFCONFIG:qcom-armv7a = "qcom_defconfig"
    
    KBUILD_CONFIG_EXTRA = "${@bb.utils.contains('DISTRO_FEATURES', 'hardened', '${S}/kernel/configs/hardening.config', '', d)}"
    KBUILD_CONFIG_EXTRA:append:aarch64 = " ${S}/arch/arm64/configs/prune.config"
    KBUILD_CONFIG_EXTRA:append:aarch64 = " ${S}/arch/arm64/configs/qcom.config"
    KBUILD_CONFIG_EXTRA:append = " ${@oe.utils.vartrue('DEBUG_BUILD', '${S}/kernel/configs/debug.config', '', d)}"
    Copy to clipboard

To generate the debug build using debug configuration fragments, run the following commands:

1. To compile debug-enabled build, set DEBUG\_BUILD to 1 using the following command:

> 
> 
> Set DEBUG_BUILD to 1 to compile debug-enabled build
>     Copy to clipboard

2. To ensure that you are in the KAS shell, run the following command:

> 
> 
> kas shell meta-qcom/ci/rb3gen2-core-kit.yml:meta-qcom/ci/linux-qcom-6.18.yml:meta-qcom/ci/qcom-distro.yml
>     DEBUG_BUILD=1 bitbake -c build qcom-multimedia-image
>     Copy to clipboard

For more information about different configuration fragments, see [Get started with Qualcomm Linux kernel](https://docs.qualcomm.com/doc/80-80022-3/topic/getting_started_chapter2.html).

## Create a debug build

To create a debug build, pass `DEBUG_BUILD=1` as variable to compile BitBake build.
You may set it as environment variable or in `build/conf/local.conf` in your workspace:

1. To ensure that you are in the KAS shell, run the following command:

> 
> 
> kas shell meta-qcom/ci/rb3gen2-core-kit.yml:meta-qcom/ci/linux-qcom-6.18.yml:meta-qcom/ci/qcom-distro.yml
>     Copy to clipboard

3. To compile debug-enabled build, set DEBUG\_BUILD to 1 in `build/conf/local.conf` or set the environment  using the following command:

> 
> 
> DEBUG_BUILD=1 bitbake -c build qcom-multimedia-image
>     Copy to clipboard

## Update the kernel command-line parameters

To update the kernel command line, modify the Yocto configuration variable `KERNEL_CMDLINE_EXTRA` in the KAS base configuration file (`ci/base.yml`) to apply the changes across all machines, or modify it in the corresponding SoC‑specific machine inclusion file, such as `meta-qcom/conf/machine/include/qcom-<SoC>.inc`.

To update the kernel command-line, modify the following variable:

KERNEL_CMDLINE_EXTRA:append = "console=ttyMSM0,115200n8 earlycon"
    Copy to clipboard

### Update the ESP images

To compile the systemd-boot boot manager and kernel images into a packaged UKI type-2 image file, use the following:

The Yocto build for the hardware SoC generates all the required images and packages the boot images as `efi.bin` and `dtb.bin`, which are flashed to the EFI partition and the DTB partition, respectively. The `efi.bin` file contains the systemd‑boot manager and the kernel image packaged in the UKI type‑2 format, while the `dtb.bin` file contains the DTB blob.

Rebuild the EFI and DTB image after updating the kernel source, configuration,
or DTS and flash the generated `efi.bin` and `dtb.bin` to the EFI partition
and DTB partition respectively.

After the changes are done, to build the kernel and the image, run the following commands:

1. To ensure that you are in the KAS shell, run the following command:

> 
> 
> kas shell meta-qcom/ci/<SoC>-<board>-<variant>.yml:meta-qcom/ci/linux-qcom-6.18.yml:meta-qcom/ci/qcom-distro.yml
>     Copy to clipboard

2. To build the Qualcomm Linux multimedia image, run the following command:

> 
> 
> DEBUG_BUILD=1 bitbake qcom-multimedia-image
>     Copy to clipboard

3. To reboot into fastboot, run the following command:

> 
> 
> fastboot flash efi efi.bin
>     fastboot flash dtb_a dtb.bin
>     Copy to clipboard

For more information about the UKI type-2 image format, see  [Type #2 EFI Unified Kernel Images](https://uapi-group.org/specifications/specs/boot_loader_specification/#type-2-efi-unified-kernel-images) and about ESP, see Boot and [Bring up the device](https://docs.qualcomm.com/doc/80-80022-3/topic/getting_started_chapter2.html#bring-up-the-device).

## Customize the initramfs package

To update the initramfs package, modify the `PACKAGE_INSTALL` list in
`meta-qcom/recipes-kernel/images/initramfs-qcom-image.bb` file:

less meta-qcom/recipes-kernel/images/initramfs-qcom-image.bb
    
    DESCRIPTION = "Ramdisk image for pivoting into rootfs"
    
    PACKAGE_INSTALL += " \
        base-passwd \
        initramfs-module-copy-modules \
        initramfs-module-rootfs \
        initramfs-module-udev \
        ${VIRTUAL-RUNTIME_base-utils} \
        ${MACHINE_ESSENTIAL_EXTRA_RDEPENDS} \
        ${ROOTFS_BOOTSTRAP_INSTALL} \
        "
    Copy to clipboard

## Add a kernel module

To compile out-of-tree kernel modules using the Yocto build system, use the following procedure:

1. Create a `Makefile` for out-of-tree kernel driver.

> 
> 
> The following is the sample `Makefile` for out-of-tree kernel driver:
> 
> 
> all: modules
>     obj-m := hello.o
>     
>     SRC := $(shell pwd)
>     
>     modules:
>       $(MAKE) -C $(KERNEL_SRC) M=$(SRC) modules $(KBUILD_OPTIONS)
>     
>     modules_install:
>       $(MAKE) -C $(KERNEL_SRC) M=$(SRC) modules_install
>     Copy to clipboard

2. Integrate the module into the Yocto build system.

> 
> 
> See the following example to integrate the kernel modules using Yocto module class.
> 
> 
> DESCRIPTION = "${SUMMARY}"
>     LICENSE = "GPL-2.0-only"
>     LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/${LICENSE};md5=801f80980d171dd6425610833a22dbe6"
>     
>     inherit module
>     
>     SRC_URI += "file://Makefile \
>                 file://hello.c  \
>                 file://COPYING  \
>                 "
>     S = "${WORKDIR}"
>     
>     EXTRA_OEMAKE += "MACHINE='${MACHINE}'"
>     MAKE_TARGETS = "modules"
>     MODULES_INSTALL_TARGET = "modules_install"
>     
>     # Kernel module to be autoloaded
>         KERNEL_MODULE_AUTOLOAD += "hello"
>     
>     # The inherit of module.bbclass will automatically name module packages with
>     # "kernel-module-" prefix as required by the oe-core build environment.
>     
>     RPROVIDES_${PN} += "kernel-module-hello"
>     Copy to clipboard

For more information about the out-of-tree module, see [Working with
Out-of-Tree
Modules](https://docs.yoctoproject.org/kernel-dev/common.html#working-with-out-of-tree-modules).

## Configure the DTB support

Qualcomm Linux uses the following procedures to choose device tree
files, change kernel configuration.

## Platform device tree

SoC device tree support is present in the kernel source in the `arch/arm64/boot/dts/qcom` directory.

Qualcomm device tree source lists the supported device tree for each platform.

**DTB build support in kernel**

To integrate the device tree of a new platform into the kernel build, update the `Makefile`.
The following example shows customizing DTB for the QCS6490 SoC.
Replicate the following method to add new DTBs.

diff --git a/arch/arm64/boot/dts/qcom/Makefile b/arch/arm64/boot/dts/qcom/Makefile
    index 183aeba47193..a7815c774f7c 100644
    --- a/arch/arm64/boot/dts/qcom/Makefile
    +++ b/arch/arm64/boot/dts/qcom/Makefile
    dtb-$(CONFIG_ARCH_QCOM)        += qcs6490-rb3gen2.dtb
    Copy to clipboard

**DTB inclusion in machine configuration**

The Yocto machine configuration is also updated to include the corresponding device tree blob. For example, to add the device tree for QCS6490 machine support, use the following file:

`meta-qcom/conf/machine/qcs6490-rb3gen2-core-kit.conf`:

# List of dtbs for corresponding supported qcs6490 platforms
    KERNEL_DEVICETREE ?= " \
                    qcom/qcs6490-rb3gen2.dtb \
                    qcom/qcs6490-rb3gen2-industrial-mezzanine.dtbo \
                    qcom/qcs6490-rb3gen2-vision-mezzanine.dtbo \
                    "
    Copy to clipboard

Note

See machine configuration files in the `meta-qcom/conf/machine/*.conf` directory for different machines.

In addition, update `conf/machine/include/fit-dtb-compatible.inc` to map the new DTB name to its board compatible string(s), so the boot firmware can select the correct DTB at runtime:

FIT_DTB_COMPATIBLE[qcs6490-rb3gen2] = " \
        qcom,qcs5430-iot \
        qcom,qcs6490-iot \
    "
    FIT_DTB_COMPATIBLE[qcs6490-rb3gen2+qcs6490-rb3gen2-staging] = " \
        qcom,qcs5430-iot-staging \
        qcom,qcs6490-iot-staging \
    "
    FIT_DTB_COMPATIBLE[qcs6490-rb3gen2+qcs6490-rb3gen2-industrial-mezzanine] = " \
        qcom,qcs5430-iot-subtype9 \
        qcom,qcs6490-iot-subtype9 \
    "
    FIT_DTB_COMPATIBLE[qcs6490-rb3gen2+qcs6490-rb3gen2-vision-mezzanine] = " \
        qcom,qcs5430-iot-subtype2 \
        qcom,qcs6490-iot-subtype2 \
    "
    FIT_DTB_COMPATIBLE[qcs6490-rb3gen2+qcs6490-rb3gen2-vision-mezzanine-camx] = " \
        qcom,qcs5430-iot-camx \
        qcom,qcs5430-iot-subtype2-camx \
        qcom,qcs6490-iot-camx \
        qcom,qcs6490-iot-subtype2-camx \
    "
    Copy to clipboard

For more information about the FIT-based DTB selection mechanism and adding your
DTB or DTBO to the FIT image, see [FIT based DTB packaging](https://docs.qualcomm.com/doc/80-80022-3/topic/boot-flow-and-architecture-overview.html#section-rx4-yjs-s1c).

For more information about the device tree specification, see [The Devicetree Specification](https://www.devicetree.org/specifications/).

For the Linux kernel documentation for device tree, see [Linux and the Devicetree](https://docs.kernel.org/devicetree/usage-model.html).

## Compile the kernel independent of Yocto

Qualcomm Linux kernel can also be compiled without Yocto build system support.

**Prerequisites**

Provision the following dependencies to setup the kernel compilation process:

> 
> 
> - aarch64 toolchain
> - systemd-boot EFI stub to include it as a part of the UKI image
> - systemd ukify tool to package the kernel image, initramfs, and optionally DTB into the UKI image
> - initramfs with UKI image
> - ESP image that carries the updated UKI and must be flashed to boot the device

These dependencies, with necessary tools, are provisioned with a
[Docker](https://github.com/qualcomm-linux/kmake-image) to develop a standalone kernel.

**Setup docker**

Setup the docker, using the following commands:

git clone https://github.com/qualcomm-linux/kmake-image.git
    cd kmake-image
    docker build --build-arg USER_ID=$(id -u) --build-arg GROUP_ID=$(id -g) --build-arg USER_NAME=$(whoami) -t kmake-image .
    cd ..
    Copy to clipboard

**Setup aliases**

Setup the aliases, using the following commands:

alias kmake-image-run='docker run -it --rm --user $(id -u):$(id -g) --workdir="$PWD" -v "$(dirname $PWD)":"$(dirname $PWD)" kmake-image'
    alias kmake='kmake-image-run make'
    Copy to clipboard

**Get the Linux kernel source**

Clone the Linux kernel source from the GitHub repository hosted at
[Qualcomm-linux Github](https://github.com/qualcomm-linux/kernel/tree/qcom-6.18.y/).

To clone the repository and get the source code, using the following commands:

git clone --branch qcom-6.18.y https://github.com/qualcomm-linux/kernel.git kernel
    Copy to clipboard

**Get ramdisk**

Use the custom initramfs to get the initramfs for the arm64 hosted at [KernelCI](http://storage.kernelci.org/images/rootfs/buildroot/buildroot-baseline/20230703.0/arm64/rootfs.cpio.gz), using the following command:

mkdir artifacts
    wget -O artifacts/ramdisk.gz http://storage.kernelci.org/images/rootfs/buildroot/buildroot-baseline/20230703.0/arm64/rootfs.cpio.gz
    Copy to clipboard

**Get systemd-boot binaries**

Get the systemd-boot binaries using the following command:

wget -O artifacts/systemd-boot-efi.deb http://ports.ubuntu.com/pool/universe/s/systemd/systemd-boot-efi_255.4-1ubuntu8_arm64.deb
    dpkg-deb -xv artifacts/systemd-boot-efi.deb artifacts/systemd
    Copy to clipboard

**Get qcom-dtb-metadata**

When building the kernel with Yocto, the meta-qcom layer manages DTB packaging
by generating a FIT image based on the configuration specified in the machine
configuration. For more information about FIT-based DTB packaging, see
:ref: <cite>FIT based DTB packaging &lt;section_rx4_yjs_s1c&gt;</cite>.

When developing the kernel as a standalone component, you must package the DTB
manually using a static ITS configuration file that this project maintains.

Clone qcom-dtb-metadata source from the GitHub repository hosted at
[qcom-dtb-metadata](https://github.com/qualcomm-linux/qcom-dtb-metadata) to
get `qcom-metadata.dts` and `qcom-next-fitimage.its` file for FIT Based DTB
packaging and selection as required by Qualcomm Linux.

To clone the repository and get the source code, using the following commands:

git clone https://github.com/qualcomm-linux/qcom-dtb-metadata.git artifacts/qcom-dtb-metadata
    Copy to clipboard

**Build kernel**

Use `defconfig, prune.config and qcom.config` to configure kernel and build using the following instructions:

cd kernel
    mkdir -p ../kobj
    env -u KCONFIG_CONFIG ./scripts/kconfig/merge_config.sh -m -O ../kobj arch/arm64/configs/defconfig \
          arch/arm64/configs/prune.config \
          arch/arm64/configs/qcom.config
    kmake O=../kobj olddefconfig
    kmake O=../kobj -j$(nproc)
    kmake O=../kobj -j$(nproc) dir-pkg INSTALL_MOD_STRIP=1
    Copy to clipboard

**Package DLKMs into ramdisk**

Package the DLKMs into the ramdisk, using the following command:

(cd ../kobj/tar-install ; find lib/modules | cpio -o -H newc -R +0:+0 | gzip -9 >> ../../artifacts/ramdisk.gz)
    Copy to clipboard

**Generate efi.bin for boot/ESP partition**

Generate the `efi.bin` for boot/ESP partition, using the following commands:

cd ..
    kmake-image-run generate_boot_bins.sh efi --ramdisk artifacts/ramdisk.gz \
       --systemd-boot artifacts/systemd/usr/lib/systemd/boot/efi/systemd-bootaa64.efi \
       --stub artifacts/systemd/usr/lib/systemd/boot/efi/linuxaa64.efi.stub \
       --linux kobj/arch/arm64/boot/Image \
       --cmdline "${CMDLINE}" \
       --output images
    Copy to clipboard

**Generate dtb.bin for targets supporting device tree**

Generate the FIT based `dtb.bin` for all targets that support the device tree, using the following command:

kmake-image-run make_fitimage.sh \
       --metadata artifacts/qcom-dtb-metadata/qcom-metadata.dts \
       --its artifacts/qcom-dtb-metadata/qcom-next-fitimage.its \
       --kobj kobj \
       --output images
    Copy to clipboard

The resulting **efi.bin** and **dtb.bin** are gathered in images directory and are ready to be booted on a QCS6490 RB3Gen2.

After you run the previous command, `efi.bin` and `dtb.bin` are present in the images directory and both files are ready to boot on a QCS6490 Qualcomm Dragonwing™ RB3 Gen 2.”

**Flash the binaries and boot**

Flash the binaries and boot the device, using the following commands:

fastboot flash efi images/efi.bin
    fastboot flash dtb_a images/dtb.bin
    fastboot reboot
    Copy to clipboard

For more information about how to flash the EFI image and reboot, see [Bring up the device](https://docs.qualcomm.com/doc/80-80022-3/topic/getting_started_chapter2.html#flash-images-and-boot).

Note

To build additional out-of-tree kernel modules, rely on the full Yocto build mechanism.

## Next steps

- To debug the kernel issues, see [Configure debug methods](https://docs.qualcomm.com/doc/80-80022-3/topic/debug.html#debug).

Last Published: Apr 27, 2026

[Previous Topic
Boot flow and architecture overview](https://docs.qualcomm.com/bundle/publicresource/80-80022-3/topics/boot-flow-and-architecture-overview.md) [Next Topic
Configure the remoteprocessor (remoteproc) subsystems](https://docs.qualcomm.com/bundle/publicresource/80-80022-3/topics/remoteproc-overview.md)