I am trying to do an auto updatable app/bootloader through a wireless link (gsm link)
My micro-controller is a ATmega4809.
In this µC, the flash is divided in 3 sections :
- the Boot section
- the AppCode section
- the AppData section
SPM in Boot section can write in AppCode and AppData (not in Boot section itself)
SPM in AppCode section can write in AppData only
SPM in AppData section can write anywhere nowhere
So basically, what I want to do is to have a "Bios" with only tools to manage things in flash (eraseBlock, buffer2flash, flash2flash, spi2flash, ... ) (I have an external SPI flash)
These bios functions will not be updatable as in Boot section.
To use this, the aim is that the app or the bootloader store the new application code coming from the wireless link in a free flash area in AppData section, then call the bios function to move to the good location and then restart to execute the new program.
(First approach is to have Boot section 1ko, AppCode 3ko, and AppData 44ko)
To do this, I want to have a jump table at 0x0000 :
#define AppcodeSectionAddr 0x400 typedef void (*fn_ptr_t)(void); /// not really C ;-) 0x0000 JMP main 0x0004 JMP eraseBlock 0x0008 JMP buffer2flash 0x000c JMP flash2flash 0x0010 JMP spi2flash __attribute__((naked)) __attribute__((section(".ctors"))) void main(void) { /* Initialize system for AVR GCC support, expects r1 = 0 */ asm volatile("clr r1"); SREG=0; SP = RAMEND; /* Go to application, located immediately after boot section */ fn_ptr_t app = (fn_ptr_t)(AppcodeSectionAddr / sizeof(fn_ptr_t)); app(); } uint8_t eraseBlock(uint8_t block) { // stuff } uint8_t flash2flash(uint8_t * src, uint8_t * dest, uint16_t length) { // stuff } ....
My question is what code should I write to achieve this jump table in C ?
Thanks.