[Xiaomi Redmi 5A Guides, News, & Discussion] sanchaz12:
Hi everyone,

Recently I messed up something causing most of the sensors not to work anymore, only proximity and light sensor were working.

After hours of trial and error I found the solution to restore functions that have been lost due to corrupted partitions.

Remember I am not responsible if anything goes wrong or gets worse, we are going to use EDL mode (Emergency Download Mode) so be careful! YOU WILL LOSE YOUR DATA!

This guide is intended for the Redmi 5A (riva), but I am pretty sure it will work with other models!

To sum it up, we are going to edit (if needed for your model) and flash the official Xiaomi fastboot rom via EDL mode to the phone.

First make sure your bootloader is unlocked. If not, follow the steps at https://en.miui.com/unlock/

Downloading and installing the required tools and drivers

First, download all the tools you need to start the process:

From http://en.miui.com/a-234.html download the MIUI ROM flashing tool, and the correct fastboot rom (I chose Stable, that worked for me).

From https://gsmusbdriver.com/xiaomi-redmi-5a download the Qualcomm driver (you can browse the website for drivers for other models).

Now, extract the rom file. You will get another compressed folder, extract that one again.

Extract and install the Qualcomm driver.

Extract and open the MI flash tool.

In the flash tool, on the upper-left click 'Driver' and 'Install', now preferably reboot your computer to be sure all drivers are loaded properly.

Editing the downloaded ROM

In my case, the 'Persist' partition was included in the rom, but not included in the flash script of the Redmi 5A rom.

By adding a few lines to the scripts I was able to include the 'Persist' partition so that the flash tool used it:

1a

Navigate to the extracted rom folder, you will find a file named 'flash_all.bat'. Open this file with notepad, and check if there is any mention of the word 'Persist'. If there is, continue from section 1b below. If not, please continue here.

Add the line that refers to 'Persist' like the other lines at the end of the script. In my case I had to add the following line just above the line that contains 'flash system':

fastboot %* flash persist "%~dp0images\persist.img" || @echo "Flash persist error" && exit /B 1

Now save and close the file.

1b

There is another file to be edited, this time inside the 'images' folder within the rom folder. Here find the file named 'rawprogram0.xml'

In this file, about halfway down you will find a line that has 'label=persist' in it, but no location to this file.

Currently it will look like this:

<program SECTOR_SIZE_IN_BYTES="512" file_sector_offset="0" filename="" label="persist" num_partition_sectors="65536" physical_partition_number="0" size_in_KB="32768.0" sparse="true" start_byte_hex="0xf4000000" start_sector="7995392"/>

Now edit the line to look like this:

<program SECTOR_SIZE_IN_BYTES="512" file_sector_offset="0" filename="[B]persist.img[/B]" label="persist" num_partition_sectors="65536" physical_partition_number="0" size_in_KB="32768.0" sparse="true" start_byte_hex="0xf4000000" start_sector="7995392"/>

Do not copy and replace this line from here, instead just type in 'persist.img'! The values at the end of this line may vary between my and your rom!

1c

The last file that needs an edit is the file named 'crclist.txt' in the 'images' folder.

First, go to https://emn178.github.io/online-tools/crc32_checksum.html and drag the 'persist.img' file into the rectangle box. Copy the result you get.

Next, open the 'crclist.txt' file with notepad. At the bottom, add 'persist 0x' followed by the value you copied (use lower-case characters), for example;

persist 0x8932e19d

Save and close the file.

Now the rom is prepared to include 'Persist.img' in the flash script.

Booting the phone into EDL mode and flashing the rom

Flashing in normal fastboot mode didn't work, but in EDL mode it does.

To boot in EDL mode, hold both 'Power' and 'Volume-down' buttons until you see the 'Fastboot' screen. Connect the phone to the PC.

Next, open the flash tool folder and open the Mi flash tool. Click the left button and select the folder where the extracted and edited rom is.

Now make sure in the bottom-right to select 'flash_all.bat' and not 'flash_all_lock.bat. If you leave it on 'flash_all_lock.bat' it will not flash 'persist.img' and will also lock the bootloader. 'flash_all.bat' does not lock the bootloader.

Go back to the flash tool folder and navigate to 'MI-FLASH 2018-5-28\MiFlash2018-5-28-0\Source\ThirdParty\Google\Android'. Copy the path to this folder.

Open CMD (Win-key + R, type cmd, hit enter) and type

cd "Paste copied path here"

and hit enter. You should be able to type 'fastboot devices' and see one line appear.

When you see the device is listed, type

fastboot oem edl

and hit enter. The fastboot screen on the phone should go away.

Next go to the opened flash tool, click 'refresh' on the right. You should see one line starting with 'COM' and a number. Now you can click 'flash' to start the flashing process.

Note that you may get an error about 'hello message', that is because there is a time limit between booting in EDL mode and flashing. Try again by holding 'Power' and 'Volume-down' until you see the 'fastboot' screen again, then type 'fastboot oem edl' again.

After some time the status in the flash tool turns green and flashing is complete. Hold 'Power' and 'Volume-down' until the phone reboots and wait for first boot (this can take a while).

I hope you were able to solve the issues you had with your phone! If anything is unclear, please let me know.