[Sony XA2 Ultra Guides, News, & Discussion] xstasi:
This is a step-by-step guide that will get you to a fully working lineageos on your sony xa2 ultra, starting from a device that was just purchased.

I used Linux, but everything should be more than doable on Windows as well.

Make sure you have:

A copy of platform-tools from google (ubuntu's version works to some extent, i had to use binaries from both). You need:

fastboot

adb

The TWRP image for XA2 ultra: twrp-3.2.3-0-discovery.img

A working copy of xperifirm. If you're on Linux set a light UI theme, or it won't work. Also

export TERM=xterm

before launching it.

A working copy of newflasher. You can build it on linux by typing

make newflasher.x64

newflasher.x64 will be the name of the binary.

A fresh lineageos build for your phone (from now on referred to as lineage.zip)

A build of gapps, if you want them

The first thing you have to do is to

Unlock your bootloader

Preliminary operations:

Start your phone

Connect to the internet (3g or wifi)

Go to Settings > System > Device info, tap "Build number" until developer mode is active

Go back, open developer options

Tick USB Debugging and OEM Unlock

Open the phone dialer and type

*#*#7378423#*#*

this will open the service menu. It could take a few seconds.

Go to Service info

Enter 'Model info', write down the string (e.g. H4213) somewhere

Go back and enter 'Configuration'.

Check that "Bootloader unlockable" is 'yes', if it's not you can't proceed.

Write down the IMEI code. If it's a dual sim, you need to write down the "Sub1" one.

Go here, select the device and paste the IMEI that you wrote down

Write down the unlock code

Put phone in fastboot mode and unlock the bootloader:

Shut down the phone completely, unplug the USB cable if plugged

Hold VolumeUp, plug USB cable

Phone should power on, press Power if it doesn't

Wait until you have a fixed blue light on the led

You are now in fastboot mode

fastboot oem unlock xxxxx

where xxxxx is the unlock code that you obtained from the previous step

Flash an updated firmware

First you need to obtain the latest firmware for your device:

Run xperifirm

Open Sony XA2 discovery

Select whatever you wrote down from the 'Model info' section of the service menu

Download whatever firmware has the highest build number

If you're on Linux xperifirm will fail to unpack the firmware. You can work around it by entering the firmware directory on a shell and running:

for i in FILE_* ; do unzip $i ; done
unzip boot.zip -d boot

Remove a bunch of files, you can copy/paste this string after 'rm' or delete them manually:

kernel_X-FLASH-ALL-18AE_0x00.hash kernel_X-FLASH-ALL-18AE.sin persist_X-FLASH-ALL-18AE_0x00.hash persist_X-FLASH-ALL-18AE.sin system_other_X-FLASH-ALL-18AE_0x00.hash system_other_X-FLASH-ALL-18AE.sin system_other_X-FLASH-ALL-9B8D_0x00.hash system_X-FLASH-ALL-18AE_0x00.hash system_X-FLASH-ALL-18AE.sin system_X-FLASH-ALL-9B8D_0x00.hash userdata_X-FLASH-CUST-18AE.sin vendor_X-FLASH-ALL-18AE_0x00.hash vendor_X-FLASH-ALL-18AE.sin vendor_X-FLASH-ALL-9B8D_0x00.hash

Put your phone in flashing mode.

Shut down the phone completely, unplug the USB cable if plugged

Hold VolumeDown, plug USB cable

Phone should power on, press Power if it doesn't

Wait until you have a fixed green light on the led

You are now in flashing mode

Run

newflasher

(or newflasher.x64 if you built it yourself) from the directory where you have the remaining firmware files. It could ask you whether to dump the TA section, feel free to answer 'n'.

Go back in fastboot mode, and run:

fastboot set_active other

Then rerun the last list (go to flashing mode, run newflasher).

If 'other' doesn't work, run "fastboot getvar current-slot" in fastboot mode and then use either 'a' or 'b' instead of 'other' - whatever is not the one returned by getvar.

Flash lineage

Boot into TWRP:

Put your phone in fastboot mode (see above)

fastboot boot twrp-3.2.3-0-discovery.img

You are now in TWRP

When I first tried this my phone kept power cycling. If this happens to you too, here is how to fix it:

Hold VolUp and let it power cycle until it goes into fastboot mode again (fixed blue led)

fastboot -w

Try booting into TWRP again

Flash lineage:

On TWRP go to advanced, enable sideload

On your computer run:

adb sideload lineage.zip

It should start flashing by itself, if it doesn't, make it.

If you want to also flash gapps, repeat steps from 'Boot into TWRP' and flash the gapps zip file.

Reboot your phone into fastboot one last time, and run

fastboot -w

.

Reboot with

fastboot reboot

.

Congratulations, you're now running lineage!