链接描述文件加载与虚拟地址

发布于 2024-12-10 15:33:31 字数 1525 浏览 0 评论 0原文

我有以下链接器脚本,该脚本应该链接代码以在基于闪存的微控制器上运行。 uC 的闪存地址为 0x0,RAM 的地址为 0x40000000。我想将数据部分放入闪存中,但链接程序以便在 RAM 中完成对数据部分的访问。重点是,当控制器启动时,我将手动将其从闪存复制到正确的 RAM 位置。

MEMORY 
{
    flash   : ORIGIN = 0x00000000, LENGTH = 512K
    ram : ORIGIN = 0x40000000, LENGTH = 32K
    usbram   : ORIGIN = 0x7FD00000, LENGTH = 8K
    ethram   : ORIGIN = 0x7FE00000, LENGTH = 16K
}

SECTIONS
{
    .text : { *(.text) } >flash
    __end_of_text__ = .;
    .data : 
    {
        __data_beg__ = .;
        __data_beg_src__ = __end_of_text__;
        *(.data)
        __data_end__ = .;
    } >ram AT>flash
    .bss : 
    {
        __bss_beg__ = .;
        *(.bss)
    } >ram
}

上面所示的代码生成以下输出:

40000000 <__data_beg__>:
40000000:   00000001    andeq   r0, r0, r1
40000004:   00000002    andeq   r0, r0, r2
40000008:   00000003    andeq   r0, r0, r3
4000000c:   00000004    andeq   r0, r0, r4
40000010:   00000005    andeq   r0, r0, r5
40000014:   00000006    andeq   r0, r0, r6

它代表以下形式的数组

int foo[] = {1,2,3,4,5,6};

问题是它链接到 0x40000000,而不是我想要的闪存区域。我期望链接器脚本的 AT>flash 部分指定链接到 flash,如 LD 手册中所述。

http://sourceware.org/binutils/docs /ld/Output-Section-Attributes.html#Output-Section-Attributes

这是我的 ld 调用:

arm-elf-ld  -T ./lpc2368.ld entry.o main.o -o binary.elf

谢谢。

I've got the following linker script that is supposed to link code to run on a flash based micrcontroller. The uC has flash at address 0x0, and RAM at 0x40000000. I want to put the data section into flash, but link the program so that access to the data section is done in RAM. The point being, I'll manually copy it out of flash into the proper RAM location when the controller starts.

MEMORY 
{
    flash   : ORIGIN = 0x00000000, LENGTH = 512K
    ram : ORIGIN = 0x40000000, LENGTH = 32K
    usbram   : ORIGIN = 0x7FD00000, LENGTH = 8K
    ethram   : ORIGIN = 0x7FE00000, LENGTH = 16K
}

SECTIONS
{
    .text : { *(.text) } >flash
    __end_of_text__ = .;
    .data : 
    {
        __data_beg__ = .;
        __data_beg_src__ = __end_of_text__;
        *(.data)
        __data_end__ = .;
    } >ram AT>flash
    .bss : 
    {
        __bss_beg__ = .;
        *(.bss)
    } >ram
}

The code as shown above generates the following output:

40000000 <__data_beg__>:
40000000:   00000001    andeq   r0, r0, r1
40000004:   00000002    andeq   r0, r0, r2
40000008:   00000003    andeq   r0, r0, r3
4000000c:   00000004    andeq   r0, r0, r4
40000010:   00000005    andeq   r0, r0, r5
40000014:   00000006    andeq   r0, r0, r6

which represents an array of the form

int foo[] = {1,2,3,4,5,6};

Problem is that it's linked to 0x40000000, and not the flash region as I wanted. I expected the AT>flash part of the linker script to specify linking into flash, as explained in the LD manual.

http://sourceware.org/binutils/docs/ld/Output-Section-Attributes.html#Output-Section-Attributes

and here is my ld invocation:

arm-elf-ld  -T ./lpc2368.ld entry.o main.o -o binary.elf

Thanks.

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

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

发布评论

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

评论(2

携余温的黄昏 2024-12-17 15:33:31

您的链接器脚本将 .data 链接到 RAM 并将 .data 加载到 FLASH 中。这是由于 AT 命令造成的。

为什么要将易失性数据链接到闪存?数据和 Bss 必须始终链接到 RAM。您的链接器脚本非常正确。您只需将文本链接并保存到闪存中。

请查看您的地图文件。它必然会为数据变量分配一个 RAM 地址。

然后,程序加载器代码将 (data_end - data_beg) 个字节从 data_beg_src 复制到 data_beg。

因此,第一个数据(即数组)被复制到 SRAM 的开头。

如果您需要将数据链接到闪存:

 Data :
  {
   *(.data);
  } > flash

链接器现在会将 .data 链接并加载到闪存中。但如果我是你,我就不会那样做。

Your linker script LINKS .data to RAM and LOADS .data into FLASH. This is due to AT command.

Why do you want to link volatile data to flash? Data and Bss must ALWAYS be linked to RAM. Your linker script is quite correct. You would only link text and constand data into flash.

Please look at your map file. It would necessarily have assigned a RAM address to data variables.

The program loader code then copies copies (data_end - data_beg) bytes from data_beg_src to data_beg.

So the first data which is the array is copied into the begining of SRAM.

If you need to link data to flash:

 Data :
  {
   *(.data);
  } > flash

Linker will now LINK and LOAD .data into flash. But if I were you, I wouldnt do that.

忆沫 2024-12-17 15:33:31

你的.data虚拟地址= 0x40000000

你的.data逻辑地址= 0x00000000

这可以用命令看到
objdump -h 文件.elf

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  8 .data         00000014  40000000  00000000  00001000  2**2
                  CONTENTS, ALLOC, LOAD, DATA

Your .data virtual address = 0x40000000

Your .data logical address = 0x00000000

This can be seen with command
objdump -h file.elf

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  8 .data         00000014  40000000  00000000  00001000  2**2
                  CONTENTS, ALLOC, LOAD, DATA
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文