Hi yaron,
if you use a gcc compiler, you have to create a separate section for your flash routines, located in RAM. You have to use the ELF - file format (arm-elf-gcc) for doing this

.
This functions are copied into the ram area if they are needed. I use a separate copy function for this.
Because you can't call this functions directly from ROM area (there is a 24 Bit jump limit), you can use a function table (located in ROM).
To tell the compiler that the flash routines are not in ROM use the following syntax:
int RamFlashEraseBlock(unsigned long adr) __attribute__((section(".ram")));
int RamFlashEraseBlock(unsigned long adr)
{
}
This tells the compiler to put the function RamFlashEraseBlock into the section RAM.
The function table looks like:
const int (*RAM_FUNC[])(unsigned long, ...) __attribute__ ((section(".text"))) =
{
(void*)&RamFlashEraseBlock,
:
:
};
To call the function use:
RAM_FUNC[0] (0);
The parameter 0 is interpreded by this function.
HINT: If you are inside a RAM function you can call other RAM functions direct. Do not use the table, because this table is located in flash, which could be erased.
Now you need an entry for the section RAM in the linker script like this:
.text 0x000000000 : { _rom_start = .; *(.text) *(.rodata) *(.glue_7) *(.glue_7t) *(.rodata.str1.4)} > rom
. = ALIGN(4);
_text_end = .;
. = 0x100000
.ram . : AT (_text_end)
{ _ram_start = .; *(.ram); _ram_end = .;} > ram
This will locate the ram-function at the end of the _text section (using the linker variable _text_end). The ram functions are now located in ROM, but they will linked for the address 0x10000.
To use it, you will generate a copy function, like this:
copy:
STMFD sp!, {r2, r3, r4, lr}
adr r0, LC0
ldmia r0, {r2, r3, r4} @ r2 - _ram_start / r3 - _ram_end / r4 - _text_end
2:
ldr r0, [r4], #4
str r0, [r2], #4
cmp r2, r3
blt 2b
LDMFD sp!, {r2, r3, r4, pc} @ return
LC1:
.long _ram_start
.long _ram_end
.long _text_end
You can also use a C copy routine. Declare the linker variables as EXTERN and use the address operator for getting the correct values.
I hope this helps

.
Best regards, Edi