FLASH_SIZE = @BOOTLOADER_PARTITION_SIZE@;
FLASH_START = 0x100000000 - @BOOTLOADER_PARTITION_SIZE@;
UCODE0_BASE = @UCODE0_BASE@;
FIT_TABLE = 0xffe00000;
FSP_S_ORIGIN = @FSP_S_BASE@;
WOLFBOOT_ORIGIN = @WOLFBOOT_ORIGIN@;
FSP_T_ORIGIN = @FSP_T_BASE@;
FSP_M_ORIGIN = @FSP_M_BASE@;
JMPTO32_ORIGIN = 0xfffffe00;
FIT_TABLE_PTR = 0xffffffc0;
RESETVECTOR_START = 0xffffffec;
DATA_MEM_START = 0x100000; /* 1Mb */
KEYSTORE_START = 0xffffe000;
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
{
   .stage2 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

    .ucode_update0 UCODE0_BASE :
    {
        KEEP(*(.ucode0))
    } > FLASH

    .fit_table FIT_TABLE :
    {
        KEEP(*(.fit));
        . = ALIGN(256*1024);
    }

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

    .bootloader WOLFBOOT_ORIGIN :
    {
       KEEP(./tgl_fsp.o(.boot))
       KEEP(*(.boot*))
       KEYSTORE_START = .;
       KEEP(*(.keystore*))
       *(.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))
    } > FLASH

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

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

    .fit_table_tr FIT_TABLE_PTR :
    {
        QUAD(fit_table);
    } > FLASH

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