AnsweredAssumed Answered

zeroing .bss in IAR with non-standard code

Question asked by Ryan Lush on Jan 22, 2018
Latest reply on Jan 23, 2018 by Ryan Lush

I have a bootloader that loads code into RAM at runtime. I have the ramcode linking and executing as I would expect but I still need to manually clear the .bss section.

 

Here is my linker script

 

/*###ICF### Section handled by ICF editor, don't touch! ****/
/*-Editor annotation file-*/
/* IcfEditorFile="$TOOLKIT_DIR$\config\ide\IcfEditor\cortex_v1_0.xml" */
/*-Specials-*/
define symbol __ICFEDIT_intvec_start__ = 0x20007000;
/*-Memory Regions-*/
define symbol __ICFEDIT_region_ROM_start__ = 0x20000000;
define symbol __ICFEDIT_region_ROM_end__   = 0x20007000;
define symbol __ICFEDIT_region_RAM_start__ = 0x1FFF0000;
define symbol __ICFEDIT_region_RAM_end__   = 0x20000000;
/*-Sizes-*/
define symbol __ICFEDIT_size_cstack__ = 0x1000;
define symbol __ICFEDIT_size_heap__   = 0x1000;
/**** End of ICF editor section. ###ICF###*/

 

define memory mem with size = 4G;
define region ROM_region   = mem:[from __ICFEDIT_region_ROM_start__   to __ICFEDIT_region_ROM_end__];
define region RAM_region   = mem:[from __ICFEDIT_region_RAM_start__   to __ICFEDIT_region_RAM_end__];

 

define block CSTACK    with alignment = 8, size = __ICFEDIT_size_cstack__   { };
define block HEAP      with alignment = 8, size = __ICFEDIT_size_heap__     { };

 

initialize by copy { readwrite };
do not initialize  { section .noinit };

 

place at address mem:__ICFEDIT_region_ROM_start__ { readonly section .init };
place at address mem:__ICFEDIT_intvec_start__ { readonly section .intvec };

 

place in ROM_region   { readonly };
place in RAM_region   { readwrite,
                        block CSTACK, block HEAP };

 

And here is my startup code

 

extern int main(void);
extern int __vector_table[];

 

#pragma location=".init"
__interwork int __low_level_init(void)
{
 
    char * from = __section_begin(".bss");
    char * to = __section_end(".bss");
    
    memset(to, from , 0x00);
    
    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;
    
}

 

but the .bss section doesn't really seem to exist in the context I'm trying to use it. I get the following error.

 

Error[Pa053]: section/block has not been declared using #pragma section/segment

 

How do I "define" the .bss section so that the start/end address is available to me in my C code.

Outcomes