# 用户定制

本节提供自定义 Qualcomm Linux 的说明，包含以下主题：

- 添加自定义机器配置
- 修改分发包配置
- 创建镜像配方
- 自定义内核

## 添加自定义机器配置

如需添加自定义机器配置并重新生成工作区，请执行以下操作：

1. 要添加机器，请在 `layers/meta-qcom-hwe/conf/machine/` 位置引入新的机器配置文件； 例如，`layers/meta-qcom-hwe/conf/machine/test-board.conf`。
2. 如果新机器使用的是 QCS6490 硬件SoC，则在新建的文件中添加以下内容：

#@TYPE: Machine
        #@NAME: TestBoard
        #@DESCRIPTION: Machine configuration for a development board, based on Qualcomm QCS6490
        
        require conf/machine/include/qcom-qcs6490.inc
        Copy to clipboard
3. 导入setup-environment脚本：

MACHINE=test-board DISTRO=qcom-wayland QCOM_SELECTED_BSP=custom source setup-environment
        Copy to clipboard

Note

如果您有权访问 `meta-qcom-extras`，请将其 `EXTRALAYERS ?=` `${WORKSPACE}/layers/meta-qcom-extras` `conf/bblayers.conf` 添加到文件中。
4. 如需为添加的计算机生成镜像，请运行以下命令：

bitbake qcom-multimedia-image
        Copy to clipboard

## 添加自定义分发包配置

以下小节介绍如何添加自定义分发包配置并重建工作区。

### Qualcomm 定义的分发包配置概述

为 Qualcomm Linux 定义的参考分发包位于 `<workspace>/layers/meta-qcom-distro/conf/distro/qcom-wayland.conf`。可以使用以下命令检查DISTRO\_FEATURES变量：

bitbake -e | grep ^DISTRO_FEATURES=
    Copy to clipboard

输出：

DISTRO_FEATURES="acl alsa argp bluetooth debuginfod ext2 ipv4 ipv6 largefile pcmcia usbgadget usbhost wifi xattr nfs zeroconf pci 3g nfc  vfat seccomp pam overlayfs acl xattr selinux ptest security virtualization tpm wayland vulkan opengl systemd pulseaudio gobject-introspection-data ldconfig"
    Copy to clipboard

Note

