/*
** ###################################################################
**     Compiler:            armgcc or clang link scripter
**     Reference manual:
**     Version:             rev. 0.1, 2020-8-15
**     Build:
**     Author: Lucien.Yin
** ###################################################################
*/
/**********************************************/
/***********CH Memory LayeOut*****************/
/**********************************************/
/*#ifdef CONFIG_SPRD_CH_DDR_RUNNING_EN */
/*

**********************************************

 AON CH IRAM (384K)(AP : 0x65016000~0x65076000)

  |--------------------|--------- 0x0000

  |code  180k

  |--------------------|--------- 0x2D000

  |heap  60K

  ---------------------|----------0x3C000

  |RW  144k

  ---------------------|----------0x60000

*/
/*

2. CH DDR MEM LAYOUT

WARNING:

            AP                         AON(CH)

  0xAE60_0000 ~~ 0xAE84_0000      0x8000_0000 ~~ 0x8024_0000

  |--------------------|--------- 0x80000000

  |sharmem for gnss sipc  256KB

  |--------------------|--------- 0x80040000

  |code  0x100000 1MB

  |--------------------|--------- 0x80140000

  |heap  0x40000  256K

  ---------------------|----------0x80180000

  |RW    0xC0000  768K

  ---------------------|----------0x80240000



  **********************************************/
/*

aon ch iram (256K) (AP : 0x800000~0x83FFFF)

  |--------------------|--------- 0x0000

  |code  144k

  |--------------------|--------- 0x24000

  |heap  20K

  ---------------------|----------0x29000

  |RW  (0x11FA0)71K

  ---------------------|----------0x3AFA0

  |sensorhub extern call  0x60

  ---------------------|----------0x3B000

  |sensor hub cali data 20k

  ---------------------|----------0x40000

   ;0x3b000~ 0x40000 is reserve for sensor hub cali data



  **********************************************/
