Linker script - exact memory align

51 views Asked by At

I develop for the STM32 environment (same IDE), and I have to change the original Linker Script. I would like to store a struct in the exact memory address. If I create a new memory item (in the MEMORY body), it could be a solution but I have to specify the length. ( but I dont want to) Can I do it without knowing the length / struct size?

This is my current solution:

.isr_vector:
...

  .text:
  {
    . = ALIGN(0x8000300);
    KEEP(*(.SWHEADER_SECTION))
    
  }>FLASH
.text:
...

So it will store SWHEADER_SECTION into 0x8000300, and the FLASH will continue on the next section. I can't add a variable to ALIGN instead of setting a constans. I have tried lots of other solutions, but they were not effecive or the linker dropped an error (ex: OVERLAPPED, etc.) Is there any other solution?

Another question: If the SWHEADER_SECTION is written like this, then between these two sections, there will be a section that will not be used. Is it possible that .isr_vector can be followed by the common .text, and the linker can skip space by the SWHEADER_SECTION section?

Thanks!

1

There are 1 answers

2
Tom V On

ALIGN tells the linker that the address must be a multiple of this, not exactly this. The argument must be a power of two.

You don't have to know the exact size of something to fix its address though. Just put the .isr_vector in a fixed size memory region and then put your headers at the start of the text section, followed by the rest of your program.

Something like:

    MEMORY
    {
        VECTORS (r)   : ORIGIN = 0x08000000, LENGTH = 768
        ROM     (rx)  : ORIGIN = 0x08000300, LENGTH = (16K - 768)
        RAM     (rwx) : ORIGIN = 0x20000000, LENGTH = 4K
    }

    SECTIONS
    {
        .vectors :
        {

            KEEP(*(.isr_vector))
        }
        >VECTORS

        .text :
        {
            KEEP(*(.SWHEADER_SECTION))
            *(.text .text.* .stub .gnu.linkonce.t.*)
        }
        >ROM