Connection to serial0 prevents Mega from booting

I have an ESP8266 connected to serial0 of an Arduino Mega. The Mega will not boot with the ESP connected. If I make the connection after power is applied no problems. A little research has indicated this is more of a software problem than hardware. Apparently, the bootloader sees a connection on Rx0 but never times out.

I know that the optiboot bootloader may have this fix, but is there a bootloader for the Atmega2560 that has this fix? Or is there a hardware fix other than using switch (manual or controlled from a digital output)?

I found this one but I don't know if it has the fix:

http://www.avr-developers.com/bootloaderdocs/index.html

Thanks.

That document appears to be ancient (it references extremely old versions of Arduino IDE).

Why must you connect the ESP8266 to Serial0? It will interfere with uploads no matter what if connected to serial 0, but the '2560 has 3 other serial ports you can use that do not present these issues. Are all of them used by something that is even more badly behaved?

Yeas I am using all four ports. In any event the ESP8266 is intended to do an field upgrade of the mega by uploading a hex file over serial0.

Oh! Huh!

Ugh. I see why this is an issue.

Can you provide details on how you're implementing that? I assume custom firmware on the ESP8266 as well...

You might have to rebuild the bootloader (which unfortunately I was only ever able to do on Linux for the atmega2560 bootloader) and fix the bug yourself. If you know your shit it shouldn't be too hard (I'd offer to do it for $, but I'm booked solid for at least the next 10 days or so).

IMHO, the atmega2560 bootloader is something less than a shining example of good programming...

Take a look at MegaCore, he has Optiboot bootloaders for the 2560 that might work for you.