Skip to content

Common Tree

Ahmed Shahin edited this page Jan 9, 2025 · 9 revisions

Unified TWRP Tree Guide 📜

Working on multiple TWRP trees can be overwhelming, especially when you notice many common targets across devices. To simplify the process, I’ve created a universal tree that you can easily adapt for various devices. Let’s dive into how you can use it! 🌱

How to Get Started 🛠️

  1. Include the Common BoardConfig
    First, add this line to your BoardConfig.mk:

    include device/android/common/BoardConfigCommon.mk
  2. Inherit the Common Device Makefile
    Then, in your twrp_"codename".mk, include:

    $(call inherit-product, device/android/common/device.mk)

    No additional inheritance needed—everything is pre-installed. 🔧


AB Devices

If your device uses the A/B partition system, add this line to your twrp_"codename".mk:

ENABLE_VIRTUAL_AB := true

Samsung Devices

For devices made by Samsung, set the vendor in your BoardConfig.mk:

BOARD_VENDOR := samsung

Header Version 🏷️

Define header versions for your recovery or boot partition:

  • For Recovery or Boot:
    BOARD_BOOTIMG_HEADER_VERSION := 2
  • For Vendor Boot:
    BOARD_BOOT_HEADER_VERSION := 4

Build Target Setup 🏗️

Depending on how your device handles boot/recovery:

  • If using boot as recovery:
    BOARD_STORE_RAMDISK_IN_BOOT := true
  • If using vendor boot:
    BOARD_STORE_RAMDISK_IN_VENDORBOOT := true
  • If using recovery partition, no extra configurations needed! ✅

Kernel Offsets 🖥️

For boot, vendor boot, and recovery, you need to define kernel and ramdisk offsets:

  • For Boot:
    BOARD_RAMDISK_OFFSET := 
    BOARD_KERNEL_TAGS_OFFSET :=
    BOARD_KERNEL_BASE :=
  • For Vendor Boot:
    BOARD_KERNEL_OFFSET  := 
    BOARD_RAMDISK_OFFSET := 
    BOARD_KERNEL_TAGS_OFFSET :=
    BOARD_DTB_OFFSET     := 
    BOARD_KERNEL_BASE    :=
  • For Recovery:
    BOARD_KERNEL_BASE := 
    BOARD_RAMDISK_OFFSET := 
    BOARD_KERNEL_TAGS_OFFSET := 

Hardware Setup 🔧

Set your device’s SoC:

  • Snapdragon:
    BOARD_USES_QCOM_HARDWARE := true
  • MTK:
    BOARD_USES_MTK_HARDWARE := true
  • UniSoC:
    BOARD_USES_SPRD_HARDWARE := true

Prebuilt Kernel & DTB 🏗️

Ensure your prebuilt kernel and DTB are correctly placed in the tree.

  • The kernel should be named kernel, and the DTB should be dtb.img. 🧰

System Reboot Fix 🔄

To fix system reboot issues, add this to BoardConfig.mk:

TW_NO_FASTBOOT_BOOT := true

Image Sizes 🧮

Depending on your boot setup, set the image sizes:

  • For Vendor Boot:
    BOARD_VENDOR_BOOTIMAGE_PARTITION_SIZE :=
  • For Recovery:
    BOARD_RECOVERYIMAGE_PARTITION_SIZE :=
  • For Boot:
    BOARD_BOOTIMAGE_PARTITION_SIZE :=

Tree Models 🌲

Check out these sample trees for reference:


Ready to Work! 🚀

Now you’re all set to work with a unified TWRP tree. Feel free to tweak it according to your device’s specific needs.