From fce1215a2ede45e5e2a0e97ca23a86c1d8bfa94a Mon Sep 17 00:00:00 2001 From: Comma Device Date: Tue, 26 Jul 2022 21:41:17 +0200 Subject: [PATCH] dynamic sector erasing --- python/__init__.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/python/__init__.py b/python/__init__.py index 2fa02cf2a9..e307d83194 100644 --- a/python/__init__.py +++ b/python/__init__.py @@ -7,6 +7,7 @@ import time import traceback import sys +import math from functools import wraps from typing import Optional from .dfu import PandaDFU, MCU_TYPE_F2, MCU_TYPE_F4, MCU_TYPE_H7 # pylint: disable=import-error @@ -304,8 +305,9 @@ def flash_static(handle, code): handle.controlWrite(Panda.REQUEST_IN, 0xb1, 0, 0, b'') # erase sectors 1 through 3 - print("flash: erasing") - for i in range(1, 4): + num_sectors = math.ceil(len(code) / 0x4000) + print(f"flash: erasing {num_sectors} sectors") + for i in range(1, num_sectors + 1): handle.controlWrite(Panda.REQUEST_IN, 0xb2, i, 0, b'') # flash over EP2