emulated EEPROM placement in Flash area

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
VinayDand
Level 3
Level 3
10 replies posted 10 questions asked 5 replies posted

Hello,

   

In PSoC4 we have to use emulated EEPROM component to use flash portion as EEPROM area. One limitation of the Em_EEPROM component of PSoC4 is, it automatically places EEPROM space in flash. This location may changes with different build cycle. This may create an tricky issue during security protection of flash (usually employed for IP protection of your firmware).

   

As you have to get the address of flash area allocated after a new build and change Flash Security file flags appropriately to allow Em_EEPROM to work within otherwise protected flash area. This is a tedious task and not intuitive as PSoC1 EEPOM component.

   
    One solution - as suggested in other forum post - is to define a fixed EEPROM area in flash using linker directive.   
   
        
   
    An example tried by me:   
   
        
   
    In global section define a variable to store emulated EEPROM data in flash as,   
   
        
   
          static const uint8  eepStrg[6]   __attribute__ ((section (".EEPROMDATA"))) = {0,0,0,0,0,0} ;   
   
        
   
    Here, const ensures that varaible will be allocated in ROM area.   
   
    section directive will creat a seperate section name to be allocated.   
   
    Note, it is must to initialize the EEPROM area with some data, for Em_EEPROM component to be allocated properly.   
   
        
   
    Next:   
   
    open project's linker script file (under Workspace Explorer - Source Tab - Generated Source - cm0gcc.ld)   
   
    in .ld file   
   
    add following lines   
   
    after ROM section  (one suggested location, after SECTION { ... ... ... } >rom )   
   
        
   
       .EEPROMDATA 0x00007f80 :   
   
       {   
   
         KEEP (*(.EEPROMDATA))   
   
       } >rom   
   
        
   
    Address 0x00007f80 is selected since it is last block of Flash - but can be other address not used by your firmware code.   
   
        
   
    Build project.   
   
        
   
    You should verify the allocation of emulated EEPROM space at the specified address in Flash ROM area, by searching the    
   
    generated map file (in Workspace Explorer under Results tab, 'Project name'.map file)   
   
        
   
    Now We can protect the Flash area excluding emulated EEPROM space by changing appropriate flag at Flash Security tab under cydwr file.   
   
        
   
    This approach has one draw back:   
   
    Whenever application is re-generated (due to change of component etc.) It generates new linker file. Needs editing the .ld    
   
    file again. (Software only change and build preserves the linker settings)   
   
        
   
    I will apreciate any     help towards,   
   
        
   
     1) Is there a method to preserve or automatically add section in linker script file?   
   
        
   
     2) Any other method to allocate EEPROM area at specific location to ease flash security allocation.   
   
        
   
    Best Regards,   
   
    Vinay   
   
        
0 Likes
12 Replies
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

There is a FAQ answer here: http://www.cypress.com/?id=4&rID=57109 , which leads to you here http://www.cypress.com/?rid=91945 for the PSoC5LP / PSoC4 (see page 30).

0 Likes
VinayDand
Level 3
Level 3
10 replies posted 10 questions asked 5 replies posted

 HLI,

   

Thanks for pointing AN89610.

   

I have got the initial idea of modifying linker script file after reading AN89610 itself.

   

After re-reading AN89610, (specially around page 23), My another work around solution is, copy generated linker script file, modify it to add custom EEPROM section at needed address. Rename the linker file. Store it in project source root folder and add it back to project. As mentioned in AN89610 :

   

"Note Linker  script  files  are  automatically  generated  by 

   

PSoC Creator at  project  build time, and changes that you 

   

make to  those files  may be overwritten on the next build. 

   

You can instruct PSoC Creator to use a  custom script  file, 

   

using  the  PSoC  Creator  menu  Project >  Build  Settings > 

   

Linker > General > Custom Linker Script.

   

If you use  a custom linker script file, it is a best  practice to 

   

add  it  to the project  (menu Project > Existing Item…)  and 

   

save  it  in  the  project  folder."

   

 

   

This solves issue of over written linker script file.

   

But I am not a GCC expert. And reading GCC documentation and creating fully custom linker script file is not easy. I would request experienced people to validate my solution, though it is working with this project.

   

Regards,

   

Vinay

0 Likes
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

Oh now I see the mistake I made 😞

   

The solution I thought was so neat only works for the MDK compiler, not for gcc. There the one you are looking at seems to be the only solution.

