Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions Bootloaders/DFU/BootloaderDFU.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ static uint16_t EndAddr = 0x0000;
*/
uint16_t MagicBootKey ATTR_NO_INIT;

/** Magic key allowing watchdog reset to bootloader from the application. If BOOTRST is programmed, the application can
* set this to the value \ref MAGIC_LOAD_KEY, which will ensure the bootloader isn't skipped.
*/
uint16_t MagicLoadKey ATTR_NO_INIT;


/** Special startup routine to check if the bootloader was started via a watchdog reset, and if the magic application
* start key has been loaded into \ref MagicBootKey. If the bootloader started via the watchdog and the key is valid,
Expand Down Expand Up @@ -135,12 +140,20 @@ void Application_Jump_Check(void)
/* Check if the device's BOOTRST fuse is set */
if (!(BootloaderAPI_ReadFuse(GET_HIGH_FUSE_BITS) & ~FUSE_BOOTRST))
{
/* If the reset source was not an external reset or the key is correct, clear it and jump to the application */
if (!(MCUSR & (1 << EXTRF)) || (MagicBootKey == MAGIC_BOOT_KEY))
JumpToApplication = true;
/* If the reset source was not an external reset jump to the application */
if (!(MCUSR & (1 << EXTRF)))
JumpToApplication = true;

/* If the reset source was a watchdog reset, and the MagicLoadKey is set, don't jump to the application*/
if ((MCUSR & (1 << WDRF)) && (MagicLoadKey == MAGIC_LOAD_KEY))
JumpToApplication = false;

/* If the boot key is set, force the jump to the application */
if (MagicBootKey == MAGIC_BOOT_KEY)
JumpToApplication = true;

/* Clear reset source */
MCUSR &= ~(1 << EXTRF);
/* Clear reset sources */
MCUSR &= ~((1 << EXTRF) && (1 << WDRF));
}
else
{
Expand Down
3 changes: 3 additions & 0 deletions Bootloaders/DFU/BootloaderDFU.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@
/** Magic bootloader key to unlock forced application start mode. */
#define MAGIC_BOOT_KEY 0xDC42

/** Magic bootloader key to ensure bootloader isn't skipped. */
#define MAGIC_LOAD_KEY 0xAC42

/** Complete bootloader version number expressed as a packed byte, constructed from the
* two individual bootloader version macros.
*/
Expand Down