Skip to content

Yusuf6411/TWRP-device-porting

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 

Repository files navigation

Porting TWRP Recovery to Any Device Using Kernel Source

Table of Contents

  1. Introduction
  2. Prerequisites
  3. Setting Up the Environment
  4. Downloading and Preparing the Kernel Source
  5. Extracting Recovery Files
  6. Building the TWRP Recovery Image
  7. Testing the TWRP Recovery
  8. Debugging and Troubleshooting
  9. Submitting Your Build
  10. Additional Resources

Introduction

This guide provides an exhaustive walkthrough on how to port Team Win Recovery Project (TWRP) to any Android device using the device’s kernel source. TWRP is a feature-rich custom recovery that supports functionalities such as flashing custom ROMs, backing up partitions, and managing device files. Mastering the porting process can help you unlock more potential from your Android device.


Prerequisites

Before starting, ensure the following requirements are fulfilled:

Basic Knowledge:

  • Familiarity with:
    • Linux command-line operations.
    • Android recovery structure.
    • Kernel compilation and troubleshooting.

Hardware Requirements:

  • A PC with:
    • At least 8GB RAM (16GB+ recommended for faster builds).
    • 50GB+ of free storage.

Software Requirements:

  • Operating System: Linux-based OS (Ubuntu 20.04+ or equivalent).
  • Essential Tools:
    • Android SDK Platform Tools (adb and fastboot).
    • Repo Tool.
    • Build essentials: Install with:
      sudo apt install build-essential git ccache python3 python3-pip openjdk-8-jdk adb fastboot
    • Java Development Kit (JDK 8 or 11).
    • Python 3.

Device-Specific Requirements:


Setting Up the Environment

Step 1: Install Necessary Packages

Ensure your system is prepared by installing the required dependencies:

sudo apt update
sudo apt install git wget curl unzip tar build-essential gcc g++ ccache python3 python3-pip openjdk-8-jdk adb fastboot

Step 2: Configure Git

Set up Git to ensure proper collaboration and commits:

git config --global user.name "Your Name"
git config --global user.email "[email protected]"

Step 3: Set Up Repo Tool

Download and configure the repo tool for managing source code:

mkdir ~/bin
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo
export PATH=~/bin:$PATH

Add the PATH export line to your ~/.bashrc or ~/.zshrc for persistence.


Downloading and Preparing the Kernel Source

Step 1: Obtain Kernel Source

Visit the manufacturer’s developer portal or GitHub page (links provided above) and download the kernel source corresponding to your device’s firmware version.

Step 2: Clone the Source

Clone the kernel source using Git:

git clone <kernel-source-url> kernel_source
cd kernel_source

Step 3: Verify Compatibility

Ensure the kernel source matches your device’s specifications, such as:

  • Processor architecture (e.g., ARMv7, ARM64).
  • Chipset (e.g., Snapdragon, MediaTek).

Step 4: Apply Necessary Patches

Look for TWRP-specific patches for your device on forums or GitHub. Apply patches using:

git am <path-to-patch>

Extracting Recovery Files

Step 1: Download Stock Firmware

Obtain your device’s stock firmware from official sources or trusted repositories. Some trusted resources:

Step 2: Extract Stock Firmware

Extract the downloaded firmware using unzip:

mkdir stock_firmware
unzip firmware.zip -d stock_firmware

Step 3: Extract Recovery.img

Locate and extract the recovery.img file from the firmware.

Step 4: Disassemble Recovery.img

Disassemble the recovery image using Android Image Kitchen:

./unpackimg.sh recovery.img

Inspect the contents of the recovery to gather necessary information, such as partition layout and kernel image.


Building the TWRP Recovery Image

Step 1: Download TWRP Source

Initialize and sync the TWRP source:

mkdir ~/twrp
cd ~/twrp
repo init -u https://github.com/minimal-manifest-twrp/platform_manifest_twrp_aosp.git -b twrp-12.1
repo sync

Step 2: Set Up Device Tree

Create a device tree directory:

mkdir -p device/<manufacturer>/<codename>
cd device/<manufacturer>/<codename>

Populate the device tree with:

  • Kernel configuration files.
  • Board-specific device files (e.g., fstab, init.rc files).
  • Proprietary blobs.

Step 3: Configure the Build Environment

Set up the environment and specify your device codename:

export ALLOW_MISSING_DEPENDENCIES=true
source build/envsetup.sh
lunch omni_<codename>-eng

Step 4: Build the Recovery Image

Compile the recovery image using:

mka recoveryimage

The output recovery image will be located at:

out/target/product/<codename>/recovery.img

Testing the TWRP Recovery

Step 1: Flash the Recovery Image

Boot your device into fastboot mode:

adb reboot bootloader
fastboot flash recovery out/target/product/<codename>/recovery.img

Step 2: Boot into Recovery Mode

Reboot directly into the recovery partition:

fastboot reboot recovery

Debugging and Troubleshooting

Capture Logs

If the recovery fails to boot, capture logs for debugging:

adb logcat > recovery_log.txt

Common Issues and Fixes

  • Bootloop:
    • Verify kernel configuration.
    • Ensure all necessary drivers are enabled.
  • Touchscreen Not Working:
    • Check for missing touch panel drivers.
    • Update device tree configurations.

Submitting Your Build

Test Thoroughly

Verify that all TWRP functionalities (e.g., backup, restore, flashing, partition mounting) work as expected.

Contribute to TWRP

  1. Fork the TWRP GitHub Repository.
  2. Push your changes and create a pull request with detailed documentation.

Share with the Community

Post your build on:


Additional Resources

By following this guide, you can successfully port TWRP to your device. For advanced use cases, explore the TWRP GitHub repository and community forums for additional resources and support.

About

A guide on how to port TWRP recovery to any device

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published