AnsweredAssumed Answered

K22 IAR Linker file for initalizing FSEC/Flash Config Fields

Question asked by Troels Østeraa on Jun 29, 2017
Latest reply on Jul 3, 2017 by Kerry Zhou

Hi,

I have implemented my own bootloader and need to add support for securing the flash, by writing to the flash configuration field,
and the FSEC field in particular. I am using IAR EWARM 8.11.

 

 

I suppose that I could get around this with doing the same as the AN2295 bootloader does:

  #pragma section = "FlashConfig"
  #pragma location = "FlashConfig"

  __root const FlashConfig_t Config =
{
 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFE,
};


and then changing 0xFFFFFFFE to 0xFFFFFFFF.

I have some severe problems in adapting my current ICF/linker file with the one for AN2295, so that I can write to the 0x400-0x40F range. I have some problems figuring out the .icf syntax, and couldn't find it documented anywhere.
I have reserved the flash from 0x410 to 0x5FFF bytes for the bootloader.

 

This is the original ICF file:

 

define symbol __ICFEDIT_intvec_start__ = 0x00000000;
/*-Memory Regions-*/
define symbol __ICFEDIT_region_ROM_start__ = 0x00000000;
define symbol __ICFEDIT_region_ROM_end__   = 0x00005FFF;
define symbol __ICFEDIT_region_RAM_start__ = 0x1FFFC410;
define symbol __ICFEDIT_region_RAM_end__   = 0x1FFFFFFF;
/*-Sizes-*/
define symbol __ICFEDIT_size_cstack__ = 0x1000;
define symbol __ICFEDIT_size_heap__   = 0x200;
/**** End of ICF editor section. ###ICF###*/

define symbol __region_RAM2_start__ = 0x20000000;
define symbol __region_RAM2_end__ = 0x2000FFFF;

define exported symbol __VECTOR_TABLE = 0x00000000;
define exported symbol __VECTOR_RAM = 0x1FFF0000;

define symbol __code_start__ = 0x00000410;

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__] | mem:[from __region_RAM2_start__ to __region_RAM2_end__];

 

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

 

initialize manually { readwrite };
initialize manually { section .data};
initialize manually { section .textrw_init };
initialize manually { section .textrw };
do not initialize  { section .noinit };

 

define block CodeRelocate { section .textrw_init };
define block CodeRelocateRam { section .textrw };

 

place at address mem:__ICFEDIT_intvec_start__ { readonly section .intvec };
place at address mem:__code_start__ { readonly section .noinit };

place in ROM_region   { readonly, block CodeRelocate};

place in RAM_region   { readwrite, block CodeRelocateRam, block CSTACK, block HEAP };

 

This is my attempt at modifying it:

define symbol __ICFEDIT_intvec_start__ = 0x00000000;
/*-Memory Regions-*/
define symbol __ICFEDIT_region_ROM_start__ = 0x00000000;
define symbol __ICFEDIT_region_ROM_end__   = 0x00005FFF;
define symbol __ICFEDIT_region_RAM_start__ = 0x1FFF0410;
define symbol __ICFEDIT_region_RAM_end__   = 0x1FFFFFFF;
/*-Sizes-*/
define symbol __ICFEDIT_size_cstack__ = 0x1000;
define symbol __ICFEDIT_size_heap__   = 0x200;
/**** End of ICF editor section. ###ICF###*/

define symbol __region_RAM2_start__ = 0x20000000;
define symbol __region_RAM2_end__ = 0x2000FFFF;

define exported symbol __VECTOR_TABLE = 0x00000000;
define exported symbol __VECTOR_RAM = 0x1FFF0000;
define symbol FlashConfig_start__               = 0x00000400;
define symbol FlashConfig_end__                 = 0x0000040F;

define symbol __code_start__ = 0x00000410;

define memory mem with size = 4G;
define region ROM_region   = mem:[from __ICFEDIT_region_ROM_start__   to (FlashConfig_start__-1)] | [from (FlashConfig_end__+1)   to __ICFEDIT_region_ROM_end__];
define region RAM_region   = mem:[from __ICFEDIT_region_RAM_start__   to __ICFEDIT_region_RAM_end__] | mem:[from __region_RAM2_start__ to __region_RAM2_end__];
define region FlashConfig_region        = mem:[from FlashConfig_start__ to FlashConfig_end__];

 

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

 

initialize manually { readwrite };
initialize manually { section .data};
initialize manually { section .textrw };
do not initialize { section .FlashConfig };
do not initialize  { section .noinit };


define block CodeRelocate { section .textrw_init };
define block CodeRelocateRam { section .textrw };

 

place at address mem:__ICFEDIT_intvec_start__ { readonly section .intvec };
place at address mem:__code_start__ { readonly section .noinit };

place in ROM_region   { readonly, block CodeRelocate};

place in RAM_region   { readwrite, block CodeRelocateRam, block CSTACK, block HEAP };
place in FlashConfig_region     { section FlashConfig};

 

IAR couldn't find space for all variables as shown in the attached image, and I just can't see what causes this. Any help/pointers?

Attachments

Outcomes