SPI support in bootstub (#1227)

* always build spi

* no dos for now

* spi gpio init

* detect bootstub

* cleanup

* revert that

* move fx stuff

* fix linter

* set erase timeout

* fix types

* cleanup

---------

Co-authored-by: Comma Device <device@comma.ai>
This commit is contained in:
Adeeb Shihadeh
2023-03-07 14:55:15 -08:00
committed by GitHub
parent deaad254d9
commit 2de7140117
7 changed files with 45 additions and 19 deletions

View File

@@ -26,12 +26,12 @@ __version__ = '0.0.10'
LOGLEVEL = os.environ.get('LOGLEVEL', 'INFO').upper()
logging.basicConfig(level=LOGLEVEL, format='%(message)s')
USBPACKET_MAX_SIZE = 0x40
CANPACKET_HEAD_SIZE = 0x6
DLC_TO_LEN = [0, 1, 2, 3, 4, 5, 6, 7, 8, 12, 16, 20, 24, 32, 48, 64]
LEN_TO_DLC = {length: dlc for (dlc, length) in enumerate(DLC_TO_LEN)}
def calculate_checksum(data):
res = 0
for b in data:
@@ -294,20 +294,22 @@ class Panda:
# get UID to confirm slave is present and up
handle = None
spi_serial = None
bootstub = None
try:
handle = PandaSpiHandle()
bootstub = Panda.flasher_present(handle)
dat = handle.controlRead(Panda.REQUEST_IN, 0xc3, 0, 0, 12)
spi_serial = binascii.hexlify(dat).decode()
except PandaSpiException:
pass
# no connection or wrong panda
if spi_serial is None or (serial is not None and (spi_serial != serial)):
if None in (spi_serial, bootstub) or (serial is not None and (spi_serial != serial)):
handle = None
spi_serial = None
bootstub = False
# TODO: detect bootstub
return handle, spi_serial, False, None
return handle, spi_serial, bootstub, None
@staticmethod
def usb_connect(serial, claim=True, wait=False):
@@ -421,13 +423,17 @@ class Panda:
if not success:
raise Exception("reconnect failed")
@staticmethod
def flasher_present(handle: BaseHandle) -> bool:
fr = handle.controlRead(Panda.REQUEST_IN, 0xb0, 0, 0, 0xc)
return fr[4:8] == b"\xde\xad\xd0\x0d"
@staticmethod
def flash_static(handle, code, mcu_type):
assert mcu_type is not None, "must set valid mcu_type to flash"
# confirm flasher is present
fr = handle.controlRead(Panda.REQUEST_IN, 0xb0, 0, 0, 0xc)
assert fr[4:8] == b"\xde\xad\xd0\x0d"
assert Panda.flasher_present(handle)
# determine sectors to erase
apps_sectors_cumsum = accumulate(mcu_type.config.sector_sizes[1:])