This might prove useful to someone - I’ve modified the Mega2560 bootloader using some code from Petit FatFS (Petit FAT File System Module) so you can overwrite your sketch using a file uploaded to the SD card.
To use it, you need to compile your sketch, and then convert it from hex to binary - I use avr-objcopy, but I’m not sure if that’s part of the standard Arudion distribution. I think there are various hex>bin converters if you Google it. Once you have your binary file, you can copy it onto the SD card (using something like GitHub - ovidiucp/TinyWebServer: Small web server for Arduino, fits in 10KB ROM, less than 512 bytes RAM) and make sure it’s called “app.bin”. To get the bootloader to overwrite the sketch, you need to set eeprom bit 0 to 1, and reboot the Arduino, either with the reset pin or with the watchdog.
If it successfully overwrites the flash on the Mega eeprom bit 0 will get set to 2, and if it can’t open your “app.bin” file, eeprom bit 0 will get set to 3.
I’m not an expert in bootloaders so it’s somewhat hacked together (and only minimally tested!), but it might prove a useful starting point for someone. The source is in the attachment, along with the compiled bootloader.
stk500boot_v2_mega2560_pff.zip (54.9 KB)