Absolute address for MAIN funcation

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

Absolute address for MAIN funcation

3,690 次查看
Frankj
Contributor I
I am using codewarrior for coldfire MCF5274. I am trying to seup the absolute address for main function, for example, 0x0060000, but I don't know how to do it,
Thanks for any help.
 
Frank
 
标签 (1)
0 项奖励
回复
6 回复数

1,748 次查看
SimonMarsden_de
Contributor II
I agree with what CrasyCat said, but I think it can be done slightly more simply. You don't need to change the source file to put main into a user-defined section, you can just use the OBJECT statement in the Linker Control File (LCF) to place it exactly, e.g:

.mysection
{
# Put 'main' function from file 'main.c' here
OBJECT (_main, main.c)
...
} > mymemory

...where ".mymemory" is the memory segment you've placed at address 0x60000, and "main.c" is the file name of the file containing the main() function.

Other than this change, my suggestion is the same as CrasyCat's, but here's a little more detail. I haven't checked this with your example, but for your guidance the whole LCF would look something like this:

MEMORY {
# Declare memory at address 0x60000 and specify length (or use 0)
mymemory(RWX): ORIGIN = 0x00060000, LENGTH = <somelength>
...Other declarations here...
}

SECTIONS {
# Say what sections/objects to put into 'mymemory'
.mysection
{
OBJECT (_main, main.c)
} > mymemory

...Other sections here

}

If the memory at 0x60000 is RAM, you'll also need to make sure that the code in main() starts off in Flash and then gets copied there, so you'll need two extra steps:

(a) Say where the code is to be placed in Flash by adding the AT keyword to the LCF section declaration:

.mysection AT 0xNNNN
{
}

(b) Add code to explicitly copy it to RAM.


Hope this helps. It might need a bit of messing around, but the outline should be OK.

Out of curiosity, why do you want 'main' to be at the magic address?


Simon
0 项奖励
回复

1,748 次查看
Frankj
Contributor I
The information that you provided is very useful. Thanks very much.
 
I am doing a project using MCF5274, codewarrior. Due to hardware limitation, we only have one flash on the board to hold monitor and application. I want to update the application if required.
 
I will divided the flash into two parts, one for monitor, one for application, I hope that I could run the code from MCF5274 internal SRAM when the application is being updated. I need to erase the flash and rewrite the data into flash.
 
That is reason why I want to move the code into absoulte address, during the regular running mode, jump to Main, on update mode, jump to SRAM to update the flash. Is it a good idea or not? or Maybe you guys can provide some thoughts on this issue too.
 
Thanks again for your help.
 
Frank
 
0 项奖励
回复

1,748 次查看
SimonMarsden_de
Contributor II

Frankj wrote:
That is reason why I want to move the code into absoulte address, during the regular running mode, jump to Main, on update mode, jump to SRAM to update the flash. Is it a good idea or not?



I assume that you cannot execute code from one part of the Flash at the same time as programming another part? (For example, the on-chip Flash on the MCF5282 allows this by dividing the Flash into multiple blocks).

If not, the scheme you suggest sounds good. I've done something similar using the LCF OBJECT method I outlined. In my case, I needed the application to temporarily transfer execution out of SDRAM into SRAM before disabling the SDRAM controller.
0 项奖励
回复

1,748 次查看
Frankj
Contributor I
Hi Simon,
 
Yes, You are right. I can run one part of flash to erase the other part of flash. what I need to do is move all the code from flash into SRAM. Change SRAM from data section into ROM section, after I done the updating, I need to jump back to Flash.
 
Thanks, I will update what I get.
 
Have a wonderful weekend.
 
Frank
 
 
0 项奖励
回复

1,748 次查看
Frankj
Contributor I
It worked,  thanks.
 
0 项奖励
回复

1,748 次查看
CrasyCat
Specialist III
Hello
 
I assume you are using CodeWarrior for Coldfire. Am I right?
 
I would define the function in a user defined section and then place the section at the appropriate address in the linker command file.
 
To define a section in a user defined section use following notation
#pragma define_section myText ".myText" far_absolute RX
__declspec(myText) int main(void) {
In the .lcf file you have then to define a memory area at address  0x0060000 and place .myText there.
 
If you are not using CodeWarrior for development, please check with your software vendor how you need to define a user defined section.
I hope that helps.
 
CrasyCat
0 项奖励
回复