In AOSP, the "device tree" (not to be confused with the kernel's Device Tree Source or DTS) refers to the directory structure containing the configuration and build files needed to compile Android for a specific hardware target. This directory acts as the blueprint for assembling the OS.
The device/<vendor>/<codename>/ Directory
The standard location for a device tree is device/<vendor>/<codename>/. For example, the Pixel 7 (codename panther) by Google has its device tree at device/google/pantah/ (sharing a common base with the Pixel 7 Pro, cheetah).
A typical device tree contains several crucial Makefiles and configuration directories:
BoardConfig.mk: Hardware-specific build variables.device.mk: Software packages and overlays.AndroidProducts.mk: Registration of the build target.overlay/: XML overlays to override framework resources.rootdir/: Scripts andinit.rcfiles placed in the root filesystem.
BoardConfig.mk: Hardware Blueprint
BoardConfig.mk is arguably the most critical file in the device tree. It defines the low-level hardware characteristics and dictates how the build system should construct the partition images.
Key variables defined here include:
- Architecture:
TARGET_ARCH := arm64,TARGET_CPU_VARIANT := cortex-a75. - Partition Sizes and Types: Defines the size limits for
system.img,vendor.img, etc., and the filesystem type (ext4, f2fs, EROFS).BOARD_SYSTEMIMAGE_PARTITION_SIZE := 3221225472 BOARD_SYSTEMIMAGE_FILE_SYSTEM_TYPE := erofs - Kernel Configuration: Specifies the prebuilt kernel image to use, or the
defconfigif building the kernel from source.TARGET_PREBUILT_KERNEL := device/google/panther-kernel/Image.lz4 - Bootloader Flags: Arguments passed to the kernel at boot (e.g.,
BOARD_KERNEL_CMDLINE). - SELinux: Paths to the device-specific SELinux policies (
BOARD_VENDOR_SEPOLICY_DIRS).
device.mk: Software Packages and Overlays
While BoardConfig.mk handles the hardware, device.mk (or a similarly named file like device_panther.mk) handles the software. It specifies which APKs, HALs, and configuration files should be installed on the device.
- PRODUCT_PACKAGES: A list of modules (defined in
Android.bporAndroid.mk) to include in the build.PRODUCT_PACKAGES += \ android.hardware.camera.provider@2.4-impl \ Camera2 \ libGLES_mali - PRODUCT_COPY_FILES: Instructions to copy static files (like audio configs, permissions XMLs, or prebuilt binaries) directly to the output image.
PRODUCT_COPY_FILES += \ frameworks/native/data/etc/android.hardware.wifi.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.wifi.xml - DEVICE_PACKAGE_OVERLAYS: Specifies directories containing resource overlays to modify the look and feel of framework apps without changing their source code.
AndroidProducts.mk: The Lunch Menu
When you run lunch in the AOSP root, the build system scans for AndroidProducts.mk files to build the list of available targets.
This file maps a "lunch choice" (e.g., aosp_panther-userdebug) to the specific Makefile that defines that product.
PRODUCT_MAKEFILES := \
$(LOCAL_DIR)/aosp_panther.mk
COMMON_LUNCH_CHOICES := \
aosp_panther-userdebug \
aosp_panther-eng
Init Files: init.<device>.rc
Android's init process uses .rc files to configure the system at boot. The device tree provides hardware-specific init scripts, usually named init.<codename>.rc.
These scripts handle tasks that must occur early in the boot process:
- Mounting specific partitions (if not handled by
fstab). - Setting file permissions and ownership for hardware nodes (e.g.,
/dev/video0). - Starting vendor-specific daemons.
# Example from init.panther.rc
on boot
# Camera
chown media camera /dev/video0
chmod 0660 /dev/video0
service vendor.camera-provider-2-4 /vendor/bin/hw/android.hardware.camera.provider@2.4-service
class hal
user cameraserver
group audio camera input drmrpc
ioprio rt 4
capabilities SYS_NICE