If you're talking about a self written bootloader, (as opposed to the ROM bootloader) I've had this kind of issue due to EMC issues before.
To fix it, I had to do several hardware EMC fixes to my PCB, mostly added ESD protection.
I also made sure any flash write function in my software had a software lock on it, in other words additional checks that a flash write was desired and it wasn't some strange behaviour.