Write OPcode to distinct Flash address

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello,

 

I'm currently porting my bootloader environment from PIC to ATSAM devices and I'm curious how I can simply write a asm instruction to flash address 0x00

(to be more distinct I want to write the branch to the bootloader start (asm("B 0x3F500")) to FLASH address 0x0000.

I'm working with atmel studio 7 and GCC.

 

Would be great if anyone knows.

Thank you very much!

Last Edited: Mon. Nov 4, 2019 - 08:35 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think you really want to change the linker file to move your bootloader to another address. Or conversely, move your application start address. You might want to research how existing bootloaders like SAMBA or BOSSAC (Arduino) work to get a feel for how they address the issue.

 

In a bootloader I wrote for a cortex m0 part, I relocated the application start address using the linker file. The bootloader started from the default location. Once the bootloader had decided to execute the application, I simply cast a function pointer to the start of the application address and called the function. 

 

There's also the issue of interrupt vectors. Different parts have different methods of handling these. There's a bit of reading ahead.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Kartman,

 

thanks for the reply, I thought that an answer like this might come up. I wrote a few bootloaders already and I know about shifting locations/calling these sections and so on.

But the thing is, very little of the bootloaders cover the fault of interrupting the bootloading process leaving you with a corrupt application and no possibility of reaching the bootloader again (Yes, I know about the lazy workaround with the "bootloader button", but that's not an option here). Therefore I need a defined value at the end of the FLASH that will be written after programming is complete and that can be deleted by the bootloader before any application is deleted. You're right I can get around my hardcoded gotos, but that doesn't change the fact that I'd like to attach a "application complete" mark at the end of the flash. This said it would be nice to have it done within the Linker file to avoid having "dead" code in my source files.

 

Would be great to find a linker command to simply append a literal at FLASH address 0x40000.

 

Thank you!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sorry I bothered,

I found a solution now:

 

By just adding the following at the end of all predefined sections in the linker file the literal 0x1337 is written into flash at starting position 0x3FFFC, like this OPcodes can be written as well :) Works for me with an ATSAMC21, should be working with all ATMEGAs though.

.endmark 0x3FFFC:
{
    LONG(0x1337);
}

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have a ‘state’ value stored in eeprom emulation to indicate the state of the loaded app.