[Miscellaneous Android Development] FEGuy:
EDIT: This guide is outdated - see this thread for up-to-date instructions.

Guide: Getting TWRP on the Visible R2

Disclaimer: this is a work-in-progress and things will probably go wrong. I take no responsibility for bricked phones, lost data, etc. By following this guide you acknowledge the risks that these steps entail. Your warranty is probably void. Always make a backup of your files first.

What you need:

prog_emmc_firehose8917.mbn (included in b10 firmware or attached a few posts below; not included in b12)

A stock firmware package

TWRP built for the R2

ADB (Linux users can install it through their package manager)

Windows users will also need to install QFIL and the drivers from the first post before starting.

Instructions

For Windows and Linux:

0) Unzip the TWRP zip to an easily-accessible (and preferably empty) directory. You can discard the META-INF folder - it's only useful for flashing TWRP from inside TWRP.

1) Open up the firmware build you downloaded from the first post. All you'll need at the moment is the prog_emmc_firehose_8917.mbn, but it wouldn't hurt to keep the stock files handy. Place the firehose in the same folder as the TWRP image and its XML files.

2)Open ADB (or a terminal window) on your PC and enable USB debugging on your phone. Reboot the phone into EDL mode via adb:

adb reboot edl

For Windows:

3) Download and set up QFIL as described in the first post. Open QFIL.

4) Select Flat Build, press the Select Programmer button, then navigate to the TWRP folder and select the prog_emmc_firehose_8917.mbn.

5) Press the Load XML button, selecting rawprogram_recovery.xml first, then patch0.xml.

6) If QFIL prompts you to select an available port, do so with the Select Port button. Unless you have another phone connected in diagnostics or EDL mode, there should only be one option available.

7) Click the download button and wait for it to finish. If there's some sort of error, post it here so someone can help sort it out. Otherwise, reboot your phone when the download finishes.

For Linux users:

3) Download qdl. If your distro supports Snap packages, this is pretty painless.

sudo snap install qdl

The snap version doesn't seem to work, sorry.

3a) If your distro doesn't have snap support, compiling qdl is also simple enough:

Download or clone the source code for qdl and open a terminal window in the directory it's extracted to.

You may need to install libudev and libxml2 to compile, and perhaps more if you don't already have build tools set up on your machine. Assuming most people reading this will be using a Ubuntu-based distro:

sudo apt install libudev-dev libxml2-dev

That should be enough to compile! Assuming you're in the directory with the Makefile, installing the program should be a breeze:

make && sudo make install

If nothing fails, you should be able to run qdl.

4) ModemManager might be running on your machine, which will likely cause qdl to hang at 'Waiting for EDL device'. Stop the service for now; you can restart it later if you need to.

sudo systemctl stop ModemMangager

5) Navigate to the folder where the image, firehose, and XML files are stored. If qdl is installed properly, one command is all you need to flash your device:

sudo qdl prog_emmc_firehose_8917.mbn rawprogram_recovery.xml patch0.xml

6) That's it! If everything goes as expected, the device should reboot in a minute or two.

Now that TWRP is installed (successfully, hopefully), you should be able to boot into it by holding the Vol Up key while starting/rebooting the phone, or over adb by sending the 'adb reboot recovery' command. From here, you can backup and restore as you please, flash zip files, and enter a root shell for modifying files on system partitions.

Note that on startup, TWRP might freeze for a minute as it tries to decrypt the data partition. TWRP doesn't know the encryption password for this device and will not be able to mount or back up an encrypted data partition. If you want to disable forced encryption, download this and follow the steps below, but keep in mind that the partition will stay encrypted until it's wiped.

Open a terminal in the same folder as the fstab.qcom file you downloaded. You'll want to have your phone in recovery mode and connected for ADB. Back up the vendor partition in TWRP first, then run the following commands, one line at a time.

adb shell mount /vendor
adb pull /vendor/etc/fstab.qcom fstab.qcom.bak
adb push fstab.qcom /vendor/etc/fstab.qcom
adb shell chmod 644 /vendor/etc/fstab.qcom
adb shell umount /vendor

This will back up the original fstab, replace it with one that doesn't force encryption on the phone's data partition, make sure the permissions are set properly, then unmount the volume. If anything goes wrong, you can restore the backup of the partition you made, or restore just the fstab by renaming fstab.qcom.bak to fstab.qcom and following the above steps.

If ADB or MTP don't work properly in recovery, press Mount and toggle the Disable MTP button. This seems to happen on boots where TWRP tried and failed to decrypt data.

If your phone starts bootlooping, boot into TWRP and boot to system from the button there. This seems to happen every once in a while when modifying system partitions, and honestly I'm not sure what the cause is. If all else fails, restore the stock boot.img.