Change code execution location

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

Change code execution location

跳至解决方案
1,643 次查看
nhinshaw
Contributor III

Hello,

 

I have been working on a project to design a custom bootloader for my k64f board.  I can successfully read in S19 files on a dedicated serial line, followed by storing that information to the determined places in memory, however because the code that loaded the new information is already on the board, I am unable to flash over top of it.  Is there a way to change the execution location of m_text to be applied on next reset?  this would allow me to load my code into empty memory, change that location and reset, followed by the board running the updated code stored previously.  This would, in theory then be flashed over the old code, and then again setting the execution location back to default with another reset.  Attached is my linker file, in case that helps

 

-Thanks

Nate Hinshaw

Original Attachment has been moved to: ProcessorExpert.lcf.zip

0 项奖励
回复
1 解答
1,354 次查看
seandema
Contributor IV

You can change the location of your code within flash, you'll just need to modify your linker file. Your bootloader will then need to start executing code from the new location when desired.

If you're using GCC look for the following section in you linker (*.ld) file.

vectorrom   (RX): ORIGIN = 0x00000000, LENGTH = 0x00000400

cfmprotrom  (R): ORIGIN = 0x00000400, LENGTH = 0x00000020

rom         (RX): ORIGIN = 0x00000420, LENGTH = 0x000FFBE0  /* Code + Const data */

You can change the address of vectorrom, cfmprotrom, and rom to start at a location after your bootloader. Program your code at the new address and then have the bootloader start executing from the new address.

Erich Styger has some articles that may help too.

https://mcuoneclipse.com/2014/10/06/putting-code-of-files-into-special-section-with-the-gnu-linker/

https://mcuoneclipse.com/2012/04/27/programming-part-of-flash/

Hope that helps,

Sean

在原帖中查看解决方案

0 项奖励
回复
7 回复数
1,354 次查看
nhinshaw
Contributor III

Using that code, i was able to first write my s19 to the memory, followed by calling that function after it was verified success.  This solved the issue i was having.  Thanks for the help everyone

-Best Regards

Nate Hinshaw

0 项奖励
回复
1,354 次查看
nhinshaw
Contributor III

I looked through Stygers work, and found where he developed a serial bootloader for a different freedom board.  He used

startup = ((uint32_t*)APP_FLASH_VECTOR_START)[1];

followed by

((void(*)(void))startup)();

I suspect this would accomplish the goal of changing the execution location by means of changing the flash vector.  am i reading his code correctly?

0 项奖励
回复
1,355 次查看
seandema
Contributor IV

You can change the location of your code within flash, you'll just need to modify your linker file. Your bootloader will then need to start executing code from the new location when desired.

If you're using GCC look for the following section in you linker (*.ld) file.

vectorrom   (RX): ORIGIN = 0x00000000, LENGTH = 0x00000400

cfmprotrom  (R): ORIGIN = 0x00000400, LENGTH = 0x00000020

rom         (RX): ORIGIN = 0x00000420, LENGTH = 0x000FFBE0  /* Code + Const data */

You can change the address of vectorrom, cfmprotrom, and rom to start at a location after your bootloader. Program your code at the new address and then have the bootloader start executing from the new address.

Erich Styger has some articles that may help too.

https://mcuoneclipse.com/2014/10/06/putting-code-of-files-into-special-section-with-the-gnu-linker/

https://mcuoneclipse.com/2012/04/27/programming-part-of-flash/

Hope that helps,

Sean

0 项奖励
回复
1,354 次查看
egoodii
Senior Contributor III

Not quite sure what you are asking, but I think the 'fundamental answer' you are looking for is NO, I don't expect you will find that ARM code from most compilers is 'freely relocatable to run anywhere'.  While MUCH will be 'PC relative', I think you will find 'just enough absolute addresses' embedded in code instructions to 'fail completely'.

0 项奖励
回复
1,354 次查看
nhinshaw
Contributor III

That does seem to be the case, although my issue remains.  I am attempting to find a way to "reflash" the program via the serial line.  I have the s19 file information on the board, i just have no way to erase what is currently on board and flash the new information on to it as a result of the read/write errors.  do you have any suggestions for how I could accomplish this function?  I do have a current idea that perhaps i could call somthing in PE_low_level_init(); to read a chunk of flash memory with a flag, if it detected that flag, it could run to the normal memory location for m_data with an offset to find the new flash code, followed by a copy over that code before things start getting initialized.

-Best

Nate Hinshaw

0 项奖励
回复
1,354 次查看
ndavies
Contributor V

This is normally the function of a bootloader in embedded systems. The bootloader allows you to keep communications up while you swap out the application code.

On larger processor the functionality you're looking for is handled by the MMU. There isn't an MMU in the kinetis parts.

0 项奖励
回复
1,354 次查看
egoodii
Senior Contributor III

All I can say to that is 'that is what bootloaders are for' within the total device flash memory.

0 项奖励
回复