Skip to content

Add direct firmware flashing from mpflash flash --file/--url with inference and interactive fallback#83

Open
Copilot wants to merge 1 commit into
mainfrom
copilot/add-direct-firmware-flashing
Open

Add direct firmware flashing from mpflash flash --file/--url with inference and interactive fallback#83
Copilot wants to merge 1 commit into
mainfrom
copilot/add-direct-firmware-flashing

Conversation

Copilot AI commented May 9, 2026

Copy link
Copy Markdown
Contributor

This change enables flashing firmware directly from a local file or URL, without requiring a prior add step into the firmware database. It also infers target metadata from the path/URL and falls back to interactive selection when inference is incomplete (especially ESP32 variant cases).

  • CLI surface update

    • Added direct source options to flash:
      • --file/-f for local firmware binaries
      • --url/-u for remote firmware binaries
    • Kept force behavior with short alias moved to -F to avoid -f collision.
  • Direct firmware flow (no DB pre-registration)

    • Added a direct-firmware path in cli_flash that:
      • prepares firmware source from local path or downloaded URL
      • infers port, board, and variant from source hints
      • attaches a runtime Firmware object to each flash task instead of requiring downloaded DB entries
    • Existing flash options (--serial, --port, --board, --variant, bootloader/retry flags, etc.) continue to apply.
  • Inference + prompt behavior

    • Uses path/URL inspection to auto-resolve target info when clear.
    • If inference is ambiguous, sets board selection to interactive (?).
    • ESP32 handling requires variant-level clarity; when missing, prompts user to choose board/variant.
  • URL download and lifecycle handling

    • Streams URL content into a temp firmware file for flashing.
    • Handles download failures with user-facing usage errors.
    • Ensures temp file cleanup in finally, including flash-error paths.
  • Targeted test coverage for new behavior

    • Added CLI tests for:
      • direct file flash with ESP32 board+variant inference
      • interactive fallback when ESP32 variant is unclear
      • direct URL flash path
      • temp-file cleanup after URL-based flash failure

Example usage:

mpflash flash --file /path/to/micropython/ports/esp32/build-ESP32_GENERIC-SPIRAM/micropython.bin --serial COM8
mpflash flash --url https://example.com/firmware.uf2 --board RPI_PICO2 --serial /dev/ttyACM0

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/repos/micropython/micropython
    • Triggering command: /home/REDACTED/work/mpflash/mpflash/.venv/bin/pytest pytest tests/cli/test_cli_flash.py (http block)
    • Triggering command: REDACTED, pid is -1 (http block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI linked an issue May 9, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Add ability to flash firmware directly from file or URL Add direct firmware flashing from mpflash flash --file/--url with inference and interactive fallback May 9, 2026
Copilot AI requested a review from Josverl May 9, 2026 15:18
Copilot finished work on behalf of Josverl May 9, 2026 15:18
@Josverl Josverl marked this pull request as ready for review May 9, 2026 21:06
@codecov

codecov Bot commented May 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 48.14815% with 112 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.87%. Comparing base (3401068) to head (02017b5).

Files with missing lines Patch % Lines
mpflash/cli_flash.py 48.66% 86 Missing and 10 partials ⚠️
mpflash/ask_input.py 25.00% 11 Missing and 1 partial ⚠️
mpflash/custom/naming.py 72.72% 1 Missing and 2 partials ⚠️
mpflash/flash/__init__.py 50.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #83      +/-   ##
==========================================
- Coverage   75.58%   73.87%   -1.72%     
==========================================
  Files          54       54              
  Lines        3023     3173     +150     
  Branches      488      525      +37     
==========================================
+ Hits         2285     2344      +59     
- Misses        618      707      +89     
- Partials      120      122       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

- Implemented direct firmware flashing via `--file` and `--url` options in the CLI.
- Enhanced parameter inference for ESP32 boards and variants from firmware paths.
- Added error handling for unsupported UF2-capable ports.
- Updated tests to cover new direct flashing functionality and ensure correct behavior.

Signed-off-by: Jos Verlinde <Jos_Verlinde@hotmail.com>
@Josverl Josverl force-pushed the copilot/add-direct-firmware-flashing branch from 16708aa to 02017b5 Compare May 10, 2026 20:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add ability to directly flash a firmware from a --file/f or --url

2 participants