我有一个微控制器,我在 ROM 中放了一个大程序,它应该在某个时刻将有效负载提取到 RAM 中并执行它,然后应该再次调用 ROM 中的函数。
前半部分(调用 RAM)看起来很简单:
/* ROM linker script */
MEMORY
{
rom (rx) : ORIGIN = 0x08000000, LENGTH = 64K /* this includes .text */
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 10K /* was 20K, cut in half to make space for payload, this includes .data, .bss, etc */
plram (rwx) : ORIGIN = 0x20002800, LENGTH = 10K /* space for payload */
}
SECTIONS{
.ramPayloadBlock : {
__RAM_PAYLOAD_START = .;
KEEP(*(.ramPayload))
} > plram
}
// ROM code
extern int __RAM_PAYLOAD_START;
void __attribute__((section (".ramPayload"))) (*ramPayload)(void) = (void(*)(void))&__RAM_PAYLOAD_START; // this works as long as the payload's entrypoint is actually at the start of .ramPayload
ramPayload();
但是现在,当实际链接代码时,ramPayload我需要以某种方式告诉链接器查看 ROM 的.map文件或.elf二进制文件或任何查找我想从 RAM 回调的 ROM 函数的地址。
在浏览文档数小时后ld,我真的不知道该怎么做,除了编写一个 shell 脚本试图解析凌乱的映射文件并每次生成一个充满函数指针的自定义头文件,从而重新发明轮子链接器。