Skip to content

Fix for sigmastar read (missing every 25th byte in the backup) - #97

Merged
compot-dev merged 3 commits into
OpenIPC:mainfrom
igorssv:main
Nov 17, 2026
Merged

compot-dev merged 3 commits into
OpenIPC:mainfrom
igorssv:main

Conversation

@igorssv

@igorssv igorssv commented Nov 17, 2026

Copy link
Copy Markdown

I found that microsnander can not verify wrote data. Every time the first difference was at 0x0000000000000018.

I used ch341a programmer and cam board with SoC ssc30kq with nor flash.

$ microsnander -m sigmastar -w u-boot.bin -v

MicroSNANDer - Spi Nor/nAND programmER v.1.43.2

Found programmer device: WinChipHead (WCH) - CH341A
Device revision is 3.0.4
Warning: the black CH341A board puts 5 V on SDA and SCL unless it is modified for 3.3 V;
the UART of the SoC is not made for that.
SigmaStar ISP through the I2C of the CH341A at 0x49.
spi_nand_probe: mfr_id = 0x18, dev_id = 0x40, dev_id_2 = 0xc8
SPI NAND Flash Not Detected!
spi device id: c8 40 18 c8 40 (4018c840)
Detected SPI NOR Flash: GD25Q128CSIG, Flash Size: 16 MB, SR: [80] [00] [40]
WRITE:
Write addr = 0x0000000000000000, len = 0x0000000000040000
Written 100% [262144] of [262144] bytes      
Elapsed time: 24 seconds
Status: OK
VERIFY:
Read addr = 0x0000000000000000, len = 0x0000000000040000
Elapsed time: 7 seconds
Status: BAD, first difference at 0x0000000000000018: wrote 0xFF, read 0x5F

After investigation I found that each 25th byte is missing in the output file when I read data from flash using microsnander. Missing bytes at 0x18, 0x31, 0x4A, ...

After review the source code I found that miss byte after additional SPI Read (0x11) command before read next 24 bytes. I updated the code to execute this command once at the read start. Now it is working for me for ch341a+ssc30kq with nor flash, but I have not another hardware for more tests.

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

Send SigmaStar ISP read command once per read

🐞 Bug fix 🕐 10-20 Minutes

Grey Divider

AI Description

• Send the SigmaStar ISP read command once before reading data in I2C-sized chunks.
• Prevent repeated commands from dropping every 25th byte in flash backups and verification reads.
Diagram

graph TD
  A["SPI read request"] --> B{"First chunk?"} -->|Yes| C["Send ISP 0x11"] --> D["I2C read chunk"] --> E["Read buffer"]
  B -->|No| D
  D -->|More bytes| B
Loading
High-Level Assessment

Conditioning the command in the existing chunked read path is the smallest targeted fix; changing I2C chunk sizes would not address the repeated-command behavior. The existing simulator does not model the reported byte loss, so a regression test and validation on other hardware would strengthen confidence.

Files changed (1) +1 / -1

Bug fix (1) +1 / -1
sigmastar.cIssue ISP_READ only for the first read chunk +1/-1

Issue ISP_READ only for the first read chunk

• Changes 'isp_send' to write command 0x11 only when 'done == 0', while continuing to read every chunk through I2C. This addresses the reported missing bytes at chunk boundaries without changing write handling.

src/sigmastar.c

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Remediation recommended

1. The read fix is verified only against a self-written simulator 🐞 Bug ⚙ Maintainability
Description
The isp_send change assumes the SigmaStar bridge drops one byte per repeated 0x11 under the same
CS, and tests/ispsim.c was edited to model exactly that assumption (if (reading) clocked++). The
only hardware evidence is the reporter's single CH341A plus GD25Q128 board, so the new test "no byte
lost between the parts" passes by construction and would not catch a different bridge behaviour on
other SoCs or programmers.
Code

tests/ispsim.c[R41-42]

