Fix sensor issues
On Xiaomi devices, sensor data is stored in a partition called persist. This partition is flashable and an image of it is included with all fastboot ROMs but devices made after 2016 don’t allow you to modify it in fastboot mode, regardless of the status of the bootloader. Unfortunately, software issues may cause the sensors in the device to misbehave or stop working completely, but usually reflashing this partition solves these problems. If the partition is write protected in fastboot mode, you’ll have to use Qualcomm’s EDL mode to flash it. The EDL flashing script originally skips the persist partition but you can modify it to flash that as well when you are flashing with MiFlash.
Requirements: Qualcomm Snapdragon chipset
Download the latest MiFlash from here and install it.
Download the Fastboot ROM you want to flash from here and unzip it.
Note: You might get a single .tar file after unzipping which has to be unzipped again in order to get the necessary files.
In the unzipped folder, enter the
imagesfolder and open the file
rawprogram0.xmlin a text editor (Notepad++ or VS Code recommended).
In the line that contains the string
If there’s a line right below it, that contains the string
label="persistbak", change its
rawprogram0.xmland close the text editor.
Connect the device to your PC and enter EDL mode.
Launch MiFlash and with the Select button browse for the unzipped folder, then click Refresh. The device should appear as a COM port.
Click Flash and wait until the flashing sequence finishes.
Disconnect the device and hold the Power button until the device turns on.
The first boot may take up to 15 minutes.