This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS中的CMD文件解析



CMD主要是用来分配rom和ram空间用的,它告诉链接程序怎样计算地址和分配空间.所以不同的芯片就有不同大小的rom和ram.放用户程序的地方也不尽相同.所以要根据芯片进行修改.分两部分.MEMORY和SECTIONS.
MEMORY
{ PAGE 0 ..........
PAGE 1.........
}
SECTIONS
{
.vectors .................
.reset .................
................
}
MEMORY是用来指定芯片的rom和ram的大小和划分出几个区间.PAGE 0 对应rom,PAGE 1对应ram。PAGE里包含的区间名字与其后面的参数反映了该区间的起始地址和长度.
SECTIONS:在程序里添加段名.XXXX(如.vectors.)用来指定该段名以下,另一个段名以上的程序(属于PAGE0)或数据(属于PAGE1)放到“>”符号后的空间名字所在的地方。下面给出一个简单的例子:
MEMORY
{
PAGE 0: VECS: origin = 00000h, length = 00040h
LOW: origin = 00040h, length = 03FC0h
SARAM: origin = 04000h, length = 00800h
B0: origin = 0FF00h, length = 00100h
PAGE 1: B0: origin = 00200h, length = 00100h
B1: origin = 00300h, length = 00100h
B2: origin = 00060h, length = 00020h
SARAM: origin = 08000h, length = 00800h
}
SECTIONS
{
.text : { } > LOW PAGE 0
.cinit : { } > LOW PAGE 0
.switch : { } > LOW PAGE 0
.const : { } > SARAM PAGE 1
.data : { } > SARAM PAGE 1
.bss : { } > SARAM PAGE 1
.stack : { } > SARAM PAGE 1
.sysmem : { } > SARAM PAGE 1
}
CMD文件由三部分组成:(1) 输入输出定义;(2) MEMORY命令;(3) SECTION命令。
输入/输出定义:这一部分,可以通过ccs的“Build Option........”菜单设置
         。obj 链接的目标文件
         。lib 链接的库文件
         。map 生成的交叉索引文件
         。out 生成的可执行代码
MEMORY命令:描述系统实际的硬件资源
SECTION命令:描述“段”如何定位
下面给出一个例子:
-c
-o hello.out
-m hello.map
-stack 100
-l rts2xx.lib
MEMORY
{
   PAGE 0: VECT:origin=0x8000,length 0x040
   PAGE 0: PROG:origin=0x8040,length 0x6000
   PAGE 1: DATA:origin=0x8000,length 0x400
}
SECTIONS
{
.vextors >VECT PAGE 0
.text >PROG PAGE 0
.bss >DATA PAGE 1
.const >DATA PAGE 1
}
存储模型说明:
.cinit 存放程序中的变量初值和常量
.const 存放程序中的字符常量、浮点常量和用const声明的常量
.switch 存放程序中switch语句的跳转地址表
.text 存放程序代码
.bss 为程序中的全局和静态变量保留存储空间
.far 为程序中用far声明的全局和静态变量保留空间
.stack 为程序系统堆栈保留存储空间,用于保存返回地址、函数间的参数传递、存储局部变量和保存中间结果 
.sysmem 用于程序中的malloc 、calloc 、和realoc 函数动态分配存储空间.text可执行代码
  • 其实TIVA系列中的.cmd文件是比较简单的,以TM4C123中的一个例子为例,启动文件如下

    /******************************************************************************
     *
     * uart_echo_ccs.cmd - CCS linker configuration file for uart_echo.
     *
     * Copyright (c) 2012-2014 Texas Instruments Incorporated.  All rights reserved.
     * Software License Agreement
     * 
     * Texas Instruments (TI) is supplying this software for use solely and
     * exclusively on TI's microcontroller products. The software is owned by
     * TI and/or its suppliers, and is protected under applicable copyright
     * laws. You may not combine this software with "viral" open-source
     * software in order to form a larger program.
     * 
     * THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
     * NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
     * NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     * A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
     * CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
     * DAMAGES, FOR ANY REASON WHATSOEVER.
     * 
     * This is part of revision 2.1.0.12573 of the EK-TM4C123GXL Firmware Package.
     *
     *****************************************************************************/
    
    --retain=g_pfnVectors
    
    /* The following command line options are set as part of the CCS project.    */
    /* If you are building using the command line, or for some reason want to    */
    /* define them here, you can uncomment and modify these lines as needed.     */
    /* If you are using CCS for building, it is probably better to make any such */
    /* modifications in your CCS project and leave this file alone.              */
    /*                                                                           */
    /* --heap_size=0                                                             */
    /* --stack_size=256                                                          */
    /* --library=rtsv7M3_T_le_eabi.lib                                           */
    
    /* The starting address of the application.  Normally the interrupt vectors  */
    /* must be located at the beginning of the application.                      */
    #define APP_BASE 0x00000000
    #define RAM_BASE 0x20000000
    
    /* System memory map */
    
    MEMORY
    {
        /* Application stored in and executes from internal flash */
        FLASH (RX) : origin = APP_BASE, length = 0x00040000
        /* Application uses internal RAM for data */
        SRAM (RWX) : origin = 0x20000000, length = 0x00008000
    }
    
    /* Section allocation in memory */
    
    SECTIONS
    {
        .intvecs:   > APP_BASE
        .text   :   > FLASH
        .const  :   > FLASH
        .cinit  :   > FLASH
        .pinit  :   > FLASH
        .init_array : > FLASH
    
        .vtable :   > RAM_BASE
        .data   :   > SRAM
        .bss    :   > SRAM
        .sysmem :   > SRAM
        .stack  :   > SRAM
    }
    
    __STACK_TOP = __stack + 256;