自 2025 年 3 月 27 日起,我們建議您使用 android-latest-release
而非 aosp-main
建構及貢獻 AOSP。詳情請參閱「Android 開放原始碼計畫變更」。
DTB 映像檔
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
Android 實作項目可以包含裝置樹狀結構 blob (DTB) 映像檔,供引導程式使用。DTB 映像檔的位置 (以及指定 DTB 圖片參數的選項) 會因 Android 版本而異。
在 Android 11 中,使用通用核心映像檔 (GKI) 的裝置必須支援供應商啟動分區,其中包含從啟動分區重新安置的所有供應商專屬資訊。由於 DTB 映像檔包含廠商專屬資料,因此現在是廠商開機分區的一部分。如要指定 DTB 映像檔參數,請參閱「供應商開機標頭」。
在 Android 10 中,裝置可以在啟動分割區中加入 DTB 映像檔。如要指定 DTB 映像檔參數,請參閱「在開機映像檔中加入 DTB 映像檔」。
在 Android 9 以下版本中,DTB 映像檔可以位於其專屬分割區,也可以附加至核心 image.gz
以建立核心 + DTB 映像檔 (然後傳遞至 mkbootimg
以建立 boot.img
)。
在 Android 10 以上版本中,DTB 圖片必須使用下列格式之一:
在開機映像檔中加入 DTB 映像檔
搭載 Android 10 的裝置可以在開機映像檔中加入 DTB 映像檔。這樣一來,Android 就不需要支援將 DTB 映像檔附加至核心的 image.gz
指令碼,並可使用供應商測試套件 (VTS) 測試,驗證 (並標準化) DTB 位置。
此外,對於非 A/B 裝置,建議將 DTB 設為復原映像檔的一部分,而非設為獨立的區隔,以免因 OTA 中斷而導致問題。在 OTA 期間,如果在更新 DTB 分割區後 (但尚未完成完整更新) 發生問題,裝置會嘗試啟動至復原模式,以完成 OTA;不過,由於 DTB 分割區已更新,因此可能會與復原映像檔 (尚未更新) 發生不相符的情形。將 DTB 映像檔納入開機映像檔格式,可讓復原映像檔自給自足 (也就是不依賴其他分割區),進而避免發生這類問題。
開機映像檔結構
搭載 Android 10 的裝置可使用下列啟動映像檔結構,納入 DTB 映像檔。
開機映像檔區段 |
頁數 |
開機頁首 (1 頁) |
1 |
核心 (l 頁面) |
l = (kernel_size + page_size -
1) / page_size |
Ramdisk (m 頁面) |
m = (ramdisk_size + page_size -
1) / page_size |
第二階段啟動載入程式 (n 個頁面) |
n = (second_size + page_size -
1) / page_size |
復原 DTBO (o 頁面) |
o = (recovery_dtbo_size + page_size -
1) / page_size |
DTB (p 頁面) |
p = (dtb_size + page_size -
1) / page_size |
DTB 映像檔路徑
如果是搭載 Android 10 的裝置,您可以使用 mkbootimg.py
工具和下列引數,指定 DTB 映像檔的路徑。
引數 |
說明 |
dtb |
開機/復原映像檔中要納入的 DTB 映像檔路徑。 |
dtb_offset |
新增至 base 引數時,會提供最終裝置樹狀結構的實際載入位址。舉例來說,如果 base 引數為 0x10000000 ,而 dtb_offset 引數為 0x01000000 ,則引導映像檔標頭中的 dtb_addr_field 會填入為 0x11000000 。 |
您必須使用板卡設定變數 BOARD_PREBUILT_DTBIMAGE_DIR
指定 DTB 映像檔的路徑。如果 BOARD_PREBUILT_DTBIMAGE_DIR
目錄中有多個副檔名為 *.dtb
的檔案,Android 建構系統會連結這些檔案,以建立在啟動映像檔建立程序中使用的最終 DTB 映像檔。
如要將引數 dtb
和 BOARD_PREBUILT_DTBIMAGE_DIR
指定目錄中的 DTB 映像檔傳遞至 mkbootimg.py
,板卡設定變數 BOARD_INCLUDE_DTB_IN_BOOTIMG
必須設為 true
。例如:
BOARD_INCLUDE_DTB_IN_BOOTIMG := true
您可以將 dtb_offset
引數附加至 BOARD_MKBOOTIMG_ARGS
板卡設定變數,並附上其他偏移量和標頭版本。例如:
BOARD_MKBOOTIMG_ARGS := --ramdisk_offset $(BOARD_RAMDISK_OFFSET) --dtb_offset $(BOARD_DTB_OFFSET) --tags_offset $(BOARD_KERNEL_TAGS_OFFSET) --header_version $(BOARD_BOOTIMG_HEADER_VERSION)
系統啟動載入程式支援
如要讓 VTS 在執行 Android 10 的裝置上順利執行,引導程式必須支援更新的啟動映像檔,並新增 androidboot.dtb_idx
核心指令列參數,指出所選裝置樹狀結構 (DT) 的索引。您只能指定一個 (1) 索引。舉例來說,參數 androidboot.dtb_idx=N
會將 N
回報為 bootloader 從啟動映像檔中一組 DTB 選取的裝置樹狀結構,以 0 為基底的索引。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-27 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-07-27 (世界標準時間)。"],[],[],null,["# DTB images\n\nAndroid implementations can include a device tree blob (DTB) image for use by\nthe bootloader. The location of the DTB image (and the options for specifying\nDTB image parameters) differs between Android releases.\n\n- In Android 11, devices using the [Generic Kernel\n Image (GKI)](/docs/core/architecture/kernel/generic-kernel-image) must\n support the [vendor boot\n partition](/docs/core/architecture/bootloader/partitions/vendor-boot-partitions),\n which includes all vendor-specific information that was relocated from the\n boot partition. Because the DTB image contains vendor-specific data, it's now\n part of the vendor boot partition. To specify DTB image parameters, see\n [Vendor boot\n header](/docs/core/architecture/bootloader/partitions/vendor-boot-partitions#vendor-boot-header).\n\n- In Android 10, devices can include the DTB image in\n the boot partition. To specify DTB image parameters, see [Including the DTB\n image in the boot image](#dtb-image-include).\n\n- In Android 9 and lower, the DTB image can exist in\n its own partition or be appended to the kernel `image.gz` to create the kernel\n + DTB image (which is then passed to `mkbootimg` to create `boot.img`).\n\nDTB image format\n----------------\n\nIn Android 10 and higher, the DTB image must use one\nof the following formats:\n\n- **DT blobs concatenated one after the other.** The bootloader uses the\n `totalsize` field in each FDT header to read and parse the corresponding blob.\n\n- **DTB/DTBO partitions.** The bootloader has an efficient way to select the\n correct DT blob by examining the `dt_table_entry` struct (contains `id`,\n `rev`, and `custom` fields) that can hold hardware identifying information for\n the entry. For details, see [DTB/DTBO\n Partitions](/docs/core/architecture/dto/partitions#structures).\n\nInclude the DTB image in the boot image\n---------------------------------------\n\nDevices running Android 10 can include the DTB image in\nthe boot image. This removes the need for Android to support scripts that append\nthe DTB image to `image.gz` in the kernel, and enables the use of [Vendor Test\nSuite (VTS)](/docs/compatibility/vts) test to verify (and standardize) DTB\nplacement.\n\nIn addition, for non-A/B devices, it's safer to have the DTB as part of the\nrecovery image rather than in a separate partition to prevent issues caused by\ninterrupted OTAs. During an OTA, if a problem occurs after the DTB partition is\nupdated (but prior to completing the full update), the device tries to boot into\nrecovery mode to complete the OTA; however, because the DTB partition has\nalready been updated, a mismatch could occur with the recovery image (which has\nnot yet been updated). Having the DTB image as part of the boot image format\nprevents such issues by making the recovery image self sufficient (that is, it\ndoesn't depend on another partition).\n\n### Boot image structure\n\nDevices running Android 10 can include a DTB image\nusing the following boot image structure.\n\n| Boot image section | Number of pages |\n|-----------------------------------|------------------------------------------------------------|\n| Boot header (1 page) | 1 |\n| Kernel (l pages) | l = (`kernel_size` + `page_size` - 1) / `page_size` |\n| Ramdisk (m pages) | m = (`ramdisk_size` + `page_size` - 1) / `page_size` |\n| Second stage bootloader (n pages) | n = (`second_size` + `page_size` - 1) / `page_size` |\n| Recovery DTBO (o pages) | o = (`recovery_dtbo_size` + `page_size` - 1) / `page_size` |\n| DTB (p pages) | p = (`dtb_size` + `page_size` - 1) / `page_size` |\n\n### DTB image path\n\nFor devices running Android 10, you can use the\n`mkbootimg.py` tool and the following arguments to specify the path to the DTB\nimage.\n\n| Argument | Description |\n|--------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `dtb` | Path to the DTB image to be included in the boot/recovery images. |\n| `dtb_offset` | When added to the `base` argument, provides the physical load address for the final device tree. For example, if the `base` argument is `0x10000000` and the `dtb_offset` argument is `0x01000000`, the `dtb_addr_field` in the boot image header is populated as `0x11000000`. |\n\nThe board config variable `BOARD_PREBUILT_DTBIMAGE_DIR` must be used to specify\nthe path to the DTB image. If more than one file with extension `*.dtb` is\npresent in the directory `BOARD_PREBUILT_DTBIMAGE_DIR`, the Android build system\nconcatenates the files to create the final DTB image used in the boot image\ncreation.\n\nTo pass the argument `dtb` to `mkbootimg.py` with the DTB image from the\ndirectory specified by `BOARD_PREBUILT_DTBIMAGE_DIR`, the board config variable\n`BOARD_INCLUDE_DTB_IN_BOOTIMG` must be set to `true`. For example: \n\n BOARD_INCLUDE_DTB_IN_BOOTIMG := true\n\nYou can append the `dtb_offset` argument to the `BOARD_MKBOOTIMG_ARGS` board\nconfig variable with the other offsets and header version. For example: \n\n BOARD_MKBOOTIMG_ARGS := --ramdisk_offset $(BOARD_RAMDISK_OFFSET) --dtb_offset $(BOARD_DTB_OFFSET) --tags_offset $(BOARD_KERNEL_TAGS_OFFSET) --header_version $(BOARD_BOOTIMG_HEADER_VERSION)\n\n### Bootloader support\n\nFor VTS to run successfully on devices running Android\n10, the bootloader must support the updated boot image\nand must add the `androidboot.dtb_idx` kernel command line parameter to indicate\nthe index of the selected device tree (DT). **You can specify only one (1)\nindex.** For example, the parameter `androidboot.dtb_idx=N` reports `N` as the\nzero-based index of the device tree selected by the bootloader from the set of\nDTBs present in the boot image."]]