ARM Technical Support Knowledge Articles

LOCATE CONSTANTS TO FIXED LOCATIONS

Applies to: RealView C Compiler

Answer


Information in this article applies to:


QUESTION

I am using a Philips LPC2000 device. To read protect the chip, I want to locate a constant at a fixed memory location (0x1FC) in the Flash ROM.

What is the best way to do this?

ANSWER

To locate a constant at a fixed address you must create a small module that contains the constant, and modify the scatter file to reference that module. Here are the steps:

  1. Write the following C module called ABS_ADDRESS.C to define the constant:

    #pragma push
    #pragma Ono_remove_unused_constdata
    unsigned int const Security_Value = 0x87654321;
    #pragma pop
    

    Make sure that you reduce optimization with:

    #pragma Ono_remove_unused_constdata
    

    Without this directive, the linker could remove the constant from the final object.

  2. Locate the project's scatter file. uVision creates a scatter file (with the extension *.SCT) when the Use Memory Layout from Target Dialog option (Project — Options for Target — Linker) is checked. The scatter file looks like this:

    LR_IROM1 0x00000000 0x00080000  {  ; load region
      ER_IROM1 0x00000000  {       ; load address = execution address
       *.o (RESET, +First)
       * (+RO)
      }
      RW_IRAM1 0x40000000 0x00008000  {  ; RW data
       * (+RW +ZI)
      }
    }
    
  3. Disable the Use Memory Layout from Target Dialog option, then specify the scatter file under Project — Options — Linker — Scatter File and change the content of this file to:

    LR_IROM1 0x00000000 0x00080000 { ; load region
      ER_IROM1 0x00000000 { ; load address = execution address
        *.o (RESET, +First)
        .ANY (*)
      }
    
      ABS_ADDRESS 0x1FC FIXED 4 {
        abs_address.o (*)
      }
    
      ER_IROM2 +0 0x80000 {
        * (+RO)
        .ANY(*)
      }
    
      RW_IRAM1 0x40000000 0x00008000 { ; RW data
        * (+RW +ZI)
      }
    }
    

This will locate the constant in the file ABS_ADDRESS.C to memory location 0x1FC.

The linker will still remove unused sections. To avoid that you need to enter the directive --keep abs_address.o(.constdata) under Project — Options — Linker — Misc controls.

MORE INFORMATION

Article last edited on: 2006-11-15 10:10:03

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential