# 用户定制

Source: [https://docs.qualcomm.com/doc/80-70014-27Y/topic/user_customizations.html](https://docs.qualcomm.com/doc/80-70014-27Y/topic/user_customizations.html)

## 定制机器配置

Source: [https://docs.qualcomm.com/doc/80-70014-27Y/topic/user_customizations.html](https://docs.qualcomm.com/doc/80-70014-27Y/topic/user_customizations.html)

### Before you begin

### About this task
用户必须遵循以下步骤来添加定制机器配置和重新编译工作区：

### Procedure

1. 要添加机器，应在 `layers/meta-qcom-hwe/conf/machine/` 处引入新的机器配置文件，例如 `layers/meta-qcom-hwe/conf/machine/testBoard.conf`。
2. 在新创建的文件中，添加以下内容：
                
#@TYPE: Machine
        #@NAME: TestBoard
        #@DESCRIPTION: Machine configuration for a development board, based on Qualcomm QCM6490
         
        MACHINEOVERRIDES =. "qcm6490:"
        require qcm6490.confCopy to clipboard
3. 导入 setup-environment 脚本：
                
MACHINE="testBoard" DISTRO="qcom-wayland" source setup-environment
        
        {WORKSPACE}/layers/meta-qcom-extras in file conf/bblayers.conf.Copy to clipboard

Note: 如果有权访问 `meta-qcom-extras`，应将其添加到文件 `conf/bblayers.conf` 中的 `EXTRALAYERS ?= ``${WORKSPACE}/layers/meta-qcom-extras`。
4. 为添加的机器编译镜像：
                
bitbake qcom-multimedia-imageCopy to clipboard

## 定制 distro 配置

Source: [https://docs.qualcomm.com/doc/80-70014-27Y/topic/user_customizations.html](https://docs.qualcomm.com/doc/80-70014-27Y/topic/user_customizations.html)

以下步骤用于添加定制 distro 配置和重新编译工作区。

### Qualcomm 定义的 distro 配置简介

用户定义的参考 distro 位于 `<workspace>/layers/meta-qcom-distro/conf/distro/qcom-wayland.conf` 路径下。可以使用以下命令检查已启用的 DISTRO\_FEATURES 变量：

    bitbake -e | grep ^DISTRO_FEATURES=
     
    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 wayland vulkan opengl systemd pulseaudio gobject-introspection-data ldconfig"
    Copy to clipboard

该 distro 启用了以下 DISTRO\_FEATURES：
- Wayland
- Vulkan
- OpenGL
- pam
- overlayfs
- acl
- xattr
- SELinux
- ptest
- security
- virtualization

Note: 以上各项全部都是标准 DISTRO\_FEATURE 设置，如需更多信息，可访问 [https://docs.yoctoproject.org/4.0.18/singleindex.html#distro-features](https://docs.yoctoproject.org/4.0.18/singleindex.html#distro-features)

### 添加新的 distro 配置

要添加 distro 配置文件，应按照以下步骤操作：
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`

完成步骤 4 后，导入环境并声明环境变量，如下所示：

    MACHINE="qcm6490" DISTRO="test-distro" source setup-environment
     Copy to clipboard

完成导入后，工作区当前目录将更改为 `<workspace>/build-test-distro`。要检查定义的 `test-distro` 是否已生效，应打开文件 `conf/auto.conf`（而不是变量 DISTRO）以确认以下内容：

    # 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，应将其添加到文件 `conf/bblayers.conf` 中的 `EXTRALAYERS ?= ``${WORKSPACE}/layers/meta-qcom-extras`。

要重新编译镜像，应运行以下命令：

    bitbake qcom-multimedia-imageCopy to clipboard

### 启用或禁用 DISTRO\_FEATURES

用户可以按照以下步骤启用或禁用想要定制的 DISTRO\_FEATURES。这些功能提供了一种机制，用于确定生成的镜像中必须包含哪些软件包。用户可以通过 DISTRO\_FEATURES 变量选择想要支持的功能，该变量在发行版本的配置文件 `test-distro.conf` 中设置或附加。选择由社区定义的功能。更多信息，可访问 [https://docs.yoctoproject.org/4.0.18/singleindex.html#distro-features](https://docs.yoctoproject.org/4.0.16/singleindex.html#distro-features)。
1. 打开文件并添加以下代码行：

        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 wayland vulkan opengl cramfs systemd pulseaudio gobject-introspection-data ldconfig"Copy to clipboard
3. 使用以下命令重新编译：

        bitbake qcom-multimedia-imageCopy to clipboard

## 镜像配方

Source: [https://docs.qualcomm.com/doc/80-70014-27Y/topic/user_customizations.html](https://docs.qualcomm.com/doc/80-70014-27Y/topic/user_customizations.html)

### About this task
**添加新的镜像配方**

### Procedure

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=qcm6490 DISTRO=qcom-wayland source setup-environment
        
        export FWZIP_PATH="/path/to/cloned/qclinux.1.0/FWZIP/"
        export CUST_ID="213195"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 ?= ""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"Copy to clipboard |
5. 使用 BitBake 命令编译：
                
bitbake test-imageCopy to clipboard

### Results

生成的镜像如下：

    build-qcom-wayland> $ ls tmp-glibc/deploy/images/qcm6490/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         vmlinuxCopy to clipboard

## 定制功能

Source: [https://docs.qualcomm.com/doc/80-70014-27Y/topic/user_customizations.html](https://docs.qualcomm.com/doc/80-70014-27Y/topic/user_customizations.html)

用户可以定制镜像，例如禁用特定的技术领域。下面给出了示例：

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

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

| 更改前 | 更改后 |
| --- | --- |
| RDEPENDS:${PN} = "\<br>        packagegroup-container \<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-opencv \<br>        packagegroup-qcom-sensors \<br>        packagegroup-qcom-video \<br>        python3-docker-compose \<br>        camera-server \<br>        "Copy to clipboard | RDEPENDS:${PN} = "\<br>        packagegroup-container \<br>        packagegroup-qcom-audio \<br>        packagegroup-qcom-bluetooth \<br>        packagegroup-qcom-camera \<br>        packagegroup-qcom-fastcv \<br>        packagegroup-qcom-graphics \<br>        packagegroup-qcom-opencv \<br>        packagegroup-qcom-sensors \<br>        packagegroup-qcom-video \<br>        python3-docker-compose \<br>        camera-server \<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} = "\<br>        packagegroup-container \<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-opencv \<br>        packagegroup-qcom-sensors \<br>        packagegroup-qcom-video \<br>        python3-docker-compose \<br>        camera-server \<br>        "Copy to clipboard | RDEPENDS:${PN} = "\<br>        packagegroup-container \<br>        packagegroup-qcom-audio \<br>        packagegroup-qcom-camera \<br>        packagegroup-qcom-display \<br>        packagegroup-qcom-fastcv \<br>        packagegroup-qcom-graphics \<br>        packagegroup-qcom-opencv \<br>        packagegroup-qcom-sensors \<br>        packagegroup-qcom-video \<br>        python3-docker-compose \<br>        camera-server \<br>        "Copy to clipboard |

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

## 修改分区布局

Source: [https://docs.qualcomm.com/doc/80-70014-27Y/topic/user_customizations.html](https://docs.qualcomm.com/doc/80-70014-27Y/topic/user_customizations.html)

本节介绍用户如何添加、删除、修改和重命名分区。定义 UFS 设备的分区的配置文件位于 `layers/meta-qcom-hwe/recipes-devtools/partition-utils/partition-confs/generic-ufs-partitions.conf`。如果用户想要添加分区，可以向该文件中添加新的行条目。如果要删除分区，则删除条目会将目标分区从要刷入的镜像集合中删除。
Note: 删除分区之前应先了解其用途。

许多分区对于实现相关功能至关重要。如需详细了解该文件在生成分区表时发挥的作用，可参见[分区](https://docs.qualcomm.com/doc/80-70014-27Y/topic/platform_software_features.html#partitioning)章节。

**示例 1 – 添加新分区**

要在 LUN0 中添加名为 `test` 的分区，应向 LUN0 部分下方的 `generic-ufs-partitions.conf` 中添加以下代码行：

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

这将在 LUN0 中添加分区测试（大小为 4 MB，GUID 由用户决定）。该分区未刷入任何镜像，但可作为设备启动后的原始分区使用。由于该分区已添加到 LUN0，因此会显示在以下任一选项中：
- `/dev/sda<N>`
- `/dev/disk/by-partlabel/test`

**示例 2 – 添加一个示例分区并将一个二进制文件刷写到新创建的分区**

要在 LUN0 中添加名为 `test1` 的分区，应向 LUN0 部分下方的 `generic-ufs-partitions.conf` 中添加以下代码行：

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

将新的二进制文件 `test1.bin` 部署在 `build-qcom-wayland\tmp-glibc\deploy\images\qcm6490\$(image_name)` 中。

## Nodistro 编译版本

Source: [https://docs.qualcomm.com/doc/80-70014-27Y/topic/user_customizations.html](https://docs.qualcomm.com/doc/80-70014-27Y/topic/user_customizations.html)

### About this task

`nodistro` 编译版本对于希望从极简镜像开始并想要控制软件选择和配置的用户来说非常实用。要创建 `nodistro` 编译版本，用户必须设置 `<WORKSPACE>/build-qcom-wayland/conf/local.conf` 并指定 `DISTRO=nodistro`。用户可以运行以下命令从使用 Qualcomm 清单创建的工作区中创建 `nodistro` 编译版本。要创建工作区，可参见 [Qualcomm Linux 编译指南](https://docs.qualcomm.com/bundle/publicresource/topics/80-70014-254/introduction.html)。

### Procedure

1. 在 DISTRO 设为 `nodistro` 的情况下运行 setup-environment：
                
MACHINE="qcm6490" DISTRO="nodistro" source setup-environmentCopy to clipboard

执行完上一条命令后，目录更改为 `build-nodistro`。配置文件中的更改如下：

        # changes in build-nodistro/conf/local.conf
        # Add following lines at end of the file.
        DISTRO_FEATURES:append = " systemd pam overlayfs"
        INITRAMFS_IMAGE = "initramfs-qcom-image"
        INITRAMFS_IMAGE_BUNDLE ?= "1"
         
        INIT_MANAGER = "systemd"
        VIRTUAL-RUNTIME_init_manager = "systemd"
        VIRTUAL-RUNTIME_dev_manager  = "udev"Copy to clipboard
2. 编译极简镜像，对于 `nodistro`，以下是经过验证的镜像：
                
bitbake qcom-minimal-imageCopy to clipboard
3. 刷写设备：
                
有关使用 QDL 工具将镜像刷入设备的步骤，参见[刷写镜像](https://docs.qualcomm.com/bundle/publicresource/topics/80-70014-254/flash_images.html)。
4. `Nodistro` 支持镜像配方：
                
`qcom-minimal-image` 支持 `nodistro`。

## 使用 devtool

Source: [https://docs.qualcomm.com/doc/80-70014-27Y/topic/user_customizations.html](https://docs.qualcomm.com/doc/80-70014-27Y/topic/user_customizations.html)

下面举例说明如何对 Qualcomm 软件组件使用 devtool：
- **内核**
    可参阅 [Yocto 支持](https://docs.qualcomm.com/bundle/publicresource/topics/80-70014-3/yocto-kernel-support.html)。
- **QDL 工具**
    使用 dev 工具修改创建的工作区中的 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/qdlCopy to clipboard

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

            tree -L 2 build-qcom-wayland/workspace/
            build-qcom-wayland/workspace/
            ├── appends
            │   └── qdl_git.bbappend
            ├── conf
            │   └── layer.conf
            ├── README
            └── sources
                └── qdlCopy 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.cCopy to clipboard
    3. 更改 `workspace/sources/qdl/` 下的源代码树并编译更改：

            devtool build weston
            devtool build-image qcom-multimedia-imageCopy to clipboard
    4. 在 `build-qcom-wayland/tmp-glibc/deploy/images/qcm6490/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/westonCopy 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
                └── westonCopy to clipboard
    2. 检查已签出的 Weston 源代码树：

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

            devtool build weston
            devtool build-image qcom-multimedia-imageCopy to clipboard
    4. 在 `build-qcom-wayland/tmp-glibc/deploy/images/qcm6490/qcom-multimedia-image` 路径下生成镜像。

## 定制内核

Source: [https://docs.qualcomm.com/doc/80-70014-27Y/topic/user_customizations.html](https://docs.qualcomm.com/doc/80-70014-27Y/topic/user_customizations.html)

有关定制内核的更多信息，参见 [Qualcomm Linux 内核指南](https://docs.qualcomm.com/bundle/publicresource/topics/80-70014-3/)。

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

Source: [https://docs.qualcomm.com/doc/80-70014-27Y/topic/user_customizations.html](https://docs.qualcomm.com/doc/80-70014-27Y/topic/user_customizations.html)

### About this task

要将任何层添加到工作区，应按以下步骤操作：

### Procedure

1. 克隆 `<WORKSPACE>/layers/` 下的层。
2. 将层作为变量 `BBLAYERS` 的一部分添加到文件 `layers/meta-qcom-distro/conf/bblayers.conf` 中，如下所示：
                
# 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

### Results
这样，BitBake 便可解析该层。

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

Source: [https://docs.qualcomm.com/doc/80-70014-27Y/topic/user_customizations.html](https://docs.qualcomm.com/doc/80-70014-27Y/topic/user_customizations.html)

在发出 Yocto BitBake 编译指令之前，可通过导出 `DEBUG_BUILD=1` 来生成调试版本：

    DEBUG_BUILD=1 bitbake qcom-multimedia-imageCopy to clipboard

如需了解在 `DEBUG_BUILD` 设为 **1** 时使用哪些内核 defconfig 和 config 文件，可参见[内核配方](https://docs.qualcomm.com/doc/80-70014-27Y/topic/platform_software_features.html#qualcomm_bsp_metadata_layers__ul_hyj_wsh_r1c_rasam_03-08-24-1448-5-931)部分中的内核配置。

## 创建用于优化启动 KPI 的编译版本

Source: [https://docs.qualcomm.com/doc/80-70014-27Y/topic/user_customizations.html](https://docs.qualcomm.com/doc/80-70014-27Y/topic/user_customizations.html)

为了实现设备的最优启动时间，可使用 `PERFORMANCE_BUILD` 变量。当 `PERFORMANCE_BUILD` 变量设为 **1** 时，会修改 `KERNEL_CMDLINE_EXTRA` 以从命令行中删除 **console** 选项。当 `DEBUG_BUILD` 设为 **0** 时，`PERFORMANCE_BUILD` 变量生效。如需了解其有效性，可参见下表：

|  | PERFORMANCE\_BUILD="0" | PERFORMANCE\_BUILD="1" |
| --- | --- | --- |
| `DEBUG_BUILD="0"` | 启用 UART 上的控制台。 | 禁用 UART 上的控制台。<br><br><br>                                <br>优化启动时间。 |
| `DEBUG_BUILD="1"` | 启用 UART 上的控制台。 | 启用 UART 上的控制台。<br><br><br>                                <br>忽略 `PERFORMANCE_BUILD="1"` 设置，因为 `DEBUG_BUILD="1"` 优先于该设置。 |

Last Published: Oct 09, 2024

[Previous Topic
Qualcomm Linux 功能](https://docs.qualcomm.com/bundle/publicresource/80-70014-27Y/topics/platform_software_features.md) [Next Topic
调试](https://docs.qualcomm.com/bundle/publicresource/80-70014-27Y/topics/debug.md)