On a atmega2560 the usable flash is meant to be 256k-8k bootloader. Ie 0-0x3E000 (253952 bytes.) but in the code is
#if FLASHEND > 0x0F000
#define BOOTSIZE 8192
#else
#define BOOTSIZE 2048
#endif
#define APP_END (FLASHEND -(2*BOOTSIZE) + 1)
FLASHEND is 0x3FFFF on mega2560's so the the BOOTSIZE is set to 8192, but the APP_END is set to (0x3FFFF - (2*0x2000)) + 1 = 0x3C000
The code then uses "if (eraseAddress < APP_END )" so uploading over serial will only erase bytes from 0x00000 to 0x3C000. So 0x3C000--0x3E000 is not erased and can't be reused till a full erase is done.
This has been causing headaches for years.