/***********CH Memory LayeOut******************/
/**********************************************/
/*#endif*/
OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
OUTPUT_ARCH(arm)
/* Entry Point */
ENTRY(__main)
/* Specify the memory areas */
MEMORY
{
  /* iram memlay out */
  IRAM (RX) : ORIGIN = (0x0000000), LENGTH = (0x60000) /* total  memory */
  IRAM_CODE (RX) : ORIGIN = (0x0000000), LENGTH = (0x2D000)
  IRAM_HEAP (RX) : ORIGIN = ((0x0000000) + (0x2D000)), LENGTH = (0xF000)
  IRAM_RW (RX) : ORIGIN = (((0x0000000) + (0x2D000)) + (0xF000)), LENGTH = ((0x60000) - (((0x0000000) + (0x2D000)) + (0xF000)))
  /* ddr memlay out */
  DDR (RX) : ORIGIN = ((0x80000000) + (0x40000)), LENGTH = (0x200000) /* total  memory */
  DDR_CODE (RX) : ORIGIN = ((0x80000000) + (0x40000)), LENGTH = (0x100000)
  DDR_HEAP (RX) : ORIGIN = (((0x80000000) + (0x40000)) + (0x100000)), LENGTH = (0x40000)
  DDR_RW (RX) : ORIGIN = ((((0x80000000) + (0x40000)) + (0x100000)) + (0x40000)), LENGTH = (0xC0000)
}
SECTIONS
{
    /* The program code and other data goes into internal RAM */
    .sprd_loader :
    {
        . = ALIGN(4);
        __sprd_loader_start = .;
        KEEP (*(.sprd_loader))
        /*
            reserved , you can place object file here running on ddr
        */
        . = ALIGN(4);
        __sprd_loader_end = .;
    } > DDR_CODE
    .gnss_ro :
    {
        . = ALIGN(4);
        __gnss_ro_start = .;
        FLCommon.* (.text .text* .rodata .rodata*)
        FWManager.* (.text .text* .rodata .rodata*)
        UartAdapter.* (.text .text* .rodata .rodata*)
        Config.* (.text .text* .rodata .rodata*)
        FWConfig.* (.text .text* .rodata .rodata*)
        GnssIf.* (.text .text* .rodata .rodata*)
        FWHandleMsg.* (.text .text* .rodata .rodata*)
        HandleMsgFunc.* (.text .text* .rodata .rodata*)
        CommonOps.* (.text .text* .rodata .rodata*)
        FWGlobalVar.* (.text .text* .rodata .rodata*)
        basicfunc.* (.text .text* .rodata .rodata*)
        nmeaenc.* (.text .text* .rodata .rodata*)
        FlashStore.* (.text .text* .rodata .rodata*)
        bbct.* (.text .text* .rodata .rodata*)
        timeConvert.* (.text .text* .rodata .rodata*)
        GnssManager.* (.text .text* .rodata .rodata*)
        SatAcqInfoEst.* (.text .text* .rodata .rodata*)
        timekeep.* (.text .text* .rodata .rodata*)
        msrcalc.* (.text .text* .rodata .rodata*)
        msrfilter.* (.text .text* .rodata .rodata*)
        correction.* (.text .text* .rodata .rodata*)
        kalman.* (.text .text* .rodata .rodata*)
        lsq.* (.text .text* .rodata .rodata*)
        matrix.* (.text .text* .rodata .rodata*)
        multipath.* (.text .text* .rodata .rodata*)
        pvt.* (.text .text* .rodata .rodata*)
        pvtentry.* (.text .text* .rodata .rodata*)
        revmonitor.* (.text .text* .rodata .rodata*)
        tsx.* (.text .text* .rodata .rodata*)
        defaultAlm.* (.text .text* .rodata .rodata*)
        Est_Msr.* (.text .text* .rodata .rodata*)
        gpscoord.* (.text .text* .rodata .rodata*)
        gpsframe.* (.text .text* .rodata .rodata*)
        gpsnavdata.* (.text .text* .rodata .rodata*)
        qzss.* (.text .text* .rodata .rodata*)
        sbas.* (.text .text* .rodata .rodata*)
        satmanage.* (.text .text* .rodata .rodata*)
        glocoord.* (.text .text* .rodata .rodata*)
        gloframe.* (.text .text* .rodata .rodata*)
        glonavdata.* (.text .text* .rodata .rodata*)
        BD2coord.* (.text .text* .rodata .rodata*)
        bd2frame.* (.text .text* .rodata .rodata*)
        bd2navdata.* (.text .text* .rodata .rodata*)
        Bd2B1cCoord.* (.text .text* .rodata .rodata*)
        Bd2B1cFrame.* (.text .text* .rodata .rodata*)
        Bd2B1cIono.* (.text .text* .rodata .rodata*)
        Bd2B1cNavData.* (.text .text* .rodata .rodata*)
/*      Ldpc_dec.*           (.text .text* .rodata .rodata*)*/
        galcoord.* (.text .text* .rodata .rodata*)
        galframe.* (.text .text* .rodata .rodata*)
        galnavdata.* (.text .text* .rodata .rodata*)
        softbitDecode.* (.text .text* .rodata .rodata*)
        SWViterbiDecoder.* (.text .text* .rodata .rodata*)
        . = ALIGN(4);
        __gnss_ro_end = .;
    } > DDR_CODE
    IMG_GNSS_DATA_BASE = LOADADDR(.gnss_data); /* caculate gnss data base address */
    .gnss_data :
    {
        . = ALIGN(4);
        __gnss_data_start = .;
        wd_ctrl_pm.* (.data .data*)
        FLCommon.* (.data .data*)
        FWManager.* (.data .data*)
        UartAdapter.* (.data .data*)
        Config.* (.data .data*)
        FWConfig.* (.data .data*)
        GnssIf.* (.data .data*)
        FWHandleMsg.* (.data .data*)
        HandleMsgFunc.* (.data .data*)
        CommonOps.* (.data .data*)
        FWGlobalVar.* (.data .data*)
        basicfunc.* (.data .data*)
        nmeaenc.* (.data .data*)
        FlashStore.* (.data .data*)
        bbct.* (.data .data*)
        timeConvert.* (.data .data*)
        GnssManager.* (.data .data*)
        SatAcqInfoEst.* (.data .data*)
        timekeep.* (.data .data*)
        msrcalc.* (.data .data*)
        msrfilter.* (.data .data*)
        correction.* (.data .data*)
        kalman.* (.data .data*)
        lsq.* (.data .data*)
        matrix.* (.data .data*)
        multipath.* (.data .data*)
        pvt.* (.data .data*)
        pvtentry.* (.data .data*)
        revmonitor.* (.data .data*)
        tsx.* (.data .data*)
        defaultAlm.* (.data .data*)
        Est_Msr.* (.data .data*)
        gpscoord.* (.data .data*)
        gpsframe.* (.data .data*)
        gpsnavdata.* (.data .data*)
        qzss.* (.data .data*)
        sbas.* (.data .data*)
        satmanage.* (.data .data*)
        glocoord.* (.data .data*)
        gloframe.* (.data .data*)
        glonavdata.* (.data .data*)
        BD2coord.* (.data .data*)
        bd2frame.* (.data .data*)
        bd2navdata.* (.data .data*)
        Bd2B1cCoord.* (.data .data*)
        Bd2B1cFrame.* (.data .data*)
        Bd2B1cIono.* (.data .data*)
        Bd2B1cNavData.* (.data .data*)
/*      Ldpc_dec.*           (.data .data*)*/
        galcoord.* (.data .data*)
        galframe.* (.data .data*)
        galnavdata.* (.data .data*)
        softbitDecode.* (.data .data*)
        SWViterbiDecoder.* (.data .data*)
        . = ALIGN(4);
        __gnss_data_end = .;
    } > DDR_RW AT>DDR_CODE
    .gnss_bss :
    {
        . = ALIGN(4);
        __gnss_bss_start = .;
        wd_ctrl_pm.* (.bss .bss*)
        FLCommon.* (.bss .bss*)
        FLCT.* (.bss .bss*)
        platform.* (.bss .bss*)
        FWManager.* (.bss .bss*)
        UartAdapter.* (.bss .bss*)
        Config.* (.bss .bss*)
        FWConfig.* (.bss .bss*)
        GnssIf.* (.bss .bss*)
        FWHandleMsg.* (.bss .bss*)
        HandleMsgFunc.* (.bss .bss*)
        CommonOps.* (.bss .bss*)
        FWGlobalVar.* (.bss .bss*)
        basicfunc.* (.bss .bss*)
        nmeaenc.* (.bss .bss*)
        FlashStore.* (.bss .bss*)
        bbct.* (.bss .bss*)
        timeConvert.* (.bss .bss*)
        GnssManager.* (.bss .bss*)
        SatAcqInfoEst.* (.bss .bss*)
        timekeep.* (.bss .bss*)
        msrcalc.* (.bss .bss*)
        msrfilter.* (.bss .bss*)
        correction.* (.bss .bss*)
        kalman.* (.bss .bss*)
        lsq.* (.bss .bss*)
        matrix.* (.bss .bss*)
        multipath.* (.bss .bss*)
        pvt.* (.bss .bss*)
        pvtentry.* (.bss .bss*)
        revmonitor.* (.bss .bss*)
        tsx.* (.bss .bss*)
        defaultAlm.* (.bss .bss*)
        Est_Msr.* (.bss .bss*)
        gpscoord.* (.bss .bss*)
        gpsframe.* (.bss .bss*)
        gpsnavdata.* (.bss .bss*)
        qzss.* (.bss .bss*)
        sbas.* (.bss .bss*)
        satmanage.* (.bss .bss*)
        glocoord.* (.bss .bss*)
        gloframe.* (.bss .bss*)
        glonavdata.* (.bss .bss*)
        BD2coord.* (.bss .bss*)
        bd2frame.* (.bss .bss*)
        bd2navdata.* (.bss .bss*)
        Bd2B1cCoord.* (.bss .bss*)
        Bd2B1cFrame.* (.bss .bss*)
        Bd2B1cIono.* (.bss .bss*)
        Bd2B1cNavData.* (.bss .bss*)
/*      Ldpc_dec.*           (.bss .bss*)*/
        galcoord.* (.bss .bss*)
        galframe.* (.bss .bss*)
        galnavdata.* (.bss .bss*)
        softbitDecode.* (.bss .bss*)
        SWViterbiDecoder.* (.bss .bss*)
        . = ALIGN(4);
        __gnss_bss_end = .;
    } > DDR_RW
     IMG_LD_RO_BASE = LOADADDR(.text.vectors); /* caculate code load base address */
     /* The startup code goes first into internal RAM */
     .text.vectors :
     {
        __text_start__ = .; /* caculate code running base address */
        . = ALIGN(8);
        KEEP(*(.isr_vector)) /* Startup code */
        . = ALIGN(8);
     } > IRAM_CODE AT>DDR_CODE
    .text :
    {
        . = ALIGN(4);
        *(.text) /* .text sections (code) */
        *(.text*) /* .text* sections (code) */
        *(.rodata) /* .rodata sections (constants, strings, etc.) */
        *(.rodata*) /* .rodata* sections (constants, strings, etc.) */
        *(.constdata)
        *(.glue_7) /* glue arm to thumb code */
        *(.glue_7t) /* glue arm to arm code */
        *(.eh_frame)
        . = ALIGN(4);
    } > IRAM_CODE AT>DDR_CODE
    sensor_init :
    {
        . = ALIGN(4);
        __sensor_init_start = .;
        KEEP(*(SENSOR_INIT));
        . = ALIGN(4);
        __sensor_init_end = .;
    } > IRAM_CODE AT>DDR_CODE
    .ARM.extab :
    {
        . = ALIGN(4);
        __extab_start = .;
        *(.ARM.extab* .gnu.linkonce.armextab.*)
        . = ALIGN(4);
        __extab_end = .;
    } > IRAM_CODE AT>DDR_CODE
    .ARM :
    {
        . = ALIGN(4);
        __exidx_start = .;
        *(.ARM.exidx*)
        . = ALIGN(4);
        __exidx_end = .;
        __text_end__ = .;
    } > IRAM_CODE AT>DDR_CODE
    /* caculate rw load base addr */
    IMG_LD_RW_BASE = LOADADDR(.data);
    .data :
    {
        . = ALIGN(4);
        __data_start__ = .; /* create a global symbol at data start */
        *(.data) /* .data sections */
        *(.data*) /* .data* sections */
        KEEP(*(.jcr*))
        . = ALIGN(4);
        __data_end__ = .; /* define a global symbol at data end */
    } > IRAM_RW AT>DDR_CODE
    .data.byte_heap_area (NOLOAD):
    {
        . = ALIGN(8);
        __data_heap_start__ = .; /* create a global symbol at data start */
        *(BYTE_HEAP_AREA)
        . = ALIGN(8);
        __data_heap_end__ = .; /* define a global symbol at data end */
    } > IRAM_HEAP AT>DDR_CODE
    .bss (NOLOAD):
    {
        /* This is used by the startup in order to initialize the .bss section */
        . = ALIGN(4);
        __bss_start__ = .;
        *(.bss)
        *(.bss*)
        *(COMMON)
        . = ALIGN(4);
        __bss_end__ = .;
        . = ALIGN(8);
        __end__ = .;
        PROVIDE(end = .);
    } > IRAM_RW
}
