Skip to content

Commit

Permalink
feat: check all device models in check_releases script
Browse files Browse the repository at this point in the history
  • Loading branch information
komret authored and vdovhanych committed Oct 9, 2024
1 parent cb711da commit f5511b6
Showing 1 changed file with 11 additions and 30 deletions.
41 changes: 11 additions & 30 deletions check_releases.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import json
import struct

firmware_dir = "firmware"
device_models = [name for name in os.listdir(firmware_dir) if os.path.isdir(os.path.join(firmware_dir, name)) and name != "translations"]


def check_bridge():
patterns = [
Expand Down Expand Up @@ -44,7 +47,7 @@ def check_bridge():

def check_firmware(model, bitcoin_only=False):

if model not in ["1", "2", "t1b1", "t2t1", "t2b1"]:
if model not in device_models:
raise ValueError("Unknown model: %s" % model)

print("Checking Firmware (model %s) data:" % model)
Expand Down Expand Up @@ -95,7 +98,7 @@ def check_firmware(model, bitcoin_only=False):
if model == "1" or model == "t1b1":
legacy_header = r["version"] < [1, 12, 0]
start = b"TRZR" if legacy_header else b"TRZF"
elif model == "2" or model == "t2t1" or model == "t2b1":
else:
start = b"TRZV"

if not data.startswith(start):
Expand Down Expand Up @@ -129,24 +132,7 @@ def check_firmware(model, bitcoin_only=False):
else:
print("OK")

if model == "2" or model == "t2t1":
vendorlen = struct.unpack("<I", data[4:8])[0]
headerlen = struct.unpack("<I", data[4 + vendorlen : 8 + vendorlen])[0]
codelen = struct.unpack("<I", data[12 + vendorlen : 16 + vendorlen])[0]

expected_len = codelen + vendorlen + headerlen
if expected_len != len(data):
print(
"INVALID SIZE (is %d bytes, should be %d bytes)"
% (expected_len, len(data))
)
ok = False
continue

else:
print("OK")

if model == "t2b1":
else:
vendorlen = struct.unpack("<I", data[4:8])[0]
headerlen = struct.unpack("<I", data[4 + vendorlen : 8 + vendorlen])[0]
codelen = struct.unpack("<I", data[12 + vendorlen : 16 + vendorlen])[0]
Expand All @@ -172,16 +158,11 @@ def check_firmware(model, bitcoin_only=False):
ok = True

ok &= check_bridge()
ok &= check_firmware("1")
ok &= check_firmware("t1b1")
ok &= check_firmware("1", bitcoin_only=True)
ok &= check_firmware("t1b1", bitcoin_only=True)
ok &= check_firmware("2")
ok &= check_firmware("t2t1")
ok &= check_firmware("2", bitcoin_only=True)
ok &= check_firmware("t2t1", bitcoin_only=True)
ok &= check_firmware("t2b1")
ok &= check_firmware("t2b1", bitcoin_only=True)

for model in device_models:
ok &= check_firmware(model)
ok &= check_firmware(model, bitcoin_only=True)

if ok:
print("EVERYTHING OK")
exit(0)
Expand Down

0 comments on commit f5511b6

Please sign in to comment.