Modifying Optiboot to Upload Sketches over RS485

You are deciding to switch over from transmit to receive when the transmit buffer register is empty. However, this becomes empty when the last byte of data is transferred from it into the output shift register. Therefore it is still being clocked out of the shift register when you switch over. As a result you chop off the last byte and it doesn't get completely sent. This is a problem with RS485 communications.

On a wider issue how are you going to implement the auto reset that normally occurs on opening the serial port on the PC.