DSP链接命令文件Linker.cmd的作用及用法举例

本文介绍了链接器中的MEMORY和SECTIONS命令的使用方法及其缺省算法。MEMORY命令用于定义存储器配置,包括存储器各部分的命名、起始地址和长度。SECTIONS命令则指导链接器如何组合输入段形成输出段,并确定输出段在存储器中的位置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

以下是我自己在学习中的一些CMD文件的资料的收集和总结。

存储器空间

链接器在处理段的时候,有如下2个主要任务:

将由汇编器产生的COFF格式的一个或多个.obj文件链接成一个可执行的.out文件;重新定位,将输出的段分配到相应的存储器空间。

链接器有2条命令支持上述任务:

(1) MEMORY命令。定义目标系统的存储器配置图,包括对存储器各部分命名,以及规定它们的起始地址和长度;

(2) SECTIONS命令。告诉链接器如何将输入段组合成输出段,以及将输出段放在存储器中的什么位置。

1. MEMORY命令

        作用:定义系统中所包含的各种形式的存储器,以及它们占据的地址范围。

        句法:

MEMORY

{

PAGE0name 1[(attr)]:   orign=constant,  length=constant

PAGElname n[attr]:             orign=constant,  length=constant

}

PAGE——对一个存储空间加以标记。PAGE 0程序存储器,PAGE l定为数据存储器。

Name——对一个存储区间取名。 

Origin——存储区的起始地址。键入OriginOrgO都可

Length——规定存储区的长度。键入LengthLenL都可以

Attr——这是一个任选项,为命名区规定14个属性。 。 

MEMORY命令的使用。

MEMORY

{

PAGE 0:         ROM:      origin=0c00h,        length=1000h

PAGE 1:  SCRATCH: origin=60h,   length=20h

                     ONCHIP:          origin=80h,   length=200h

}

上述MEMORY命令所定义的系统的存储器配置如下:

PAGE 0为程序存储器,名ROM,起始地址0C00H,长度4K字。

PAGE l为数据存储器,名SCRATCH,起始地址60H,长32字。 

PAGEl为数据存储器,名ONCHIP,起始地址80H,长度512字。

2. SECTIONS命令

作用:说明如何将输入段组合成输出段;

            规定输出段在存储器中的存放位置;

            并允许重新命名输出段。

句法:

SECTIONS

{

name:[propertypropertyproperty……]

name:[propertypropertyproperty……]

name:[propertypropertyproperty……]

}

Name——段名,每一个输出段的说明都从段名开始。

Property——性能参数,段名后面是一行说明段的内容和如何给

                      段分配存储单元的性能参数。 

一个段主要的性能参数有:

装入存储器分配(Load allocation)

     定义段装入时的存储器地址,语法为

          Load=allocation(这里allocation指地址)

          或allocation

          或>allocation

(2) 运行存储器分配(Run allocation)

       定义段运行时的存储器地址,语法为

            Run=allocation

            run>allocation

      链接器为每个输出段在目标存储器中分配两个地址:一个是加载的地址,另一个是执行程序的地址。通常,这两个地址是相同的。有时要先将程序加载到ROM,然后在RAM中以较快的速度运行,只要用SECTIONS命令让链接器对这个段定位两次就行了。如.fir:    loadROMrun=RAM  

SECTIONS命令的使用。

file1.obj     file2.obj

SECTIONS

{

     .text:             load=ROM,   run=800h

     .bss:               load=RAM

     .vectors:          load=FF80h

}

.bss段结合file1.objfile2.obj.bss段且被装入RAM空间。

.text段结合file1.objfile2.obj.text段,链接器将所有命名为.text   

       的段都结合进该段,在程序运行时该段必须重新定位在地址   

       0800h

.vectors段定位在地址FF80h

3. MEMORYSECTIONS命令的缺省算法

        如果没有利用MEMORYSECTIONS命令,链接器就按缺省算法来定位输出段:

MEMORY

{

PAGE 0PROGorigin=0x0080,    length=0xFF00

PAGE 1DATAorigin=0x0080,    length=0xFF80

}

SECTIONS

{

     .text:        PAGE=0

     .data:        PAGE=0

     .cinit:        PAGE=0

     .bss:         PAGE=1

块是目标文件中的最小单位。一个块就是最终在存储器映像中占据空间的一块代码或数据,目标文件中的每一个块都是相互独立的。一般的,COFF目标文件中包含三个默认的块:

.text :通常包含可执行代码

.data :通常包含已初始化的数据

.bss :通常为未初始化的数据保留空间

所有的块分为两大类:已初始化块和未初始化块。对块的处理主要通过六个命令实现:.bss,.uset,.data,.sect,.asect,.text.其中.bss.usect用于建立未初始化块。

.bss建立的块名就是.bss

.usect  “块名” 分配

.data.text建立的块名就是其本身。

后两个建立包含代码或者数据的块,用法类似于.data.text.只不过可以自己命名。

.sect “块名”

.asect “块名”  地址

C编译器编译的目标程序还有以下块:

已初始化块:

.cinit:包含初始化变量和常数表

.const:字符串和switch表,

未初始化块:

.stack:为系统堆栈分配存储器,这个存储器用于将变量传递给函数以及分配局部变量。

.sysmem:为动态存储器函数分配存储器空间。

### DSP28335 RAM Enable Configuration For the DSP28335, enabling and configuring RAM involves modifying linker command files (`.cmd`) and ensuring proper settings within the code. When changing from a different device like F280025C to using a generic flash link file such as `28002x_generic_flash_lnk.cmd`, it's important that specific configurations are adjusted accordingly[^1]. For instance, adding `_FLASH` in macro definitions prevents hardware initialization issues. Specifically for RAM enablement on the DSP28335: - **Linker Command File Adjustments**: The `.cmd` file must correctly map memory sections including RAM areas. This ensures functions intended to run in RAM (`ramfunc`) operate at designated addresses without conflicts. ```plaintext MEMORY { PAGE 0: /* Program Memory */ ... VECTORS: org = 0x008000 length = 0x000400 ... PAGE 1: /* Data Memory */ ... RAMLS08 : origin = 0x00B000, length = 0x000800 /* On-chip RAM LS */ ... } ``` - **Macro Definitions**: Ensure any necessary macros related to RAM usage or execution-in-place (XIP) modes are defined appropriately. Adding symbols like `_RAMfuncsRunFromRam` can direct certain operations into RAM space directly during compilation/linking stages. - **Initialization Code**: Within startup routines or main application logic, commands may be required to explicitly initialize or switch contexts regarding where executable instructions reside—either Flash or RAM. An example might involve setting up interrupt vectors pointing towards RAM-based handlers after copying them over post-boot. Regarding error messages about EABI versus COFF formats concerning floating-point sizes, these typically relate more closely with compiler toolchain selections rather than direct RAM activation steps but could influence how variables/functions interact across different storage types. #### Example of Enabling RAM Execution To ensure functions execute out of RAM instead of Flash which improves performance especially under tight timing constraints seen often in real-time systems involving DSPs: ```c #pragma CODE_SECTION(RamFuncExample,"ramfuncs"); __interrupt void RamFuncExample(void){ // Function body here... } ``` This pragma directive along with appropriate placement via the linker script allows relocating this function into an area mapped by the symbol `"ramfuncs"` inside your CMD file setup.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值