FLASH_SIZE = @BOOTLOADER_PARTITION_SIZE@;
FLASH_START = 0x100000000 - @BOOTLOADER_PARTITION_SIZE@;
BOOTLOADER_JUMP32_START = 0xfffff000;
RESETVECTOR_START = 0xffffffec;
KEYSTORE_START = 0xffffe000;
FSP_T_ORIGIN = @FSP_T_BASE@; /* default base:size 0xFFFFF000:0x3000 [0xfffff000:0x100002000] */
FSP_M_ORIGIN = @FSP_M_BASE@; /* default base:size 0xfffdd000:0x22000 [0xfffdd000:0xfffff000] */
FSP_S_ORIGIN = @FSP_S_BASE@; /* default base:size 0xfffc8000:0x15000 [0xfffdd000:0xfffdd000] */
WOLFBOOT_ORIGIN = @WOLFBOOT_ORIGIN@;
DATA_MEM_START = 0x800000; /* 8 MB */
MAX_POLICY_SIZE = 512;

OUTPUT_FORMAT(elf32-i386)

MEMORY
{
    FLASH (rx) : ORIGIN = FLASH_START LENGTH = FLASH_SIZE
    RAM (rwx) : ORIGIN = 0x0 LENGTH = FLASH_START
}

SECTIONS
{
    .wolfboot FLASH_START :
    {
        _wolfboot_flash_start = .;
        KEEP(*(.sig_wolfboot_raw*))
        KEEP(*(.wolfboot))
        _wolfboot_flash_end = .;
    } > FLASH

    .policy :
    {
        . = ALIGN(4);
        _policy_size_u32 = .;
        . += 4;
        _start_policy = .;
    	. += MAX_POLICY_SIZE;
        _end_policy = .;
    } > FLASH

    .keystore KEYSTORE_START :
    {
        _start_keystore = .;
        KEEP(*(.keystore*))
    } > FLASH

    .jmpto32 BOOTLOADER_JUMP32_START :
    {
       _off_boot = ABSOLUTE(.) & 0xffff;
       KEEP(*(.jmpto32))
    } > FLASH

    .reset_vector RESETVECTOR_START :
    {
       KEEP(*(.reset_vector))
    } > FLASH

    .bootloader WOLFBOOT_ORIGIN :
    {
       KEEP(*(.boot*))
       *(.text*)
       *(.rodata*)
       . = ALIGN(256);
    } > FLASH

    _stored_data = .;
    .data DATA_MEM_START : AT (_stored_data)
    {
        _start_data = .;
        KEEP(*(.data*))
        . = ALIGN(4);
        KEEP(*(.ramcode))
        . = ALIGN(4);
        _end_data = .;
    } > RAM

    .bss(NOLOAD) : AT (_end_data)
    {
        _start_bss = .;
        __bss_start__ = .;
        *(.bss*)
        . = ALIGN(4);
        _end_bss = .;
        __bss_end__ = .;
        _end = .;
    } > RAM

    .fsp_t FSP_T_ORIGIN :
    AT(FSP_T_ORIGIN)
    {
       _start_fsp_t = .;
       KEEP(*(.fsp_t))
    }

    .fsp_s FSP_S_ORIGIN :
    {
       _fsp_s_hdr = .;
       KEEP(*(.sig_fsp_s*))
       _start_fsp_s = .;
       KEEP(*(.fsp_s))
       _end_fsp_s = .;
    }

    .fsp_m FSP_M_ORIGIN :
    {
       _start_fsp_m = .;
       KEEP(*(.fsp_m))
       _end_fsp_m = .;
    }
}
