使用链接器文件向地址添加固定值

时间:2017-06-27 14:17:19

标签: c linker embedded gnu

我有一个使用GNU工具链设计的嵌入式系统。其中一个要求是它需要在运行时计算可执行代码(ROM)的校验和,并将其与已知值进行比较。根据天气,计算值等于它将引发错误的已知值。我需要将已知值放在闪存中(存储我的可执行代码的地方),其方式不会改变可执行代码。 AKA我无法在可执行代码中将值写入闪存。

我知道有些工具可以修改输出文件以将校验和放在已知地址中,但出于IT原因,外部工具不是一种选择。我决定在链接器中使用SHORT()命令,只需编辑链接器,在写入时将已知的校验和放在已知地址中。它不起作用,我不知道为什么。

我有链接器脚本的部分:

MEMORY {
m_interrupts          (RX)  : ORIGIN = 0x00000000, LENGTH = 0x00000400
m_flash_config        (RX)  : ORIGIN = 0x00000400, LENGTH = 0x00000010
m_interrupts_ram      (RW)  : ORIGIN = 0x1FFF0000, LENGTH = 0x00000400
m_text                (RX)  : ORIGIN = 0x00000410, LENGTH = 0x000FFBE0
m_data                (RX)  : ORIGIN = 0x1FFF0400, LENGTH = 0x0000FC00
m_data_2              (RW)  : ORIGIN = 0x20000000, LENGTH = 0x00030000
}
SECTIONS
{
.text :
{
  . = ALIGN(4);
  *(.fill)
  *(.text)                 /* .text sections (code) */
  *(.text*)                /* .text* sections (code) */
  *(.rodata)               /* .rodata sections (constants, strings, etc.) */
  *(.rodata*)              /* .rodata* sections (constants, strings, etc.) */
  *(.glue_7)               /* glue arm to thumb code */
  *(.glue_7t)              /* glue thumb to arm code */
  *(.eh_frame)
  KEEP (*(.init))
  KEEP (*(.fini))
  . = ALIGN(4);
} > m_text
.... More similar sections
....down at the bottom right before stack/heap definition
__ChecksumStart = 0xFFFE0;

.checksum  : AT(__ChecksumStart)
{
. = ALIGN (0x4);
SHORT(0xABCD)
} > m_text

__ChecksumSize = SIZEOF(.checksum);
.heap :
{
  . = ALIGN(8);
  __end__ = .;
  PROVIDE(end = .);
  __HeapBase = .;
  . += HEAP_SIZE;
  __HeapLimit = .;
} > m_data_2

.stack :
{
  . = ALIGN(8);
  . += STACK_SIZE;
} > m_data_2

__StackTop   = ORIGIN(m_data_2) + LENGTH(m_data_2);
__StackLimit = __StackTop - STACK_SIZE;
PROVIDE(__stack = __StackTop);

.ARM.attributes 0 : { *(.ARM.attributes) }
} //end of SECTIONS block here

我应该能够在可执行代码中查看位置0xFFFE0并查看0xABCD。我不。我看到默认值为0xFFFFFFFF。为了使这项工作,我需要改变什么?我看了this tutorial来实现这个目标

0 个答案:

没有答案