[En-Nut-Discussion] Move some code parts from an application running in ROM to RAM

Harald Kipp harald.kipp at egnite.de
Fri Nov 16 13:00:57 CET 2007

Matthias Wilde schrieb:
> Dear Harald,
> thank you for the quick reply and support.
> Unfortunately  I still have some problems. In the linker script you refer
> to "__ramfunc_image" which is an undefined symbol for the linker.
Well, Matthias, I must admit, that I just pasted snippets from Ethernut 
3 uMon in the hope, that you'll sort out the missing parts. :-)

Let's try it in more detail. These things need to be done:

1. The routines need to be compiled and linked for running in RAM. This 
is done by the function attribute.
2. The linker must include the image in Flash area.
3. The startup routine must copy the routine from flash to RAM.

The first part was easy. The second part needs two additional entries in 
the linker script:

A) The one I posted earlier

.ramfunc : AT (__ramfunc_image)
        PROVIDE (__ramfunc_start = .);
        . = ALIGN(4);
        PROVIDE (__ramfunc_end = .);
    } >ram

B) The location where it is put into the binary image, for example

.got    :
        . = ALIGN(4);
        __ramfunc_image = .;
    } >rom

Nothing mysterious. It simply defines __ramfunc_image somewhere in ROM.

uMon doesn't do the third part in the startup, but in application code.

    extern int __ramfunc_image, __ramfunc_start, __ramfunc_end;
        int *sp;
        int *dp;

    sp = &__ramfunc_image;
    dp = &__ramfunc_start;
    while (dp < &__ramfunc_end) {
        *dp++ = *sp++;

Of course this part must be executed before using any function with

__attribute__ ((section(".ramfunc")))

Hope this description is easier to follow than my simplified first one.


More information about the En-Nut-Discussion mailing list