# Yocto 支持

Qualcomm Linux `meta-qcom-hwe` 层支持 `linux-qcom-base_6.6.bb` 和 `linux-qcom-custom_6.6.bb`
recipe，该 recipe 会获取和编译适用于支持的机器的 Qualcomm Linux 内核。

有关可用 recipe 的详细信息，参见 [编译 Yocto 镜像 recipe 和内核配置](https://docs.qualcomm.com/doc/80-70015-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-70015-254)。

## 内核 recipe

Qualcomm Linux 维护 `meta-qcom-hwe` 层，并将内核 recipe 文件存放在以下位置：

- 基本 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`
。

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

# 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
    
    # 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/<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
    
    # 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: Dec 15, 2024

[Previous Topic
功能](https://docs.qualcomm.com/bundle/publicresource/80-70015-3SC/topics/features.md) [Next Topic
定制](https://docs.qualcomm.com/bundle/publicresource/80-70015-3SC/topics/customize.md)