【发布时间】:2020-06-26 10:35:46
【问题描述】:
我有一个微控制器,我在 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 二进制文件或任何查找我想要调用的 ROM 函数的地址从 RAM 中返回。
在浏览ld 文档数小时后,我真的不知道该怎么做,除了编写一个 shell 脚本尝试解析凌乱的地图文件并每次生成一个充满函数指针的自定义标头,从而重新发明了 wheel 链接器。
【问题讨论】: