• Introducing XDA Computing: Discussion zones for Hardware, Software, and more!    Check it out!

Development [RECOVERY][OFFICIAL] TWRP for ASUS ROG Phone 5 & ROG Phone 5S

Search This thread

Alexio34

Member
Sep 15, 2021
12
2
Flashing a custom kernel also won't install / restore Magisk. The custom builds are meant to retain Magisk, but don't actually perform any of the installation.

You can install TWRP over a custom kernel and the kernel will remain, but Magisk will be gone and need to be reinstalled. At this point, the app will only allow you to patch a supported image (img / tar, but also supports win without saying it) and the custom kernels include none of those. This means you need a Magisk recovery zip or need a backup of the kernel to patch with Magisk.

You can also install a custom kernel over TWRP, but you would need to already have Magisk patched in after installing TWRP or install it after the kernel (see above).

TL;DR

The easiest way (for me) to install TWRP with a custom kernel was to
boot and install TWRP
make a backup of the boot
reboot to system
patch the boot in Magisk
return to TWRP and install the image.
Flashing a custom kernel also won't install / restore Magisk. The custom builds are meant to retain Magisk, but don't actually perform any of the installation.

You can install TWRP over a custom kernel and the kernel will remain, but Magisk will be gone and need to be reinstalled. At this point, the app will only allow you to patch a supported image (img / tar, but also supports win without saying it) and the custom kernels include none of those. This means you need a Magisk recovery zip or need a backup of the kernel to patch with Magisk.

You can also install a custom kernel over TWRP, but you would need to already have Magisk patched in after installing TWRP or install it after the kernel (see above).

TL;DR

The easiest way (for me) to install TWRP with a custom kernel was to
boot and install TWRP
make a backup of the boot
reboot to system
patch the boot in Magisk
return to TWRP and install the patched boot image.
Thanks for explaining in details, this will be useful as mini guide, can anyone pin the answer, please?
 

Captain_Throwback

Recognized Developer
Flashing a custom kernel also won't install / restore Magisk. The custom builds are meant to retain Magisk, but don't actually perform any of the installation.

You can install TWRP over a custom kernel and the kernel will remain, but Magisk will be gone and need to be reinstalled. At this point, the app will only allow you to patch a supported image (img / tar, but also supports win without saying it) and the custom kernels include none of those. This means you need a Magisk recovery zip or need a backup of the kernel to patch with Magisk.

You can also install a custom kernel over TWRP, but you would need to already have Magisk patched in after installing TWRP or install it after the kernel (see above).

TL;DR

The easiest way (for me) to install TWRP with a custom kernel was to
boot and install TWRP
make a backup of the boot
reboot to system
patch the boot in Magisk
return to TWRP and install the patched boot image.
That seems like a lot of unnecessary steps. If you already have Magisk installed, then you must have the Magisk apk somewhere already. That being the case, why not just:
-Boot and install TWRP
-Install Magisk apk in TWRP (this re-installs it after the TWRP install overwrites it)
-Reboot to system and profit

The custom kernel won't be affected at all, and you'll be restored to your previously rooted state. Fiddling around with patched boot images doesn't seem reasonable for such a simple operation. TWRP is supposed to make things easier, not more complicated.
 
That seems like a lot of unnecessary steps. If you already have Magisk installed, then you must have the Magisk apk somewhere already. That being the case, why not just:
-Boot and install TWRP
-Install Magisk apk in TWRP (this re-installs it after the TWRP install overwrites it)
-Reboot to system and profit

The custom kernel won't be affected at all, and you'll be restored to your previously rooted state. Fiddling around with patched boot images doesn't seem reasonable for such a simple operation. TWRP is supposed to make things easier, not more complicated.

Actually, I did not have the apk or know that TWRP could install it, but thanks for the extra ~45 seconds you'll save the next person if they have it.
 

Captain_Throwback

