跳至主要内容

【转】ADS下的分散加载文件应用实例

ADS下的分散加载文件应用实例

load_region_name  start_address | "+"offset  [attributes] [max_size]
{
    execution_region_name  start_address | "+"offset  [attributes][max_size]
    {
        module_select_pattern  ["("
                                    ("+" input_section_attr | input_section_pattern)
                                    ([","] "+" input_section_attr | "," input_section_pattern)) *
                               ")"]
    }
}

load_region:       加载区,用来保存永久性数据(程序和只读变量)的区域;
execution_region:  执行区,程序执行时,从加载区域将数据复制到相应执行区后才能被正确执行;
load_region_name:  加载区域名,用于"Linker"区别不同的加载区域,最多31个字符;
start_address:     起始地址,指示区域的首地址;
+offset:           前一个加载区域尾地址+offset 做为当前的起始地址,且"offset"应为"0"或"4"的倍数;
attributes:        区域属性,可设置如下属性:
                    PI       与地址无关方式存放;
                    RELOC    重新部署,保留定位信息,以便重新定位该段到新的执行区;
                    OVERLAY  覆盖,允许多个可执行区域在同一个地址,ADS不支持;
                    ABSOLUTE 绝对地址(默认);
max_size:          该区域的大小;

execution_region_name:执行区域名;
start_address:     该执行区的首地址,必须字对齐;
+offset:           同上;
attributes:        同上;
                    PI          与地址无关,该区域的代码可任意移动后执行;
                    OVERLAY     覆盖;
                    ABSOLUTE    绝对地址(默认);
                    FIXED       固定地址;
                    UNINIT      不用初始化该区域的ZI段;
module_select_pattern: 目标文件滤波器,支持通配符"*"和"?";
                        *.o匹配所有目标,* (或".ANY")匹配所有目标文件和库。
input_section_attr:    每个input_section_attr必须跟随在"+"后;且大小写不敏感;
                        RO-CODE 或 CODE
                        RO-DATA 或 CONST
                        RO或TEXT, selects both RO-CODE and RO-DATA
                        RW-DATA
                        RW-CODE
                        RW 或 DATA, selects both RW-CODE and RW-DATA
                        ZI 或 BSS
                        ENTRY, that is a section containing an ENTRY point.
                        FIRST,用于指定存放在一个执行区域的第一个或最后一个区域;
                        LAST,同上;
input_section_pattern: 段名;

汇编中指定段:
     AREA    vectors, CODE, READONLY
C中指定段:
#pragma arm section [sort_type[[=]"name"]] [,sort_type="name"]*
sort_type:      code、rwdata、rodata、zidata
                如果"sort_type"指定了但没有指定"name",那么之前的修改的段名将被恢复成默认值。
#pragma arm section     // 恢复所有段名为默认设置。
应用:
    #pragma arm section rwdata = "SRAM",zidata = "SRAM"
        static OS_STK  SecondTaskStk[256];              // "rwdata""zidata"将定位在"sram"段中。
    #pragma arm section                                 // 恢复默认设置
分散加载文件中定义如下:
    Exec_Sram  0x80000000  0x40000
    {
        * (sram)
    }

"PI" 属性使用示例:
LR_1 0x010000 PI                ; The first load region is at 0x010000.
{
    ER_RO +0                    ; The PI attribute is inherited from parent.
                                ; The default execution address is 0x010000, but the code can be moved.
    {
        *(+RO)                  ; All the RO sections go here.
    }
    ER_RW +0 ABSOLUTE           ; PI attribute is overridden by ABSOLUTE.
    {
        *(+RW)                  ; The RW sections are placed next. They cannot be moved.
    }
    ER_ZI +0                    ; ER_ZI region placed after ER_RW region.
    {
        *(+ZI)                  ; All the ZI sections are placed consecutively here.
    }
}

LR_1 0x010000                   ; The first load region is at 0x010000.
{
    ER_RO +0                    ; Default ABSOLUTE attribute is inherited from parent. The execution address
                                ; is 0x010000. The code and ro data cannot be moved.
    {
        *(+RO)                  ; All the RO sections go here.
    }
    ER_RW 0x018000 PI           ; PI attribute overrides ABSOLUTE
    {
        *(+RW)                  ; The RW sections are placed at 0x018000 and they can be moved.
    }
    ER_ZI +0                    ; ER_ZI region placed after ER_RW region.
    {
        *(+ZI)                  ; All the ZI sections are placed consecutively here.
    }
}

程序中对某区域地址等的引用方法:
Load$$region_name$$Base             Load address of the region.
Image$$region_name$$Base            Execution address of the region.
Image$$region_name$$Length          Execution region length in bytes (multiple of 4).
Image$$region_name$$Limit           Address of the byte beyond the end of the execution region.

Image$$region_name$$ZI$$Base        Execution address of the ZI output section in this region.
Image$$region_name$$ZI$$Length      Length of the ZI output section in bytes (multiple of 4).
Image$$region_name$$ZI$$Limit       Address of the byte beyond the end of the ZI output sectionin the execution region.

