Problem with LCF file ROM code relocation

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Problem with LCF file ROM code relocation

Jump to solution
1,133 Views
pierreschmidt
Contributor III

Hello,

 

I started an MPC5668G project where during startup, I need to copy a portion of code from ROM=>RAM. I want the code to be compiled as beeing part of RAM but located in ROM (so that it can be flashed in non volatile memory).

I say compiled as "part of RAM" because the .elf file should contain RAM located debuging symbols so that when I run the code on a demo board, I can see the high level source at the right place in the RAM.

 

Here is part of my lcf file content:

 

MEMORY {

    /*  section allocation */

    applvect_fromCan:    org = 0x10000, len = 0x08

    romfbl:     org = 0x00010008,  len = 0x0001FFF0

    /* ROM 2M*/

    rom2:      org = 0x00012000,   len = 0x001EE000

    /* Code and data to external RAM */

    ram:      org = 0x40004000,   len = 0x32000

    /* Stack at top of external RAM */

    stack:  org = 0x40036000,    len = 0x2000

    /* FLASHDRV */

    flashdrv: org = 0x40000000,   len = 0x1000

    /* Vectors allocated to external RAM */

    vec:    org = 0x40038000,    len = 0x2000

    eth:    org = 0x40001000,   len = 0x3000

}

 

 

SECTIONS {

/* The first group contains code and constant data */

    /* The second group will allocate space for the initialized data

     * (.data/.sdata) and the unititialized data (.bss/.sbss)

     */

    GROUP : {

      EEPDATA  (BSS) : {}

      __DATA_RAM = .;

      .data  (DATA) LOAD(__DATA_ROM) : { *(.data) }

      .sdata (DATA) LOAD(ADDR(.sdata) - ADDR(.data) + __DATA_ROM) : { *(.sdata) }

      .sbss  (BSS) : {}

      .bss   (BSS) : {}

      .osdata (DATA): {}

      .ossdata (DATA): {}

      __DATA_RAM_START   = .;

     

      RAMCODE    (VLECODE)  LOAD(__TEXT_ROM) :

      {

          *(.text) 

    } 

      .sdata2    (TEXT)  LOAD(ADDR(.sdata2) - ADDR(RAMCODE) + __TEXT_ROM) :

      {

          *(.sdata2)

    }

      __DATA_RAM_END = .;

    } >ram

 

 

    GROUP : {

        APPLVECT_FROMCAN   (DATA) : {}

    } > applvect_fromCan

 

 

    GROUP : {

        .text1(VLECODE) : {*(.text_vle)}

       

        FBLHEADER   (DATA) : {}

 

        /* This is a dummy section to satisfy the linker for vle!*/

        /* This section should not contain any code.             */

        .text_e (TEXT) : {

            *(.text)

            . = (.+15) & ~15;

        }

       

        .ctors : {}

        .dtors : {}

        .oscode (TEXT) : {}

        .osconst (CONST) : {}

        .ossconst (CONST) : {}

        .osstring (CONST) : {}

        APPLVECT   (DATA) : {}

        FLASHROM   (DATA) : {}

       

        __TEXT_ROM = .;

        }

    } > romfbl

 

 

The problem is that when I open the generated .hex file, the code corresponding to the .text sections is in the RAM (adresses from 0x40004000) and not in ROM. I expected the code beeing located at __TEXT_ROM address and a free space in RAM from address 0x40004000.

 

What is wrong with the lcf file?

 

Thanks a lot.

 

P.SCHMIDT

 

 

Labels (1)
Tags (2)
1 Solution
628 Views
pierreschmidt
Contributor III

Hello Stanish,

It's OK now, the reason was I had the "Generate ROM image" option unchecked in the control panel. Now everything's fine

View solution in original post

2 Replies
628 Views
stanish
NXP Employee
NXP Employee

Hello Pierre,

perhaps the link below answers your question:

How to Copy Function from Flash to RAM & execute it

Stanish

629 Views
pierreschmidt
Contributor III

Hello Stanish,

It's OK now, the reason was I had the "Generate ROM image" option unchecked in the control panel. Now everything's fine