@toniox if the phone is mediatek, use spflashtool.
its a pain in the *** to do, i recommend using windows for rhis because otherwise you'll need a custom kernel and all the tutorials will use windows.
the steps go like this:
download drivers, and set them up
use bootrom bypass tool
flash with sp flash
i recommemd dumping nvdata,nvram,nvcfg,protect1,protect2 from NAND using spflashtool before flashing anything at all (think of it like youre phones ID it is needed for service ,wifi ,bluetooth)
there is also ways to regenerate the checksums so with lockee xiaomi bootloader you can run custom code but i dont really remember how i managed that one.