Understanding Moving ARM Cortex-M0 +

I'm just starting out with the development of built-in leverage, and there is a piece of code that really listens to me:

/* Initialize the relocate segment */
pSrc = &_etext;
pDest = &_srelocate;

if (pSrc != pDest) 
{
    while (pDest < &_erelocate) 
    {
        *pDest++ = *pSrc++;
    }
}

Where _etextand _srelocateare the characters defined in the script builder:

. = ALIGN(4);
_etext = .;

.relocate : AT (_etext)
{
    . = ALIGN(4);
    _srelocate = .;
    *(.ramfunc .ramfunc.*);
    *(.data .data.*);
    . = ALIGN(4);
    _erelocate = .;
} > ram

Where ramis the segment of memory whose beginning 0x20000000. The problem, as I see it, is that _etext- it is a symbol that marks the final segment of the border .text, which is part of another memory segment rom. This means that if the aforementioned memory segment was not 100% full, _etext != _srelocateit will always be true. This means that we copy the memory outside the section .textwhere nothing is defined for life according to the linker script.

: A) , rom .text, .relocate ( .data), B ) .text , .relocate , C). , .data .text rom ram; s/relocate/data.

, , script, . - ?

+4
1

, . AT() .ramfunc .data​​strong > ( read/write) _etext. " > Ram" , , MEMORY, : https://sourceware.org/binutils/docs/ld/MEMORY.html#MEMORY / .

gnu ld, LMA ( ): https://sourceware.org/binutils/docs/ld/Output-Section-LMA.html

+1

Source: https://habr.com/ru/post/1664775/


All Articles