Skip to content

Commit

Permalink
Checksum calculation considers firmware size
Browse files Browse the repository at this point in the history
  • Loading branch information
FiorixF1 committed Feb 2, 2024
1 parent 9ccc6b1 commit 573ae74
Show file tree
Hide file tree
Showing 3 changed files with 193 additions and 51 deletions.
2 changes: 2 additions & 0 deletions ch341_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def __init__(self):
self.write_crc = 0
self.read_crc = 0
self.success = 0
self.crc_table = dict()

try:
self.dll = cdll.LoadLibrary(self.dll_path)
Expand Down Expand Up @@ -96,6 +97,7 @@ def __init__(self):
self.write_crc = 0
self.read_crc = 0
self.success = 0
self.crc_table = dict()

try:
self.dll = cdll.LoadLibrary(self.dll_path)
Expand Down
10 changes: 10 additions & 0 deletions flash.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import time
import zlib
from Download import *

pageNum = 0
Expand Down Expand Up @@ -186,6 +187,10 @@ def flash_read_file(ch341, size=0):

ch341.precent = 50
ch341.read_crc = 0
ch341.crc_table = dict()

buffer = bytes()
dump = open('dump.bin', 'wb')

if size == 0: size = pageNum
for page in range(size):
Expand All @@ -208,3 +213,8 @@ def flash_read_file(ch341, size=0):
ch341.read_crc += int.from_bytes(
ch341.iobuffer[4 + i], byteorder='big')
ch341.read_crc &= 0xffff
buffer += ch341.iobuffer[4 + i]
ch341.crc_table[page+1] = "0x"+hex(zlib.crc32(buffer) & 0xffffffff)[2:].rjust(8, '0')

dump.write(buffer)
dump.close()
232 changes: 181 additions & 51 deletions ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,57 +16,187 @@
version = "1.0.2"


