I'd like to develop a bootloader that can decrypt Arduino code, load it into memory and launch it.
For now I followed the application note of Atmel "Safe and Secure Bootloader". I managed to compile the bootloader as well as the associated tests.
I managed to install bootloader and run Atmel's tests but when I try to load an Arduino binary, it doesn't work. Maybe I did not take the problem by the right end or then there's something I've done wrong.
I followed this Note and loaded two exemples given by Atmel and it worked (leds connected on port 17, 20 and 21 blinked).
But when I try to load Arduino compiled binary and execute it with the custom bootloader it doesn't work.
This compiled binary is a simple blink given by Arduino exemples. So when it upload and launch, LED connected on port 13 should blink but it doesn't.
I never tried to make a bootloader for decryption and I guess this is something very complex. There might be a simpler method to ensure a safe transfer of a new software.
Since each Sam3x8e has its own Unique Identifier (128 bits), prior to deliver a new version of a software for a device you sold with a Sam3x8e, you will be using the different parts of its Unique Identifier at several check points of the software, then release a binary file. Of course the software will have a Unique Identifier reader in its setup().
The customer will upload the binary successfully only with the device you previously sold and any decompiler could only give glimpses of the actual code.
So I load this code at address 0x80000 (start of flash), set GPNVM1 (boot from flash), and load my app at address 0x88000.
It's very simple but I think I don't launch my app correctly.
I don't understand why you are not using l_code_addr in _binExec().
I would try this:
void _binExec(void *code_addr)
{
void (*pFct)(void) = NULL;
/* Point on __main address located in the second word in vector table */
pFct = (void (*)(void))(*(uint32_t *)((uint32_t)code_addr + 4));
pFct();
}
Edit : I Wonder whether the vector table should be relocated ?