Device Tree Overlay
Implementation
on AOSP 9.0
WIG CHENG IN COSCUP 2020
2020/8/1
Me
Name: Wig
Work: Technexion
#> Embedded Linux
#> Industrial Android BSP
#> Robotic OS
Github: @wigcheng
Contents
• Introduce Device Tree Overlay
• AOSP 9.0 new feature: DTBO
• Implement DTBO on AOSP 9.0
•Big issue
•Make a DTBO image including DTB and DTBO
•U-boot Tweaking
• Future work
• Android 10 and 11
• Conclusion
Introduce Device Tree Overlay
Why Device Tree Overlay?
NFC HAT
VOICE HAT
RS485 HAT
CAN BUS HAT
LED HAT
a.dtb
DTB: Device Tree BlobDTS: Device Tree Source DTBO: Device Tree Blob for Overlay
a-nfc.dtbTraditional Solution
a-voicehat.dtb
a-rs485.dtb
a-can.dtb
a-led.dtb
Multiple inch LCD
a-5inch-lcd.dtb
a-10inch-lcd.dtb
...
a-60inch-lcd.dtb
U-boot
Kernel Image
a-nfc.dtb
a-voicehat.dtb
a-rs485.dtb
a-60inch-lcd.dtb
...
Why Device Tree Overlay? (cont.)
NFC HAT
VOICE HAT
RS485 HAT
CAN BUS HAT
LED HAT
a.dtb
nfc.dtboOverlay Solution
voicehat.dtbo
rs485.dtbo
can.dtbo
led.dtbo
Multiple inch LCD
5inch-lcd.dtbo
10inch-lcd.dtbo
...
60inch-lcd.dtbo
U-boot
Kernel Image
a.dtb
nfc.dtbo
voicehat.dtbo
60inch-lcd.dtbo
...
Linux example (in u-boot)
~# fdt addr ${fdt_addr}
~# fdt resize ${fdt_buffer}
~# setexpr fdtovaddr ${fdt_addr} + 0xF0000;
~# fatload mmc ${mmcdev}:${mmcpart} ${fdtovaddr} xxx.dtbo
~# fdt apply ${fdtovaddr}
U-boot
Kernel Image
a.dtb
nfc.dtbo
voicehat.dtbo
60inch-lcd.dtbo
...
Rootfs
FAT partition
AOSP 9.0 new feature: DTBO
AOSP 9.0 partitions
bootloader
boot
dtbo
vbmeta
system
vendor
recovery
presister
user data
Non-AB system
bootloader
user data
system
boot vendor
AB system
dtbo
vbmeta
presister
Source: https://source.android.com/devices/architec ture/dto/partitions
DTBO Overview
o Special Image format such as boot.img
o Depend on dt_table structure
o Depend on boot image header version
Pie
Pie Non AB
DTBO Overview (cont.d)
Structure prototype in U-boot:
1. Boot Image header: <source>/include/android_image.h
2. DT table: <source>/include/dt_table.h
Implement DTBO on AOSP 9.0
Big issue
ANDROID OPEN SOURCE BSP
Case: PICO-IMX8MM
• CPU: NXP ARM Cortex-A53 IMX8M-Mini 4-core 1.2GHz
• DRAM: 4GB
• OS: Android 9.0.0
• Complexity issue: NXP does not support multiple dtb in DTBO
[** L**] The dtbo image will be loaded from eMMC to dram in the process
of AVB verify, after verify pass the correct dtb will then be loaded to the
right address. We have only one dtb so the load process is quite simple,
you can check do_boota() in “drivers/usb/gadget/f_fastboot.c” for more
details. You don’t see the custom dtb because only the first dtb in the
dtbo will be loaded by default, what you have to do is load the second
(custom dtb) yourself.
I'm not very familiar with the dtbo.img loading process or format, I merely
helped Linaro get the headers from AOSP to U-Boot. In your case I would ask
Sam ( s***n.p******o@linaro.org ) about it. This dtbo.img is relatively new
and a bit of a niche so googling might not help.
Regards,
d****
Raspberry PI case
Classic AOSP A/B system case
bootloader boot_a
dtbo_a
vbmeta_a
system_a
vendor_a
Normal reboot
Fastboot mode
Upgrade mode
Raspberry PI case
bootloader boot_a
dtbo_a
vmeta_a
system
vendor
FAT partition
zImage bootargs dtb,dtbos uramdisk
Raspberry Open source project (Reference: android-rpi repo)
Is it useable?
Make a DTBO image
Path: <source>/device/fsl/imx8m/pico_imx8mm/AndroidBoard.mk
LOCAL_PATH := $(call my-dir)
include device/fsl/common/build/kernel.mk
include device/fsl/common/build/uboot.mk
include device/fsl/common/build/dtbo.mk
...
include $(LOCAL_PATH)/AndroidTee.mk
include $(FSL_PROPRIETARY_PATH)/fsl-proprietary/media-profile/media-profile.mk
include $(FSL_PROPRIETARY_PATH)/fsl-proprietary/sensor/fsl-sensor.mk
Make a DTBO image (cont.d)
Path: <source>/device/fsl/common/build/dtbo.mk
TARGET_BOARD_DTS_CONFIG := imx8mm:imx8mm-pico-pi-ili9881c.dtb dtbo-imx8mm.img
Make a DTBO image (cont.d)
/host/linux-x86/bin/mkdtimg create dtbo.img
target/product/pico_imx8mm/obj/KERNEL_OBJ/arch/arm64/boot/dts/freescale/imx8mm-pico-pi.dtb
target/product/pico_imx8mm/obj/KERNEL_OBJ/arch/arm64/boot/dts/freescale/overlays/imx8mm-pico-pi-nfc.dtbo
Make a DTBO image (cont.d)
TARGET_BOARD_DTS_CONFIG := imx8mm:imx8mm-pico-pi-ili9881c.dtb
TARGET_BOARD_DTBO_CONFIG := imx8mm:imx8mm-pico-pi-mipi_5-overlay.dts.dtbo
dtbo-imx8mm.img
dtbo.img
Get A/B slot
boot.img
Load kernel addr
Load boot header
U-boot Tweaking (before)
Path: <source>/vendor/nxp-opensource/uboot-imx/drivers/usb/gadget/f_fastboot.c
Start boota
AVB verification
Checking
AB/ NonAB
Load ramdisk addr
Second addr
Load table
Load entry[0] boot
kernel
U-boot V2018.03
dtbo.img
Get A/B slot
boot.img
Load kernel addr
Load boot header
U-boot Tweaking (after)
Path: <source>/vendor/nxp-opensource/uboot-imx/drivers/usb/gadget/f_fastboot.c
Start boota
AVB verification
Checking
AB/ NonAB
Load ramdisk addr
Second addr
Load table
Load entry[0] (dtb)
boot
kernel
Load entry[n] (dtbo)
merge entry[n]
Update second addr
U-boot V2018.03
Merge API: CONFIG_OF_LIBFDT_OVERLAY=y
Patch link
[** L**]
Nice to hear it works out! We are glad to see the patches if you can share
it with us.
Future Work
What about boot image V2
• For Android 10
• Add "DTB" field
• Keep DTB files in Boot Image
(concatenated or in DTBO image format)
• All DTBO files must be stored in ‘dtbo’
partition
End?? No, V3 format coming
• For Android 11
• Needed for GKI (Generic Kernel Image)
• Other new features and partition layouts...
Other vendors....
V1 V2 V3
NXP IMX8
Android 10
✔
TI Beagle Board
Android 10
✔
Rockchip RK3399
Android 10
✔
MTK Android 11 ✔
Summary
• DTBO discussion
Pros
• Overcome complexity issue for runtime level
• Match AOSP security architecture
• Easy to make a DTBO image
Cons
• The version of Boot image header changes are being made too fast
• Google said it's universal for all vendors, but the truth is different implement
methods for each vendors
Thank you for your listen!
Reference
• Google DTBO overview
• Linaro Connect resource:
SAN19-217 - New Android requirements for bootloaders
• Linux example: load device tree overlay on u-boot

