MarsTechHAN / ch552tool

An open sourced python tool for flashing WCH CH55x series USB microcontroller with bootloader v2.30, v2.31 & v2.40.
GNU General Public License v3.0
158 stars 24 forks source link

Fails to verify once the size is big #17

Closed fabiodl closed 2 years ago

fabiodl commented 3 years ago

In several projects, the tool works flawlessly for small files. Once I reach a certain size, it stars giving this kind of error

`python3 -m ch55xtool -f build/fat32.bin -r

Found CH559.

BTVER: V2.40.

Failed to verify firmware of CH55x.`

I attach a CH559 binary file that fails. In all the cases, the official programmer works.

fat32.zip

MarsTechHAN commented 2 years ago

Sorry I got so busy recently. I will take a look.

fabiodl commented 2 years ago

Thank you! let me know if you need other binaries that fail.

frank-zago commented 2 years ago

The problem is likely with the erase command. It only erases 8 KB. The length needs to be adjusted to the size of the firmware being flashed.

The 0x08 is the size. Change it to 0x10, and it should work. ERASE_CHIP_CMD_V2 = [0xa4, 0x01, 0x00, 0x08]

fabiodl commented 2 years ago

Thanks, that seems to fix the issue!

Pe3ucTop commented 2 years ago

Latest original software pass sizes in 32 bits also. For my 192kb chip erase original soft send : [0xA4, 0x04, 0x00, 0xC0, 0x00, 0x00, 0x00] 0xA4 - erase 0x0004 - command payload size = 4 byte = 32 bit 0x000000c0 = 192 = so 192 1k pages to erase

frank-zago commented 2 years ago

Indeed. I've also used 4 bytes for that command, even on a CH551 with a 2.3.1 bootloader. I think the bootloader is too small to have extra checks.

MarsTechHAN commented 2 years ago

The problem is likely with the erase command. It only erases 8 KB. The length needs to be adjusted to the size of the firmware being flashed.

The 0x08 is the size. Change it to 0x10, and it should work. ERASE_CHIP_CMD_V2 = [0xa4, 0x01, 0x00, 0x08]

See that... I should really fix it. Welcome PR for that :p

Pe3ucTop commented 2 years ago

Sorry, your latest commit has wrong divisor for erase size calculation !

erase_size = math.ceil(binary_size/0x1000) & 0xff but should be : / 1024 or / 0x400 because it is in 1k pages