/*###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__ = 0x00000000;
/*-Memory Regions-*/
define symbol __ICFEDIT_region_ROM_start__ = 0x0;
define symbol __ICFEDIT_region_ROM_end__   = 131072 - 1;
define symbol __ICFEDIT_region_RAM_start__ = 0x20000000 - (32768 / 2);
define symbol __ICFEDIT_region_RAM_end__   = 0x20000000 + (32768 / 2) - 1;
/*-Sizes-*/
define symbol __ICFEDIT_size_cstack__ = 0x2000;
define symbol __ICFEDIT_size_heap__   = 0x0400;
/**** End of ICF editor section. ###ICF###*/


/******** Definitions ********/
define symbol CY_APPL_LOADABLE  = 1;
define symbol CY_APPL_LOADER    = 0;
define symbol CY_APPL_NUM       = 1;
define symbol CY_APPL_MAX       = 1;
define symbol CY_METADATA_SIZE  = 64;
define symbol CY_EE_IN_BTLDR    = 0x00;
define symbol CY_EE_SIZE        = 2048;
include "cybootloader.icf";
if (!CY_APPL_LOADABLE) {
    define symbol CYDEV_BTLDR_SIZE = 0;
}

define symbol CY_FLASH_SIZE     = 131072;
define symbol CY_APPL_ORIGIN    = 0; 
define symbol CY_FLASH_ROW_SIZE = 256;
define symbol CY_ECC_ROW_SIZE   = 32;

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__     { };
define block HSTACK      {block HEAP, last block CSTACK};

define block LOADER     { readonly section .cybootloader };
define block APPL       with fixed order {readonly section .romvectors, readonly};

/* The address of Flash row next after Bootloader image */
define symbol CY_BTLDR_END      = CYDEV_BTLDR_SIZE +
                                    ((CYDEV_BTLDR_SIZE % CY_FLASH_ROW_SIZE) ?
                                    (CY_FLASH_ROW_SIZE - (CYDEV_BTLDR_SIZE % CY_FLASH_ROW_SIZE)) : 0);

/* The start address of Standard/Loader/Loadable#1 image */
define symbol CY_APPL1_START    = CY_APPL_ORIGIN ? CY_APPL_ORIGIN : CY_BTLDR_END;

/* The number of metadata records located at the end of Flash */
define symbol CY_METADATA_CNT   = (CY_APPL_NUM == 2) ? 2 : ((CY_APPL_LOADER || CY_APPL_LOADABLE) ? 1 : 0);

/* The application area size measured in rows */
define symbol CY_APPL_ROW_CNT   = ((CY_FLASH_SIZE - CY_APPL1_START) / CY_FLASH_ROW_SIZE) - CY_METADATA_CNT;

/* The start address of Loadable#2 image if any */
define symbol CY_APPL2_START    = CY_APPL1_START + (CY_APPL_ROW_CNT / 2 + CY_APPL_ROW_CNT % 2) * CY_FLASH_ROW_SIZE;

/* The current image (Standard/Loader/Loadable) start address */
define symbol CY_APPL_START     = (CY_APPL_NUM == 1) ? CY_APPL1_START : CY_APPL2_START;

/* The ECC data placement address */
define exported symbol CY_ECC_OFFSET     = (CY_APPL_START / CY_FLASH_ROW_SIZE) * CY_ECC_ROW_SIZE;

/* The EEPROM offset and size that can be used by current application (Standard/Loader/Loadable) */
define symbol CY_EE_OFFSET      = (CY_APPL_LOADABLE && !CY_EE_IN_BTLDR) ? ((CY_EE_SIZE / CY_APPL_MAX) * (CY_APPL_NUM - 1)) : 0;
define symbol CY_EE_IN_USE      = (CY_APPL_LOADABLE && !CY_EE_IN_BTLDR) ? (CY_EE_SIZE / CY_APPL_MAX) : CY_EE_SIZE;

/* Define EEPROM region */
define region EEPROM_region     = mem:[from (0x90200000 + CY_EE_OFFSET) size CY_EE_IN_USE];

/* Define APPL region that will limit application size */
define region APPL_region       = mem:[from CY_APPL_START size CY_APPL_ROW_CNT * CY_FLASH_ROW_SIZE];


/****** Initializations ******/
initialize by copy { readwrite };
do not initialize  { section .noinit };
do not initialize  { readwrite section .ramvectors };

/******** Placements *********/
".cybootloader"    : place at start of ROM_region {block LOADER};
"APPL"             : place at start of APPL_region {block APPL};

"RAMVEC"           : place at start of RAM_region { readwrite section .ramvectors };
"readwrite"        : place in RAM_region          { readwrite };
"HSTACK"           : place at end of RAM_region   { block HSTACK};

keep {  section .cybootloader, 
        section .cyloadermeta, 
        section .cyloadablemeta,
        section .cyconfigecc, 
        section .cycustnvl, 
        section .cywolatch,
        section .cyeeprom, 
        section .cyflashprotect,
        section .cymeta };

".cyloadermeta"   : place at address mem : (CY_APPL_LOADER ? (CY_FLASH_SIZE - CY_METADATA_SIZE) : 0xF0000000) { readonly section .cyloadermeta };
".cyloadablemeta" : place at address mem : (CY_FLASH_SIZE - CY_FLASH_ROW_SIZE * (CY_APPL_NUM - 1) - CY_METADATA_SIZE) { readonly section .cyloadablemeta };
".cyconfigecc"    : place at address mem : (0x80000000 + CY_ECC_OFFSET) { readonly section .cyconfigecc };
".cycustnvl"      : place at address mem : 0x90000000 { readonly section .cycustnvl };
".cywolatch"      : place at address mem : 0x90100000 { readonly section .cywolatch };
".cyeeprom"       : place in EEPROM_region { readonly section .cyeeprom };
".cyflashprotect" : place at address mem : 0x90400000 { readonly section .cyflashprotect };
".cymeta"         : place at address mem : 0x90500000 { readonly section .cymeta };


/* EOF */
