This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Prevent RW data initialization in hex file

Hi I have a problem with hex file generation in MDK-ARM.
I want the hex file only contain data in FLASH not RAM. But for all RW data there is some output in the resulting hex file which points to RAM not FLASH:

:020000042000DA
:1000400000000000000000000000000000000000B0
:1000500000000000000000000000000000000000A0
:100060000000000000000000000000000000000090
:100070000000000000000000000000000000000080
:100080000000000000000000000000000000000070
:100090000000000000000000000000000000000060
:1000A0000000000000000000000000000000000050
:1000B0000000000000000000000000000000000040
:1000C0000000000000000000000000000000000030
:1000D0000044950800000000000000000102030435
:0400E00006070809FE

Portion from map file:

     Code (inc. data)   RO Data    RW Data    ZI Data      Debug

     16930       1348        678        164      21140     541021   Grand Totals
     16930       1348        678        164      21140     541021   ELF Image Totals
     16930       1348        678        164          0          0   ROM Totals

Portion from linker script (scatter):

LOAD_RAM 0x20000040
{
  DATA_RAM +0
  {
    * (+RW,+ZI)
  }
}

I have read about the UNINIT attribute but it is not the case I need. RW data is produced from something like

static uip_timer timerPeriodic;

But I don't want specify zero-init attribute for each of this variable, as there are libraries used and other linkers (such as GNU linker) have the NOLOAD directive which prevents these RAM segments in hex file.

How to avoid this?

Parents
  • With a scatter file that tells the linker that initialized variables should be stored in flash and loaded into RAM, the hex file will have the data within the address range of the flash. And the startup code will copy the initial values into RAM when your processor boots.

    This is the normal result you get when you configure the memory layout using the normal dialogs.

    This is a scatter file that manages just that:

    LR_IROM1 0x00008000 0x00018000  {    ; load region size_region
      ER_IROM2 0x00008000 FIXED {  ; load address = execution address
       *.o (RESET, +First)
       * (InRoot$$Sections)
       .ANY (+RO)
      }
    
      RW_IRAM1 0x40000080 0x0000E7C0  {  ; RW data
       .ANY (+RW +ZI)
      }
    }
    


    Note that the RAM starts at 0x40000080 (I reserved 0x80 bytes) an have size 0xE7C0. But the RAM is inside the load region LR_IROM1. So the hex file stores the data in the IROM1 region.

Reply
  • With a scatter file that tells the linker that initialized variables should be stored in flash and loaded into RAM, the hex file will have the data within the address range of the flash. And the startup code will copy the initial values into RAM when your processor boots.

    This is the normal result you get when you configure the memory layout using the normal dialogs.

    This is a scatter file that manages just that:

    LR_IROM1 0x00008000 0x00018000  {    ; load region size_region
      ER_IROM2 0x00008000 FIXED {  ; load address = execution address
       *.o (RESET, +First)
       * (InRoot$$Sections)
       .ANY (+RO)
      }
    
      RW_IRAM1 0x40000080 0x0000E7C0  {  ; RW data
       .ANY (+RW +ZI)
      }
    }
    


    Note that the RAM starts at 0x40000080 (I reserved 0x80 bytes) an have size 0xE7C0. But the RAM is inside the load region LR_IROM1. So the hex file stores the data in the IROM1 region.

Children