I had installed in this phone a custom rom a few months back for my friend. Yesterday he told me that the device froze when he was browsing the phone gallery app, and a few minutes later the phone rebooted and couldn't pass the mi logo (so the system wasn't loading I guessed, because the logo of the ROM wasn't showing). I tried to enter TWRP, but even there the phone would get stuck on the TWRP splash page and rebooted back to the MI logo. So I tried to reinstall TWRP (I have still access to fastboot mode) and, after, a newer version, but the problem was the same. I tried booting a recovery image without installing it (fastboot boot twrp.img) and the problem was similar, but instead of rebooting to the MI logo, the phone would get stuck on the TWRP logo. I tried with OrangeFox recovery too, but same problem. I read in another post that it may be a problem with the /data partition, so I (fastboot erase userdata) and tried again the above recovery installation, but it didn't work. I, then, tried to wipe all partion via fastboot, and tried the command "fastboot erase system -w", but it didn't work either. So I tried the way to restore the phone with MiFlash tool, I found the firmware I needed, I flashed it, and after ~4s it gave me the error "failed to write partiton" (see image).
I tried with another firmware (this time based on Oreo instead of Nougat), same error. I searched a solution for this error, but I found nothing helpful. Now I have the phone working (=it can power on) and can access to fastboot, but don't know what to do. Can someone out there, with maybe a clearer idea of what's going on, help me? Thanks in advance