> ## Documentation Index
> Fetch the complete documentation index at: https://dragonwingdocs.qualcomm.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Build and install the RT kernel

The Qualcomm<sup>®</sup> Linux RT kernel is built using the same Yocto toolchain as the
standard kernel. The `meta-qcom` layer provides a dedicated Bitbake recipe that
fetches the LTS RT kernel sources, applies the `PREEMPT_RT` patch set, and
enables the required Kconfig options automatically.

## Choose the correct RT recipe

Two RT recipes are available depending on the target branch:

| **Recipe**                  | **Kernel track** | **Use when**                                          |
| :-------------------------- | :--------------: | :---------------------------------------------------- |
| `linux-qcom-rt_6.18.bb`     |    LTS 6.18.x    | Building for a QLI release (stable, production-ready) |
| `linux-qcom-next-rt_git.bb` |    `qcom-next`   | Building from the latest development tree             |

Both recipes are in `meta-qcom/recipes-kernel/linux/`. The LTS recipe is used
for all examples on this page.

## Build the RT kernel image

### 1. Sync the workspace

Clone `meta-qcom` at a release tag and sync all Qualcomm Linux meta layers before building.
For workspace setup instructions, see
[Build the kernel with Yocto](./build-kernel-yocto).

### 2. Open the kas shell for the RT kernel

```bash theme={null}
kas shell meta-qcom/ci/qcs6490-rb3gen2-core-kit.yml:meta-qcom/ci/linux-qcom-rt-6.18.yml:meta-qcom/ci/qcom-distro-kvm.yml
```

Replace `qcs6490-rb3gen2-core-kit.yml` with the kas machine file for your
target board.

### 3. Build the image

```bash theme={null}
bitbake qcom-multimedia-image
```

Build output is in:

```text theme={null}
build/tmp/deploy/images/<Machine>/<Image>-*.rootfs.qcomflash/
```

### 4. Flash to the device

```bash theme={null}
cd build/tmp/deploy/images/<Machine>/<Image>-*.rootfs.qcomflash/
fastboot flash efi efi.bin
fastboot flash dtb_a dtb.bin
fastboot reboot
```

## Customise the RT kernel

### Add a patch

1. Place the patch file in `recipes-kernel/linux/linux-qcom-6.18/`:

   ```text theme={null}
   meta-qcom/recipes-kernel/linux/linux-qcom-6.18/your_patch.patch
   ```

2. Append it to `SRC_URI` in `linux-qcom-rt_6.18.bb`:

   ```bitbake theme={null}
   SRC_URI += " \
       file://your_patch.patch \
   "
   ```

### Add a Kconfig configuration fragment

1. Create a `.cfg` file with the required `CONFIG_*` symbols:

   ```text theme={null}
   meta-qcom/recipes-kernel/linux/linux-qcom-6.18/configs/qcom_rt_custom.cfg
   ```

   Example contents:

   ```text theme={null}
   CONFIG_CPU_ISOLATION=y
   CONFIG_HZ_1000=y
   # CONFIG_TRANSPARENT_HUGEPAGE is not set
   ```

2. Append it to `SRC_URI` in `linux-qcom-rt_6.18.bb`:

   ```bitbake theme={null}
   SRC_URI += " \
       file://configs/qcom_rt_custom.cfg \
   "
   ```

### Modify the kernel command line

Add or override command-line parameters in `meta-qcom/ci/base.yml` using the
`KERNEL_CMDLINE_EXTRA` variable:

```yaml theme={null}
KERNEL_CMDLINE_EXTRA:append: " isolcpus=7 nohz_full=7 rcu_nocbs=7"
```

For platform-specific command-line tuning variables, set them in
`meta-qcom/conf/machine/<machine-name>.conf`:

```text theme={null}
QCOM_RT_CPU        = "7"
QCOM_IRQAFF        = "0-6"
QCOM_RCU_NOCBS     = "7"
QCOM_RCU_EXPEDITED = "1"
QCOM_CPUIDLE_OFF   = "1"
```

These variables configure the RT core isolation, IRQ affinity, and RCU
callback exclusion on the platform kernel command line.

## Verify the RT kernel is installed

After flashing and rebooting, confirm the RT kernel is active:

```bash theme={null}
uname -r
# Expected: a version string with the -rt suffix, e.g. 6.18.0-rt1+

zcat /proc/config.gz | grep CONFIG_PREEMPT_RT
# Expected: CONFIG_PREEMPT_RT=y
```

For latency validation after installation, see
[RT validation and known limitations](./rt-validation-and-known-limitations).