Recognized Developer
Actually, I did not have the apk or know that TWRP could install it, but thanks for the extra ~45 seconds you'll save the next person if they have it.
How did you install the Magisk app without the APK? Also, I think you underestimate how much time it'll take a "normal" user to patch a boot image and install it ;)
 
How did you install the Magisk app without the APK? Also, I think you overestimate how much it'll take a "normal" user to patch a boot image and install it ;)

It restored when I did setup, but I usually 'adb install -r' and delete the once and done stuff. Haven't updated it recently, so there was no copy from that.

Also haven't used TWRP in at least 4 years.

The custom kernel won't be affected at all, and you'll be restored to your previously rooted state. Fiddling around with patched boot images doesn't seem reasonable for such a simple operation. TWRP is supposed to make things easier, not more complicated.

Looks like you'd be better off installing the custom kernel before / after Magisk, even if it was already installed first. In addition to Magisk, any overlay.d scripts are discarded. On the 5, that is how you load the secondary display and sound drivers.
 
Last edited:

Captain_Throwback

Recognized Developer
insmod "/v/lib/modules/$1.ko" -> insmod "/vendor/lib/modules/$1.ko"

If my tests were accurate, it fixes the issues with lost magisk / kernel install
Not sure where this change would be? Nothing in TWRP should be affecting how modules get loaded in Android.

If there are any ramdisk changes done by the kernel, then it does make sense that they would be lost when repacking TWRP into the boot.img. There is some issue with the TWRP ramdisk not being available for the kernel module addon and some items aren't getting copied for the Magisk module. Working with @Freak07 on that presently.

Boot TWRP
Install TWRP
Install Magisk
Install Kernel
Reboot

No issues, everything works.
Your change here doesn't make any sense. The code you changed is loading modules from the temporarily mounted vendor partition when TWRP is installed in the boot.img. Loading the modules from /vendor/lib/modules will just load them from the TWRP ramdisk, which is redundant with what already happens in init.recovery.qcom.rc. All of this is irrelevant anyway as that was just a temporary fix and has been deprecated in the official tree on the TeamWin repo.

Please check the official tree instead and if you have any changes to it, you can push to TWRP Gerrit for review.
 
Not sure where this change would be? Nothing in TWRP should be affecting how modules get loaded in Android.

If there are any ramdisk changes done by the kernel, then it does make sense that they would be lost when repacking TWRP into the boot.img. There is some issue with the TWRP ramdisk not being available for the kernel module addon and some items aren't getting copied for the Magisk module. Working with @Freak07 on that presently.

Your change here doesn't make any sense. The code you changed is loading modules from the temporarily mounted vendor partition when TWRP is installed in the boot.img. Loading the modules from /vendor/lib/modules will just load them from the TWRP ramdisk, which is redundant with what already happens in init.recovery.qcom.rc. All of this is irrelevant anyway as that was just a temporary fix and has been deprecated in the official tree on the TeamWin repo.

Please check the official tree instead and if you have any changes to it, you can push to TWRP Gerrit for review.


The issue you are facing is that you aren't preserving magisk when the image tinkers with the boot to install TWRP.

In trying to look for that issue, I came across a typo that fixes loading modules.

I read across a few people reporting that installing TWRP broke all ability to install kernels from TWRP and have the helper module load. I did not find this to be the case and was reporting that.

I'm not entirely sure what point you are trying to make, but the reason the post was edited was that I realized the modules and magisk were unrelated. I'm sure you already figured that out, but I get what you are trying to accomplish.
 

Captain_Throwback

Recognized Developer
The issue you are facing is that you aren't preserving magisk when the image tinkers with the boot to install TWRP.

In trying to look for that issue, I came across a typo that fixes loading modules.

I read across a few people reporting that installing TWRP broke all ability to install kernels from TWRP and have the helper module load. I did not find this to be the case and was reporting that.

I'm not entirely sure what point you are trying to make, but the reason the post was edited was that I realized the modules and magisk were unrelated. I'm sure you already figured that out, but I get what you are trying to accomplish.
Yeah I thought I had posted that original reply before you edited the message, and then my second reply was only dealing with your pull request. But when I posted that, both replies got posted.

