cancel
Showing results for 
Search instead for 
Did you mean: 

How to detect last used address in flash?

kurta999
Senior

Hi,

I would like to detect last used address in flash to be able to backup the firmware from internal flash memory to external from my bootloader. I know the start address where from start copying data, but don't know the end. I was unable to found a good working solution for detecting firmware "latest address" in flash. I tried to look after something to create custom linker script section at end of the flash with special data but I was unable to do it. My temponary solution currently is splitting the internal flash into two parts, use the first one for actual firmware and second for backup, which I don't want to use anymore since it's not effective.

Could somebody help with this? Thanks!

3 REPLIES 3

Use the symbols defined in the linker script - like "_etext" or "_edata". You can also define your own symbol there in the end of the last section which goes into flash, then use the symbol in your code with extern.

Uwe Bonnes
Principal III

A pragmatic approach would be: Scan from Flash end to the first non-erased flash cell. But using linker variables is the right way to go.

The linker frequently generates symbolic information the program itself can use. For external applications these symbols can be stored in unused vector table locations, and recovered from there.​

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..