Add Dediprog bulk read/write and WASM support with page-aligned smart write#20
Merged
ArthurHeymans merged 4 commits intomasterfrom Feb 23, 2026
Merged
Add Dediprog bulk read/write and WASM support with page-aligned smart write#20ArthurHeymans merged 4 commits intomasterfrom
ArthurHeymans merged 4 commits intomasterfrom
Conversation
Increase READ_CHUNK_SIZE from 4 KiB to 256 KiB — the old value caused unified read/verify paths to issue a separate CMD_READ control transfer per 4 KiB chunk (~3072 USB round-trips for a 4 MiB flash). Remove per-call set_leds() from OpaqueMaster::read/write — each call added 2 uncached USB control transfers that flashprog only issues once per top-level operation. Fix MAX_BLOCK_COUNT chunking: the old expression bulk_len.min(MAX * chunk) - offset silently dropped the remainder for transfers exceeding the single-command limit (>32 MiB reads, >16 MiB writes). Scale USB timeouts with transfer size instead of using a fixed 10 s cap that was too short for large flash at slow SPI speeds. Add HybridFlashDevice adapter and wire up Dediprog to use OpaqueMaster for bulk read/write while keeping SpiMaster for erase/status/WP.
570443d to
b05c1c9
Compare
…size Add maybe_async to the Dediprog driver so the same codebase compiles for both native (blocking) and WASM (async WebUSB) targets. Limit bulk transfer URB sizes to prevent usbfs allocation failures: - MAX_WRITE_PAGES (4096): caps write URBs at 2 MiB (4096 pages x 512 B) - MAX_READ_BLOCKS (8192): caps read URBs at 4 MiB Previously a 16 MiB flash write tried to allocate a single 32 MiB zero-copy buffer (65535 pages x 512 B with padding), which exceeded the Linux usbfs memory limit.
smart_write produced byte-exact write ranges via get_all_write_ranges(). After erasing, scattered 0xFF bytes in the desired image matched the erased flash, fragmenting writes into many small unaligned ranges. For Dediprog (and any OpaqueMaster), sub-page or misaligned writes fell through to slow_write() -- manual WREN+PP+RDSR via individual USB control transfers instead of the fast CMD_WRITE bulk path. Fix by coalescing write ranges to page boundaries before writing: - Add page_size() to FlashDevice trait (returns chip page size, default 1) - Add coalesce_write_ranges() that aligns to page boundaries and merges adjacent ranges (writing 0xFF to erased cells is a harmless no-op) - Split large coalesced ranges into 256 KiB sub-chunks so the progress bar updates regularly (~64 updates for 16 MiB flash) - Count writes_performed per actual device.write() call, not per range
b05c1c9 to
a6851d5
Compare
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.
Overview
This PR adds hardware-accelerated bulk read/write support for Dediprog programmers and enables WASM support via WebUSB. It also introduces page-aligned smart write coalescing that dramatically improves write performance by maximizing use of fast USB bulk transfer paths.
Key Changes
Core Flash Infrastructure
HybridFlashDevice: New adapter for programmers that implement bothSpiMaster(for probe, erase, status, write protection) andOpaqueMaster(for fast bulk read/write)FlashDevice::page_size(): New trait method for alignment hints. Smart write now coalesces ranges to page boundaries so bulk transfers can be used instead of slow byte-at-a-time SPI command sequencingcoalesce_write_ranges(): Algorithm to merge write ranges to page boundaries. Writing page-aligned 0xFF to erased flash is harmless but enables the entire write to use the fast pathDediprog Improvements
CMD_READ/CMD_WRITEwith USB bulk transfers (previously only used slow SPI transceive)maybe_asyncis_syncfeaturerequest_device()APIset_flash_size()called after probe soOpaqueMasterknows boundsWASM UI Integration
rflasher-wasmFlashHandleregistry to useHybridFlashDevicefor DediprogBuild System
rflasher-dediprog: Newwasmfeature (dependencies:web-sys,wasm-bindgen,wasm-bindgen-futures,js-sys)flake.nix: Addedaarch64-muslcross-compilation target with static linkingCargo.lock: Updated dependenciesPerformance Impact
For a typical 16 MiB firmware flash with Dediprog SF600:
Read performance similarly improved from ~800 KiB/s to full USB 2.0 rates (~30 MiB/s for typical SPI speeds).
Testing