Device Tree Overlay implementation on AOSP 9.0

  • 1.
    Device Tree Overlay Implementation onAOSP 9.0 WIG CHENG IN COSCUP 2020 2020/8/1
  • 2.
    Me Name: Wig Work: Technexion #>Embedded Linux #> Industrial Android BSP #> Robotic OS Github: @wigcheng
  • 3.
    Contents • Introduce DeviceTree Overlay • AOSP 9.0 new feature: DTBO • Implement DTBO on AOSP 9.0 •Big issue •Make a DTBO image including DTB and DTBO •U-boot Tweaking • Future work • Android 10 and 11 • Conclusion
  • 4.
  • 5.
    Why Device TreeOverlay? NFC HAT VOICE HAT RS485 HAT CAN BUS HAT LED HAT a.dtb DTB: Device Tree BlobDTS: Device Tree Source DTBO: Device Tree Blob for Overlay a-nfc.dtbTraditional Solution a-voicehat.dtb a-rs485.dtb a-can.dtb a-led.dtb Multiple inch LCD a-5inch-lcd.dtb a-10inch-lcd.dtb ... a-60inch-lcd.dtb U-boot Kernel Image a-nfc.dtb a-voicehat.dtb a-rs485.dtb a-60inch-lcd.dtb ...
  • 6.
    Why Device TreeOverlay? (cont.) NFC HAT VOICE HAT RS485 HAT CAN BUS HAT LED HAT a.dtb nfc.dtboOverlay Solution voicehat.dtbo rs485.dtbo can.dtbo led.dtbo Multiple inch LCD 5inch-lcd.dtbo 10inch-lcd.dtbo ... 60inch-lcd.dtbo U-boot Kernel Image a.dtb nfc.dtbo voicehat.dtbo 60inch-lcd.dtbo ...
  • 7.
    Linux example (inu-boot) ~# fdt addr ${fdt_addr} ~# fdt resize ${fdt_buffer} ~# setexpr fdtovaddr ${fdt_addr} + 0xF0000; ~# fatload mmc ${mmcdev}:${mmcpart} ${fdtovaddr} xxx.dtbo ~# fdt apply ${fdtovaddr} U-boot Kernel Image a.dtb nfc.dtbo voicehat.dtbo 60inch-lcd.dtbo ... Rootfs FAT partition
  • 8.
    AOSP 9.0 newfeature: DTBO
  • 9.
    AOSP 9.0 partitions bootloader boot dtbo vbmeta system vendor recovery presister userdata Non-AB system bootloader user data system boot vendor AB system dtbo vbmeta presister
  • 10.
    Source: https://source.android.com/devices/architec ture/dto/partitions DTBOOverview o Special Image format such as boot.img o Depend on dt_table structure o Depend on boot image header version Pie Pie Non AB
  • 11.
    DTBO Overview (cont.d) Structureprototype in U-boot: 1. Boot Image header: <source>/include/android_image.h 2. DT table: <source>/include/dt_table.h
  • 12.
  • 13.
  • 14.
    Case: PICO-IMX8MM • CPU:NXP ARM Cortex-A53 IMX8M-Mini 4-core 1.2GHz • DRAM: 4GB • OS: Android 9.0.0 • Complexity issue: NXP does not support multiple dtb in DTBO
  • 15.
    [** L**] Thedtbo image will be loaded from eMMC to dram in the process of AVB verify, after verify pass the correct dtb will then be loaded to the right address. We have only one dtb so the load process is quite simple, you can check do_boota() in “drivers/usb/gadget/f_fastboot.c” for more details. You don’t see the custom dtb because only the first dtb in the dtbo will be loaded by default, what you have to do is load the second (custom dtb) yourself.
  • 16.
    I'm not veryfamiliar with the dtbo.img loading process or format, I merely helped Linaro get the headers from AOSP to U-Boot. In your case I would ask Sam ( s***n.p******o@linaro.org ) about it. This dtbo.img is relatively new and a bit of a niche so googling might not help. Regards, d****
  • 17.
    Raspberry PI case ClassicAOSP A/B system case bootloader boot_a dtbo_a vbmeta_a system_a vendor_a Normal reboot Fastboot mode Upgrade mode
  • 18.
    Raspberry PI case bootloaderboot_a dtbo_a vmeta_a system vendor FAT partition zImage bootargs dtb,dtbos uramdisk Raspberry Open source project (Reference: android-rpi repo)
  • 19.
  • 20.
    Make a DTBOimage Path: <source>/device/fsl/imx8m/pico_imx8mm/AndroidBoard.mk LOCAL_PATH := $(call my-dir) include device/fsl/common/build/kernel.mk include device/fsl/common/build/uboot.mk include device/fsl/common/build/dtbo.mk ... include $(LOCAL_PATH)/AndroidTee.mk include $(FSL_PROPRIETARY_PATH)/fsl-proprietary/media-profile/media-profile.mk include $(FSL_PROPRIETARY_PATH)/fsl-proprietary/sensor/fsl-sensor.mk
  • 21.
    Make a DTBOimage (cont.d) Path: <source>/device/fsl/common/build/dtbo.mk TARGET_BOARD_DTS_CONFIG := imx8mm:imx8mm-pico-pi-ili9881c.dtb dtbo-imx8mm.img
  • 22.
    Make a DTBOimage (cont.d) /host/linux-x86/bin/mkdtimg create dtbo.img target/product/pico_imx8mm/obj/KERNEL_OBJ/arch/arm64/boot/dts/freescale/imx8mm-pico-pi.dtb target/product/pico_imx8mm/obj/KERNEL_OBJ/arch/arm64/boot/dts/freescale/overlays/imx8mm-pico-pi-nfc.dtbo
  • 24.
    Make a DTBOimage (cont.d) TARGET_BOARD_DTS_CONFIG := imx8mm:imx8mm-pico-pi-ili9881c.dtb TARGET_BOARD_DTBO_CONFIG := imx8mm:imx8mm-pico-pi-mipi_5-overlay.dts.dtbo dtbo-imx8mm.img
  • 25.
    dtbo.img Get A/B slot boot.img Loadkernel addr Load boot header U-boot Tweaking (before) Path: <source>/vendor/nxp-opensource/uboot-imx/drivers/usb/gadget/f_fastboot.c Start boota AVB verification Checking AB/ NonAB Load ramdisk addr Second addr Load table Load entry[0] boot kernel U-boot V2018.03
  • 26.
    dtbo.img Get A/B slot boot.img Loadkernel addr Load boot header U-boot Tweaking (after) Path: <source>/vendor/nxp-opensource/uboot-imx/drivers/usb/gadget/f_fastboot.c Start boota AVB verification Checking AB/ NonAB Load ramdisk addr Second addr Load table Load entry[0] (dtb) boot kernel Load entry[n] (dtbo) merge entry[n] Update second addr U-boot V2018.03 Merge API: CONFIG_OF_LIBFDT_OVERLAY=y
  • 27.
  • 28.
    [** L**] Nice tohear it works out! We are glad to see the patches if you can share it with us.
  • 29.
  • 30.
    What about bootimage V2 • For Android 10 • Add "DTB" field • Keep DTB files in Boot Image (concatenated or in DTBO image format) • All DTBO files must be stored in ‘dtbo’ partition
  • 31.
    End?? No, V3format coming • For Android 11 • Needed for GKI (Generic Kernel Image) • Other new features and partition layouts...
  • 32.
    Other vendors.... V1 V2V3 NXP IMX8 Android 10 ✔ TI Beagle Board Android 10 ✔ Rockchip RK3399 Android 10 ✔ MTK Android 11 ✔
  • 33.
    Summary • DTBO discussion Pros •Overcome complexity issue for runtime level • Match AOSP security architecture • Easy to make a DTBO image Cons • The version of Boot image header changes are being made too fast • Google said it's universal for all vendors, but the truth is different implement methods for each vendors
  • 34.
    Thank you foryour listen!
  • 35.
    Reference • Google DTBOoverview • Linaro Connect resource: SAN19-217 - New Android requirements for bootloaders • Linux example: load device tree overlay on u-boot