def getFirmwareFromCRC(crc):
crc_list = {
"0x6995": "hdzero_freestyle @ 1.0.0",
"0x565b": "hdzero_race_v1 @ 1.0.0",
"0x565f": "hdzero_race_v2 @ 1.0.0",
"0x586a": "hdzero_whoop @ 1.0.0",
"0xebf2": "hdzero_whoop_lite @ 1.0.0",
"0x41b0": "hdzero_freestyle @ 1.1.0",
"0x9df6": "hdzero_race_v1 @ 1.1.0",
"0x9dfa": "hdzero_race_v2 @ 1.1.0",
"0x772a": "hdzero_whoop @ 1.1.0",
"0x4acd": "hdzero_whoop_lite @ 1.1.0",
"0xa0fc": "hdzero_freestyle @ 1.2.0",
"0xc129": "hdzero_race_v1 @ 1.2.0",
"0xc12d": "hdzero_race_v2 @ 1.2.0",
"0x65a0": "hdzero_whoop @ 1.2.0",
"0x14a4": "hdzero_whoop_lite @ 1.2.0",
"0x55db": "foxeer_vtx @ 1.3.0",
"0x1dc6": "hdzero_freestyle @ 1.3.0",
"0x5423": "hdzero_race_v1 @ 1.3.0",
"0x5427": "hdzero_race_v2 @ 1.3.0",
"0x742b": "hdzero_race_v3 @ 1.3.0",
"0x3a0e": "hdzero_whoop @ 1.3.0",
"0xee00": "hdzero_whoop_lite @ 1.3.0",
"0x61b0": "foxeer_vtx @ 1.4.0",
"0x19be": "hdzero_freestyle @ 1.4.0",
"0x5e46": "hdzero_race_v1 @ 1.4.0",
"0x3ff8": "hdzero_race_v2 @ 1.4.0",
"0x613a": "hdzero_race_v3 @ 1.4.0",
"0xc3a1": "hdzero_whoop @ 1.4.0",
"0xe5b8": "hdzero_whoop_lite @ 1.4.0",
"0xc8ea": "foxeer_vtx @ 1.5.0",
"0x8697": "hdzero_freestyle @ 1.5.0",
"0x7b82": "hdzero_freestyle_v2 @ 1.5.0",
"0xc5f4": "hdzero_race_v1 @ 1.5.0",
"0x64db": "hdzero_race_v2 @ 1.5.0",
"0x6ee0": "hdzero_race_v3 @ 1.5.0",
"0x4200": "hdzero_whoop @ 1.5.0",
"0xb954": "hdzero_whoop_lite @ 1.5.0",
"0x6d7e": "foxeer_vtx @ 1.5.0-CITA",
"0x6e61": "hdzero_race_v1 @ 1.5.0-CITA",
"0x3af9": "hdzero_race_v2 @ 1.5.0-CITA",
"0xf58b": "hdzero_race_v3 @ 1.5.0-CITA",
"0x4a4e": "hdzero_whoop @ 1.5.0-CITA",
"0xed83": "hdzero_whoop_lite @ 1.5.0-CITA"
def getFirmwareFromCRC(crc_table):
firmware_list = {
"hdzero_freestyle_v1 @ 1.0.0": {
"pageNum": 187,
"read_crc": "0x2c7871ad",
},
"hdzero_race_v1 @ 1.0.0": {
"pageNum": 183,
"read_crc": "0xed18964a",
},
"hdzero_race_v2 @ 1.0.0": {
"pageNum": 183,
"read_crc": "0xf88dc480",
},
"hdzero_whoop @ 1.0.0": {
"pageNum": 172,
"read_crc": "0xa9649ace",
},
"hdzero_whoop_lite @ 1.0.0": {
"pageNum": 182,
"read_crc": "0xaeed4934",
},
"hdzero_freestyle_v1 @ 1.1.0": {
"pageNum": 188,
"read_crc": "0xa36937e4",
},
"hdzero_race_v1 @ 1.1.0": {
"pageNum": 184,
"read_crc": "0xb3c0e07a",
},
"hdzero_race_v2 @ 1.1.0": {
"pageNum": 184,
"read_crc": "0x153f831e",
},
"hdzero_whoop @ 1.1.0": {
"pageNum": 172,
"read_crc": "0x98ba4b29",
},
"hdzero_whoop_lite @ 1.1.0": {
"pageNum": 183,
"read_crc": "0x30758bc7",
},
"hdzero_freestyle_v1 @ 1.2.0": {
"pageNum": 195,
"read_crc": "0xc31a3596",
},
"hdzero_race_v1 @ 1.2.0": {
"pageNum": 191,
"read_crc": "0x4b4d7aeb",
},
"hdzero_race_v2 @ 1.2.0": {
"pageNum": 191,
"read_crc": "0x5d6d7f88",
},
"hdzero_whoop @ 1.2.0": {
"pageNum": 180,
"read_crc": "0xa97b865d",
},
"hdzero_whoop_lite @ 1.2.0": {
"pageNum": 190,
"read_crc": "0x90957a34",
},
"foxeer_vtx @ 1.3.0": {
"pageNum": 195,
"read_crc": "0x47be5d3a",
},
"hdzero_freestyle_v1 @ 1.3.0": {
"pageNum": 200,
"read_crc": "0xdc45f45f",
},
"hdzero_race_v1 @ 1.3.0": {
"pageNum": 195,
"read_crc": "0x1c4220a0",
},
"hdzero_race_v2 @ 1.3.0": {
"pageNum": 195,
"read_crc": "0x1207d32d",
},
"hdzero_race_v3 @ 1.3.0": {
"pageNum": 190,
"read_crc": "0x0894030d",
},
"hdzero_whoop @ 1.3.0": {
"pageNum": 184,
"read_crc": "0xf2297c3f",
},
"hdzero_whoop_lite @ 1.3.0": {
"pageNum": 195,
"read_crc": "0x4a873a8b",
},
"foxeer_vtx @ 1.4.0": {
"pageNum": 200,
"read_crc": "0x2b758ebd",
},
"hdzero_freestyle_v1 @ 1.4.0": {
"pageNum": 205,
"read_crc": "0xdbb9c87f",
},
"hdzero_race_v1 @ 1.4.0": {
"pageNum": 200,
"read_crc": "0xa3ca64bd",
},
"hdzero_race_v2 @ 1.4.0": {
"pageNum": 199,
"read_crc": "0x40a5716b",
},
"hdzero_race_v3 @ 1.4.0": {
"pageNum": 195,
"read_crc": "0xa9925181",
},
"hdzero_whoop @ 1.4.0": {
"pageNum": 189,
"read_crc": "0x69bdd828",
},
"hdzero_whoop_lite @ 1.4.0": {
"pageNum": 200,
"read_crc": "0x785b02f5",
},
"foxeer_vtx @ 1.5.0": {
"pageNum": 207,
"read_crc": "0xed2133b3",
},
"hdzero_freestyle_v1 @ 1.5.0": {
"pageNum": 212,
"read_crc": "0xfad37aba",
},
"hdzero_freestyle_v2 @ 1.5.0": {
"pageNum": 213,
"read_crc": "0xfe479852",
},
"hdzero_race_v1 @ 1.5.0": {
"pageNum": 207,
"read_crc": "0xdfe1f8d4",
},
"hdzero_race_v2 @ 1.5.0": {
"pageNum": 207,
"read_crc": "0x602030a7",
},
"hdzero_race_v3 @ 1.5.0": {
"pageNum": 201,
"read_crc": "0xc31605fd",
},
"hdzero_whoop @ 1.5.0": {
"pageNum": 197,
"read_crc": "0x855da136",
},
"hdzero_whoop_lite @ 1.5.0": {
"pageNum": 207,
"read_crc": "0x7f1a74be",
},
"foxeer_vtx @ 1.5.0-CITA": {
"pageNum": 195,
"read_crc": "0x1b06017f",
},
"hdzero_race_v1 @ 1.5.0-CITA": {
"pageNum": 195,
"read_crc": "0x815fb9a6",
},
"hdzero_race_v2 @ 1.5.0-CITA": {
"pageNum": 194,
"read_crc": "0x9c95b6c1",
},
"hdzero_race_v3 @ 1.5.0-CITA": {
"pageNum": 195,
"read_crc": "0xe966412a",
},
"hdzero_whoop @ 1.5.0-CITA": {
"pageNum": 195,
"read_crc": "0x193c4a95",
},
"hdzero_whoop_lite @ 1.5.0-CITA": {
"pageNum": 195,
"read_crc": "0xc6162081",
},
}
if crc in crc_list:
if crc_list[crc].endswith("CITA"):
return crc_list[crc] + "\nFirmware is valid"
else:
return crc_list[crc] + "\nFirmware is NOT valid"
for firmware, metadata in firmware_list.items():
if crc_table[metadata["pageNum"]] == metadata["read_crc"]:
if firmware.endswith("CITA"):
return firmware + "\nFirmware is valid"
else:
return firmware + "\nFirmware is NOT valid"
else:
return "Unknown firmware" + "\nFirmware is NOT valid"

Expand Down Expand Up @@ -431,7 +561,7 @@ def update_connection_state(self):
self.target_combobox.current(j)
self.vtx_name_select = i
self.vtx_index_select = j
self.create_window(getFirmwareFromCRC("0x"+hex(ch341.read_crc)[2:].ljust(4, '0')))
self.create_window(getFirmwareFromCRC(ch341.crc_table))
self.ch341Command = 0
elif self.ch341Command == 2:
if ch341.command == 0:
Expand Down

0 comments on commit 573ae74

Please sign in to comment.