Questions about an A-B memory schema on an stm32 microcontroller
I'm trying to figure out if an A-B memory schema on a microcontroller is feasible. Right now I have a bootloader and an application. I basically want to duplicate the application onto two sections of memory: A and B. This way I can receive a firmware update and write it to whatever section of memory isn't active, try and boot it, and if it doesn't work I can simply switch back to section A and write over the corrupt section B with the valid and working section A.
My first problem is with the vector table offset. It seems like the vector table address must be hard coded at compile time and cannot be switched at runtime. Is this true? If not, is there a way for me to change the vector table offset at runtime?
My second problem is with the linker script. Right now I have everything [FLASH] being created for section A. Can I simply just duplicate these lines of code for section B? I think .isr_vector won't like being there twice:
/* The startup code into "FLASH" Rom type memory */
.isr_vector :
{
. = ALIGN(4);
KEEP(*(.isr_vector)) /* Startup code */
. = ALIGN(4);
} >FLASH_A
/* The startup code into "FLASH" Rom type memory */
.isr_vector :
{
. = ALIGN(4);
KEEP(*(.isr_vector)) /* Startup code */
. = ALIGN(4);
} >FLASH_B
/* The program code and other data into "FLASH" Rom type memory */
.text :
{
. = ALIGN(4);
*(.text) /* .text sections (code) */
*(.text*) /* .text* sections (code) */
*(.glue_7) /* glue arm to thumb code */
*(.glue_7t) /* glue thumb to arm code */
*(.eh_frame)
KEEP (*(.init))
KEEP (*(.fini))
. = ALIGN(4);
_etext = .; /* define a global symbols at end of code */
} >FLASH_A
/* The program code and other data into "FLASH" Rom type memory */
.text :
{
. = ALIGN(4);
*(.text) /* .text sections (code) */
*(.text*) /* .text* sections (code) */
*(.glue_7) /* glue arm to thumb code */
*(.glue_7t) /* glue thumb to arm code */
*(.eh_frame)
KEEP (*(.init))
KEEP (*(.fini))
. = ALIGN(4);
_etext = .; /* define a global symbols at end of code */
} >FLASH_B