# Yocto 支持

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

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

有关可用 recipe 的详细信息，参见[编译 Yocto 镜像 recipe 和内核配置](https://docs.qualcomm.com/doc/80-70014-3Y/topic/getting_started_chapter2.html#kernel-configuration1)章节。

## 内核源代码

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

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

**Yocto 内核**

    $ 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

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

## 内核 recipe

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

Qualcomm Linux 维护 `meta-qcom-hwe` 层，并将内核 recipe 存放在 ` meta-qcom-hwe/recipes-kernel/linux/linux-kernel-qcom_6.6.bb` 文件中。

`PREFERRED_PROVIDER_virtual/kernel` 在 `meta-qcom-hwe/conf/machine/include/qti-common.inc` 文件中被定义为 `linux-kernel-qcom`。对 `virtual/kernel` 的所有引用都指向 `linux-kernel-qcom` recipe 文件。

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

    $ 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

## 解包内核源代码

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

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

解包源代码可使用下列命令：

    # 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

运行命令后，BitBake 会从工作区选取内核，并应用
 `bbappend` recipe。

## 更改内核

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

内核的更改或定制在 `build-qcom-wayland/workspace/sources/linux-kernel-qcom` 工作区完成。

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

    # 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

## 提交内核更改

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

使用下列 Git 命令提交修改：

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

## 编译内核镜像

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

更改完成后，可以按照以下步骤编译内核和镜像：

# 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

## 维护内核更改

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

使用 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-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

执行 `devtool finish` 命令后，`~/meta-mylayer` 层更新如下：

- 相应的内核更改将作为补丁存放在 `meta-mylayer/recipes-kernel/linux/linux-kernel-qcom/*.patch` 中。
- 添加和更新 `meta-mylayer/recipes-kernel/linux/linux-kernel-qcom_%.bbappend SRC_URI` 以及这些补丁。
- `build-qcom-wayland/workspace` 在开发完成后可以移除。

## 清理工作区

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

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

# 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: Aug 22, 2024

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