# 用户定制

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

- 添加自定义设备配置
- 修改distro配置
- 创建图像配方
- 自定义内核

## 自定义设备配置

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

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`，请将下面的内容添加到 `conf/bblayers.conf` 文件中：
    - `EXTRALAYERS ?=${WORKSPACE}/layers/meta-qcom-extras`
4. 如需为添加的设备生成镜像，请运行以下命令：

bitbake qcom-multimedia-image
        Copy to clipboard

## 自定义 distro 配置

以下小节介绍了如何添加自定义distro配置和
重新生成工作区。

### Qualcomm 定义的distro配置概述

为 Qualcomm Linux 定义的参考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 tpm 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设置。有关详细信息，请参阅 [Distro功能](https://docs.yoctoproject.org/4.0.20/singleindex.html#distro-features)。

### 添加distro配置

要添加distro的配置文件，请执行以下操作：

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

MACHINE="qcs6490-rb3gen2-core-kit" 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`，请将其 `EXTRALAYERS ?=` `${WORKSPACE}/layers/meta-qcom-extras`  `conf/bblayers.conf` 添加到文件中。

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

bitbake qcom-multimedia-image
    Copy to clipboard

### 启用或禁用 DISTRO\_FEATURES

功能提供了一种机制来验证生成的镜像中必须包含哪些包。
您可以通过DISTRO\_FEATURES选择要启用的功能
该变量在发行版的配置文件 `test-distro.conf` 中设置或附加到该变量。
有关更多信息，请参阅
[distro功能](https://docs.yoctoproject.org/4.0.20/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 wayland vulkan opengl cramfs systemd pulseaudio gobject-introspection-data ldconfig”

3.若要重新生成，请运行以下命令：

> 
> 
> bitbake qcom-multimedia-image
>     Copy to clipboard

## 镜像Recipe

**添加镜像Recipe**

1. 要添加镜像recipe，请将目录更改为
`<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. 用source命令设置环境：

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-k8s \<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-k8s \<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` 包组的内容会从镜像中删除。

**从镜像删除Bluetooth** ^®^

`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-k8s \<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-k8s \<br>       packagegroup-qcom-location \<br>       packagegroup-qcom-video \<br>       packagegroup-qcom-voiceai \<br>       "<br>    Copy to clipboard |

执行 `bitbake qcom-multimedia-image` 命令后，与蓝牙相关的软件包会从build中删除。来自 `packagegroup-qcom-bluetooth.bb` 包组的内容会从镜像recipe中删除。

## 修改分区布局

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

Note

在删除任何分区之前，请确保完全确定每个分区的用途。

许多分区对于实现相关功能至关重要。若要了解
关于此文件在生成分区表中作用的详细信息，请参阅
分区。

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

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

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

这将为LUN0和GUID添加4MB的分区测试，
具体由用户决定。此分区不会刷入任何镜像，
但它在设备启动后可作为原始分区使用。由于
此分区将添加到LUN0中，它会显示在以下任一位置
：

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

**示例2 – 在新创建的分区中，添加一个包含要闪存到的二进制文件的示例分区**

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

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

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

## Nodistro 编译版本

如果您想从最小化的镜像开始，并希望能控制软件的选择和配置，那么 `nodistro` build
可能会
很有用。要创建 `nodistro` build，请设置
`<WORKSPACE>/build-qcom-wayland/conf/local.conf` 并指定
`DISTRO=nodistro`。

运行以下命令，
从使用Qualcomm manifest创建的工作区创建 `nodistro` 。若要创建工作区，请参阅 [Qualcomm Linux 编译
指南](https://docs.qualcomm.com/bundle/publicresource/topics/80-70015-254/github_workflow_unregistered_users.html)。

1. 要运行 setup-environment with `nodistro` set for DISTRO，请运行以下命令：

MACHINE="qcm6490" DISTRO="nodistro" source setup-environment
        Copy 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-image
        Copy to clipboard
3. 将镜像刷写到设备：

    要使用 QDL工具将image刷写到设备，请参阅 [刷写镜像](https://docs.qualcomm.com/bundle/publicresource/topics/80-70015-254/flash_images.html)。
4. `nodistro` build支持镜像recipe：

    `qcom-minimal-image` 支持 `nodistro`.

## devtool的使用

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

- **内核**

    参见 [Yocto 支持](https://docs.qualcomm.com/bundle/publicresource/topics/80-70015-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 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` 。
- **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-70015-3/)。

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

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

1. 克隆 `<WORKSPACE>/layers/` 下的layer。
2. 将layer添加到
`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可以解析layer。

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

要生成调试版本在发送Yocto BitBake编译指令前 导出 `DEBUG_BUILD=1`
可运行以下命令：

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

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

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

要实现设备的最佳启动时间，
使用变量 `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>UART上的控制台已启用</p></li><br><li><p>该 <code class="docutils literal notranslate"><span class="pre">PERFORMANCE_BUILD=&quot;1&quot;</span></code> 设置可以忽略，因为 <code class="docutils literal notranslate"><span class="pre">DEBUG_BUILD=&quot;1&quot;</span></code> 设置优先于此设置。</p></li><br></ul> |

Last Published: Dec 15, 2024

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