There isn't a typo in the script, though - /v/lib/modules is the correct path. /vendor/lib/modules is the TWRP ramdisk, and the same modules already attempt to get loaded from there in init.recovery.qcom.rc. If TWRP is booted, though, those modules may not match the installed kernel, which is why we temp mount vendor at /v (so as not to interfere with the TWRP ramdisk) and load the modules from there that should match the installed kernel.

So I'm still confused on your pull request, unless you're saying you understand what's happening there now.
 
Yeah I thought I had posted that original reply before you edited the message, and then my second reply was only dealing with your pull request. But when I posted that, both replies got posted.

There isn't a typo in the script, though - /v/lib/modules is the correct path. /vendor/lib/modules is the TWRP ramdisk, and the same modules already attempt to get loaded from there in init.recovery.qcom.rc. If TWRP is booted, though, those modules may not match the installed kernel, which is why we temp mount vendor at /v (so as not to interfere with the TWRP ramdisk) and load the modules from there that should match the installed kernel.

So I'm still confused on your pull request, unless you're saying you understand what's happening there now.

You're loading the modules for use by TWRP, correct? The modules you load in that script are the ones in the TWRP ramdisk or you just happened to pick the same ones by complete coincidence. If that were the case, why load the tuxera that was dropped by Kirisakura or not load the others used by stock?

One of your other issues is a rather obnoxious sound that accompanies vibration and one of the modules you aren't loading is a sound driver. It didn't fix the issue to fix the typo, but there was no harm notifying you of it beyond the hostility.
 

Captain_Throwback

Recognized Developer
You're loading the modules for use by TWRP, correct? The modules you load in that script are the ones in the TWRP ramdisk or you just happened to pick the same ones by complete coincidence. If that were the case, why load the tuxera that was dropped by Kirisakura or not load the others used by stock?

One of your other issues is a rather obnoxious sound that accompanies vibration and one of the modules you aren't loading is a sound driver. It didn't fix the issue to fix the typo, but there was no harm notifying you of it beyond the hostility.
The modules are being loaded for use in TWRP, yes. But there are two different situations for which the modules are being loaded, requiring 2 different sets of modules:
- When TWRP is fastboot booted, the prebuilt kernel built with the TWRP image is used, and the modules in the TWRP ramdisk are loaded by default (via the insmod commands in init.recovery.qcom.rc). Those are the modules associated with the custom kernel built specifically for TWRP.
- When TWRP is permanently installed, and the user boots into recovery, the device boot.img kernel is used. The modules in the TWRP ramdisk may not load for that kernel, so the insmod commands for the TWRP ramdisk will fail. In that case, the load_modules script will run, which loads modules from the temporarily mounted device vendor partition, where the modules can be loaded that will match the boot.img kernel. Vendor is temp mounted at /v by the prepdecrypt script, so the modules are loaded from /v/lib/modules/$1.ko.
If the script loaded the modules from /vendor/lib/modules, that would just be attempting to load the same modules from the first bullet point, which would be redundant.

For the sound/vibration issue, I think that's an issue with the device tree, for which I already applied a fix to the official trees. Which device do you have, btw? Depending on whether you have a 5 or 5S, the vibration support in TWRP is different. The 5 uses TSPDRV and the 5S uses the aw8697_haptic driver (same as ZF8).

P.S. We only load the modules that are needed for TWRP to fully function, so there's no need to load any other modules besides the haptic and vibration and the exfat/NTFS support.

P.P.S. Not sure if you were insinuating that I was being hostile but I'm just trying to explain that the script is correct, and I'm getting a little frustrated that you keep saying it isn't.
 
