Flashing compiled .bin from SD card to Due?

ard_newbie:
The Flash memory is divided into two banks of 256 KBytes and each banck is divided in pages of
256 Bytes.

To copy your new firmware from SD card, provided you have already uploaded a first firmware , this first firmware, running from Flash bank 0, will have to copy page by page the new firmware in Flash bank 1 (begins at IFLASH1_ADDR). The bootloader sets the gpnvm bit 1 so you have the possibility to run code from Flash bank 0 or 1 by setting the gpnvm bit 2 yourself.

You have 2 copies of your bootloader loaded at the beginning of each Flash bank (see Atmel application Note AT02333: Safe and Secure Bootloader implementation).

Use the command WP (see datasheet Sam3x 18.4.3) inside a Write subroutine preceded with the Ram Function attribute, or use the IAP function.
The In Application Programming feature is a function located in ROM that can be called by any software application ( at address IROM + 8, see datasheet 20.4.4). When called, this function sends the desired FLASH command to the EEFC and waits for the Flash to be ready. Inside the subroutine, disable interruptions at entrance, and re_enable the previous enabled interruptions at exit (get Primask, disable irq, set primask).

Once your new firmware uploaded in Flash bank 1, set the gpnvm bit 2 with the command SGPB
(see datasheet 18.4.3.5) using the IAP function the same way as previously, then read the gpnvm bits 0 to 2 with the command GGPB to ensure they are properly set. Then reset manually your board and it should automatically run from Flash bank 1.

Show your code if any pending questions with this.

Thanks really. I'm not sure how can I set the GPNVM bit 2. I looked at libraries but I really don't know how can or what can I do...

Looks sebnil's DueFlashStorage library writes to Flash Bank 1, then can I write my compiled program with DueFlashStorage?

Just setting GPNVM bit 2 will make start program from Flash Bank 1, but I don't know how can I set it.