SectionName$$Base                   Input Address of the start of the consolidated section called SectionName.
SectionName$$Limit                  Input Address of the byte beyond the end of the consolidated section called SectionName.

Load:          加载区,即存放地址;
Image:         执行区,即运行地址;
Base:          区首地址;
Limit:         区尾地址;
Length:        区长度;
region_name:   RO、RW、ZI、load_region_name、execution_region_name;

例如:
    "RAM1"区域的首地址:      Image$$RAM1$$Base
    上例中"sram"段首地址:    sram$$Base

汇编引用示例:
  IMPORT |Load$$Exec_RAM1$$Base|              // Exec_RAM1 为"RW"段
  IMPORT |Image$$Exec_RAM1$$Base|
  IMPORT |Image$$Exec_RAM1$$Length|
  IMPORT |Image$$Exec_RAM1$$Limit|

  LDR  R0, =|Load$$Exec_RAM1$$Base|
  LDR  R1, =|Image$$Exec_RAM1$$Base|
  LDR  R2, =|Image$$Exec_RAM1$$Limit|
0
  CMP  R1,   R2
  LDRCC R3,   [R0], #4
  STRCC R3,   [R1], #4
  BCC  %b0
C 引用:
extern unsigned char Load$$Exec_RAM1$$Base;
extern unsigned char Image$$Exec_RAM1$$Base;
extern unsigned char Image$$Exec_RAM1$$Length;

void MoveRO(void)
{
 unsigned char * psrc, *pdst;
 unsigned int  count;

 count = (unsigned int)   &Image$$Exec_RAM1$$Length;
 psrc  = (unsigned char *)&Load$$Exec_RAM1$$Base;
 pdst  = (unsigned char *)&Image$$Exec_RAM1$$Base;

 while (count--) {
  *pdst++ = *psrc++;
 }
}

加载文件示例一:
        起始地址      大小
ROM:    0x00000000    256K      ;0x1fc 保留为加密字,程序在ROM中运行;
RAM     0x40000000     16K      ;用于全局变量及任务堆栈;
SRAM    0x80000000    512K      ;SRAM速度慢,主要用于存放大的数据表;

LOAD_ROM1 0x00000000  0x1f8                 ; 指定该加载区域首地址、大小
{
    EXEC_ROM1  +0  0x1f8                    ; 没有前一加载区域,所以该执行区域首地址为加载去首地址
                                            ; 并指定该区域长度
    {
        Startup.o (vectors, +FIRST)         ; 目标文件的"vectors"段放在该执行区域的第一段
        irq.o (+RO)                         ; 目标文件的所有"RO"段放在该执行区域
    }
}

LOAD_ROM2 0x00000200                        ; 第二个加载区域
{
    EXEC_ROM2  +0  0x3e600
    {
        * (+RO)                             ; 所有目标文件和库文件中的"RO"段存放在该区域
    }

    RAM1   0x40000000   0x4000
    {
        * (+RW, +ZI)                        ; 所有目标文件和库文件的"RW"和"ZI"段存放在该区域
    }

    SRAM2  0x80000000  0x80000
    {
        * (sram)                            ; 所有目标文件中的"sram"段存放在该区域
    }
}

示例二:
    "iap.o"定义在"Exec_RAM1"中运行,所以设置"PI"属性;
    在调用"iap.c"中函数之前应该将其从"Load$$Exec_IAP$$Base"复制到指定的"Exec_RAM1"区域;

Load_region1  0x00000000  0x1fc
{
    EXEC_ROM1  +0
    {
        Startup.o (vectors, +FIRST)
        irq.o (+RO)
    }
}

Load_region2  0x00000200  0x3e600
{
    EXEC_ROM2  +0
    {
        * (+RO)
    }

    Exec_IAP   +0  PI               // 可能引起链接器未使用该属性警告,忽略
    {
        iap.o (+RO)
    }

    Exec_RAM1  0x40000000  0x4000
    {
        * (+RW, +ZI)
    }

    Exec_Sram  0x80000000  0x40000
    {
        * (SRAM)
    }
}

// 移动"IAP.o"中的所有函数到"ImageExecIAPBase"加载区,并调用其中的函数
extern unsigned char Load$$Exec_IAP$$Base;
extern unsigned char Image$$Exec_IAP$$Length;

#define  ImageExecIAPBase  (0x40000000+0x1000)   // 加载区首址

void MoveIAPRO(void)
{
 unsigned char * psrc, *pdst;
 unsigned int  count;

 count = (unsigned int)   &Image$$Exec_IAP$$Length;
 psrc  = (unsigned char *)&Load$$Exec_IAP$$Base;
 pdst  = (unsigned char *)ImageExecIAPBase;

 while (count--) {
  *pdst++ = *psrc++;
 }
}

// 调用"IAP.O"中的某函数
 {
  void (* pfnIAPWrite)(unsigned long, int);

  pfnIAPWrite = (void (*)(unsigned long, int))
   (ImageExecIAPBase +
   (unsigned int)IAPWrite -                        // 被调用函数名
   (unsigned int)&Load$$Exec_IAP$$Base);

  pfnIAPWrite((int)((CUPDATA *)CODESTARTADDR)->data,
     ((CUPDATA *)CODESTARTADDR)->length);
    }

