cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
blavoie
Observer
Observer
3,100 Views
Registered: ‎09-30-2009

Forcing memory sections to be read only at linker level

Hello,

I would like to be able to set a section of memory as read only at the linker level. In the end I will simply permanently de-assert  the write enable to the port of the BRAM controller, but as a short fix I want to do it at the linker level. I know I can do this in the source code by declaring with the const attribute, but it makes it more difficult with multiple people writing code. If I can do it at the linker level then the tooling will handle doing the checking, rather than relying on several people to make sure all variables/pointers/etc are const. I tried the memory attribute (r) as indicated in the linker manual, but it id not do it. I think the memory attribute only instructs the linker where to place data that is not explicitly mapped. For example, the following does not force the memory section to be read only:

 

MEMORY
{
   xps_0_mb4_bram_cntlr  : ORIGIN = 0x81418000, LENGTH = 0x00004000
}

 

Any suggestions?

 

many thanks.,

--

0 Kudos
2 Replies
brianhill
Xilinx Employee
Xilinx Employee
3,083 Views
Registered: ‎04-23-2008

Nothing forces a section to be read only.

 

Global data declared as 'const' is assumed to be read only.  The compiler assigns such data to the .rodata section.  You could assign the .rodata section to the BRAM in question in your linker script.  While the compiler will complain if your software modifies something which was declared as 'const', it's "read only"ness is entirely a software construct. Software can still happily attempt to overwrite 'const' data.

 

Alternately, you can create your own unique section mapped to this bram (i.e. .rodata_bram) and use compiler directives in your source code to assign the specific hand-tailored global data you want to this section. 

 

-Brian 

0 Kudos
blavoie
Observer
Observer
3,072 Views
Registered: ‎09-30-2009

Hi Brian,

 

Thanks for your reply.You're right, the read-onlyness would not truely be enforced by the software tools. In the end we will create a custom BRAM IP that has one port read/write and the other port read only. I was hoping to use the linker to provide some level of checking that we were not trying to write to the read only port as I start coding. I wanted to try this global approach over using const since if I forget to make every pointer or type cast const it defeats the whole thing. Don't misundestand, I do use const all the time in my real code when called for, but what I'm trying to do now is just a stop-gap until we create the custom BRAM block. I just wanted to have a quick high level check.

 

I can live without it, but was hoping that by setting some linker flags I could have forced the compiler to do a "soft" check and throw an error or warning.

 

thanks again,

--

0 Kudos