链接脚本中定义的变量未在C+&#x2B中进行。启动文件
我有以下链接器脚本(遗漏了无关的部分),
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_start | 0x6002000 | 0x20010000 |
vector_table_dtc_start | 0x6002000 | 0x20010000 |
vector_table_size | 0x45 | 0x45 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 extern
s 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
Variable | Expected | Actual |
---|---|---|
vector_table_flash_start | 0x6002000 | 0x20010000 |
vector_table_dtc_start | 0x6002000 | 0x20010000 |
vector_table_size | 0x45 | 0xffffffff |
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
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要检查链接脚本变量的地址而不是其价值。地址是链接脚本设置的。该值恰好是该地址 - 大概是向量表中的第一个向量。
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.