I have written a bootloader for a Kinetis K24 Cortex M4. The bootloader loads additional functionality over USB into ram at runtime. This ramcode exists as its own EWARM project generating a binary. The entry point to this binary must always be 0x20000000 and the vector table must always live at 0x20007000 in order to play nicely with my .NET tool. The IAR startup code handles clearing of the .bss and the .data copy but it also does some other things I dont want. I can't figure out how to force the IAR entry point to a specific address so I have created my own entry point like so
#pragma section=".bss"
#pragma location=".init"
__interwork int __low_level_init(void)
{
char * from = __section_begin(".bss");
char * to = __section_end(".bss");
__DI(); // Disable interrupts
memset(from, 0x00 , (to - from));
memcpy(__vector_table, (unsigned char *)ROM_VECTOR_LOCATION, VECTOR_TABLE_SIZE);
SCB_VTOR = (unsigned int) & __vector_table;
main();
SCB_VTOR = (uint32_t)ROM_VECTOR_LOCATION;
}
When I debug the code I can see that my global variables initialized to non-zero values take on random values. I believe this is because I am not copying the .data section from the LMA to the VMA.
My question is how do I duplicate this copy of the .data section from LMA to VMA?
I would also settle for using the IAR startup code if I could figure out how to break it up but the entry point can't be the reset vector. The entry point has to be 0x20000000 and the vector table has to live at 0x20007000