Telegram

Creating a Custom TWRP Recovery Without Kernel Source for Chinese Phones: A Comprehensive Guide

The world of custom ROMs and modifications can be an exciting, yet challenging, space, especially when dealing with devices that have limited official support. This is often the case with some Chinese phone models where obtaining the kernel source code required for building a custom recovery such as TWRP (Team Win Recovery Project) can be a major obstacle. However, this doesn’t mean customization is entirely off-limits. In this guide, we’ll explore methods for creating a custom TWRP recovery image even when the kernel source isn’t readily available, leveraging tools like AIK (Android Image Kitchen) and GitHub-based builders.

Understanding the Challenges and Potential Solutions

The primary challenge in building a custom TWRP without kernel source lies in the kernel incompatibility. TWRP requires a kernel compiled specifically for the device it’s intended for. Without the source, we can’t compile a kernel from scratch. However, there are several strategies we can employ:

Essential Tools and Preparations

Before we begin, we’ll need to gather the necessary tools and information.

Gathering the Essentials

Setting Up the Environment

  1. Install ADB and Fastboot: Follow the instructions specific to your operating system to install ADB and Fastboot. Make sure they are correctly configured in your system’s PATH environment variable so you can use the commands from any command prompt.
  2. Extract AIK: Extract the downloaded AIK archive to a dedicated folder on your computer (e.g., C:\AIK or /opt/AIK).
  3. Download Stock Recovery: Place the stock recovery image (usually a .img file) in the same directory as the AIK scripts.
  4. Clone TWRP Builder (GitHub): Clone the desired TWRP builder repository from GitHub to a folder on your computer using Git. If you don’t have Git installed, download and install it first.
  5. Install Dependencies: Refer to the TWRP builder’s documentation for specific dependencies that need to be installed. This often includes Python packages and other development tools.

Step-by-Step Guide: Building the Custom TWRP

1. Unpacking the Stock Recovery Image

This step involves using AIK to extract the components of the stock recovery image.

  1. Open a command prompt or terminal in the AIK directory.

  2. Execute the following command:

    unpackimg recovery.img
    

    Replace recovery.img with the actual filename of your stock recovery image.

  3. AIK will create several folders, including kernel, ramdisk, and split_img. The ramdisk folder is where the recovery environment’s file system resides.

2. Modifying the Ramdisk

The ramdisk contains the files and scripts that define the TWRP environment. We’ll need to modify it to ensure compatibility and add necessary features.

  1. Navigate to the ramdisk folder.

  2. default.prop: Edit this file to adjust properties like ro.debuggable=1 and ro.secure=0. Ensure the fingerprint matches your device and firmware version.

  3. fstab.[device]: This file defines the mount points for your device’s partitions. This is a critical file. You’ll need to modify it to ensure TWRP can correctly mount the necessary partitions (system, data, cache, etc.).

    • Identify Mount Points: Examine the stock fstab file or your device’s /proc/mounts (if you have root access) to determine the correct mount points and file system types for each partition.
    • Update fstab: Modify the fstab file in the ramdisk to reflect these mount points and file system types. Incorrect entries here will prevent TWRP from functioning correctly.
  4. init.rc and init.[device].rc: These files contain initialization scripts that are executed when TWRP starts.

    • Mounting Partitions: Review these scripts to ensure the necessary partitions are being mounted correctly.
    • SELinux: If your device uses SELinux, you might need to adjust the SELinux policies in these files to allow TWRP to access the necessary resources. This is an advanced topic that requires a solid understanding of SELinux.
  5. Add TWRP Binary: Obtain the TWRP binary specifically compiled for your device’s architecture (arm, arm64). You can find pre-built binaries on the TWRP website or forums. Place the TWRP binary in the ramdisk/sbin folder and ensure it has execute permissions.

  6. recovery.fstab: This file tells TWRP how to mount partitions. It’s slightly different from fstab.[device]. Add your device partitions here using the correct device name. For example:

    /system ext4 /dev/block/mmcblk0pXX flags=display="System";flashimg=1
    /data ext4 /dev/block/mmcblk0pYY flags=display="Data";wipeingui=1
    /cache ext4 /dev/block/mmcblk0pZZ flags=display="Cache";wipeingui=1
    /sdcard vfat /dev/block/mmcblk1p1 flags=display="SDCard";storage;wipeingui=1;removable
    

    Replace /dev/block/mmcblk0pXX, /dev/block/mmcblk0pYY, /dev/block/mmcblk0pZZ, and /dev/block/mmcblk1p1 with the actual partition names for your device.