[分发包特性](https://docs.yoctoproject.org/5.0.6/singleindex.html#distro-features)描述了输出中显示的 DISTRO\_FEATURES。

### 添加分发配置

要添加分发包配置文件，请执行以下操作：

1. 在 `<workspace>/layers/meta-qcom-distro/conf/distro` 中添加一个 `test-distro.conf` 文件。
2. 使用与 `qcom-wayland.conf` 相同的内容， 即，`cp qcom-wayland.conf test-distro.conf`。
3. 在 `test-distro.conf` 文件中配置 `DISTRO_NAME = "Test Reference Distro with Wayland"`。
4. 在 `test-distro.conf` 文件中配置 `DISTROOVERRIDES = "test-dist"`。
5. 使用source设置环境并用export配置环境变量，如下所示：

MACHINE="qcs6490-rb3gen2-core-kit" DISTRO="test-distro" source setup-environment
        Copy to clipboard

用source配置环境后，当前工作区目录更改为 `<workspace>/build-test-distro`。要验证定义的 `test-distro` 是否已生效，请打开 `conf/auto.conf` 文件以确认以下内容：

# This configuration file is dynamically generated every time
    # set_bb_env.sh is sourced to set up a workspace.  DO NOT EDIT.
    #--------------------------------------------------------------
    DISTRO ?= "test-distro"
    Copy to clipboard

若要验证输出，请运行以下命令：

bitbake -e | grep ^DISTROOVERRIDES=
    DISTROOVERRIDES="test-dist"
    Copy to clipboard

Note

如果您有权访问 `meta-qcom-extras`，请将其 `EXTRALAYERS ?=` `${WORKSPACE}/layers/meta-qcom-extras` `conf/bblayers.conf` 添加到文件中。

若要重新生成镜像，请运行以下命令：

bitbake qcom-multimedia-image
    Copy to clipboard

### 启用或禁用 DISTRO\_FEATURES

DISTRO\_FEATURES 提供一种机制来验证哪些软件包必须包含在生成的镜像中。您可以通过 DISTRO\_FEATURES 变量选择要启用的功能，该变量在 `test-distro.conf` 分发包的配置文件中设置或附加。有关更多信息，请参阅[分发包特性](https://docs.yoctoproject.org/5.0.6/singleindex.html#distro-features)。

Note

选择由社区定义的功能。

1. 打开文件 `test-distro.conf` 并添加下面一行内容 ：

DISTRO_FEATURES:append = " cramfs"
        Copy to clipboard
2. 测试更改是否已生效，然后重新生成：

bitbake -e | grep ^DISTRO_FEATURES=
        Copy to clipboard

    输出如下：

DISTRO_FEATURES="acl alsa argp bluetooth debuginfod ext2 ipv4 ipv6 largefile pcmcia usbgadget usbhost wifi xattr nfs zeroconf pci 3g nfc  vfat seccomp pam overlayfs acl xattr selinux ptest security virtualization tpm usrmerge sota wayland vulkan opengl cramfs systemd pulseaudio gobject-introspection-data ldconfig"
        Copy to clipboard
3. 若要重新生成，请运行以下命令：

bitbake qcom-multimedia-image
        Copy to clipboard

## 添加镜像配方

**添加镜像配方**

1. 要添加镜像配方，请将当前目录更改为 `<workspace>/layers/meta-qcom-distro/recipes-products/images`。
2. 创建一个文件，例如 `test-image.bb`，并添加以下内容：

SUMMARY = "Test image"
        
        LICENSE = "BSD-3-Clause-Clear"
        
        IMAGE_FEATURES += "splash \
            tools-debug \
            debug-tweaks \
            enable-adbd \
        "
        
        inherit core-image features_check extrausers image-adbd image-qcom-deploy image-efi
        
        REQUIRED_DISTRO_FEATURES = "pam systemd"
        
        CORE_IMAGE_BASE_INSTALL += " \
            kernel-modules \
            packagegroup-filesystem-utils \
        "
        
        CORE_IMAGE_EXTRA_INSTALL += "overlayfs-qcom-paths"
        Copy to clipboard
3. 源环境：

MACHINE=qcs6490-rb3gen2-core-kit DISTRO=qcom-wayland source setup-environment
        Copy to clipboard
4. 以下步骤是可选的，仅当您已经在工作区中克隆 `meta-qcom-extras` 时适用。

    打开文件 `conf/bblayer.conf` 并验证内容中的更改：

    | 更改前 | 更改后 |
    | --- | --- |
    | # Add your overlay location to EXTRALAYERS<br>        # Make sure to have a conf/layers.conf in there<br>        EXTRALAYERS ?= ""<br>        Copy to clipboard | # Add your overlay location to EXTRALAYERS<br>        # Make sure to have a conf/layers.conf in there<br>        EXTRALAYERS ?= "${WORKSPACE}/layers/meta-qcom-extras"<br>        Copy to clipboard |
5. 使用BitBake命令编译：

bitbake test-image
        Copy to clipboard

生成的镜像如下：

build-qcom-wayland> $ ls tmp-glibc/deploy/images/qcs6490-rb3gen2-core-kit/test-image
    aop.mbn     gpt_backup0.bin  gpt_backup5.bin  gpt_main4.bin  kernel-modules.tgz  patch2.xml             prog_firehose_lite.elf  rawprogram2.xml  system.img    xbl_config.elf
    cpucp.elf   gpt_backup1.bin  gpt_main0.bin    gpt_main5.bin  logfs_ufs_8mb.bin   patch3.xml             qdl                     rawprogram3.xml  tz.mbn        xbl.elf
    devcfg.mbn  gpt_backup2.bin  gpt_main1.bin    hypvm.mbn      multi_image.mbn     patch4.xml             qupv3fw.elf             rawprogram4.xml  uefi.elf      XblRamdump.elf
    dtb.bin     gpt_backup3.bin  gpt_main2.bin    Image          patch0.xml          patch5.xml             rawprogram0.xml         rawprogram5.xml  uefi_sec.mbn  zeros_5sectors.bin
    efi.bin     gpt_backup4.bin  gpt_main3.bin    imagefv.elf    patch1.xml          prog_firehose_ddr.elf  rawprogram1.xml         shrm.elf         vmlinux
    Copy to clipboard

## 定制镜像特性

本节将举例说明如何自定义镜像：

**从镜像中删除显示软件包**

`layers/meta-qcom-distro/recipes-products/packagegroups/packagegroup-qcom-multimedia.bb`

| 更改前 | 更改后 |
| --- | --- |
| RDEPENDS:${PN}:append:qcom-custom-bsp = "\<br>        camera-server \<br>        packagegroup-qcom-audio \<br>        packagegroup-qcom-bluetooth \<br>        packagegroup-qcom-camera \<br>        packagegroup-qcom-display \<br>        packagegroup-qcom-fastcv \<br>        packagegroup-qcom-graphics \<br>        packagegroup-qcom-iot-base-utils \<br>        packagegroup-qcom-location \<br>        packagegroup-qcom-video \<br>        packagegroup-qcom-voiceai \<br>        "<br>    Copy to clipboard | RDEPENDS:${PN}:append:qcom-custom-bsp = "\<br>        camera-server \<br>        packagegroup-qcom-audio \<br>        packagegroup-qcom-bluetooth \<br>        packagegroup-qcom-camera \<br>        packagegroup-qcom-fastcv \<br>        packagegroup-qcom-graphics \<br>        packagegroup-qcom-iot-base-utils \<br>        packagegroup-qcom-location \<br>        packagegroup-qcom-video \<br>        packagegroup-qcom-voiceai \<br>        "<br>    Copy to clipboard |

运行 `bitbake qcom-multimedia-image` 命令后，显示相关软件包将从编译版本中删除。来自 `packagegroup-qcom-display.bb` 软件包组的内容已从镜像中删除。

**从镜像** **移除蓝牙**^®^

`layers/meta-qcom-distro/recipes-products/packagegroups/packagegroup-qcom-multimedia.bb`

| 更改前 | 更改后 |
| --- | --- |
| RDEPENDS:${PN}:append:qcom-custom-bsp = "\<br>       camera-server \<br>       packagegroup-qcom-audio \<br>       packagegroup-qcom-bluetooth \<br>       packagegroup-qcom-camera \<br>       packagegroup-qcom-display \<br>       packagegroup-qcom-fastcv \<br>       packagegroup-qcom-graphics \<br>       packagegroup-qcom-iot-base-utils \<br>       packagegroup-qcom-location \<br>       packagegroup-qcom-video \<br>       packagegroup-qcom-voiceai \<br>       "<br>    Copy to clipboard | RDEPENDS:${PN}:append:qcom-custom-bsp = "\<br>       camera-server \<br>       packagegroup-qcom-audio \<br>       packagegroup-qcom-camera \<br>       packagegroup-qcom-fastcv \<br>       packagegroup-qcom-graphics \<br>       packagegroup-qcom-iot-base-utils \<br>       packagegroup-qcom-location \<br>       packagegroup-qcom-video \<br>       packagegroup-qcom-voiceai \<br>       "<br>    Copy to clipboard |

运行 `bitbake qcom-multimedia-image` 命令后，蓝牙相关软件包将从编译版本中删除。来自 `packagegroup-qcom-bluetooth.bb` 软件包组的内容已从镜像配方中删除。

## 修改分区布局

本节介绍如何添加、删除、修改或重命名分区。定义 UFS 设备分区的配置文件位于 `layers/meta-qcom-hwe/recipes-devtools/partition-utils/qcom-partition-confs/qcm6490-partitions.conf`。若要添加分区，请向此文件添加行条目。要删除分区，请删除相应的条目以从要刷写的镜像集中删除目标分区。

许多分区对于实现相关功能至关重要。要了解此文件在生成分区表中的作用的详细信息，请参阅[在 Qualcomm Linux 中管理分区](https://docs.qualcomm.com/doc/80-70018-27SC/topic/qualcomm_linux_software_components.html#managing-partitions-in-qualcomm-linux)。

**示例 1：添加分区**

要在 LUN0 中添加名称为 `test` 的分区，请以下行添加到 `qcm6490-partitions.conf` 中的LUN0 下：

--partition --lun=0 --name=test --size=4096KB --type-guid=1B81F7E6-F50D-419B-A739-2AEFF8DA3335
    Copy to clipboard

这会向 LUN0 添加一个 4 MB 的分区测试和一个由您确定的 GUID。此分区未刷写任何镜像，但在设备启动后可用作原始分区。由于该分区已添加到 LUN0，因此会显示在以下任一选项的路径下：

- `/dev/sda<N>`
- `/dev/disk/by-partlabel/test`

Note

要反映 `qcm6490-partitions.conf` 中的更改，请更新首选提供程序。有关更多信息，请参阅[修改分区](https://docs.qualcomm.com/doc/80-70018-27SC/topic/qualcomm_linux_software_components.html#modify-partition)。

**示例 2：添加一个示例分区，其中包含要刷写到新创建的分区的二进制文件**

要在 LUN0 中添加名称为 `test1` 的分区，请以下行添加到LUN0 部分下的 `qcm6490-partitions.conf`：

--partition --lun=0 --name=test --size=4096KB --type-guid=1B81F7E6-F50D-419B-A739-2AEFF8DA3335 --filename=test1.bin
    Copy to clipboard

在 `build-qcom-wayland/tmp-glibc/deploy/images/qcs6490-rb3gen2-core-kit/$(image_name)` 中部署新的 `test1.bin` 二进制文件。

## devtool的使用

以下示例展示了 Qualcomm 软件组件devtool的用法：

- **内核**

    可参阅 [Yocto 支持](https://docs.qualcomm.com/bundle/publicresource/topics/80-70018-3/yocto-kernel-support.html)。
- **QDL 工具**

    使用devtool修改创建的工作区中的QDL源。

devtool modify qdl
        INFO: Source tree extracted to <workspace>/build-qcom-wayland/workspace/sources/qdl
        INFO: Using source tree as build directory since that would be the default for this recipe
        INFO: Recipe qdl now set up to build from <workspace>/build-qcom-wayland/workspace/sources/qdl
        Copy to clipboard

    1. 以下源代码树在本地签出：

tree -L 2 build-qcom-wayland/workspace/
            build-qcom-wayland/workspace/
            ├── appends
            │   └── qdl_git.bbappend
            ├── conf
            │   └── layer.conf
            ├── README
            └── sources
                └── qdl
            Copy to clipboard
    2. 检查已签出的QDL源代码树：

ls workspace/sources/qdl/
            firehose.c  LICENSE  Makefile  patch.c  patch.h  program.c  program.h  qdl.c  qdl.h  README  sahara.c  ufs.c  ufs.h  util.c
            Copy to clipboard
    3. 在 `workspace/sources/qdl/` 下更改源代码树并编译您的更改：

devtool build qdl
            devtool build-image qcom-multimedia-image
            Copy to clipboard
    4. 生成的镜像位于路径 `build-qcom-wayland/tmp-glibc/deploy/images/qcs6490-rb3gen2-core-kit/qcom-multimedia-image` 中。
- **Weston**

devtool modify weston
        INFO: Adding local source files to srctree...
        INFO: Source tree extracted to <workspace>/build-qcom-wayland/workspace/sources/pulseaudio
        INFO: Recipe weston now set up to build from <workspace>/build-qcom-wayland/workspace/sources/weston
        Copy to clipboard

    1. 以下源代码树在本地签出：

tree -L 2 build-qcom-wayland/workspace/
            build-qcom-wayland/workspace/
            ├── appends
            │   └── weston_10.0.2.bbappend
            ├── conf
            │   └── layer.conf
            ├── README
            └── sources
                └── weston
            Copy to clipboard
    2. 检查已签出的 Weston 源代码树：

ls workspace/sources/weston/
            clients           COPYING      desktop-shell     include      libweston          meson.build        oe-local-files  pipewire    releasing.rst  tests  weston.ini.in
            compositor        data         doc               ivi-shell    libweston-desktop  meson_options.txt  oe-logs         protocol    remoting       tools  xwayland
            CONTRIBUTING.rst  DCO-1.1.txt  fullscreen-shell  kiosk-shell  man                notes.txt          oe-workdir      README.rst  shared         wcap
            Copy to clipboard
    3. 在 `workspace/sources/weston/` 下更改源代码树并编译您的更改：

devtool build weston
            devtool build-image qcom-multimedia-image
            Copy to clipboard
    4. 生成的镜像位于路径 `build-qcom-wayland/tmp-glibc/deploy/images/qcs6490-rb3gen2-core-kit/qcom-multimedia-image` 中。

## 自定义内核

要定制内核，请参阅 [Qualcomm Linux 内核指南](https://docs.qualcomm.com/bundle/publicresource/topics/80-70018-3/)。

## 将第三方层添加到工作区

要将第三方层添加到工作空间，请执行以下步骤：

1. 克隆 `<WORKSPACE>/layers/` 下的层。
2. 在 `layers/meta-qcom-distro/conf/bblayers.conf` 文件中添加层作为 `BBLAYERS` 变量，如下所示：

# These layers hold machine specific content, aka Board Support Packages
        BSPLAYERS ?= " \
          ${WORKSPACE}/layers/meta-testlayer \
          ${WORKSPACE}/layers/meta-qcom-hwe \
          ${WORKSPACE}/layers/meta-qcom \
        "
        Copy to clipboard

克隆和添加layer使BitBake可以解析层。

## 创建用于调试的编译版本

要在发出 Yocto BitBake 编译指令之前生成导出 `DEBUG_BUILD=1` 的调试build，运行以下命令：

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

要了解在 `DEBUG_BUILD` 设为 **1** 时使用哪些内核的 defconfig 和 config 片段，可参见[内核配方](https://docs.qualcomm.com/doc/80-70018-27SC/topic/qualcomm_linux_metadata_layers_overview.html#kernel-recipes-section)下的内核配置。

## 为最优化的启动 KPI 创建build

要实现设备的最佳启动时间，请使用 `PERFORMANCE_BUILD` 变量。当 `PERFORMANCE_BUILD` 变量设置为 **1** 时，它修改 `KERNEL_CMDLINE_EXTRA` 以从命令行中删除 **console** 选项。当 `DEBUG_BUILD` 设置为 **0** 时，`PERFORMANCE_BUILD` 变量生效。

要了解该 `PERFORMANCE_BUILD` 变量如何影响启动时间，请参阅下表：

|  | PERFORMANCE\_BUILD=“0” | PERFORMANCE\_BUILD=“1” |
| --- | --- | --- |
| `DEBUG_BUILD=0` | UART上的控制台已启用 | <ul class="simple"><br><li><p>UART上的控制台已禁用</p></li><br><li><p>最佳启动时间</p></li><br></ul> |
| `DEBUG_BUILD=1` | UART上的控制台已启用 | <ul class="simple"><br><li><p>当 <code class="docutils literal notranslate"><span class="pre">DEBUG_BUILD</span></code> 设置为 <code class="docutils literal notranslate"><span class="pre">&quot;1&quot;</span></code> 时，<code class="docutils literal notranslate"><span class="pre">PERFORMANCE_BUILD=&quot;1&quot;</span></code>。</p></li><br></ul> |

Last Published: May 06, 2025

[Previous Topic
Qualcomm Linux软件组件](https://docs.qualcomm.com/bundle/publicresource/80-70018-27SC/topics/qualcomm_linux_software_components.md) [Next Topic
调试](https://docs.qualcomm.com/bundle/publicresource/80-70018-27SC/topics/debug.md)