# Yocto 支持

Qualcomm Linux `meta-qcom-hwe` 层支持 `linux-qcom-base_6.6.bb` 和 `linux-qcom-custom_6.6.bb` 配方，这些配方为受支持的机器获取并编译 Qualcomm Linux 内核。

有关可用配方的更多信息，请参见[编译 Yocto 镜像配方和内核配置](https://docs.qualcomm.com/doc/80-70018-3SC/topic/getting_started_chapter2.html#kernel-configuration-image)。

## 获取内核源代码

内核源代码可作为 BitBake 编译版本的一部分从 Codelinaro 存储库中获取。

**Yocto 内核**

MACHINE=<SoC>-<board>-<variant> 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/<SoC>-<board>-<variant>/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

该命令的计算机名称与 SoC-board-variant 名称相同。例如，对于 QCS6490 SoC，机器名称为 `QCS6490`，板卡为 `rb3gen2`，变体为 `Visionkit`。

有关设置和获取源代码的更多信息，请参见 [Qualcomm Linux 编译指南](bundle/publicresource/topics/80-70018-254)。

## 获取内核配方

Qualcomm Linux 维护 `meta-qcom-hwe` 层，并将内核配方文件托管在以下位置：

- 基本 BSP：`meta-qcom-hwe/recipes-kernel/linux//linux-qcom-base_6.6.bb` 文件。
- 自定义 BSP：`meta-qcom-hwe/recipes-kernel/linux//linux-qcom-custom_6.6.bb` 文件。

`PREFERRED_PROVIDER_virtual/kernel` 在 `meta-qcom-hwe/conf/machine/include/qcom-base.inc` 文件中定义为 `linux-qcom-base` 或 `linux-qcom-custom`。

如需获取内核配方，运行以下命令：

# kernel recipe location
       ls -l meta-qcom-hwe/recipes-kernel/linux/
       linux-kernel-headers-install_6.6.bb
       linux-kernel-qcom-headers_6.6.bb
       linux-qcom-base-6.6
       linux-qcom-base_6.6.bb
       linux-qcom-custom
       linux-qcom-custom_6.6.bb
    Copy to clipboard

## 解压内核源代码

克隆元数据层后，解包内核源代码，以便进行开发和定制。

要解包源代码，请运行以下命令：

# unpack kernel
    # checkout kernel source aligned to upstream LTS base with patches applied from recipe
    # Following would checkout kernel source in build-qcom-wayland/workspace/sources/linux-qcom-base/
    $  devtool modify linux-qcom-base
    Copy to clipboard

Note

对于定制 BSP 变体，请使用 `linux-qcom-custom`。

## 更改内核

内核的更改或定制在 `build-qcom-wayland/workspace/sources/linux-qcom-base` 工作区进行。

若要修改内核配置，可运行以下命令：

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

Note

对于定制 BSP 变体，请使用 `linux-qcom-custom`。

## 提交内核更改

要提交更改，请运行以下 Git 命令：

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

## 编译内核镜像

完成更改后，若要编译内核和镜像，请运行以下命令：

> 
> 
> # to build kernel use
>       devtool build linux-qcom-base
>     Copy to clipboard

# and following to build the image
      devtool build-image qcom-console-image
    Copy to clipboard

# built images are produced in standard location
      ls build-qcom-wayland/tmp-glibc/deploy/images/<SoC>-<board>-<variant>/
    Copy to clipboard

Note

要编译定制 BSP，使用 `linux-qcom-custom`。

## 维护内核更改

使用 Devtool 开发并导出补丁，并在 `meta-mylayer` 层创建一个附加文件。要创建自己的层，首先将其添加到主机内核 `bbappend` 文件并进行更改。

运行以下命令，在元数据层创建并添加内核补丁：

# 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-qcom-base
      bitbake-layers add-layer ~/meta-mylayer
    
    # following would update the meta-mylayer recipe and the change
      devtool finish linux-qcom-base ~/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-qcom-base  linux-qcom-base_%.bbappend
    
    meta-mylayer/recipes-kernel/linux/linux-qcom-base:
    0001-my-patch.patch  devtool-fragment.cfg
    
      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

运行 `devtool finish` 命令后，`~/meta-mylayer` 层会更新以下内容：

- 相应的内核更改以补丁形式托管在 `meta-mylayer/recipes-kernel/linux/linux-qcom-base/*.patch`。
- 使用这些补丁添加和更新 `meta-mylayer/recipes-kernel/linux/linux-qcom-base_%.bbappend SRC_URI`。
- 开发完成后移除 `build-qcom-wayland/workspace`。

Note

对于定制 BSP 变体，请使用 `linux-qcom-custom`。

## 清理工作区

使用以下 Devtool 和 BitBake 命令清理工作区：

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

Last Published: May 05, 2025

[Previous Topic
实时 (RT) 内核概述](https://docs.qualcomm.com/bundle/publicresource/80-70018-3SC/topics/real_time_kernel_overview.md) [Next Topic
自定义内核](https://docs.qualcomm.com/bundle/publicresource/80-70018-3SC/topics/customize.md)