Skip to content

[DFU] BootloaderDFU doesn't allow entering bootloader from software when using BOOTRST #150

@Duckle29

Description

@Duckle29

Hey there, I'm working on getting BOOTRST and reset source detection working for entering bootloader on a qmk based keyboard qmk#5

In that process, I noticed that the example given here: http://www.fourwalledcubicle.com/files/LUFA/Doc/120730/html/_page__software_bootloader_start.html
and the check in BootloaderDFU.c seem to be opposit of each other:

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;
/* Clear reset source */
MCUSR &= ~(1 << EXTRF);
}
else
{
/* If the reset source was the bootloader and the key is correct, clear it and jump to the application;
* this can happen in the HWBE fuse is set, and the HBE pin is low during the watchdog reset */
if ((MCUSR & (1 << WDRF)) && (MagicBootKey == MAGIC_BOOT_KEY))
JumpToApplication = true;
/* Clear reset source */
MCUSR &= ~(1 << WDRF);
}

It seems the example uses the magic key to enter the bootloader, while the bootloader uses it to exit the bootloader.

Additionally, it seems with this check, if using BOOTRST fuse, that the only way to enter bootloader is through an external reset, and not reachable via a watchdog timer reset.

Am I correct in assuming that this is not the intended behavior?

As I read the code DFU bootloader, the magic key is used to exit the code, which is fine, however in that case I think the mentioned check should be changed to:

if(MCUSR & (1 << PORF) || MCUSR & (1 << BORF) || (MagicBootKey == MAGIC_BOOT_KEY))
  JumpToApplication = true;

MCUSR &= ~((1 << PORF) & (1 << BORF));

I have opened a PR with a suggestion on this solution. Here: #151

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions