"Auto-load" sketch on arduino Due. FLASH REWRITE

Hi all!!

I'm experimenting some things with the flash memory of Due. I've found a good library at this link: GitHub - sebnil/DueFlashStorage: DueFlashStorage saves non-volatile data for Arduino Due. The library is made to be similar to the EEPROM library. that allow you to easly read and write byte data on flash and it works fine. Now i want to make my arduino able to load .bin file from sd (not yet implemented) and then overwrite from address 0x00000000 the flash with the data of an Hello World like sketch.

To do that first of all i convert with a Hex editor the .bin file, resuting from the compilation of the Hello World like sketch, into a .cpp file like that:

/* C:\Users\Toshiba\AppData\Local\Temp\build221920796828153054.tmp\ProgrammaDaCaricare.cpp.bin (07/04/2014 14:13:04)
   StartOffset: 00000000, EndOffset: 00010879, Length: 00010880 */

unsigned char rawData[10880] = {
	0x00, 0x80, 0x08, 0x20, 0x65, 0x01, 0x08, 0x00, 0xE5, 0x01, 0x08, 0x00,
	0xE5, 0x01, 0x08, 0x00, 0xE5, 0x01, 0x08, 0x00, 0xE5, 0x01, 0x08, 0x00,
	0xE5, 0x01, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

       .........                                                                                                                        ..........
       .........                                                                                                                        ..........

	0xFE, 0xE7, 0x00, 0xBF, 0x00, 0x0A, 0x0E, 0x40, 0x0C, 0x01, 0x00, 0x5A,
	0x05, 0x00, 0x00, 0xA5, 0x00, 0x1A, 0x0E, 0x40, 0xFF, 0xFF, 0xFF, 0xFF,
	0x00, 0xE1, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x01, 0x01, 0x00, 0x00,
	0x00, 0x09, 0x3D, 0x00, 0x01, 0x00, 0x00, 0x00
};

then i customize the DueFlashStorage library a bit. Infact this library work interally with address that start from a default address called FLASH_START. This address is somehow calculated and it point the first cell of the "safe" part of memory . So i create a new function writePro by removing FLASH_START check of any kind. Than with a "for" cycle i rewrite byte-by-byte the memory and in the and call "asm jmp 0" or press reset buttom.

Here there is the question? Can i do somethings like that??
Because i've tryed alot but the execution stops (with no warnings) in an istruction in the flash_efc.h, a class made by Atmel for the control of sam3x8e that the developer of DueFlashStorage.h include in his code.

Here is the code:

#include<DueFlashStorage.h>

DueFlashStorage mem;
extern byte rawData[10880];

// SD not yet implemented 
 
void setup()
{ 
 Serial.begin(9600);
 for(int i=0;i<sizeof(rawData)/sizeof(byte);i++)
 {
 Serial.println(mem.writePro(i,rawData[i]));
 }
 Serial.println("Complete, press reset");
}

void loop()
{

if someone can help me i very appreciate, infact i'm very new to arduino and i'm not very pro with cpp so the atmel class is too difficult tobe understandable for me

thx in advance :smiley: :smiley: