I am stuck with a problem here. I wrote a sketch which requests for an application code from another PC/server. Now the PC will send the .hex file to the arduino as requested. Now how do I run the received application code sketch from there on. If a RESET is required, that's OK. I am using an Arduino UNO with the ethernet shield (Wiznet).
Using raspberry-pi, I was able to achieve it easily because of Linux.
Code running in the bootload area can change code in the regular flash area.
Revise the bootloader to accept code from this other PC application (vs accepting it from avrdude type commands).
I can modify the boorloader to run "Code Section 1" (flashed manually first time) which, during run-time will receive a "Code Section 2" over ethernet and store it in the flash, reboot and start executing "Code Section 2 " from here on.
Not really, the BL resides in a special flash area and only code running in that area can change the flash memory.
So I think your main code will have to field the "reflash" command and jump into the BL which will then take over. Off hand I don't know the address(es) of AVR bootloaders but it will be documented.
I looked at this a while back to allow a forth like language with a token threaded interpreter for Cosa. The problem is that most bootloaders have embedded the flash programming section and there is no entry point to that. It is nested in a lot of getch(), conditions and control structures.
The simplest solution is to add the function(s) last in a bootloader and do a simple function pointer based wrapper to call it from the application area.