Repository navigation
Browser interface: the Firmware button flashes an ESP board with esptool - #92
Merged
Merged
Conversation
Choose a .bin, check the port and Erase, press Flash: the server lets go of the board (through the ROM download port for a TinyUSB CDC board), runs the CLI's own esptool path at the chip's offset, streams progress and reconnects. UF2 files and non-ESP boards are refused with a hint. Also: esptool gets --chip from the image header, --erase is one write-flash --erase-all run, the C5's offset is 0x2000, the page's WebSocket joins continuation frames (Chromium splits messages over ~128 KB), the menu calls the entry Flash Firmware in the browser, and the status line no longer sticks at Installing after a package install.
# Conflicts: # CHANGELOG.md # cli/src/mpftp/webui/app.css # cli/src/mpftp/webui/app.js # ui/src/main.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The browser interface's Firmware button now flashes an ESP board. It opens a small dialog: choose a firmware
.binfrom your computer, check the serial port (the connected board's by default), tick "Erase all of flash first" if you want a clean board, and press Flash. The server lets go of the board, runs the CLI's own esptool path (python -m mpftp.firmware flash, the enginempftp firmware flashand the extension's Firmware panel already use) at the offset the image's chip needs, streams esptool's output and a progress bar into the dialog, and the page reconnects once the board restarts.It is esptool only. A
.uf2(by name or by its magic) and a connected board whosesys.platformisn't an ESP are refused with "For UF2 boards, drag the .uf2 onto the board's drive." The extension's Firmware panel is unchanged.How it works
ui/src/firmware.ts: the dialog. The file goes to the server in 512 KB chunks (firmware_upload), thenfirmware_flashruns whilefirmware_log/firmware_progressnotifications fill the dialog.cli/src/mpftp/webflash.py: the server side, answered by the relay rather than the sidecar. It checks the image before touching the board: ESP image magic, the chip from the image header, the offset for that chip, and that it isn't an app image aimed at the bootloader offset. Then it releases the board. A board on a USB-UART bridge or the chip's USB-Serial/JTAG keeps its port. A board whose REPL is MicroPython's TinyUSB CDC (S2/S3 on native USB) is sent to its bootloader and the ROM download port that appears is flashed instead, as the extension does. If no download port appears, the dialog says to hold BOOT and tap RESET.Thonny's esptool dialog compared with ours
I read Thonny 5.0.0's
plugins/micropython/esptool_dialog.py(withbase_flashing_dialog.py,workdlg.pyandplugins/esp/__init__.py), which bundles esptool 5.2.0.proxy.disconnect()if Thonny holds that port, sleep 1.5 s, then open and close the port to prove it is free (another 1.5 s), with a "Can't connect" error if notrepl_stop+disconnect, wait for the port to be listed again, settle 1 s. A busy port's esptool error becomes "another program has it ... close it and Flash again"machine.bootloader(), wait up to 15 s for the ROM's download port (303A:1001 or a new 303A port), flash thatimage_infoon the file gives the family, passed as--chip--chip(esptool auto-detects). Now:--chipfrom the image header, so a board that is another chip is refused before anything is writtenboard.jsonwhen building, else the chip: 0x1000 (ESP32, S2), 0x2000 (P4, and C5, which was wrong at 0x0 before), 0x0 (S3, C2, C3, C6, C61, H2). Checked against ESP-IDF 5.5.4'sCONFIG_BOOTLOADER_OFFSET_IN_FLASHand esptool'sBOOTLOADER_FLASH_OFFSET. Thonny has no 0x2000 case, so a P4 or C5 image goes to 0x0 therewrite_flash --erase-allin the same runerase-flashrun, thenwrite-flash. Now: onewrite-flash --erase-allrun, so the board is reset into its ROM loader once, not twice (the second reset is the one a native-USB board can miss)keepkeep--no-stub--before/--afterdefault_reset/hard_reset)default-reset/hard-reset, overridable on the CLI\r) shown as the action text; indeterminate barWriting at ... NN.N%lines drive a real percentage; other lines go to the log (blank padding dropped)Adopted from Thonny:
--chipfrom the image, erase-and-write in one run, a plain reason when another program holds the port, and a slower-baud fallback (automatic here, manual there). Not adopted: the flash-mode/size/--no-stubknobs, which the maintainer asked to keep out of a minimal dialog.The ⋯ menu, toolbar and context menus, exercised in the browser
Driven with Playwright (Chromium) against the LCD-7 (ESP32-S3, MicroPython 1.29.0) on COM17. VS Code behaviour is from
extension.tsandFtpViewProvider.ts.buffer ran 42in the REPL3for1 + 2exec says 42functoolsto /lib; the status line stayed on "Installing…"mpremote mountof a picked folder..So nothing new needed hiding: the entries that only make sense in VS Code were already hidden by #85's host command list.
ftp.jsnow also accepts a host-suppliedcommandTitlesmap so the browser can call the entry what it does there; VS Code sends none and is unchanged.Also fixed on the way
mainand passes here.Proof
--chip esp32s3, 4,587,520 bytes at 0x0 in 61.5 s, "Hash of data verified", hard reset, "Reconnected to COM17" at about 80 s, and Exec Code on the reconnected board printedafter flash: v1.29.0-1.g0484529dd1.dirty on 2026-10-07 esp32. The board's files were untouched.cli/tests/fixtures/fake-esptool.test_webflash(new, 19),test_pwa,test_app_image_offset,test_panel,test_firmware_download,test_partition_table,test_detect.