Skip to content

Conversation

@sensei-hacker
Copy link
Member

@sensei-hacker sensei-hacker commented Jan 11, 2026

User description

Summary

Add optional parameter to MSP_REBOOT (message 68) to trigger DFU mode directly via MSP protocol. This provides a reliable programmatic method for tools and scripts to enter DFU mode without CLI timing issues or manual hardware button presses.

Changes

Firmware (src/main/fc/fc_msp.c):

  • Add static variable mspRebootBootloader to store DFU mode flag
  • Modify mspRebootFn() to use bootloader flag when calling fcReboot()
  • Add mspFcRebootCommand() helper function to read optional parameter
  • Update mspFcProcessCommand() to handle MSP_REBOOT with new logic

Documentation (docs/USB Flashing.md):

  • Update DFU mode entry methods with proper CLI sequence
  • Remove deprecated 'R' character method
  • Add MSP_REBOOT method as recommended programmatic approach

Protocol Details

Backwards Compatibility:

  • Empty payload (existing behavior) = normal reboot
  • Parameter 0x00 = explicit normal reboot
  • Parameter 0x01 = reboot to DFU/bootloader mode

MSP Message:

  • Message ID: 68 (MSP_REBOOT)
  • Payload: 0 or 1 byte
  • Direction: IN (configurator → FC)

Testing

Tested on AOCODARCF722AIO hardware:

  • ✅ Empty payload reboots normally (backwards compatible with existing tools)
  • ✅ Parameter 0x00 reboots normally
  • ✅ Parameter 0x01 enters DFU mode (verified with dfu-util -l showing device 0483:df11)

All three test cases passed successfully.

Motivation

Current DFU entry methods have limitations:

  • Hardware button: Requires physical access and manual intervention
  • CLI sequence: Timing-sensitive, requires waiting for prompt, prone to race conditions
  • Single 'R' character: Can be triggered accidentally

The MSP_REBOOT method:

  • Works through standard MSP protocol
  • No CLI timing issues
  • Suitable for automation and scripting
  • Backwards compatible with existing configurator implementations

PR Type

Enhancement, Bug fix


Description

  • Add optional DFU mode parameter to MSP_REBOOT command for programmatic bootloader entry

  • Support backwards-compatible reboot behavior with optional bootloader flag parameter

  • Improve DFU mode entry documentation with reliable serial CLI sequence


Diagram Walkthrough

flowchart LR
  MSP["MSP_REBOOT Command"] -->|"Empty payload"| Normal["Normal Reboot"]
  MSP -->|"Parameter 0x00"| Normal
  MSP -->|"Parameter 0x01"| DFU["DFU/Bootloader Mode"]
  DFU --> Device["Device enters bootloader"]
  Normal --> Reboot["System reboots normally"]
Loading

File Walkthrough

Relevant files
Enhancement
fc_msp.c
Implement MSP_REBOOT DFU mode parameter support                   

src/main/fc/fc_msp.c

  • Add static variable mspRebootBootloader to store DFU mode flag
  • Create new mspFcRebootCommand() function to parse optional bootloader
    parameter from MSP payload
  • Modify mspRebootFn() to use bootloader flag when calling fcReboot()
  • Move MSP_REBOOT handling from mspFcProcessOutCommand() to main command
    processor with proper armed state check
+25/-9   
Documentation
USB Flashing.md
Improve DFU mode entry documentation with reliable methods

docs/USB Flashing.md

  • Replace unreliable single 'R' character method with proper serial CLI
    sequence documentation
  • Add detailed bash example showing #### CLI entry followed by dfu
    command
  • Add warning about timing requirements and importance of waiting for
    CLI prompt
  • Add MSP_REBOOT as recommended programmatic DFU entry method for INAV
    9.x+
  • Clarify hardware button method with explicit instructions
+18/-6   

@qodo-code-review
Copy link
Contributor

qodo-code-review bot commented Jan 11, 2026

PR Compliance Guide 🔍

All compliance sections have been disabled in the configurations.

@sensei-hacker sensei-hacker added this to the 9.1 milestone Jan 11, 2026
Add optional parameter to MSP_REBOOT (message 68) to trigger DFU mode
directly via MSP protocol. This provides a reliable programmatic method
for tools and scripts to enter DFU mode without CLI timing issues.

Changes:
- Add static variable mspRebootBootloader to store DFU mode flag
- Modify mspRebootFn to use the bootloader flag when calling fcReboot()
- Add mspFcRebootCommand() helper to read optional parameter
- Update mspFcProcessCommand() to handle MSP_REBOOT with new logic
- Update USB Flashing.md documentation with proper CLI sequence
- Add MSP method as recommended approach for programmatic DFU entry

Backwards compatibility:
- Empty payload (existing behavior) = normal reboot
- Parameter 0x00 = explicit normal reboot
- Parameter 0x01 = reboot to DFU/bootloader mode

Tested on AOCODARCF722AIO:
- ✓ Empty payload reboots normally (backwards compatible)
- ✓ Parameter 0x00 reboots normally
- ✓ Parameter 0x01 enters DFU mode (verified with dfu-util)
After moving MSP_REBOOT to mspFcProcessCommand, the mspPostProcessFn
parameter in mspFcProcessOutCommand became unused. Remove it from both
the function signature and call site to fix CI build warnings.
Validate that MSP_REBOOT payload is exactly 0 or 1 byte. Reject
malformed packets with larger payloads to improve protocol robustness.

Suggested-by: qodo-merge bot
@sensei-hacker sensei-hacker marked this pull request as draft January 11, 2026 06:56
@sensei-hacker sensei-hacker marked this pull request as ready for review January 11, 2026 07:09
@qodo-code-review
Copy link
Contributor

PR Compliance Guide 🔍

All compliance sections have been disabled in the configurations.

Based on qodo-merge bot review suggestion (importance: 7).

Changes:
- Remove static global variable mspRebootBootloader
- Add two distinct post-process functions:
  - mspRebootNormalFn() for normal reboot
  - mspRebootDfuFn() for DFU mode reboot
- Update mspFcRebootCommand() to directly assign function pointer

Benefits:
- Eliminates global state
- Makes control flow more explicit
- Easier to maintain and understand
- Improves code quality per qodo review

Tested on AOCODARCF722AIO hardware:
✅ Backwards compatible reboot (empty payload)
✅ Explicit normal reboot (payload 0x00)
✅ DFU mode reboot (payload 0x01)
@sensei-hacker sensei-hacker merged commit d4fac2c into iNavFlight:maintenance-9.x Jan 11, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant