How to fill unused memory for CW for 8/16bit and kinetis Gnu.

Document created by ZhangJennie Employee on Jul 3, 2014Last modified by Diana Torres on Feb 28, 2017
Version 3Show Document
  • View in full screen mode

In many of user applications we use a CRC/checksum to verify that the code/flash on the target is not modified. For this, not only the code/data in flash counts, but as well all the unused gaps in the memory map. Instead to leave it up to the flasher/debugger (which usually erases it to 0xFF), I want to fill it with my pattern. For example 0xAA.

 

How to implement?

There may be several ways,  but I think the easiest way is to modify linker file.   the linker file structures are different for different MCUs.   For example, CW for 8bit/16bit and Coldfire V1 uses PRM file;  while CW for kinetis Gnu compiler uses ld file. We will talk about each of the case separately.


1. CW for 8bit/16bit and Coldfire V1.

1.1 .  NO FILL command involved.

We define a segment  in prm file

MYCONST_ROM     =  READ_ONLY    0x0870 TO 0x08FF;

Then allocate MYCONST  into it inside PLACEMENT.

MYCONST    INTO  MYCONST_ROM;

In C code, we only define  my_const_var(0xCCDD) at this range.

#pragma CONST_SEG MYCONST

const unsigned int my_const_var = 0xCCDD;

#pragma CONST_SEG DEFAULT

 

After build, we will see only 0xCCDD in this area in generated s19 file:

S1050870CCDDD9

 

1.2  use FILL command to fill unused area of MYCONST_ROM

With FILL command we can fill unused area of a section.  Add “FILL 0xAA” :

MYCONST_ROM       =  READ_ONLY 0x0870 TO 0x08FF FILL 0XAA;

 

Rebuild the project. we will see the rest of the field of MYCONST_ROM  is filled in  S19 file:

S1230870CCDDAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACF

S1230890AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA04

S12308B0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAE4

S12308D0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAC4

S11308F0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA54


2. CW for kinetis GNU compiler:

2.1 . No fill() command involed.

Define segment in MEMORY section:

my_section    (rx) : ORIGIN = 0X00000800, LENGTH = 0x20

 

define output  SECTION:

.myData :

{

    . = ALIGN(4); 

         KEEP(*(.myData))

    . = ALIGN(4);

}> my_section

In C code, define const variable “my_const” (0xCCCCDDDD)

const int my_const __attribute__((section(".myData"))) = 0xCCCCDDDD;

 

After build, we will see only 0xCCCCDDDD in this area in generated s19 file:

S1070800DDDDCCCC9E


2.2 Use FILL(0xaa)  command to fill unused area of my_section with 0xAA.

Here is the modified code in ld file, I highlight the code I add:

.myData :

{

       . = ALIGN(4); 

                 KEEP(*(.myData))

    . = ALIGN(4);

    FILL(0xaa)

    . = ORIGIN(my_section) + LENGTH(my_section) ;

  }> my_section

Rebuild the project. we will see the rest of the field of my_section is filled with 0xAA in  S19 file:

S1130800DDDDCCCCAAAAAAAAAAAAAAAAAAAAAAAA9A

S1130810AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA34



Attachments

    Outcomes