链接脚本中定义的变量未在C+&#x2B中进行。启动文件

发布于 2025-01-22 14:26:41 字数 2957 浏览 4 评论 0原文

我有以下链接器脚本(遗漏了无关的部分),

MEMORY
{
  PROGRAM_FLASH (rx) : ORIGIN = 0x60000000, LENGTH = 0x40000 
  SRAM_DTC (rwx) : ORIGIN = 0x20000000, LENGTH = 0x10000 
  SRAM_ITC (rwx) : ORIGIN = 0x0, LENGTH = 0x10000
  SRAM_OC (rwx) : ORIGIN = 0x20200000, LENGTH = 0x20000 
}

ENTRY(ResetISR)

SECTIONS
{
     /* Image Vector Table and Boot Data for booting from external flash */
.boot_hdr : ALIGN(4)
{
    FILL(0xff)
    __boot_hdr_start__ = ABSOLUTE(.) ;
    KEEP(*(.boot_hdr.conf))
    . = 0x1000 ;
    KEEP(*(.boot_hdr.ivt))
    . = 0x1020 ;
    KEEP(*(.boot_hdr.boot_data))
    . = 0x1030 ;
    KEEP(*(.boot_hdr.dcd_data))
    __boot_hdr_end__ = ABSOLUTE(.) ;
    . = 0x2000 ;
} >PROGRAM_FLASH

.vector : ALIGN(4)
{
    FILL(0xff)
    __vector_table_flash_start__ = . ;
    __vector_table_dtc_start__ = LOADADDR(.vector) ;
    
    KEEP(*(.isr_vector))
    
    . = ALIGN(4) ;
    
    __vector_table_size__ = . ;
     
} >PROGRAM_FLASH

因此相关的外卖:

  • 闪存从0x600000000开始,
  • 一些XIP启动字节写入了闪光灯开始的专用位置,然后是“我自己的东西”。
  • 我将矢量表放置在0x60002000(或者更好的是,NXP SDK期望有些XIP字节并跳到0x60002000,我可以将自己的东西放在那里)。
  • 我正在使用当前位置创建一些变量,以便
  • 在查看拆卸代码时可以在启动脚本中使用它们,我可以清楚地看到我的矢量表描述了0x45单词,因此,使用上述链接器脚本,我希望我的<我<代码> __ vector_table_size __ 至少

在我的启动.cpp中是0x45,我添加了一些extern s,以便我可以阅读链接器创建的内存信息。

extern unsigned int __vector_table_flash_start__;
extern unsigned int __vector_table_dtc_start__;
extern unsigned int __vector_table_size__;
    
/* some temp vars so that my assignments don't get optimized out */
volatile unsigned int i;
volatile unsigned int ii;
volatile unsigned int iii;

__attribute__ ((naked, section(".after_vectors.reset")))
void ResetISR(void) {
    // Disable interrupts
    __asm volatile ("cpsid i");
    __asm volatile ("MSR MSP, %0" : : "r" (&_vStackTop) : );
    //__asm volatile ("LDR r9, = __global_offset_table_flash_start__");
    
    i = __vector_table_flash_start__;
    ii = __vector_table_dtc_start__;
    iii = __vector_table_size__;
}

同样,没有什么有趣的,只有一些代码可以确保没有任何优化的代码,并且我可以看到调试器中变量的实际值。

当我们知道我的闪光灯从0x60000000开始,并且我的.vector e节的偏移0x2000

变量预期的实际
vector_table_flash_start0x60020000x20010000
vector_table_dtc_start0x60020000x20010000
vector_table_size0x450x45 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff

作为参考,拆卸的相关部分(ARM-NONE-NONE-EABI-OBJDUMP-DISASSEMEM-ALL ECLIPSE/MIMXRT1024_PROject/debug/debug/mimxrt1024_project.axf&gt; disassemble_pic

) i.sstatic.net/wzbt5.png“ rel =“ nofollow noreferrer”>

I have the following linker script (left out irrelevant parts)

MEMORY
{
  PROGRAM_FLASH (rx) : ORIGIN = 0x60000000, LENGTH = 0x40000 
  SRAM_DTC (rwx) : ORIGIN = 0x20000000, LENGTH = 0x10000 
  SRAM_ITC (rwx) : ORIGIN = 0x0, LENGTH = 0x10000
  SRAM_OC (rwx) : ORIGIN = 0x20200000, LENGTH = 0x20000 
}

ENTRY(ResetISR)

SECTIONS
{
     /* Image Vector Table and Boot Data for booting from external flash */
.boot_hdr : ALIGN(4)
{
    FILL(0xff)
    __boot_hdr_start__ = ABSOLUTE(.) ;
    KEEP(*(.boot_hdr.conf))
    . = 0x1000 ;
    KEEP(*(.boot_hdr.ivt))
    . = 0x1020 ;
    KEEP(*(.boot_hdr.boot_data))
    . = 0x1030 ;
    KEEP(*(.boot_hdr.dcd_data))
    __boot_hdr_end__ = ABSOLUTE(.) ;
    . = 0x2000 ;
} >PROGRAM_FLASH

.vector : ALIGN(4)
{
    FILL(0xff)
    __vector_table_flash_start__ = . ;
    __vector_table_dtc_start__ = LOADADDR(.vector) ;
    
    KEEP(*(.isr_vector))
    
    . = ALIGN(4) ;
    
    __vector_table_size__ = . ;
     
} >PROGRAM_FLASH

So relevant takeaways:

  • flash memory starts at 0x600000000
  • some XIP boot bytes are written to dedicated locations beginning of flash, followed by "my own stuff".
  • I put vector tables at 0x60002000 (or better put, nxp sdk expects some xip bytes and jumps to 0x60002000 where I can put my own stuff).
  • I am creating some variables with the current location so that I can use them in my startup script
  • When I look at the disassembled code, i can clearly see that my vector tables described 0x45 words, so with above linker script I would expect that my __vector_table_size__ at least would be 0x45

In my startup .cpp I added some externs so that I can read the memory info created by the linker.

extern unsigned int __vector_table_flash_start__;
extern unsigned int __vector_table_dtc_start__;
extern unsigned int __vector_table_size__;
    
/* some temp vars so that my assignments don't get optimized out */
volatile unsigned int i;
volatile unsigned int ii;
volatile unsigned int iii;

__attribute__ ((naked, section(".after_vectors.reset")))
void ResetISR(void) {
    // Disable interrupts
    __asm volatile ("cpsid i");
    __asm volatile ("MSR MSP, %0" : : "r" (&_vStackTop) : );
    //__asm volatile ("LDR r9, = __global_offset_table_flash_start__");
    
    i = __vector_table_flash_start__;
    ii = __vector_table_dtc_start__;
    iii = __vector_table_size__;
}

Again, nothing interesting, just some code to make sure nothing is optimized out, and that I can see the actual values of the variables in the debugger.

When we know that my flash starts at 0x60000000 and that my .vector section has an offset of 0x2000

VariableExpectedActual
vector_table_flash_start0x60020000x20010000
vector_table_dtc_start0x60020000x20010000
vector_table_size0x450xffffffff

What I am doing wrong here??

For reference, the relevant section of disassemble (arm-none-eabi-objdump --disassemble-all eclipse/MIMXRT1024_Project/Debug/MIMXRT1024_Project.axf > disassemble_pic)

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

薆情海 2025-01-29 14:26:41

您需要检查链接脚本变量的地址而不是其价值。地址是链接脚本设置的。该值恰好是该地址 - 大概是向量表中的第一个向量。

You need to check the address of the linker script variables, not their value. The address is what the linker script sets. The value is what happens to be at that address - presumably the first vector in the vector table.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文