rockusb: erase carries no data phase, so its CBW must declare zero length - #133
Merged
Merged
Conversation
…ngth build_cbw() defaulted the CBW's dCBWDataTransferLength to count*SECTOR_SIZE whenever a count was given. That is right for READ_LBA/WRITE_LBA, but ERASE_LBA and ERASE_NORMAL carry their sector count in the CDB while moving no data. With a nonzero length declared, the usbplug waits for a data phase that never comes; on an RV1106 this surfaces as "moved -1024 of 0 bytes (residue 1024)" and the erase never lands. Exclude the erase opcodes from the default so their CBW declares a zero-length transfer.
Code Review by Qodo🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)
Great, no issues found!Qodo reviewed your code and found no material issues that require reviewTip of the day💡 Did you know, you can copy the agent prompt from any finding and feed it to your IDE agent |
PR Summary by QodoFix zero-length RockUSB erase CBWs
AI Description
Diagram
High-Level Assessment
Files changed (2)
|
widgetii
added a commit
that referenced
this pull request
Sep 8, 2026
) ## What Adds `defib dump-flash` reading over the RockUSB path, so a board whose boot ROM only answers on USB (e.g. RV1106) can be backed up — the one thing missing before any USB write can be attempted safely. ``` defib dump-flash -c rv1106 --ddr ... --usbplug ... \ --partition rootfs -o rootfs.bin ``` - `--chip` is optional; the serial path is untouched for chips that already worked. For a USB-only profile, `-p` isn't consulted. - Capacity comes from `READ_FLASH_INFO`, not a guess or flag. A reply claiming zero capacity is refused (loader up but flash not brought up → a file full of nothing), and a range past the reported end is refused (the LBA commands just stall there). - `--partition` reads one region from the profile; the usbplug's LBA space maps directly onto the kernel's mtd partitions, so it compares byte-for-byte with `cat /dev/mtdN` on a booted board. - Reads stream to disk rather than buffering in memory. ## Evidence Exercised on an RV1106 (Luckfox Pico Max, 256 MB SPI-NAND) this session: `READ_FLASH_INFO` reported `255.5 MiB (523264 sectors), block 128 KiB, page 2048 B` — the 0.5 MiB gap being the FTL reserve, and the block/page matching `/proc/mtd` on the same board booted. Partition reads matched byte-for-byte. Tests: `tests/test_rockusb_flashinfo.py` (flash-info parse, zero-capacity and out-of-range refusal). Full suite **755 passed, 2 skipped**. ## Notes Rebased onto current master (post #133). Depends on nothing outside it. A separate return-to-MaskROM recovery enhancement (handling a stale usbplug a prior run left running) is still WIP on my side and not included here.
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.
What
build_cbw()defaulted the CBW'sdCBWDataTransferLengthtocount * SECTOR_SIZEwhenever acountwas given. That is correct forREAD_LBA/WRITE_LBA, butERASE_LBAandERASE_NORMALcarry their sectorcount in the CDB while moving no data.
With a nonzero transfer length declared for an erase, the usbplug waits for a
data phase that never arrives. On an RV1106 this surfaces as:
and the erase never lands — which blocks erase-before-write flows (e.g. clearing
stale UBI PEBs before writing a fresh image).
Fix
Exclude
ERASE_LBA/ERASE_NORMALfrom thecount * SECTOR_SIZEdefault, sotheir CBW declares a zero-length transfer. Read/write are unchanged.
Test
Added
TestBuildCbwEraseTransfer:dCBWDataTransferLength == 0READ_LBA/WRITE_LBAstill declarecount * SECTOR_SIZEVerified on hardware: with this fix,
ERASE_LBAclears the target region(reads back
0xff) on an RV1106 SPI-NAND, where before it failed with theresidue error above.