[Desire 820 Q&A, Help & Troubleshooting] Stefan2142:
So basically I made this guide for myself and though that It would be good for sharing it.

My problems started when phone just started restarting after one of the components failed. Sometimes it would be google play services, sometimes htc backup, sometimes others.. Plus, phone didnt wanna recognize my SIM card. Okay, tried with other roms here (sadly, there are only a couple of roms for this phone). None of them worked fully, while I could get rid of random restarts SIM still wasnt recognized. I was starting to lose my mind here, but hopefully found the solution. Here is a process of it:

Important note: Its really important that you read through everything first (especially useful links in the last section "Useful guides" ) and then to try and fix your phone

1. Usefull commands:

fastboot.exe getvar all -gets info about device, but you need to be in fastboot mode

Result:

(bootloader) version: 0.5
(bootloader) version-bootloader: 3.19.0.0000
(bootloader) version-baseband: 01.01.010_U10305041_08.01.50512
(bootloader) version-cpld: None
(bootloader) version-microp: None
(bootloader) version-main:
(bootloader) version-misc: PVT SHIP S-ON
(bootloader) serialno: MB622YC03068
(bootloader) imei: ***
(bootloader) imei2: Not Support
(bootloader) meid: 00000000000000
(bootloader) product: a51_ul
(bootloader) platform: hTCBmsm8939
(bootloader) modelid: 0PFJ40000
(bootloader) cidnum: HTC__032
(bootloader) battery-status: good
(bootloader) battery-voltage: 0mV
(bootloader) partition-layout: Generic
(bootloader) security: on
(bootloader) build-mode: SHIP
(bootloader) boot-mode: FASTBOOT
(bootloader) commitno-bootloader: 1be89947
(bootloader) hbootpreupdate: 11
(bootloader) gencheckpt: 0
(bootloader) mfg-name: 0001
all: Done!

fastboot.exe oem readcid -gets CID from device. List of CIDs(https://xdaforums.com/desire-820/general/htc-cid-list-t3359862)

Result:

(bootloader) cid: HTC__032

2. To unlock bootlader:

You need Unlock_code.bin file from htcdev.com(obtained by pasting the result of a command:)

fastboot oem get_identifier_token -gets you code for generating Unlock_code.bin.

<<<< Identifier Token Start >>>>
7AC0E35FE034FCAB88DEC6B8E650EC33
63556D84723B05EE4B2CE16AA8E6B1A4
B3E94B50C50EF1F6016D39CD16021F03
CBB2BEF798EE9FE77E395895449C4AC7
017E71B15D5E2C9AEBEBB41C491BA255
6D3F7E66005B5A36856DE0F59CCAE258
C944A80FACD0DBBD684297F15BE4AE26
183302EFBA2BF7A99B7A5CB1D4895E39
818A3F562FBCC159568F77C54C27EC16
6FD4F5200326F2B0E6E2B417A4145D85
1C692E7E62BDF4EC1B34A12CEB98E0EC
AB09CECABCDC11E60A3EAA28F0C81A0A
688F2A62591B21EEA7560DD07D14CBC8
9E536469D50C1DD79D5ACA6858D12155
199C47F8951658C98D11314467138082
787381ECA7DA832308497380A53EE403
<<<<< Identifier Token End >>>>>

After pasting that code into htcdev.com (you need to register), and getting Unlock_code.bin in your mailbox...

Run this command to unlock your bootloader.

And, to relock it, run this:

fastboot oem lock

Important: After the first unlock you will never get a status "LOCKED" in hboot.

Only "RELOCKED". Some say that to get trully again "LOCKED" status you need to S-OFF (Security-OFF)

3. To update firmware (not the same as rom:)

I was before on marshmallow.

First you need to download a firmware, which is in the zip format. Note that it cant be extracted and its not supposed to.

File name is in a like this format:

0PFJIMG_A51_UL_M60_DESIRE_SENSE70_MR_HTC_Europe_3.17.401.3_Radio_01.01.010_U10305041_08.01.50512_release_476105_signed_2.zip

Note the part A51_UL - matches the "product" property of "fastboot.exe getvar all" command;

M60 - i can only assume that it is a code for Marshmallow 6.0;

SENSE70 - HTC Sense version;

Europe - I can assume that this has to match your CID. (mine is 032 which is EastEurope);

3.17.401.3 - My assumption is that this has to match your bootloader version. Mine is 3.19.0.0000 so you should find a closest version to yours

Radio_01.01.010_U10305041_08.01.50512 - this is important also! Its the radio version and *must* be the same as the one you get from "fastboot.exe getvar all" command.

4. Flashing:

There are two ways to flash the firmware. Via usb(adb/fastboot) and directly copying firmware to your sdcard and booting into bootlader.

Keep in mind that your bootlader has to be either relocked or locked. It wont work if you have "UNLOCKED" status.

For both ways you have to rename that long file name to a short, in exactly following manner:

Mine, from "0PFJIMG_A51_UL_M60_DESIRE_SENSE70_MR_HTC_Europe_3.17.401.3_Radio_01.01.010_U10305041_08.01.50512_release_476105_signed_2.zip" became "0PFJIMG.zip". You only need to keep that first parameter as the file name.

4a. Via usb (boot into fastboot mode):

fastboot oem rebootRUU - Reboot into RUU mode, you will get black screen with silver htc logo

fastboot flash 0PFJIMG.zip -this will flash your file and take a while. However, you might get an error like me(failed remote: 32 header), or similar header number. If so, try the other method (4b).

4b. Via sd card:

Copy the 0PFJIMG.zip in the root of your sd card;

Reboot your phone into hboot and it should automatically recognize that file and start flashing.

It takes a bit, aroound 10-20 minutes? I forgot, but as long as the bar is moving you're good.

After that, phone will prompt for a restart and go into usual procedure of first start.

Keep in mind that your data on microsd card will not be deleted, so you're good.

5. Where to find image for your device?

This took me long to find but you have it on gsmdevelopers in this big thread:

For example I found mine on

You need to search through it by your product(model), radio, bootloader and android version. These three should match. Also, the CID too (or take the region closest to you if previos four parametres are matching and you cant find your specific cid).

6. Drivers:

The usual adb/fastboot binaries are required as well as the special "Htc special fastboot Driver" from here.

I dont think your fastboot will recognize your device without these drivers. If the link gets broken those drivers can be found on XDA too.

So if you are getting an error where fastboot cant recognize your device - check the drivers first from that and other sources as well.

7. What after?

You can now safely again unlock the bootloader and install twrp and after that root your phone if you need it.

8. Installing twrp:

Unlock bootloader(check 1.) and follow this guide:

For rooting I havent tried SuperSU, but used Magisk root.

9. Useful pages:

Flashing guide:

http://forum.gsmdevelopers.com/htc-...-file-flashing-via-sdcard-flashing-guide.html

https://www.hardreset.info/devices/htc/htc-desire-820/faq/firmware-flash/update-change-repair-htc/

To obtain Unlock_code: https://www.htcdev.com/

Firmware mention in this guide: https://androidfilehost.com/?fid=24572369242687630, taken from this page:http://forum.gsmdevelopers.com/htc-firmware-unified/42090-htc-desire-820n-a51-ul-firmware.html

Extremely useful guide: http://forum.gsmdevelopers.com/htc-...t-unrevealed-complete-guide-informations.html