Skip to content

Commit

Permalink
bootloader: robustify uploader detection
Browse files Browse the repository at this point in the history
The bootloader can often get stuck parsing random MAVLink traffic,
thinking it had seen a GET_SYNC.

Therefore, this commits adds a two step check which requires a GET_SYNC
followed by a GET_DEVICE to make sure it's really an uploader script
talking to it, and not just random data.
  • Loading branch information
julianoes authored and davids5 committed Oct 14, 2024
1 parent b9942ad commit e3dd050
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions platforms/nuttx/src/bootloader/common/bl.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@
#define STATE_ALLOWS_REBOOT (STATE_ALLOWS_ERASE|STATE_PROTO_PROG_MULTI|STATE_PROTO_GET_CRC)
# define SET_BL_STATE(s) bl_state |= (s)
#endif
#define STATE_ALLOWS_BOOTLOADER (STATE_PROTO_GET_SYNC|STATE_PROTO_GET_DEVICE)

static uint8_t bl_type;
static uint8_t last_input;
Expand Down Expand Up @@ -1107,9 +1108,10 @@ bootloader(unsigned timeout)
continue;
}

// we got a command worth syncing, so kill the timeout because
// we are probably talking to the uploader
timeout = 0;
// We got a sync command as well as a get_device command, we are very likely talking to the uploader.
if ((bl_state & STATE_ALLOWS_BOOTLOADER) == STATE_ALLOWS_BOOTLOADER) {
timeout = 0;
}

// Set the bootloader port based on the port from which we received the first valid command
if (bl_type == NONE) {
Expand Down

0 comments on commit e3dd050

Please sign in to comment.