⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 armcc locate constants to fixed locations.htm

📁 LPC2214 Chip Protection
💻 HTM
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<!-- saved from url=(0041)http://www.keil.com/support/docs/3237.htm -->
<HTML><HEAD><TITLE>ARMCC: LOCATE CONSTANTS TO FIXED LOCATIONS</TITLE>
<META http-equiv=description 
content="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...">
<META 
content="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..." 
name=Description>
<META content=ARM name=KeilToolSet>
<META content="ARMCC: LOCATE CONSTANTS TO FIXED LOCATIONS" name=Keywords>
<META http-equiv=content-type content="text/html; charset=utf-8">
<META http-equiv=content-language content=en-us>
<META http-equiv=content-style-type content=text/css>
<META content="Keil™, An ARM® Company" name=Author>
<META 
content="Copyright (c) 2008, Keil™, An ARM® Company.  All rights reserved." 
name=Copyright><LINK title="ICRA labels" href="http://www.keil.com/labels.xml" 
type=application/rdf+xml rel=meta><LINK 
href="ARMCC LOCATE CONSTANTS TO FIXED LOCATIONS.files/t6_ncm.css" type=text/css 
rel=stylesheet><!--[if IE]><LINK 
href="ARMCC LOCATE CONSTANTS TO FIXED LOCATIONS.files/t6_nie.css" type=text/css 
rel=stylesheet><![endif]--><LINK 
href="ARMCC LOCATE CONSTANTS TO FIXED LOCATIONS.files/t6_cmn.css" type=text/css 
rel=stylesheet><!--[if lt IE 7]>
<SCRIPT src="ARMCC LOCATE CONSTANTS TO FIXED LOCATIONS.files/t6_supersleight.js" 
type=text/javascript></SCRIPT>
<![endif]--><LINK 
href="ARMCC LOCATE CONSTANTS TO FIXED LOCATIONS.files/t6_kb.css" type=text/css 
rel=stylesheet>
<META content="MSHTML 6.00.2800.1609" name=GENERATOR></HEAD>
<BODY>
<TABLE class=Main cellSpacing=0 cellPadding=0 border=0>
  <TBODY>
  <TR>
    <TD class=Top colSpan=2>
      <TABLE>
        <TBODY>
        <TR class=Titl>
          <TD colSpan=2><A href="http://www.keil.com/"><IMG 
            title="Keil™, An ARM® Company" height=47 
            alt="Keil™, An ARM® Company" 
            src="ARMCC LOCATE CONSTANTS TO FIXED LOCATIONS.files/keilarm.gif" 
            width=151></A>
            <DIV class=Titl>
            <P>Technical Support</P></DIV></TD></TR>
        <TR class=Menu>
          <TD class=LMenu><A title="Visit the Keil Home Page" 
            href="http://www.keil.com/">Home</A> <A 
            title="Get Information About Keil Products" 
            href="http://www.keil.com/product/">Products</A> <A 
            title="Upcoming Trade Shows, Workshops, and Seminars" 
            href="http://www.keil.com/events/">Events</A> <A 
            title="Get Technical Support for Keil Products" 
            href="http://www.keil.com/support/">Support</A></TD>
          <TD class=RMenu>
            <FORM id=keilsrchfm name=keilsrchfm 
            action=http://www.keil.com/support/search.asp method=get>
            <DIV><INPUT type=hidden value=1 name=PG><INPUT type=hidden value=1 
            name=PX><SPAN style="FONT-SIZE: 7pt">Search knowledgebase 
            for:</SPAN> <INPUT 
            style="FONT-SIZE: 7pt; FONT-FAMILY: verdana, sans-serif" name=Q> <INPUT class=button type=submit value=Go></DIV></FORM></TD></TR></TBODY></TABLE></TD></TR>
  <TR>
    <TD class=Bar>
      <DIV id=vm>
      <P>Technical Support</P>
      <UL>
        <LI><A href="http://www.keil.com/support/">Overview</A>
        <LI><A href="http://www.keil.com/support/search.asp">Search</A>
        <LI><A href="http://www.keil.com/support/contact.asp">Contact</A>
        <LI><A href="https://www.keil.com/support/gethelp.asp">Assistance 
        Request</A>
        <LI><A 
      href="https://www.keil.com/support/feedback.asp">Feedback</A></LI></UL>
      <P>Support Resources</P>
      <UL>
        <LI><A href="http://www.keil.com/support/knowledgebase.asp">Support 
        Knowledgebase</A>
        <UL>
          <LI><A href="http://www.keil.com/support/topics.asp">Article Index</A>
          <LI><A href="http://www.keil.com/support/topten.asp">Top 10 
          Articles</A></LI></UL>
        <LI><A href="http://www.keil.com/support/man/">Product Manuals</A>
        <LI><A href="http://www.keil.com/appnotes/">Application Notes</A>
        <LI><A href="http://www.keil.com/download/">File Download Area</A>
        <LI><A href="http://www.keil.com/update/">Product Updates</A>
        <LI><A href="http://www.keil.com/forum/">Discussion Forum</A>
        <LI><A href="http://www.keil.com/books/">Books</A></LI></UL>
      <P>Product Information</P>
      <UL>
        <LI><A href="http://www.keil.com/product/">Software &amp; Hardware 
        Products</A>
        <LI><A href="http://www.keil.com/product/whybuy.asp">Why Buy Tools From 
        Keil?</A>
        <LI><A href="http://www.keil.com/product/contact.asp">Contact</A>
        <UL>
          <LI><A href="http://www.keil.com/product/ordering.asp">Ordering 
          Instructions</A>
          <LI><A href="https://www.keil.com/product/info.asp">Product 
          Information Request</A>
          <LI><A href="https://www.keil.com/product/prices.asp">Pricing 
          Information Request</A></LI></UL>
        <LI><A href="http://www.keil.com/product/brochures.asp">Product 
        Brochures</A>
        <LI><A 
        href="http://www.keil.com/product/newsletters.asp">Newsletters</A></LI></UL></DIV></TD>
    <TD class=Bdy>
      <DIV class=Bdy>
      <H1>ARMCC: LOCATE CONSTANTS TO FIXED LOCATIONS</H1>
      <HR>

      <P>Information in this article applies to:</P>
      <UL>
        <LI>RealView C Compiler Version 3</LI></UL>
      <HR>

      <H3>QUESTION</H3>
      <P>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.</P>
      <P>What is the best way to do this?</P>
      <H3>ANSWER</H3>
      <P>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:</P>
      <OL>
        <LI>
        <P>Write the following C module called <B>ABS_ADDRESS.C</B> to define 
        the constant:</P><PRE>#pragma push
