0
votes

Shortly, what I need is to place one section after another. An issue though that sections should be in different virtual address spaces.

Detailed: There are two pieces of code. One section (boot) works with MMU disabled and should be linked so that virtual and physical addresses be the same. Another section works while MMU enabled (app) and virtual address is offseted from physical.

Physically both sections should be placed one after another.

That is a part of a linker script I'm struggling with

MEMORY {
    DDR_MEMORY  : ORIGIN = 0x00002000, LENGTH = 0xFFFFFF
    APP_VMA     : ORIGIN = 0xFF002000, LENGTH = 0xFFFFFF
    BOOT_LMA    : ORIGIN = 0x00002000, LENGTH = 0xFFFFFF
}

SECTIONS
{
    .boot : {
        *(.startup)
    } >BOOT_LMA AT>DDR_MEMORY

    .app : {
        *(.text)
        *(.text*)
    } >APP_VMA AT>DDR_MEMORY
}

Result is: Lets say 'startup' code is 0x5C bytes. So boot section is linked as 0x2000 - 0x205C virtual and physical.

App code should be behind boot section and I want it to be placed at 0xFF002060 (virtual) and 0x2060 (physical). But APP_VMA I get is 0xFF002000 (no 0x60 offset) with physical location being 0x2060 (that's as expected).


So the question is how to add an offset to APP_VMA so to get virtual address matching a physical (eg. 0xFF002060)?

Thanks.

PS: I'm using a clang linker, but pretty much sure that this is applicable for a gcc as well.

1

1 Answers

0
votes

Shortly, the solution is to add a 'phony' section to increment APP_VMA and DDR_MEMORY linker counters.

I added a new section with a size of 'boot' section which increment linker counters and force linker to place 'app' in right virtual address space and physically behind a boot section.

MEMORY {
    DDR_MEMORY  : ORIGIN = 0x00002000, LENGTH = 0xFFFFFF
    APP_VMA     : ORIGIN = 0xFF002000, LENGTH = 0xFFFFFF
    BOOT_LMA    : ORIGIN = 0x00002000, LENGTH = 0xFFFFFF
}

PHDRS
{
    mmu_on      PT_LOAD;
    no_mmu      PT_LOAD;
}

SECTIONS
{
    .boot : {
        *(.startup)
        _boot_sizeof = SIZEOF(.boot);
    } >BOOT_LMA : no_mmu

    .boot_phony : {
        . += _boot_sizeof ;
        /* Reserve a space to adjust counters APP_VMA and DDR_MEMORY */
    } >APP_VMA AT>DDR_MEMORY :no_mmu

    .app : {
        *(.text)
        *(.text*)
    } >APP_VMA AT>DDR_MEMORY : mmu_on
}