+	/* a 0x11 again under the same CS costs a byte: the bridge clocks one in and drops it (#97) */
+	case 0x11: if (n != 1) bad = 3; if (reading) clocked++; reading = 1; return 0;
Evidence
The simulator's drop rule and the fix are derived from the same hypothesis, so the test confirms
internal consistency, not the hardware behaviour. The code comment in src/sigmastar.c states the
drop as fact ('a 0x11 again under the same CS drops a byte'), which future readers will take as
verified across bridges.

tests/ispsim.c[41-42]
src/sigmastar.c[8-10]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
Issue description
The read fix in isp_send and the simulator's byte-drop model rest on one board's observation, but the code comment and CHANGELOG state the bridge behaviour as a general fact.
Fix Focus Areas
- src/sigmastar.c[8-10]
- src/sigmastar.c[82-88]
- tests/ispsim.c[41-42]
Recommended Fix
Reword the comment in src/sigmastar.c to say the bridge was observed to drop a byte on a repeated 0x11 on the tested board (SSC30KQ with CH341A), and note in the CHANGELOG entry which board was verified. Keep the simulator model but label it as the assumed model, not a reproduction of the bridge.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Tip of the day
💡 Did you know, you can enable the Remediation agent and Qodo fixes findings in a dedicated fix PR

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@compot-dev

compot-dev commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Thank you @igorssv, this is a real bug, and the fix is right: a repeated 0x11 under the same CS makes the bridge drop a byte, so every part after the first 24 bytes started one byte late.

I reproduced it in our ISP simulator (tests/ispsim.c): with a second 0x11 costing a byte, the current code fails the 200-byte read test, and with your change all tests pass.

We will also check it on a SigmaStar board in our lab. A question: have you tried OpenIPC/snander-mstar on the same board (CH341A + SSC30KQ)? It would be interesting to compare how it reads and writes there.

@compot-dev

Copy link
Copy Markdown
Collaborator

/review

@compot-dev
compot-dev merged commit 3ddc82a into OpenIPC:main Nov 17, 2026
9 checks passed
@compot-dev

Copy link
Copy Markdown
Collaborator

