I've managed to restore OpenWrt to functional state after UBIFS failed only by re-flashing the factory firmware via SSH. All other methods to factory reset firmware didn't work, including attempt to flash sysupgrade via LuCi.
Failed attempt #1:
Using username "root".
root@10.0.1.1's password:
BusyBox v1.30.1 () built-in shell (ash)
_______ ________ __
| |.-----.-----.-----.| | | |.----.| |_
| - || _ | -__| || | | || _|| _|
|_______|| __|_____|__|__||________||__| |____|
|__| W I R E L E S S F R E E D O M
-----------------------------------------------------
OpenWrt 19.07.5, r11257-5090152ae3
-----------------------------------------------------
root@Mi-Router-Pro:~# umount /overlay
root@Mi-Router-Pro:~# firstboot
This will erase all settings and remove any installed packages. Are you sure? [N /y]
y
/dev/ubi0_1 is not mounted
/dev/ubi0_1 will be erased on next mount
writing /dev/ubi0_1 failed: Bad file descriptor
root@Mi-Router-Pro:~# reboot
root@Mi-Router-Pro:~#
Failed attempt #2:
Using username "root".
root@10.0.1.1's password:
BusyBox v1.30.1 () built-in shell (ash)
_______ ________ __
| |.-----.-----.-----.| | | |.----.| |_
| - || _ | -__| || | | || _|| _|
|_______|| __|_____|__|__||________||__| |____|
|__| W I R E L E S S F R E E D O M
-----------------------------------------------------
OpenWrt 19.07.5, r11257-5090152ae3
-----------------------------------------------------
root@Mi-Router-Pro:~# firstboot
This will erase all settings and remove any installed packages. Are you sure? [N/y]
y
/dev/ubi0_1 is mounted as /overlay, only erasing files
root@Mi-Router-Pro:~# reboot
root@Mi-Router-Pro:~#
Successful attempt (firstly openwrt-19.07.5-ramips-mt7621-xiaomi_mir3p-squashfs-factory.bin was copied to /tmp
):
Using username "root".
root@10.0.1.1's password:
BusyBox v1.30.1 () built-in shell (ash)
_______ ________ __
| |.-----.-----.-----.| | | |.----.| |_
| - || _ | -__| || | | || _|| _|
|_______|| __|_____|__|__||________||__| |____|
|__| W I R E L E S S F R E E D O M
-----------------------------------------------------
OpenWrt 19.07.5, r11257-5090152ae3
-----------------------------------------------------
root@Mi-Router-Pro:~# cd /tmp
root@Mi-Router-Pro:/tmp# dd if=factory.bin bs=1M count=4 | mtd write - kernel
Unlocking kernel ...
Writing from <stdin> to kernel ... [e]4+0 records in
4+0 records out
root@Mi-Router-Pro:/tmp# dd if=factory.bin bs=1M skip=4 | mtd write - ubi
Unlocking ubi ...
Writing from <stdin> to ubi ... [e]4+0 records in
4+0 records out
root@Mi-Router-Pro:/tmp# reboot
root@Mi-Router-Pro:/tmp#
I also believe I found the source of UBIFS failure: my wall socket's contacts were not tight enough inside and the plug's contact to electricity was probably a little unreliable. I figured it only after I disassembled the damn wall socket, you couldn't tell otherwise. Hopefully fixing that will prevent same situation from happening again in the future.
Maybe someone finds this information useful!
P.S. @hnyman, 6.1–6.2 MB in /overlay
looks like to be default space usage of OpenWrt 19.07.5 for Mi Router Pro. That's the usage after factory image installation.