diff --git a/panda/board/early_init.h b/panda/board/early_init.h index c6f12ed6d..709ea2dfd 100644 --- a/panda/board/early_init.h +++ b/panda/board/early_init.h @@ -33,15 +33,10 @@ void early_initialization(void) { // Init register and interrupt tables init_registers(); - // after it's been in the bootloader, things are initted differently, so we reset - if ((enter_bootloader_mode != BOOT_NORMAL) && - (enter_bootloader_mode != ENTER_BOOTLOADER_MAGIC) && - (enter_bootloader_mode != ENTER_SOFTLOADER_MAGIC)) { - enter_bootloader_mode = BOOT_NORMAL; - // NOTE: no NVIC_SystemReset here - a stale RAM value during a plain - // hardware-reset boot was observed to hang before USB init on this board. - // Just clear the stale value and continue. - } + // Always clear any bootloader magic left in RAM. A stale value from a + // previous bootloader/DFU session would otherwise send us back into the ROM + // bootloader on a plain hardware reset (which then does not enumerate USB). + enter_bootloader_mode = BOOT_NORMAL; // if wrong chip, reboot volatile unsigned int id = DBGMCU->IDCODE; @@ -57,10 +52,6 @@ void early_initialization(void) { detect_board_type(); - if (enter_bootloader_mode == ENTER_BOOTLOADER_MAGIC) { - led_init(); - current_board->init_bootloader(); - led_set(LED_GREEN, 1); - jump_to_bootloader(); - } + // Bootloader entry is done directly by the 0xd1 comms handler via + // jump_to_bootloader(), not through a magic RAM value (which can be stale). } diff --git a/panda/board/flasher.h b/panda/board/flasher.h index 5dfa759c1..65a2d33ae 100644 --- a/panda/board/flasher.h +++ b/panda/board/flasher.h @@ -71,8 +71,7 @@ int comms_control_handler(ControlPacket_t *req, uint8_t *resp) { switch (req->param1) { case 0: print("-> entering bootloader\n"); - enter_bootloader_mode = ENTER_BOOTLOADER_MAGIC; - NVIC_SystemReset(); + jump_to_bootloader(); break; case 1: print("-> entering softloader\n"); diff --git a/panda/board/main_comms.h b/panda/board/main_comms.h index 9de8275e6..3b9bee7f4 100644 --- a/panda/board/main_comms.h +++ b/panda/board/main_comms.h @@ -180,8 +180,7 @@ int comms_control_handler(ControlPacket_t *req, uint8_t *resp) { // only allow bootloader entry on debug builds #ifdef ALLOW_DEBUG print("-> entering bootloader\n"); - enter_bootloader_mode = ENTER_BOOTLOADER_MAGIC; - NVIC_SystemReset(); + jump_to_bootloader(); #endif break; case 1: