Android DTB/DTBO Format

From postmarketOS

On modern Android devices, there is a 64-byte DTB header which can make porting slightly painful at first since the kernel does not generate it automatically.

To work around this, use mkdtboimg to generate a proper Android DTB image using the DTB that the kernel source tree generates.

For example, here are the commands used in the APKBUILD for the Samsung Galaxy Tab A7 Lite:

# We also need to convert the kernel DTB into a proper android dtb image with the 64-byte header
	
mv "$pkgdir"/boot/dtbs/mediatek/mt6765.dtb "$pkgdir"/boot/dtbs/mediatek/mt6765.dtb.bak
mkdtboimg create "$pkgdir"/boot/dtbs/mediatek/mt6765.dtb "$pkgdir"/boot/dtbs/mediatek/mt6765.dtb.bak
rm "$pkgdir"/boot/dtbs/mediatek/mt6765.dtb.bak

Data Structure

Length (bytes) Details
4 Magic bytes. Always 0xd7b7ab1e.
4 Total size. Combination of the header size itself and all of the table entries. Device-specific.
4 Header size. Always 0x00000020 in this case.
4 Entry size. Always 0x00000020 in this case.
4 The number of table entries. Always 0x00000001 in this case.
4 Offset to the first table entry. Always 0x00000020 in this case.
4 Page size. Always 0x00000800 in this case.
4 DTBO image version. Always null bytes in this case - the current version is 0. This is where the table header ends, and the next bytes are for the table entry in the DTB header.
4 DTB size. Device-specific.
4 DTB offset. Always 0x00000040 in this case.
4 Device ID. Unused.
4 Device revision. Unused.
16 Unused.

See also

The data structure information on the AOSP documentation website