Android Device Tree Basics
Want to port a ROM to an unsupported device? You need a device tree. This guide introduces the fundamentals.
What is a Device Tree?
A device tree is a collection of configuration files that tells Android how to work with specific hardware.
Components
- device/[vendor]/[codename]/: Main device configuration
- kernel/[vendor]/[codename]/: Kernel source
- vendor/[vendor]/[codename]/: Proprietary blobs
Device Tree Structure
Typical structure:
device/vendor/codename/
├── AndroidProducts.mk
├── BoardConfig.mk
├── device.mk
├── vendorsetup.sh
├── overlay/
├── configs/
├── rootdir/
└── sepolicy/
Key Files
| File | Purpose |
|---|---|
| BoardConfig.mk | Hardware configuration |
| device.mk | Product configuration |
| AndroidProducts.mk | Build targets |
| system.prop | System properties |
BoardConfig.mk
Hardware definitions:
# Platform
TARGET_ARCH := arm64
TARGET_ARCH_VARIANT := armv8-a
TARGET_CPU_ABI := arm64-v8a
# Bootloader
TARGET_BOOTLOADER_BOARD_NAME := device_codename
TARGET_NO_BOOTLOADER := true
# Kernel
BOARD_KERNEL_CMDLINE := console=ttyMSM0,115200n8
TARGET_KERNEL_CONFIG := device_defconfig
# Partitions
BOARD_BOOTIMAGE_PARTITION_SIZE := 67108864
BOARD_SYSTEMIMAGE_PARTITION_SIZE := 3221225472
Getting Started with Porting
Step 1: Find Similar Device
Look for devices with:
- Same chipset (Snapdragon, MediaTek, Exynos)
- Similar launch date
- Same manufacturer if possible
Step 2: Extract Information
From stock ROM, extract:
# Mount system
mount system.img /mnt/system
# Get build.prop values
cat /mnt/system/build.prop
# Find hardware info
cat /mnt/system/etc/*.xml
Step 3: Use Reference Tree
Start with device tree from similar device, modify:
- Partition sizes
- Kernel configuration
- Hardware features
Vendor Blobs
Proprietary files from manufacturer:
- Camera libraries
- Audio HAL
- Sensor drivers
- Fingerprint HAL
Extracting Blobs
# From running device
./extract-files.sh
# From ROM package
./extract-files.sh /path/to/system
Testing Your Tree
Build First
source build/envsetup.sh
lunch lineage_codename-userdebug
mka bacon
Common First Issues
- Boot fails: Kernel config wrong
- No display: Gralloc/HWC issues
- No touch: Input driver issues
- No audio: Audio HAL config
Next Steps
- Get device booting
- Fix hardware (WiFi, Bluetooth, GPS)
- Fix camera
- Polish and optimize
Resources
- LineageOS Wiki (device tree examples)
- XDA device subforum
- Similar device trees on GitHub
Device tree porting has a steep learning curve, but each device you port teaches you more about Android internals.
Keywords: android device tree, rom porting, device tree tutorial, android development, custom rom porting