3. Repacking the Recovery Image

Once you’ve modified the ramdisk, you need to repack it into a new recovery image.

  1. Return to the AIK directory in the command prompt or terminal.

  2. Execute the following command:

    repackimg
    
  3. AIK will create a new recovery image named new-recovery.img. This is your custom TWRP recovery image.

4. Flashing the Custom TWRP

Now that you have the custom TWRP image, you can flash it to your device.

  1. Enable USB Debugging: On your device, go to Settings > About phone and tap “Build number” repeatedly until Developer options are enabled. Then, go to Settings > Developer options and enable USB debugging.

  2. Boot into Bootloader Mode: The method for entering bootloader mode varies depending on your device. Common methods include holding the Power button and Volume Down button simultaneously while the device is off or using the adb reboot bootloader command.

  3. Flash the Recovery Image: In the command prompt or terminal, navigate to the directory where you saved new-recovery.img. Then, execute the following command:

    fastboot flash recovery new-recovery.img
    
  4. Reboot into Recovery: After flashing is complete, reboot your device into recovery mode. Again, the method for doing this varies. Common methods include holding the Power button and Volume Up button simultaneously or using the fastboot reboot recovery command.

5. Testing and Troubleshooting

Once you’ve booted into TWRP, thoroughly test its functionality.

If you encounter issues, carefully review the steps above and check the following:

Leveraging GitHub Builders

GitHub-based TWRP builders offer a more automated approach to creating custom recovery images. These builders typically provide a web interface or command-line interface that allows you to specify your device details and build a TWRP image without manually modifying the ramdisk.

How to Use a GitHub TWRP Builder

  1. Choose a Builder: Select a reputable TWRP builder repository on GitHub. Look for builders that are actively maintained and have positive feedback from other users.
  2. Follow the Instructions: Each builder will have its own specific instructions for usage. These instructions typically involve cloning the repository, installing dependencies, and configuring the builder with your device details.
  3. Provide Device Information: The builder will typically require you to provide information such as your device’s model number, Android version, and kernel configuration.
  4. Build the Image: Once you’ve configured the builder, you can initiate the build process. The builder will automatically download the necessary files, modify the ramdisk, and create a TWRP image.
  5. Flash and Test: After the image is built, flash it to your device and test its functionality as described above.

Advantages of Using a GitHub Builder

Disadvantages of Using a GitHub Builder

Important Considerations and Precautions

Alternative Solutions: Dynamic Partitions and A/B Devices

Many modern Android devices use A/B partitioning and/or dynamic partitions, which can complicate the process of creating a custom recovery.

If your device uses A/B partitions or dynamic partitions, you’ll need to ensure that the TWRP image you build supports these features. Some TWRP builders provide options for building images that are compatible with A/B partitions and dynamic partitions.

Magisk Modules and Post-Installation Tweaks

Once you have a working custom TWRP recovery, you can further enhance your device by flashing Magisk modules.

Conclusion

Creating a custom TWRP recovery without kernel source for Chinese phones requires careful planning, thorough research, and attention to detail. While challenging, it is possible with the right tools and techniques. By following the steps outlined in this guide and taking the necessary precautions, you can unlock the full potential of your device and customize it to your liking. Remember to back up your device, research thoroughly, and be patient throughout the process. Good luck!

Redirecting in 20 seconds...

Explore More