# 使用者自訂

本節提供自訂 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. 設置環境腳本：

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

備註

如果您有權訪問 `meta-qcom-extras`，請將其添加到 `conf/bblayers.conf` 檔案中的 `EXTRALAYERS ?=` `${WORKSPACE}/layers/meta-qcom-extras`。
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

備註

[發行版特性](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. 按如下方式設置環境並導出變量：

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

設置環境後，當前工作區目錄更改為 `<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

備註

如果您有權訪問 `meta-qcom-extras`，請將其添加到 `conf/bblayers.conf` 檔案中的 `EXTRALAYERS ?=` `${WORKSPACE}/layers/meta-qcom-extras`。

要重建映像，請運行以下命令：

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)。

備註

選擇社區定義的功能。

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

## 自定義圖像功能

本節提供了如何自定義圖像的示例：

**Remove display packages from image**

`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` 包組的內容將從映像中移除。

**從映像中移除藍牙**^®^ **from image**

`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-27TC/topic/qualcomm_linux_software_components.html#managing-partitions-in-qualcomm-linux)。

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

要在 LUN0 中添加名為 `test` 的分區，請在 LUN0 部分下的 `qcm6490-partitions.conf` 中添加以下行：

--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`

備註

要反映 `qcm6490-partitions.conf` 中的更改，請更新首選提供程序。更多信息，請參見 [修改分區](https://docs.qualcomm.com/doc/80-70018-27TC/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

將新的 `test1.bin` 二進位檔部署到 `build-qcom-wayland/tmp-glibc/deploy/images/qcs6490-rb3gen2-core-kit/$(image_name)`。

## 使用 devtool

以下示例顯示了 Qualcomm 軟體組件的 devtool 用法：

- **內核**

    請參見 [Yocto 支持](https://docs.qualcomm.com/bundle/publicresource/topics/80-70018-3/yocto-kernel-support.html)。
- **QDL tool**

    使用 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 Kernel Guide](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

克隆並添加該層允許 BitBake 解析該層。

## 創建調試構建

要生成調試構建以在發出 Yocto BitBake 構建指令之前導出 `DEBUG_BUILD=1`，請運行以下命令：

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

要了解將 `DEBUG_BUILD` 設置為 **1** 時使用了哪些內核 defconfig 和配置片段，請參見內核配置，位於 [Kernel recipes](https://docs.qualcomm.com/doc/80-70018-27TC/topic/qualcomm_linux_metadata_layers_overview.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>當 <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: Jul 30, 2025

[Previous Topic
Qualcomm Linux 軟體元件](https://docs.qualcomm.com/bundle/publicresource/80-70018-27TC/topics/qualcomm_linux_software_components.md) [Next Topic
調試](https://docs.qualcomm.com/bundle/publicresource/80-70018-27TC/topics/debug.md)