#pragma Ono_remove_unused_constdata
unsigned int const Security_Value = 0x87654321;
#pragma pop
</PRE>
        <P>Make sure that you reduce optimization with:</P><PRE><STRONG>#pragma Ono_remove_unused_constdata</STRONG>
</PRE>
        <P>Without this directive, the linker could remove the constant from the 
        final object.</P>
        <LI>
        <P>Locate the project's scatter file. µVision creates a scatter file 
        (with the extension *.SCT) when the <B>Use Memory Layout from Target 
        Dialog</B> option (<B>Project — Options for Target — Linker</B>) is 
        checked. The scatter file looks like this:</P><PRE>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)
  }
}
</PRE>
        <LI>
        <P>Disable the <B>Use Memory Layout from Target Dialog</B> option, then 
        specify the scatter file under <B>Project — Options — Linker — Scatter 
        File</B> and change the content of this file to:</P><PRE>LR_IROM1 0x00000000 0x00080000 { ; load region
  ER_IROM1 0x00000000 { ; load address = execution address
    *.o (RESET, +First)
<STRONG>    .ANY (*)</STRONG>
  }

<STRONG>  ABS_ADDRESS 0x1FC FIXED 4 {
    abs_address.o (*)
  }

  ER_IROM2 +0 0x80000 {
    * (+RO)
    .ANY(*)
  }</STRONG>

  RW_IRAM1 0x40000000 0x00008000 { ; RW data
    * (+RW +ZI)
  }
}
</PRE></LI></OL>
      <P>This will locate the constant in the file ABS_ADDRESS.C to memory 
      location 0x1FC.</P>
      <P>The linker will still remove unused sections. To avoid that you need to 
      enter the directive <B>--keep abs_address.o(.constdata)</B> under 
      <B>Project — Options — Linker — Misc controls</B>.</P>
      <H3>MORE INFORMATION</H3>
      <UL>
        <LI>RealView Linker and Utilities User's Guide</LI></UL>
      <H3>FORUM THREADS</H3>
      <P>The following <A href="http://www.keil.com/forum/">Discussion Forum</A> 
      threads may provide information related to this topic.</P>
      <UL>
        <LI><A href="http://www.keil.com/forum/docs/thread10802.asp">Ading a 
        flash table</A>
        <LI><A href="http://www.keil.com/forum/docs/thread10579.asp">How can i 
        protect a program from write/erase?</A></LI></UL>
      <P class=TabNotes>Last Reviewed: Wednesday, November 15, 2006</P>
      <HR>

      <FORM action=/support/fb_support.asp method=post>
      <TABLE class=Form style="MARGIN: 12px auto 0px">
        <TBODY>
        <TR>
          <TH>Did this article provide the answer you needed?</TH></TR>
        <TR>
          <TD>&nbsp;</TD></TR>
        <TR>
          <TD>
            <DIV 
            style="MARGIN: 0px auto; FONT: bold 10pt verdana, sans-serif; WIDTH: 30%; COLOR: #900; WHITE-SPACE: nowrap"><INPUT 
            style="VERTICAL-ALIGN: middle" type=radio CHECKED value=YES 
            name=Helped> Yes<BR><INPUT style="VERTICAL-ALIGN: middle" type=radio 
            value=NO name=Helped> No<BR><INPUT style="VERTICAL-ALIGN: middle" 
            type=radio value=UNSURE name=Helped> Not Sure</DIV></TD></TR>
        <TR>
          <TD>&nbsp;</TD></TR>
        <TR>
          <TD class=BAR><INPUT type=hidden 
            value="ARMCC: LOCATE CONSTANTS TO FIXED LOCATIONS" name=Title> 
            <INPUT type=hidden value=3237 name=Number> <INPUT type=submit value=Submit></TD></TR></TBODY></TABLE></FORM></DIV></TD></TR>
  <TR>
    <TD class=Bot colSpan=2>
      <TABLE>
        <TBODY>
        <TR class=Menu>
          <TD class=LMenu><A title="Contact Details" 
            href="http://www.keil.com/company/contact.asp">Contact</A> <A 
            title="Site Map" href="http://www.keil.com/siteindx.asp">Site 
            Map</A> <A title="Press Releases" 
            href="http://www.keil.com/pr/">Press</A> <A 
            title="Privacy Information" 
            href="http://www.keil.com/company/privacy.asp">Privacy</A></TD>
          <TD class=RMenu><A title="Copyright Information" 
            href="http://www.keil.com/company/copyright.asp">Copyright</A> © 
            2008 <A title="Keil™, An ARM® Company, Corporate Information" 
            href="http://www.keil.com/company/">Keil™, An ARM® Company.</A> All 
            rights reserved.</TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>
<SCRIPT src="ARMCC LOCATE CONSTANTS TO FIXED LOCATIONS.files/t6_ptg.js" 
type=text/javascript></SCRIPT>
<NOSCRIPT>
<DIV><IMG title="" 
style="BORDER-TOP-STYLE: none; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BORDER-BOTTOM-STYLE: none" 
height=1 alt="" src="" width=1> </DIV></NOSCRIPT></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -