[Sony Xperia XZ Guides, News, & Discussion] nathan30:
Hi,

After some errors I did, I decide to write a guide for new people with the Xperia XZ. First of all, I want to thanks @DGHE for his complete guide on my thread. Lot of informations here are coming from his post.

Also thank a lot to @shoey63 for his guide to restore TA partition

Let's go now

*** Disclaimer

Your waranty is now void
Do all this manipulations at your own risk.
Me, XDA and any members are not responsible if you brick your device while doing any of this manipulations

PRE-REQUISITES
​

ADB and FASTBOOT : https://xdaforums.com/showthread.php?t=2317790

Xperia XZ drivers : http://developer.sonymobile.com/downloads/drivers/xperia-xz/

FlashTool : http://www.flashtool.net/downloads.php *optional*

UNLOCK your bootloader
​

Before doing any things like rooting or flashing TWRP you have to unlock your bootloader. To begin, you have to check if your bootloader could be unlock.

Open dialer app

Type *#*#7378423#*#*

Go to Service info/Configuration

Under "Rooting status" check if "Bootloader unlock allowed " is on "yes". If not, you can leave this thread, there is no solutions for you.

Before unlock it, you have to know a things. If you unlock your bootloader, you will loose the DRM Keys (More infos here : https://xdaforums.com/z3-compact/general/loss-drm-keys-t2890936) and your device will be factory reset. So you HAVE TO BACKUP YOUR TRIM AREA partition first and backup your data(like pictures, SMS etc..). For this, follow this steps :

If you are under Nougat already, you have to downgrade to Marshmallow first. The TA Backup Tool won't work under Nougat (If you're under MM, go to 6) )

Download the latest version of FlashTool from the official website : http://www.flashtool.net/downloads.php

Install it and install the drivers for fastmode and for your device (stituated in the driver folder of flashtool)

Go to XperiFirm (hint : http://imgur.com/cjTzitM) and choose Xperia XZ (Kagura) then F8831 or F8832. Click on "Check All" on the top right and choose a 39.0.A.1.250 firmware. Personnaly I took the FR/PT - Altice FR/PT fw. On you're right you'll see, under the Xperia XZ pic, something like this : http://imgur.com/Nb78HWT. Just click on the fw name and download it. Close it after download, and close XperiFirm. FlashTool will now unpack the new firmware, wait for the end. Then click on Flash (hint : http://imgur.com/Yp9dpVx) and choose Flashmode option. Choose your downloaded firmware on the left and check the following : http://imgur.com/6U2PRvC then click on "Flash". Last step is to put your phone in Flashmode : Power OFF then Press VOLUME DOWN while you're plug the USB cable IN, you'll see a black screen with a green LED. Don't forget to wait until FlashTool say the job is done !

Reboot, you are now on MM

Go to this thread and download the "backup-TA.zip" file : https://xdaforums.com/crossdevice-dev/sony/universal-dirtycow-based-ta-backup-t3514236

Check USB debugging in your phone and check ADB is installed

Run BackupTA.sh or BackupTA.cmd if you're on Windows

Your partition will be saved in a file called TA-ModelNumber-Serial-Timestamp.img. BACKUP IT

Next step is ask Sony for an unlock code. Go to http://developer.sonymobile.com/unlockbootloader/unlock-yourboot-loader/ and follow the following steps :

Read carrefully the disclaimer

Check OEM UNLOCKING and USB Debugging under Developer Options

Choose XPERIA XZ at the bottom of the page

Enter your email address and click on the link you'll received in your inbox and follow the instructions given by Sony.

BE CAREFUL and, from now on, NEVER EVER enable the MyXperia software. It could hard brick your phone

If you want to go back to Nougat, just repeat the step into Flashtool, but with the last firmware now ( 39.2.A.0.442 )

Flash AndroPlus Kernel​

This kernel includes some battery improvements and DRM fixes, to recover some of the lost functions. Here is how to install it :

Upgrade to latest firmware via Flashtool

Go to the official thread and download the latest XZ_AndroPlusKernel_vXX.zip file : https://xdaforums.com/xperia-xz/development/kernel-andropluskernel-v01-t3475240

Unzip the boot.img

Put your phone in bootloader mode (POWER OFF then VOL UP while you're plug the USB cable IN or adb reboot bootloader)

Flash the kernel with : fastboot flash boot boot.img

Reboot your phone

Flash TWRP​

Last step before rooting your XPERIA XZ ! :D

Thanks to AndroPlus, again, go to this link and download the latest TWRP img (TWRP-3.0.2-4-kagura.img) : https://drive.google.com/drive/folders/0B0j3VJ1Xp5N8Y1FZSmMwM1BOZDQ

Put your phone in bootloader mode

Flash the recovery with : fastboot flash recovery TWRP-3.0.2-4-kagura.img

Reboot your phone in recovery (POWER and VOLUME DOWN) to see if all is working good

ROOT your XPERIA XZ​

Finally, you can root your phone ;)

Download the flashable zip of SuperSU : https://download.chainfire.eu/1021/

Reboot to recovery

Flash SuperSU zip and wipe cache/dalvik

Here it is, your phone is now root ! :)

RESTORE TA partition and RELOCK bootloader​

Now, if you want to restore your TA partition and relock your Bootloader this is absolutely simple.

First of all, backup all the data you care of. Because your phone will be factory reset. Take your backuped TA partition and rename it TAbackup.img

Then, start your phone into recovery mode (TWRP)

Plug your phone with USB and check your device is recognized in recovery mode : adb devices

If it's okay, let's run this command now : adb push TAbackup.img /data/local/tmp/TAbackup.img

Then run this one : adb shell dd if=/data/local/tmp/TAbackup.img of=/dev/block/bootdevice/by-name/TA

Well, your TA partition is now back. Plug your phone off and you just have to flash a new STOCK ROM via FlashTool.

Now you have your original DRM and your bootloader is automatically relock !

Flash the stock ROM you want with Flashtool and enjoy a fresh and clean install