The modules are being loaded for use in TWRP, yes. But there are two different situations for which the modules are being loaded, requiring 2 different sets of modules:
- When TWRP is fastboot booted, the prebuilt kernel built with the TWRP image is used, and the modules in the TWRP ramdisk are loaded by default (via the insmod commands in init.recovery.qcom.rc). Those are the modules associated with the custom kernel built specifically for TWRP.
- When TWRP is permanently installed, and the user boots into recovery, the device boot.img kernel is used. The modules in the TWRP ramdisk may not load for that kernel, so the insmod commands for the TWRP ramdisk will fail. In that case, the load_modules script will run, which loads modules from the temporarily mounted device vendor partition, where the modules can be loaded that will match the boot.img kernel. Vendor is temp mounted at /v by the prepdecrypt script, so the modules are loaded from /v/lib/modules/$1.ko.
If the script loaded the modules from /vendor/lib/modules, that would just be attempting to load the same modules from the first bullet point, which would be redundant.

For the sound/vibration issue, I think that's an issue with the device tree, for which I already applied a fix to the official trees. Which device do you have, btw? Depending on whether you have a 5 or 5S, the vibration support in TWRP is different. The 5 uses TSPDRV and the 5S uses the aw8697_haptic driver (same as ZF8).

P.S. We only load the modules that are needed for TWRP to fully function, so there's no need to load any other modules besides the haptic and vibration and the exfat/NTFS support.

P.P.S. Not sure if you were insinuating that I was being hostile but I'm just trying to explain that the script is correct, and I'm getting a little frustrated that you keep saying it isn't.

I have a 5.

There is no need to load the secondary display module unless TWRP intends to use the rear display / touch. I haven't tracked down the actual purpose of the secondary sound driver.

I missed where it was loaded as "v" and... you can figure out the rest from what I was trying to verify.
 

Captain_Throwback

Recognized Developer
I have a 5.

There is no need to load the secondary display module unless TWRP intends to use the rear display / touch. I haven't tracked down the actual purpose of the secondary sound driver.

I missed where it was loaded as "v" and... you can figure out the rest from what I was trying to verify.
Good to know on the second touch driver. But we're not loading any sound driver at all.

Sinve you have a 5, your device needs the tspdrv support which isn't currently enabled in this tree. The official tree does have that support added, so that build should work fine for you. If you want to test one built with that support, you can try this build:

 
Good to know on the second touch driver. But we're not loading any sound driver at all.

Sinve you have a 5, your device needs the tspdrv support which isn't currently enabled in this tree. The official tree does have that support added, so that build should work fine for you. If you want to test one built with that support, you can try this build:


I am ok with disabling vibration, but thanks for the link.

Ah, you aren't loading sound. I'm so used to the two drivers being the fts_rog2 and sx932x that I didn't even realize it was aw8697 and the other indented line was fts_rog. This is what I get for looking at too many repositories at once.
 

Ipedrot

Member
Aug 12, 2021
7
0
ASUS ROG Phone 5
very good contribution .. I managed to do a firmware downgrade, I had tried many methods but only with this one I could do it. The but is that after installing the firmware it throws me an error when starting android with the message that the software is corrupt after this it sends me to recovery where I get several "no" and 1 "yes" I select yes and it reboot the phone and managed to start the phone. Is it normal for me to throw that error?

Ícono de validado por la comunidad
 

zel-jko

Member
Feb 23, 2009
13
0
Oh heck yes!!!! This phone will finally be perfect. Thanks for your work and effort.

Here's my trip around the sun;

