Copying ROM -> RAM

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Copying ROM -> RAM

4,027 次查看
bizio
Contributor I
Hi all,
I'm working with 5275EVB. I have to copy the data code from Flash to SRAM, but until now unsuccesfullness.

I have tried with the command memcpy() from my application but the result is not correct.

I have also tried the linker Command:

_romp_at = .text_rom + SIZEOF(.text_ram);
.romp : AT (_romp_at)
{
__S_romp = _romp_at;
WRITEW(ADDR(.text_rom));
WRITEW(ADDR(.text_ram));
WRITEW(SIZEOF(.text_ram));
WRITEW(0);
WRITEW(0);
WRITEW(0);
}
where:
.text_rom --> it is an section in memory flash with *(.text) & *(.data)
.text_ram --> it is an section in SRAM


Anybody can help me to solve this problem, please ?


Thank you in advance for your help.
标签 (1)
0 项奖励
回复
3 回复数

1,523 次查看
mvincent
Contributor I
I am assuming you are writing your own startup code. You can define symbols in your link script and use them for memcpy/memset. For example:

SECTIONS
{
.text: {start.o (.text) *(.text) *(.rodata) TextEnd=ALIGN(4);} >rom
.data: AT(TextEnd) {DataStart=ALIGN(4); *(.data)} >ram
.bss : {BssStart=ALIGN(4); *(.bss) BssEnd=ALIGN(4);} >ram
}

then your variable initializer would look like this:

extern char TextEnd[], DataStart[], BssStart[], BssEnd[];
void varInit(void)
{
// copy initialized data:
memcpy(DataStart, TextEnd, BssStart - DataStart);
// zero-out uninitialized data:
memset(BssStart, 0, BssEnd - BssStart);
}

This would work for C programs with GCC/LD. With C++, you have additional init. CodeWarrior uses almost the same syntax. Hope this helps.

Marc
0 项奖励
回复

1,523 次查看
bizio
Contributor I
Hi Marc
I have tried this code

SECTIONS
{
.text: {start.o (.text) *(.text) *(.rodata) TextEnd=ALIGN(4);} >rom
.data: AT(TextEnd) {DataStart=ALIGN(4); *(.data)} >ram
.bss : {BssStart=ALIGN(4); *(.bss) BssEnd=ALIGN(4);} >ram
}

extern char TextEnd[], DataStart[], BssStart[], BssEnd[];
void varInit(void)
{
// copy initialized data:
memcpy(DataStart, TextEnd, BssStart - DataStart);
// zero-out uninitialized data:
memset(BssStart, 0, BssEnd - BssStart);
}

but now my problem is to execute the code from ram.

How I can realize it?

Many thanks in advance.
0 项奖励
回复

1,523 次查看
mvincent
Contributor I
Re: copying code from ROM to RAM

This is different issue, and the question is much too generic to answer here since we don't know your design requirements and constraints (memory map, OS, field updatability, ...)

Many designs implement a bootloader that copies code from flash to ram and execute there. Sometimes the bootloader is "built-in" the final app; more often, it is a separate firmware executable. Some bootloaders are very simple: initialize PLL, cache, SDRAM, copy flash to SDRAM, jump. Others are much more elaborate with downloaders (serial or Ethernet), file system support, scripting, etc. I suggest you research open-source bootloaders such as Redboot and U-Boot.

Marc
0 项奖励
回复