rew wrote:I used the flag-at-a-constant address method at first too. However, after a while I changed to simply using a variable.
You have to be careful with this, as now the linker is free to place your variable wherever it wants.
If this space is used by the bootloader, the bootloader could leave some data in there after flashing. This could be your magic value, depending on what the space is used for in the bootloader. So when the bootloader then does a soft reset after flashing, you end up in the bootloader again. As the address of the variable changes with your code and linker version, this problem could appear out of the blue, just by recompiling.
So I think using a hardcoded memory address for the flag is a better solution as you can now test if and how it is used by the bootloader.