[Sony Xperia X Compact Guides, News, & Discussion] tuten1000:
There are way too many people to thank individually, but hopefully I linked to all the relevant threads. When you visit those threads, press the thank you.

this comprehensive guide helped me a lot:

https://xdaforums.com/crossdevice-dev/sony/root-root-stock-firmware-modern-sony-t3558904

Thanks to a lot of helpful info on these forums, I was able to start from the Sony stock rom and end up with a very clean install (mostly no Sony/Google stuff) with root.

I started from a stock 34.1.A.1.198. If you have a higher version, you'll have to downgrade. If you have any sort of data on this phone, back it up as you will likely lose everything. Here is what I did:

Computer Setup (Windows 10):

- disable secure boot in your bios. I had trouble installing stuff without this, YMMV.

http://www.windowspasswordsrecovery...isable-uefi-secure-boot-in-windows-8-1-8.html

- disable windows driver signing:

http://windowsreport.com/driver-signature-enforcement-windows-10/

Use Restart option. (The admin cmd doesn't really work).

- ADB/Fastboot install: see

https://xdaforums.com/showpost.php?p=48915118

- Flashtool:

http://www.flashtool.net/index.php

download 0.9.23.1 and patch to 0.9.23.2

install 0.9.23.1, then replace the x10flasher.jar file by the patch
​

install the drivers in drivers directory: select the common & fastboot
​

- install Sony USB driver:

https://developer.sonymobile.com/downloads/drivers/xperia-x-compact/

Phone setup:

On phone, enable developer

settings->about phone

click Build number 7 times
​

On phone, enable usb debugging

settings -> developer -> USB Debugging
​

Connect phone to USB

allow the computer when asked
​

Test adb:

Open a command prompt on the computer and type

adb devices

should show a device.
​

Backup TA (DRM keys):

https://xdaforums.com/crossdevice-dev/sony/universal-dirtycow-based-ta-backup-t3514236

Unzip backupTA_v2

cd backupTA_v2
backupTA.cmd

- it doesn't always work the first time. Run backupTA.cmd many times until it succeeds. Phone reboots supposedly help.

- reboot phone afterward

check drm status:

dial *#*#7378423#*#* on phone

brings up service menu

Service Tests->Security

Keys should show as "[Key OK][Active]"

FIDO_KEYS: Provisioned
​

Unlocking bootloader. do this only after backing up TA.

https://developer.sonymobile.com/unlockbootloader/unlock-yourboot-loader/

on phone:

settings -> developer -> OEM Unlocking -> enable

asks for pin, it's actually just your normal wakeup pin.
​

Turn phone off. Press Vol Up while plugging into USB cable (do not press power).

check it's working:

fastboot devices

should show something

use fastboot command from sony:

fastboot -i 0x0fce oem unlock 0xyyyy

(replace yyyy with whatever code you got)

after unlock, check drm status. It should say "generic error" and FIDO_KEYS won't be provisioned.

reboot the phone and connect to computer for file transfer.

put a memory card in the phone.

Preparing a kernel

Download new kernel: https://xdaforums.com/x-compact/development/kernel-xc-genesis-kernel-v1-01-t3525060

Get XC-GenesisKernel-v1.04-nodrm.zip

Download ta_proc.rar from https://xdaforums.com/crossdevice-dev/sony/poc-real-trim-instead-drm-fix-t3552893

unrar ta_proc

copy boot.img from the kernel zip to ta_proc directory

copy your TA backup to the ta_proc directory

double click DOUBLECLICKME.bat and choose the files you just copied. It should create new_boot.img

delete old boot.img in that directory and rename new_boot.img to boot.img

start with XC-GenesisKernel-v1.04-nodrm.zip, do not unzip, just drop and drop the new boot.img into that file.

Copy new kernel to the phone's SD card.

download superuser.zip from https://superuser.phh.me/

copy to memory card

this will be used later.

remove memory card.

Put rom 34.2.A.0.311 on the phone:

Xperifirm -- firmware downloading tool

https://xdaforums.com/crossdevice-dev/sony/pc-xperifirm-xperia-firmware-downloader-t2834142

Run xperifirm and download the "service exchange unit - 34.1.A.1.198" firmware for posterity and latest rom for your region.

I got 34.2.A.0.311.

Use flashtool tools->bundles->create

double click the device, pick X Compact

Fill in the other boxes.

select all the files and ->

create the ftf
​

Flash (big lightning button)

Flash using "flashmode"

under wipe, select everything

flash

follow instructions (vol -, plug in usb cable)
​

Don't reboot the phone after.

Download twrp:

https://xdaforums.com/x-compact/development/recovery-twrp-t3522249

put the phone in fastboot mode (vol +, usb plugin) check with

fastboot devices

Install twrp:

fastboot flash recovery twrp_6.0.img

unplug phone

put in the memory card

boot to recovery:

https://developer.sonymobile.com/20...for-a-range-of-unlocked-xperia-devices-video/

At the same time, press the Power button and Volume down until your device vibrates.

Quickly release the Power button, but keep pressing Volume down
​

twrp will show up. Select the kernel zip to flash. For me, that meant going up one level, then external_sd

install superuser.zip

reboot the phone, but be aware that a few boot loops is not unusual. Be patient, let it finish.

get through "getting started", enable debug

now is a good time to check your DRM keys again via the service menu.

Install busybox

https://f-droid.org/repository/browse/?fdfilter=busybox&fdid=ru.meefik.busybox

with adb:

adb install ru.meefik.busybox_27.apk

Install phh SU

https://f-droid.org/repository/browse/?fdid=me.phh.superuser

adb install me.phh.superuser_1033.apk

Run the busybox app on the phone (which does the binary install)

Cleaning the system:

(mostly from this thread: https://xdaforums.com/x-compact/help/apps-safe-to-remove-root-t3549871)

adb shell
su
cd /
busybox mount -o rw,remount system

cd /system/app:
rm -rf com.s.antivirus
rm -rf com.facebook.appmanager com.facebook.katana

rm -rf AnonymousData CalendarGoogle Chrome Drive Hangouts
rm -rf com.amazon.mShop.android.shopping Lifelog-3.0.B.4.15-6295567-googlePreloadLive-release
rm -rf EasterEgg com.spotify.music com.sonymobile.xperialounge.services Gmail2 Maps

rm -rf playstationapp newssuite YouTube YouTubeKaraokePlugin YouTubePlugin
rm -rf WikipediaPlugin SomcMovieCreatorRmm-release
rm -rf SemcEmail SomcSketch-live
rm -rf FaceLock GoogleAnalyticsProxy
rm -rf GoogleContactsSyncAdapter GoogleLyricsPlugin
rm -rf GooglePrintRecommendationService GoogleTTS
rm -rf EditorsDocs EditorsSheets EditorsSlides
rm -rf GetMoreClient-standard-release OmaDownload PartnerBookmarksProvider PrintSpooler
rm -rf RemoteControlService SomcPOBox SyncHub-release TopContactsWidget-release
rm -rf com.sonyericsson.xhs com.sonymobile.deqp talkback videoplaceholder videotvsideview

cd /system/prvi-app:
rm -rf com.facebook.system GetMore-standard-release SharedStorageBackup
rm -rf SomcMovieCreator-release GoogleBackupTransport GoogleFeedback
rm -rf com.sonymobile.retaildemo MyXperia-release RcsVideoShare
rm -rf SocialphonebookStub somc-get-to-know-it-release

pm disable-user com.google.android.apps.photos
pm disable-user com.google.android.googlequicksearchbox
pm disable-user com.google.android.tag
pm disable-user com.google.android.videos
pm disable-user com.google.android.webview
pm disable-user com.sonyericsson.updatecenter
pm disable-user com.sonymobile.demoappchecker
pm disable-user com.sonymobile.enterprise.service
pm disable-user com.sonymobile.entrance
pm disable-user com.sonymobile.exchange
pm disable-user com.sonymobile.mwutil
pm disable-user com.sonymobile.phoneusage
pm disable-user com.sonymobile.rcs.settings
pm disable-user com.sonymobile.xperiaservices
pm disable-user com.sonymobile.xperiatransfermobile
pm disable-user com.google.android.music

Disabling more Google stuff:

can replace /system/priv-app/GmsCore/GmsCore.apk with microG version

https://github.com/microg/android_packages_apps_GmsCore

can get rid of Google play by replacing /system/priv-app/Phonesky/Phonesky.apk with FakeStore

https://github.com/microg/android_packages_apps_FakeStore/releases

Download and install f-droid from f-droid.org

adb install FDroid.apk

install a bunch of FOSS apps

There are way too many people to thank individually, but hopefully I linked to all the relevant threads. When you visit those threads, press the thank you.