Merged, thank you @igorssv. It is in microsnander 1.47.3: the latest release is rebuilt in a few minutes (https://github.com/OpenIPC/microsnander/releases/latest). Could you check it on your board, a full read twice and -w ... -v, and say here how it went?

@igorssv

igorssv commented Nov 18, 2026 •

Copy link
Copy Markdown
Author

I checked snander-mstar and it is working correctly (I also did other tests for reading and verification data):

# snander -w test.bin -v
SNANDer - Spi Nor/nAND programmER 1.8.0 by McMCC

Found programmer device: WinChipHead (WCH) - CH341A
Using I2C default speed mode

spi device id: c8 40 18 c8 40 (4018c840)
Detected SPI NOR Flash: GD25Q128CSIG, Flash Size: 16MB
WRITE:
Write addr = 0x0000000000000000, len = 0x0000000000040000
Written 100% [262144] of [262144] bytes      
Elapsed time: 27 seconds
Status: OK
VERIFY:
Read addr = 0x0000000000000000, len = 0x0000000000040000
Read 100% [262144] of [262144] bytes      
Elapsed time: 47 seconds
Status: OK
# 

I confirmed that current version microsnander 1.47.5 is work working correctly too for my CH341A + SSC30KQ:

# md5sum test.bin
7d44fd819bcda84b59ed0a58b986f03d  test.bin
# ./microsnander -m sigmastar -e -l 0x40000 -v

MicroSNANDer - Spi Nor/nAND programmER v.1.47.5

Found programmer device: WinChipHead (WCH) - CH341A
Device revision is 3.0.4
Warning: the black CH341A board puts 5 V on SDA and SCL unless it is modified for 3.3 V;
the UART of the SoC is not made for that.
SigmaStar ISP through the I2C of the CH341A at 0x49.
spi_nand_probe: mfr_id = 0x18, dev_id = 0x40, dev_id_2 = 0xc8
SPI NAND Flash Not Detected!
spi device id: c8 40 18 c8 40 (4018c840)
Detected SPI NOR Flash: GD25Q128CSIG, Flash Size: 16 MB, SR: [80] [00] [40]
Erase blocks of the SFDP table: 4 KB (20h) 32 KB (52h) 64 KB (D8h)
ERASE:
Erase addr = 0x0000000000000000, len = 0x0000000000040000
Erase 100% [262144] of [262144] bytes      
Elapsed time: 0 seconds
Status: OK
VERIFY:
Read addr = 0x0000000000000000, len = 0x0000000000040000
Read 100% [262144] of [262144] bytes      
Elapsed time: 23 seconds
Status: OK, all 0xFF
# ./microsnander -m sigmastar -r empty.bin -l 0x40000

MicroSNANDer - Spi Nor/nAND programmER v.1.47.5

Found programmer device: WinChipHead (WCH) - CH341A
Device revision is 3.0.4
Warning: the black CH341A board puts 5 V on SDA and SCL unless it is modified for 3.3 V;
the UART of the SoC is not made for that.
SigmaStar ISP through the I2C of the CH341A at 0x49.
spi_nand_probe: mfr_id = 0x18, dev_id = 0x40, dev_id_2 = 0xc8
SPI NAND Flash Not Detected!
spi device id: c8 40 18 c8 40 (4018c840)
Detected SPI NOR Flash: GD25Q128CSIG, Flash Size: 16 MB, SR: [80] [00] [40]
Erase blocks of the SFDP table: 4 KB (20h) 32 KB (52h) 64 KB (D8h)
READ:
Read addr = 0x0000000000000000, len = 0x0000000000040000
Read 100% [262144] of [262144] bytes      
Elapsed time: 23 seconds
Status: OK
# hexdump empty.bin 
0000000 ffff ffff ffff ffff ffff ffff ffff ffff
*
0040000
# ./microsnander -m sigmastar -w test.bin -v

MicroSNANDer - Spi Nor/nAND programmER v.1.47.5

Found programmer device: WinChipHead (WCH) - CH341A
Device revision is 3.0.4
Warning: the black CH341A board puts 5 V on SDA and SCL unless it is modified for 3.3 V;
the UART of the SoC is not made for that.
SigmaStar ISP through the I2C of the CH341A at 0x49.
spi_nand_probe: mfr_id = 0x18, dev_id = 0x40, dev_id_2 = 0xc8
SPI NAND Flash Not Detected!
spi device id: c8 40 18 c8 40 (4018c840)
Detected SPI NOR Flash: GD25Q128CSIG, Flash Size: 16 MB, SR: [80] [00] [40]
Erase blocks of the SFDP table: 4 KB (20h) 32 KB (52h) 64 KB (D8h)
WRITE:
Write addr = 0x0000000000000000, len = 0x0000000000040000
Written 100% [262144] of [262144] bytes      
Elapsed time: 25 seconds
Status: OK
VERIFY:
Read addr = 0x0000000000000000, len = 0x0000000000040000
Read 100% [262144] of [262144] bytes      
Elapsed time: 23 seconds
Status: OK
# ./microsnander -m sigmastar -r read.bin -l 0x40000

MicroSNANDer - Spi Nor/nAND programmER v.1.47.5

Found programmer device: WinChipHead (WCH) - CH341A
Device revision is 3.0.4
Warning: the black CH341A board puts 5 V on SDA and SCL unless it is modified for 3.3 V;
the UART of the SoC is not made for that.
SigmaStar ISP through the I2C of the CH341A at 0x49.
spi_nand_probe: mfr_id = 0x18, dev_id = 0x40, dev_id_2 = 0xc8
SPI NAND Flash Not Detected!
spi device id: c8 40 18 c8 40 (4018c840)
Detected SPI NOR Flash: GD25Q128CSIG, Flash Size: 16 MB, SR: [80] [00] [40]
Erase blocks of the SFDP table: 4 KB (20h) 32 KB (52h) 64 KB (D8h)
READ:
Read addr = 0x0000000000000000, len = 0x0000000000040000
Read 100% [262144] of [262144] bytes      
Elapsed time: 23 seconds
Status: OK
# md5sum read.bin 
7d44fd819bcda84b59ed0a58b986f03d  read.bin
# 

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.

3 participants