Downloaded the file twrp-3.5.2_11-2zs673ks.img and renamed it to just twrp.img. (So it's easier to type in CMD).
Placed it on the root of my C: Drive where I keep all my flash files.

Shut down phone, Then Volume up and power to go to fastboot mode. That's the screen where it shows some options like Power On, Recovery Mode and Reboot. Just stay there, dont select anything.

Connected the cable via side USB port and executed the following commands;

View attachment 5411207

First command to check connectivity, second command is to boot to TWRP.
No flashing !! remember always; new TWRP cannot be flashed through fastboot because recovery is a part of the existing partition, not a separate one like it used to be on Android 8 and below.

Once you execute the above command, be patient. Your phone will come back to bootloader screen making it look like it failed. Just wait, it will reboot again and it will go to TWRP. Now you can enter you pin code, and enter the recovery.
I flashed a kernel, I cleared my dalvik cache .. everything went well.




Now if you want to keep TWRP permanent;

Copy the twrp.img to your phone memory, preferably downloads folder of the phone, and follow the above steps mentioned - again up to entering TWRP.

In TWRP, select advanced, and you will see the below screen -

View attachment 5411209

Select the option - Install Recovery Ramdisk and it will ask where your TWRP.img is, and point it to the file you earlier saved in the phone / downloads folder. This will flash TWRP within the kernel making it permanent along with your kernel.

That's it, reboot and enjoy.

EDIT : How to get to TWRP again;
From CMD - send adb reboot recovery or
shut down phone, Volume UP + Power .. In bootloader press volume down until you see recovery mode, and then press the power button once to select it.
hi why do i get :
PS C:\Users\user> fastboot boot twrp.img
downloading 'boot.img'...
OKAY [ 2.176s]
booting...
FAILED (remote: Unrecognized command boot)
finished. total time: 2.192s
PS C:\Users\user> fastboot flash twrp.img
unknown partition 'twrp.img'
error: cannot determine image filename for 'twrp.img'
 

Captain_Throwback

Recognized Developer
hi why do i get :
PS C:\Users\user> fastboot boot twrp.img
downloading 'boot.img'...
OKAY [ 2.176s]
booting...
FAILED (remote: Unrecognized command boot)
finished. total time: 2.192s
PS C:\Users\user> fastboot flash twrp.img
unknown partition 'twrp.img'
error: cannot determine image filename for 'twrp.img'
You need to be in bootloader, not fastbootd.
 

zel-jko

Member
Feb 23, 2009
13
0
what command needs to be issued to go to bootloader and once in bootloader how is fastboot going to boot into twrp if adb does not see device (not in fastboot you said).Could someone please show exact steps!
Thanks in advance!
 

Top Liked Posts

  • There are no posts matching your filters.
  • 11
    Code:
    *** Disclaimer ***
    
    All flashing is done at your own risk!
    While nothing from this thread should break your device,
    don't come back here blaming anyone if it does!

    Introduction

    Team Win Recovery Project 3.x, or twrp3 for short, is a custom recovery built with ease of use and customization in mind. Its a fully touch driven user interface no more volume rocker or power buttons to mash. The GUI is also fully XML driven and completely theme-able. You can change just about every aspect of the look and

    Images



    Prerequisites

    Installation instructions

    Fastboot Install Method:
    You will need the platform-tools from the Android SDK on your computer. Find the Android command line tools section on the page linked and install the SDK tools package. From the SDK Manager, download only the platform-tools to get adb and fastboot binaries.

    Windows users will need proper drivers installed on their computer. You can try the Naked ADB drivers or the Universal ADB drivers if you don't already have a working driver installed

    On your device, go into Settings -> About and find the Build Number and tap on it 7 times to enable developer settings. Press back and go into Developer Options and enable USB debugging. From your computer, open a command prompt and type:
    Code:
    Code:
    adb reboot bootloader
    You should now be in fastboot mode.

    Download the correct image file and copy the file into the same folder as your adb and fastboot binaries. Rename the image to twrp.img and type:
    Code:
    Code:
    fastboot boot twrp.img

    Now you are booted into TWRP, but it is NOT permanently installed. To install it permanently, use the "Flash current TWRP" option in the Advanced menu. This will install the currently booted TWRP permanently to both slots. NOTE: If you were previously rooted, you will need to re-install the root apk/zip as the TWRP install will overwrite it!

    Device Changelog

    Current version: 3.5.2_11-2:
    3.5.2_11-2
    • Common version for all ROG 5 versions.
    • Fixed decryption issue
    3.5.2_11-0:

    Initial version (Tested only on ROG Phone 5S, need info about ROG Phone 5).



    Device Changelog


    Known issues

    Device-specific
    • USB-OTG not working
    • Battery Status not working

    Bug reporting

    If you have an issue, the first step is to post a recovery log so we can determine the cause of the issue. This is done in recovery using Advanced -> Copy Log, or adb pull /tmp/recovery.log. Once a log is uploaded we can determine how best to proceed. NOTE: Posts that are reporting bugs or issues without an accompanying recovery log will be ignored! Additionally, providing details about your device setup, including variant, firmware version, and exact steps to reproduce your issue will also be helpful in diagnosing the problem.

    If your issue is determined to be a bug, please consider posting it to our github issues log. It's pretty much impossible for us to keep up with the more than 40 threads that we have for the devices that we "directly" support. If you have a significant problem that cannot be answered in this thread, your best bet is to contact us via our website. If you see someone that's struggling, feel free to point it out to us. We need your help to help us keep track of all of our devices! Thanks!

    Additional Help/Support

    Live support is available on Zulip.

    Credits

    @Freak07 and @Captain_Throwback for advices
    @Qtr1st and @danfrid for testing
    5
    Here's my trip around the sun;

    Downloaded the file twrp-3.5.2_11-2zs673ks.img and renamed it to just twrp.img. (So it's easier to type in CMD).
    Placed it on the root of my C: Drive where I keep all my flash files.

    Shut down phone, Then Volume up and power to go to fastboot mode. That's the screen where it shows some options like Power On, Recovery Mode and Reboot. Just stay there, dont select anything.

    Connected the cable via side USB port and executed the following commands;

    0023.png


    First command to check connectivity, second command is to boot to TWRP.
    No flashing !! remember always; new TWRP cannot be flashed through fastboot because recovery is a part of the existing partition, not a separate one like it used to be on Android 8 and below.

    Once you execute the above command, be patient. Your phone will come back to bootloader screen making it look like it failed. Just wait, it will reboot again and it will go to TWRP. Now you can enter you pin code, and enter the recovery.
    I flashed a kernel, I cleared my dalvik cache .. everything went well.




    Now if you want to keep TWRP permanent;

    Copy the twrp.img to your phone memory, preferably downloads folder of the phone, and follow the above steps mentioned - again up to entering TWRP.

    In TWRP, select advanced, and you will see the below screen -

    Screenshot_2021-09-16-07-36-25 (Medium).png


    Select the option - Install Recovery Ramdisk and it will ask where your TWRP.img is, and point it to the file you earlier saved in the phone / downloads folder. This will flash TWRP within the kernel making it permanent along with your kernel.

    That's it, reboot and enjoy.

    EDIT : How to get to TWRP again;
    From CMD - send adb reboot recovery or
    shut down phone, Volume UP + Power .. In bootloader press volume down until you see recovery mode, and then press the power button once to select it.
    2
    Flashing a custom kernel also won't install / restore Magisk. The custom builds are meant to retain Magisk, but don't actually perform any of the installation.

    You can install TWRP over a custom kernel and the kernel will remain, but Magisk will be gone and need to be reinstalled. At this point, the app will only allow you to patch a supported image (img / tar, but also supports win without saying it) and the custom kernels include none of those. This means you need a Magisk recovery zip or need a backup of the kernel to patch with Magisk.

    You can also install a custom kernel over TWRP, but you would need to already have Magisk patched in after installing TWRP or install it after the kernel (see above).

    TL;DR

    The easiest way (for me) to install TWRP with a custom kernel was to
    boot and install TWRP
    make a backup of the boot
    reboot to system
    patch the boot in Magisk
    return to TWRP and install the patched boot image.
    That seems like a lot of unnecessary steps. If you already have Magisk installed, then you must have the Magisk apk somewhere already. That being the case, why not just:
    -Boot and install TWRP
    -Install Magisk apk in TWRP (this re-installs it after the TWRP install overwrites it)
    -Reboot to system and profit

    The custom kernel won't be affected at all, and you'll be restored to your previously rooted state. Fiddling around with patched boot images doesn't seem reasonable for such a simple operation. TWRP is supposed to make things easier, not more complicated.