// 结束,更具体的信息参考ADS帮助文档

评论

此博客中的热门博文

【转】VxWorks中的地址映射

在运用嵌入式系统VxWorks和MPC860进行通信系统设计开发时,会遇到一个映射地址不能访问的问题。 缺省情况下,VxWorks系统已经进行了如下地址的映射:   memory地址、bcsr(Board Control and Status)地址、PC_BASE_ADRS(PCMCIA)地址、Internal Memory地址、rom(Flach memory)地址等,但是当你的硬件开发中要加上别的外设时,如(falsh、dsp、FPGA等),对这些外设的访问也是通过地址形式进行读写,如果你没有加相应的地址映射,那么是无法访问这些外设的。   和VxWorks缺省地址映射类似,你也可以进行相应的地址映射。   如下是地址映射原理及实现:   1、 地址映射结构 在Tornado\target\h\vmLib.h文件中 typedef struct phys_mem_desc { void *virtualAddr; void *physicalAddr; UINT len; UINT initialStateMask; /* mask parameter to vmStateSet */ UINT initialState; /* state parameter to vmStateSet */ } PHYS_MEM_DESC; virtualAddr:你要映射的虚拟地址 physicalAddr:硬件设计时定义的实际物理地址 len;要进行映射的地址长度 initialStateMask:可以初始化的地址状态: 有如下状态: #define VM_STATE_MASK_VALID 0x03 #define VM_STATE_MASK_WRITABLE 0x0c #define VM_STATE_MASK_CACHEABLE 0x30 #define VM_STATE_MASK_MEM_COHERENCY 0x40 #define VM_STATE_MASK_GUARDED 0x80 不同的CPU芯片类型还有其特殊状态 initialState:实际初始化的地址状态: 有如下状态: #define VM_STATE_VALID 0x01 #define VM_STATE_VALID_NOT 0x00 #define VM_STATE_WRITA

【转】多迷人Gtkmm啊

前边已经说过用glade设计界面然后动态装载,接下来再来看看怎么改变程序的皮肤(主题)     首先从 http://art.gnome.org/themes/gtk2 下载喜欢的主题,从压缩包里提取gtk-2.0文件夹让它和我们下边代码生成的可执行文件放在同一个目录下,这里我下载的的 http://art.gnome.org/download/themes/gtk2/1317/GTK2-CillopMidnite.tar.gz     然后用glade设计界面,命名为main.glade,一会让它和我们下边代码生成的可执行程序放在同一个目录下边     然后开始写代码如下: //main.cc #include <gtkmm.h> #include <libglademm/xml.h> int main(int argc, char *argv[]) {     Gtk::Main kit(argc,argv);         Gtk::Window *pWnd;        gtk_rc_parse("E:\\theme-viewer\\themes\\gtk-2.0\\gtkrc");       Glib::RefPtr<Gnome::Glade::Xml> refXml;     try     {         refXml = Gnome::Glade::Xml::create("main.glade");     }     catch(const Gnome::Glade::XmlError& ex)     {         Gtk::MessageDialog dialog("Load glade file failed!", false,       \                                   Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK);         dialog.run();               return 1;     }         refXml->get_widget("main", pWnd);     if(pW

【转】https客户端的实现(libcurl)

一、              概念 1.         为什么要使用libcurl 1)        作为http的客户端,可以直接用socket连接服务器,然后对到的数据进行http解析,但要分析协议头,实现代理…这样太麻烦了。 2)        libcurl是一个开源的客户端url传输库,支持FTP,FTPS,TFTP,HTTP,HTTPS,GOPHER,TELNET,DICT,FILE和LDAP,支持Windows,Unix,Linux等平台,简单易用,且库文件占用空间不到200K 2.         get和post方式 客户端在http连接时向服务提交数据的方式分为get和post两种 1)        Get方式将所要传输的数据附在网址后面,然后一起送达服务器,它的优点是效率比较高;缺点是安全性差、数据不超过1024个字符、必须是7位的ASCII编码;查询时经常用此方法。 2)        Post通过Http post处理发送数据,它的优点是安全性较强、支持数据量大、支持字符多;缺点是效率相对低;编辑修改时多使用此方法。 3.         cookie与session 1)        cookie cookie是发送到客户浏览器的文本串句柄,并保存在客户机硬盘上,可以用来在某个Web站点会话之间持久地保持数据。cookie在客户端。 2)        session session是访问者从到达某个特定主页到离开为止的那段时间。每一访问者都会单独获得一个session,实现站点多个用户之间在所有页面中共享信息。session在服务器上。 3)        libcurl中使用cookie 保存cookie, 使之后的链接与此链接使用相同的cookie a)         在关闭链接的时候把cookie写入指定的文件 curl_easy_setopt(curl, CURLOPT_COOKIEJAR, "/tmp/cookie.txt"); b)        取用现在有的cookie,而不重新得到cookie curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "/tmp/cookie.txt"); b)        ht