gun 连接脚本指定地址插入自定义section

连接脚本 ld 文件:


/* Memories definition */
MEMORY
{
  RAM (xrw)		        : ORIGIN = 0x20000000, LENGTH = 16K
  ROM (rx)		        : ORIGIN = 0x08000000, LENGTH = 128K
}

/* Sections */
SECTIONS
{
  /* The startup code into ROM memory */
  .isr_vector :
  {
    . = ALIGN(4);
    KEEP(*(.isr_vector)) /* Startup code */
    . = ALIGN(4);
  } >ROM

  /* The program code and other data into ROM memory */
  .myvars :
  {
    . = ALIGN(4);
    KEEP(*(.myvars*))
    _smyvars = .;
    *(.myvars.ROM_VERSION)
    *(.myvars.CRC)
    *(.myvars.LENGTH)
    *(.myvars.BUILD_ID)
    *(.myvars*);
  } > ROM
  .text :
  {
    . = ALIGN(4);
	_stext = .;
    *(.text)           /* .text sections (code) */
    *(.text*)          /* .text* sections (code) */
    *(.glue_7)         /* glue arm to thumb code */
    *(.glue_7t)        /* glue thumb to arm code */
    *(.eh_frame)

    KEEP (*(.init))
    KEEP (*(.fini))

    . = ALIGN(4);
    _etext = .;        /* define a global symbols at end of code */
  } >ROM

  /* Constant data into ROM memory*/
  .rodata :
  {
    . = ALIGN(4);
    *(.rodata)         /* .rodata sections (constants, strings, etc.) */
    *(.rodata*)        /* .rodata* sections (constants, strings, etc.) */
    . = ALIGN(4);
  } >ROM

自定义的section段即:
 

  .myvars :
  {
    . = ALIGN(4);
    KEEP(*(.myvars*))
    _smyvars = .;
    *(.myvars.ROM_VERSION)
    *(.myvars.CRC)
    *(.myvars.LENGTH)
    *(.myvars.BUILD_ID)
    *(.myvars*);
  } > ROM

在C代码中使用:
 

#define MYVARS_START         _smyvars
extern const int MYVARS_START;


#pragma optimize=none
__attribute__((section(".myvars.ROM_VERSION"))) const char ROM_VERSION[16]= FW_VERSION_BOARD;
__attribute__((section(".myvars.CRC"))) const uint32_t CRC;
__attribute__((section(".myvars.LENGTH"))) const uint32_t LENGTH = (uint32_t) &TotalFlashUsed;
__attribute__((section(".myvars.BUILD_ID"))) const uint32_t BUILD_ID=0xAAAAAAAA;


void rom_info(void)
{
    myvars_start_addr = (uint32_t)&MYVARS_START;
    logi("myvars offset:%#x\r\n",myvars_start_addr );
	logi("version number =%s \r\n",ROM_VERSION);
    logi("TotalFlashUsed =%d \r\n",LENGTH);
}

_smyvars 为自定义段的起始地址, 该地址位于 中断向量表的后面,芯片信号选定后这个起始地址一般就是固定。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值