A Python library/script to automatically generate TWRP-compatible device tree from a boot/recovery image .
  • Python 56.8%
  • Jinja 43.2%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-08-09 01:02:34 +05:00
.github добавил файлы 2026-08-09 01:02:34 +05:00
twrpdtgen добавил файлы 2026-08-09 01:02:34 +05:00
.gitignore добавил файлы 2026-08-09 01:02:34 +05:00
poetry.lock добавил файлы 2026-08-09 01:02:34 +05:00
pyproject.toml добавил файлы 2026-08-09 01:02:34 +05:00
README.md добавил файлы 2026-08-09 01:02:34 +05:00

twrpdtgen-sprd

PyPi version Codacy Badge

Create a TWRP-compatible device tree only from an Android recovery image (or a boot image if the device uses non-dynamic partitions A/B) of your device's stock ROM. The generic path has been confirmed for Android 4.4 through Android 16.

Unisoc vendor_boot

This fork also recognizes Android vendor_boot v3/v4 images and generates a Unisoc/SPRD TWRP tree. It extracts the vendor ramdisk, DTB, vendor command line, ramdisk table, and bootconfig directly from the input image.

  • The generated Unisoc vendor_boot product is twrp_<codename>, never omni_<codename>.
  • BoardConfig.mk includes BOARD_USES_SPRD_HARDWARE := true and the stock vendor_boot parameters.
  • prop.default is read from the stock ramdisk. Android 14 and newer selects twrp-14.1 with the -ap2a lunch variant; Android 13 and earlier selects twrp-12.1.
  • The generated vendor ramdisk keeps the stock DTB, first-stage fstab, kernel modules, recovery fstab, ueventd configuration, and a TWRP fstab with a slot-aware vendor_boot entry.

The generated README records the selected source branch and exact lunch target. When a factory image exposes a generic Unisoc identity rather than the device codename, provide the intended tree location explicitly:

python3 -m twrpdtgen your_vendor_boot.img \
    --manufacturer Manufacturer --codename Codename

Requires Python 3.8 or greater

Installation

For this Unisoc vendor_boot fork, unpack the archive and install the local project rather than the unmodified PyPI release:

python3 -m pip install .

Then run the installed command, or use python3 -m twrpdtgen from the project directory:

twrpdtgen /path/to/vendor_boot.img -o output

If the stock properties expose a generic Unisoc codename, supply the intended device-tree identity:

twrpdtgen /path/to/vendor_boot.img -o output \
    --manufacturer Manufacturer --codename Codename

The generated README.md identifies the required TWRP source branch and lunch target. Use Linux or WSL with cpio installed; LZ4-compressed ramdisks also require lz4.

The upstream release remains available with:

pip3 install twrpdtgen

Instructions

python3 -m twrpdtgen <path to image>

When an image is provided, if everything goes well, there will be a device tree at output/manufacturer/codename

You can also use the module in a script, with the following code:

from twrpdtgen.device_tree import DeviceTree

# Get image info
device_tree = DeviceTree(image_path)

# Dump device tree to folder
device_tree.dump_to_folder(output_path)

License

#
# Copyright (C) 2022 The Android Open Source Project
#
# SPDX-License-Identifier: Apache-2.0
#