Loading new Arduino Due programs from ESP8266

What I want to do is a proof of concept app that that lets the ESP8266 download a sam3x .hex file over wifi, stores that hex file to the esp's SPIFFs (flash memory), and then reprograms the Arduino Due with that file. The first 2 parts of this are easy, but I'm not so sure about programming the Due over serial from an esp8266.

I'm pretty sure if I connect all the the correct wires and use Due's TX0/RX0 and then send the right bytes over serial this is possible (basically we'd be using the esp8266 to simulate the ATMEGA16 that does programming on the Due board). However, I have an added complexity that TX0/RX0 are used for other things so I'd like to use a different serial line on the Due. The default bootloader for sam3x (SAM-BA) only supports bootloading over USB or TX0/RX0. So one solution to this would be to use my own bootloader. I've never done that and I'm not sure how it would interact with the Arduino IDE. Making this work in the Arduino IDE without modifying it is important since I want to use this for educational purposes. I would be willing to install a custom library to do this though if that helps (perhaps storing the compiled bootloader in file that the library loads...). Another idea I had is that the Due has 2 banks of flash memory and you can have it boot from either one. As long as the program is less than half the flash space it should be possible to load a second program while the current program is running and then update the Due to boot from the other flash memory bank. However, again I don't know how this interacts with existing Arduino IDE.

I'd really appreciate it if people with more experience in this could comment on the steps they see to making this work and any roadblocks problems they foresee. Or if anyone knows of a project doing something like this for the Due please send a link. If someone wants to do this I'd probably be willing to send you a few hundred dollars if you could send me a proof of concept app that does this (contact me if you're interested).

This topic might help you:

Thanks for the pointer! That is certainly work towards a possible solution.