Initted data linker problem

Showing results for 
Search instead for 
Did you mean: 

Initted data linker problem

Contributor III

Hi all,


Using CW for MPC5554 V2.8 - I'm having trouble with linking.  I've read through the PA_Build_RM but am still not 'getting it'. Could someone take a look and help point me in the right direction?


I've got a fairly standard app,  runs from Flash and has an initialized data section that needs to be copied to RAM at run time.  If I turn off 'Generate Rom Image" it'll link but will have problems with the initialized data.  If I turn on "Generate Rom Image"  I get 3 overlap errors...


Overlap of the ROM image address of .text section with executable address of .entry_point section.
Overlap of the ROM image address of .text section with executable address of .text section.
Overlap of the ROM image address of .rodata section with executable address of .rodata section.

My LCF looks like this...

    ROM sections
 // bam_bootarea:           org = 0x00000000,   len = 0x00000008   // bam_bootarea is set up in boot, not app
  init_mwerks:            org = 0x00000010,   len = 0x00000FF0
  fault_rom:              org = 0x00020000,   len = 0x00020000 
  execption_handlers:     org = 0x00040000,   len = 0x00002000
  init_data_rom:          org = 0x00042000,   len = 0x00001000
  application_code:       org = 0x00043000,   len = 0x0003CFFC
  application_crc:        org = 0x0007FFFC,   len = 0x00000004 
  calibration_rom_0:      org = 0x00100000,   len = 0x00020000 
  calibration_rom_1:      org = 0x00120000,   len = 0x00020000
  parameter_rom_0:        org = 0x00140000,   len = 0x00020000
  parameter_rom_1:        org = 0x00160000,   len = 0x00020000
    RAM sections
  init_data_ram:          org = 0x20000000,   len = 0x00001000
  zero_init_data:         org = 0x20001000,   len = 0x000FF000
  persistent_ram:         org = 0x40000000,   len = 0x00001000
  interrupt_stack:        org = 0x40008000,   len = 0x00001000
  shutdown_task_stack:    org = 0x40009000,   len = 0x00001000
  analog_task_stack:      org = 0x4000A000,   len = 0x00001000
  control_task_stack:     org = 0x4000B000,   len = 0x00001000
  j1939_task_stack:       org = 0x4000C000,   len = 0x00001000
  background_task_stack:  org = 0x4000D000,   len = 0x00001000
  heap:                   org = 0x4000E000,   len = 0x00001000 
  stack:                  org = 0x4000F000,   len = 0x00001000  
    Error Detection
  unused_sections:        org = 0xFFFFFFFF,   len = 0x00000000

//FORCEACTIVE { "bam_rchw" "bam_resetvector" }

  .init                   LOAD (0x00000010) : {} > init_mwerks
  .execption_handlers    LOAD (0x00040000) : { vector_table.o handlers.o } > execption_handlers  /* order of files important */
    .entry_point (TEXT)   : { __start.o }  /* entry point for application code must be at fixed location */
    .text        (TEXT)   : {}          
    .rodata      (CONST)  : { *(.rdata) *(.rodata) }
    .ctors                : {}
    .dtors                : {}
    extab                 : {}
    extabindex            : {}
  } > application_code

   .data : {}               
  } > init_data_ram                   
    .bss    : { calibrations.o(.bss) *(.bss) }
  } > zero_init_data
    .sdata  : {}
    .sbss   : {}
    .sdata2 : {}
    .sbss2  : {}
  } > unused_sections





Labels (1)
3 Replies

Specialist III



If you want to get initialization data copied over from ROM to RAM at startup you have to enable generation of a ROM image.


Your .lcf file looks OK as far as I can tell.

The next question is what did you specify as RAM BufferAddress and ROM Image Address while generating the .lcf?

These edit box need to be set to the start address of the memory area, where you want to append the initialization data.

According to the .lcf file you provide they should be set to 0x00043000 (both of them).


The attached document should explain a bit how ROM Images should be configured and also provide ways for you to double check if your executable is generated correctly.




Contributor III

Thanks for the response, Crasy.


I've seen the 'Run From Rom' PDF in the searches I did before posting..  Looks like it came from the PA Build Reference Manual,  which I've also been through pretty thouroughly. 


I need the data stored at 0x42000 in FLASH and at 2000 0000 at run time (external RAM).  I have the ROM Image set to 0x42000 and the RAM buffer address set to 0x2000 4000. 


The ROM image address seems pretty clear,  that's the address in FLASH that I want to store the initialized data in.  It is still not clear to me what the 'RAM buffer' is used for.  The docs read as if this is used for 'loader' code,  so all I need to do is give it a block of unused RAM to use for the transfer.  Is that correct?


At this point the linker seems happy (link map shows variables at the correct address)  but the initialized data does not end up in the correct place in the linker output file.  The rest of the code is OK,  but the initialized dataends up at 0x2000 000 instead of 0x42000,  so the loader moves 'ff's to ram at startup.





0 Kudos

Specialist III



  Here is what experience teaches me about ROM images.

  1- I always set RAM BufferAddress and ROM Image Address to the same value.

      As far as I know RAM BufferAddress is there for legacy purpose and was for a kind of botloader

      that could be used to reprogram the code into flash. I am not sure this is still supported today.


  2- ROM Image Address should be set to the start address of one of the read only memory area defined in the .lcf file.

      The linker will place initialization data that needs to be copied from RAM to ROM at the end of this memory area 

      (i.e. after all sections that are  explicitly placed there).


3- All Read Only sections that are placed in another memory area than the one where the ROM image is located

    should use the LOAD function to specify their LOAD address.


In your .lcf file you intend to use a dedicated memory area for the initialization data. Is there any reason for that?


Now to fix the problem in your linker file I see 2 solutions

  1- Use the application_code memory area to store initialization data

       Here define application_code as

              application_code:       org = 0x00042000,   len = 0x0003DFFC
      and remove definition of init_data_rom memory area.

     Then make sure to specify 0x00042000 as RAM BufferAddress and ROM Image Address.


  2- Use the  init_data_rom memory area to store initialization data

      In that case add the appropriate LOAD command to all sections allocated in application_code area.

      Then make sure to specify 0x00042000 as RAM BufferAddress and ROM Image Address.




0 Kudos