0 Likes
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

Oh, Google gave me a better answer after looking around. Its possible to set symbol addresses via the command line, see e.g. https://stackoverflow.com/questions/495262/linking-symbols-to-fixed-addresses-on-linux

   

So you can use e.g.

   
extern struct FooBar foobar;
   

in your code, the then call gcc with

   
gcc -Wl,--defsym,foobar=0x76543210 file.c
   

Or you use a so-called symbol file, storing the addresses of the variables you need placed (see the same link). Both should work without modifying the linker file.

0 Likes
VinayDand
Level 3
Level 3
10 replies posted 10 questions asked 5 replies posted

 HLI,

   

 

   

Thanks, for giving a nice tip.

   

I will try it out and post my result to complete the solution.

   

 

   

Regards,

   

Vinay

0 Likes
lock attach
Attachments are accessible only for community members.
VinayDand
Level 3
Level 3
10 replies posted 10 questions asked 5 replies posted

 Hello,

   

 

   

--defsym defines sysmbol as specified address value.

   

But linker does not allocate the eeprom flash locations at that address.

   

 

   

--section commands works well.

   

example as:

   

-Wl,--section-start=.EEPROMDATA=0x00007f80

   

 

   

I am repeating the solution of defining Em_EEPROM allocation at user specified location on flash memory with out modifying 

   

 

   

linker script file as below:

   

 

   

1) In global section define a variable to store emulated EEPROM data in flash as,

   

 

   

static const uint8  eepStrg[6]   __attribute__ ((section (".EEPROMDATA"))) = {0,0,0,0,0,0} ;

   

 

   

Here, const ensures that variable will be allocated in ROM area.

   

section directive will create a separate section name to be allocated.

   

Note, it is must to initialize the EEPROM area with some data, for Em_EEPROM component to be allocated properly.

   

 

   

2) specify custom linker flag on command line as

   

 

   

-Wl,--section-start=.EEPROMDATA=0x00007f80

   

 

   

(Address 0x00007f80 is selected since it is last block of Flash - but can be other address not used by your firmware code.

   

)

   

Go to Project->Build Settings->ARM GCC x.x.x->Linker->Command Line->Custom Flags->add -Wl,--section-

   

 

   

start=.EEPROMDATA=0x00007f80

   

 

   

You can verify .EEPROMDATA section allocated at 0x7f70 flash location in project's map file.

   

Also attaching a sample project for the same.

   

You can step through the code using MiniProg3 on a CY8CKit-049-42xx

   

 

   

Hope this may be useful towards IP protecting flash while keeping Em_EEPROM area seperate as unproteced block using Flash 

   

 

   

Security file.

   

 

   

Regards,

   

Vinay

0 Likes
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

Glad you got this working. And thanks for reporting back!

0 Likes
Anonymous
Not applicable

 Hello

   

Can someone please explain the EM_EEPROM to me. All the exemples work well untill I unpleg and replug my dev kit. The data I saved is then lost , yet the datasheet states 

   

"The Emulated EEPROM component should be used when:

   

 Data needs to be preserved across power cycles, and the target device does not have

   

dedicated EEPROM memory."

   

but I loose all my data at each power cycle. 

   

Help please

   

Thanks

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Some questions -

   

 

   

1) What dev kit are you using ?

   

2) How are you powering the devkit ?

   

3) How are you debugging, what interface are you using ?

   

 

   

You are not reprogramming the part and expecting the data to still

   

reside ? Like a build /  program / debug cycle ?

   

 

   

Some considerations -

   

 

   

www.cypress.com/

   

 

   

www.cypress.com/

   

 

   

www.cypress.com/

   

 

   

Regards, Dana.

0 Likes
Anonymous
Not applicable

>> Can someone please explain the EM_EEPROM to me. All the exemples work well untill I unpleg and replug my dev kit. The >> data I saved is then lost , yet the datasheet states 

   
    Here you can found some examples:   
       
        
   
        
   
    Reiner   
   
        
0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

@it

   

Can you post your actual complete project, so that we all can have a look at all of your settings? To do so, use
Creator->File->Create Workspace Bundle (minimal)
and attach the resulting file.



Bob
 

0 Likes
Anonymous
Not applicable

 Problem solved, Thanks all for your pointers. I forgot that when you debug it reprograms the whole device as hinted by Dana.

   

   

new to PSOC and loving it so far.

0 Likes