• Introducing XDA Computing: Discussion zones for Hardware, Software, and more!    Check it out!

[GUIDE] Restoring 'Persist' partition to fix all kinds of (sensor) issues

Search This thread

sanchaz12

Senior Member
Apr 7, 2011
55
31
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':

Code:
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:
Code:
<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:
Code:
<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;

Code:
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

Code:
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

Code:
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.
 

jeevan bk

Member
Jan 7, 2016
29
6
Hey there,
The accelerometer on my Redmi 5A was messed up badly after a few miui.eu rom flashes and none of the other custom roms would boot up too. I found your guide to be very helpful and to the point. I was able to flash the stable rom successfully which fixed the sensors. Huge thanks to you! .

---------- Post added at 07:08 AM ---------- Previous post was at 06:58 AM ----------

Hey there,
The accelerometer on my Redmi 5A was messed up badly after a few miui.eu rom flashes and none of the other custom roms would boot up too. I found your guide to be very helpful and to the point. I was able to flash the stable rom successfully which fixed the sensors. Huge thanks to you! .
 
  • Like
Reactions: sanchaz12

elemefaaoo

Senior Member
Jun 28, 2018
358
74
21
Kasaragod
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':



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:


Now edit the line to look like this:


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;



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



and hit enter. You should be able to type 'fastboot devices' and see one line appear.
When you see the device is listed, type



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.
We can just flash the sensorfix zip via twrp
 
Feb 12, 2017
25
3
Here is the link for sensorfix.xip

https://drive.google.com/file/d/1ZgaWydW4c7Eo5vuRw_Vhc6EVmBFThNV2/view

Give me thanks:p

---------- Post added at 08:46 AM ---------- Previous post was at 08:40 AM ----------

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':

Code:
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:
Code:
<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:
Code:
<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;

Code:
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

Code:
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

Code:
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.

You don't need to this much sh*t !
Just flash the provided zip via twrp.
You won't loose data
 
Last edited:
  • Like
Reactions: Hrihik21

SandipS

Member
Mar 31, 2017
16
6
thank you Asif the legend ?. however i found a alternate way to fix it. fastboot or edl mode or normal twrp are not able to access the persist location. i flashed orage fox recovery to mount persist location. then in miui official fastboot rom i got persist image. and i am able to flash it via new recovery. all sensors are working fine now.
 

Hrihik21

New member
Jun 23, 2018
3
2
Atif the legend sir you are truly legend thank uh so much. I tryed many things to fix this problem but now all sensors working fine. Thanks for your help.
 

jasonhelene

Senior Member
Dec 23, 2016
80
16
How to quit edl mode? i received the hello error, and then even when i do press power and vol down i cant reboot it

---------- Post added at 12:35 PM ---------- Previous post was at 12:10 PM ----------

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':

Code:
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:
Code:
<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:
Code:
<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;

Code:
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

Code:
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

Code:
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.


Help plz? it shows the qualcomm on devices manager but i cant quit edl mode and gives me that error from hello message, holding power plus anything does not reboots it
 

sanchaz12

Senior Member
Apr 7, 2011
55
31
How to quit edl mode? i received the hello error, and then even when i do press power and vol down i cant reboot it

---------- Post added at 12:35 PM ---------- Previous post was at 12:10 PM ----------




Help plz? it shows the qualcomm on devices manager but i cant quit edl mode and gives me that error from hello message, holding power plus anything does not reboots it

You may have to hold the buttons for up to 30 seconds for the phone to reset, longer than usual.
 

kacike69

New member
Aug 13, 2019
2
0
Mimax 3

Hi, I need to know if this process is valid for a MiMax 3 with Chinese rom and with closed bootloader.
I have the phone without being able to activate Wi-Fi, sim and bluettoh and I think it's because of the persist partition ...
I can put the phone in edl mode. Please help
 

rafaeimarques

Member
Aug 2, 2019
32
5
Hi,
I have no idea how to extract the MIUI11 beta file to MI 6X, I wanted to use its tutorials but the download link doesn't open, could you tell me which program used to edit this persist.img file? Or if you can make this file available. I have but it works only with MIUI 10 and I'm on MIUI 11.
 

Kali327

New member
Nov 11, 2019
1
0
Is using EDL mode without unlock bootloader?

I have same issue.
I get same issue error (find device is…. your device unsafe)

But , All the sensors are not work.
#proximity sensor
#Auto rotation
#Camara(full Black Screen)
#Youtube
#Flash light
Are not working….
Please help me.
_______________________________________
Is i am using flash the phone without unlock bootloader Using EDL mode.

Please help me.
_____________________________________
 

ozkr0606

New member
Jan 11, 2020
2
0
How can i do to make my own sensorsfix.zip?

Give me thanks:p

---------- Post added at 08:46 AM ---------- Previous post was at 08:40 AM ----------



You don't need to this much sh*t !
Just flash the provided zip via twrp.
You won't loose data[/QUOTE]

Friend i want to make my own file to flash in other device (MI 9T Pro), can you show us how try it. I did extracted the files into persist.img, but i didn't find the sns.reg, file included in your .zip.

This instruction could help to many people with this problem.

Thank u so much. :good:
 

Top Liked Posts

  • There are no posts matching your filters.
  • 10
    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':

    Code:
    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:
    Code:
    <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:
    Code:
    <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;

    Code:
    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

    Code:
    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

    Code:
    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.
    2
    thank you Asif the legend ?. however i found a alternate way to fix it. fastboot or edl mode or normal twrp are not able to access the persist location. i flashed orage fox recovery to mount persist location. then in miui official fastboot rom i got persist image. and i am able to flash it via new recovery. all sensors are working fine now.
    1
    Hey there,
    The accelerometer on my Redmi 5A was messed up badly after a few miui.eu rom flashes and none of the other custom roms would boot up too. I found your guide to be very helpful and to the point. I was able to flash the stable rom successfully which fixed the sensors. Huge thanks to you! .

    ---------- Post added at 07:08 AM ---------- Previous post was at 06:58 AM ----------

    Hey there,
    The accelerometer on my Redmi 5A was messed up badly after a few miui.eu rom flashes and none of the other custom roms would boot up too. I found your guide to be very helpful and to the point. I was able to flash the stable rom successfully which fixed the sensors. Huge thanks to you! .
    1
    We can just flash the sensorfix zip via twrp
    link >???
    1
    this method worked, at first I was confused, I was looking for ways to fix it. after I found this, this worked. thanks man