Note that there are some explanatory texts on larger screens.

plurals
  1. POlinker script load vs. virtual address
    text
    copied!<p>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.</p> <pre><code>MEMORY { flash : ORIGIN = 0x00000000, LENGTH = 512K ram : ORIGIN = 0x40000000, LENGTH = 32K usbram : ORIGIN = 0x7FD00000, LENGTH = 8K ethram : ORIGIN = 0x7FE00000, LENGTH = 16K } SECTIONS { .text : { *(.text) } &gt;flash __end_of_text__ = .; .data : { __data_beg__ = .; __data_beg_src__ = __end_of_text__; *(.data) __data_end__ = .; } &gt;ram AT&gt;flash .bss : { __bss_beg__ = .; *(.bss) } &gt;ram } </code></pre> <p>The code as shown above generates the following output:</p> <pre><code>40000000 &lt;__data_beg__&gt;: 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 </code></pre> <p>which represents an array of the form</p> <pre><code>int foo[] = {1,2,3,4,5,6}; </code></pre> <p>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. </p> <p><a href="http://sourceware.org/binutils/docs/ld/Output-Section-Attributes.html#Output-Section-Attributes" rel="nofollow">http://sourceware.org/binutils/docs/ld/Output-Section-Attributes.html#Output-Section-Attributes</a></p> <p>and here is my ld invocation:</p> <pre><code>arm-elf-ld -T ./lpc2368.ld entry.o main.o -o binary.elf </code></pre> <p>Thanks.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload