fix: Check status byte for errors#110
Open
emolitor wants to merge 2 commits into
Open
Conversation
The ISP response parser and the code-flash program loop both ignored error status, so a rejected operation could be reported as a successful flash. - Response::from_raw() had `if true`, returning Response::Ok for any correctly-framed reply regardless of the status byte (raw[1]). Honor the status byte: 0x00 (and 0x82, ok-with-data) -> Ok, anything else -> Err. Resolves the existing FIXME. - flash_chunk() only checked response framing, not the per-chunk Program result carried in the payload (payload[0]). A rejected Program returns a well-framed reply with payload[0] != 0 yet was treated as success. Check payload[0] and fail with the reported status. Without these, `wchisp flash` can print "bytes written" / "Verify OK" for a device the BootROM never actually programmed.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes error handling in the WCH ISP response parsing and code flashing paths by honoring protocol status bytes that were previously ignored, preventing failed operations from being reported as successful.
Changes:
- Update
Response::from_raw()to validate framing and interpret the response status byte (0x00/0x82 =>Ok, otherwiseErrvariant). - Update
flash_chunk()to also validate the per-chunk Program result encoded inpayload[0]and fail on non-zero status.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/protocol.rs | Honors the response status byte when parsing raw ISP replies so error replies no longer appear successful. |
| src/flashing.rs | Detects per-chunk BootROM Program rejection via payload[0] so rejected flashes are surfaced as errors. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Author
|
@andelf could you take a look when you have a chance? |
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 ISP response parser and code-flash both ignored error status. This allows a rejected operation to be reported as a successful.
if truereturning Response::Ok for any correctly structured reply regardless of the status byte. Honour the status byte: 0x00 (OK) and 0x82 (OK with Data) -> Ok, anything else -> Err. Resolves the existing FIXME.