* DFU fix

* fix test 2

* this should fix all the remaining jenkins test

* Fixed pyenv shim not being a python file, but a sh script
This commit is contained in:
rbiasini
2019-10-03 19:46:28 -07:00
committed by robbederks
parent 70219d7bb2
commit af0960ad3d
5 changed files with 30 additions and 30 deletions

View File

@@ -3,6 +3,7 @@ import os
import usb1
import struct
import time
import binascii
# *** DFU mode ***
@@ -46,28 +47,27 @@ class PandaDFU(object):
def st_serial_to_dfu_serial(st):
if st == None or st == "none":
return None
uid_base = struct.unpack("H"*6, st.decode("hex"))
return struct.pack("!HHH", uid_base[1] + uid_base[5], uid_base[0] + uid_base[4] + 0xA, uid_base[3]).encode("hex").upper()
uid_base = struct.unpack("H"*6, bytes.fromhex(st))
return binascii.hexlify(struct.pack("!HHH", uid_base[1] + uid_base[5], uid_base[0] + uid_base[4] + 0xA, uid_base[3])).upper().decode("utf-8")
def status(self):
while 1:
dat = str(self._handle.controlRead(0x21, DFU_GETSTATUS, 0, 0, 6))
if dat[1] == "\x00":
dat = self._handle.controlRead(0x21, DFU_GETSTATUS, 0, 0, 6)
if dat[1] == 0:
break
def clear_status(self):
# Clear status
stat = str(self._handle.controlRead(0x21, DFU_GETSTATUS, 0, 0, 6))
if stat[4] == "\x0a":
stat = self._handle.controlRead(0x21, DFU_GETSTATUS, 0, 0, 6)
if stat[4] == 0xa:
self._handle.controlRead(0x21, DFU_CLRSTATUS, 0, 0, 0)
elif stat[4] == "\x09":
self._handle.controlWrite(0x21, DFU_ABORT, 0, 0, "")
elif stat[4] == 0x9:
self._handle.controlWrite(0x21, DFU_ABORT, 0, 0, b"")
self.status()
stat = str(self._handle.controlRead(0x21, DFU_GETSTATUS, 0, 0, 6))
def erase(self, address):
self._handle.controlWrite(0x21, DFU_DNLOAD, 0, 0, "\x41" + struct.pack("I", address))
self._handle.controlWrite(0x21, DFU_DNLOAD, 0, 0, b"\x41" + struct.pack("I", address))
self.status()
def program(self, address, dat, block_size=None):
@@ -75,12 +75,12 @@ class PandaDFU(object):
block_size = len(dat)
# Set Address Pointer
self._handle.controlWrite(0x21, DFU_DNLOAD, 0, 0, "\x21" + struct.pack("I", address))
self._handle.controlWrite(0x21, DFU_DNLOAD, 0, 0, b"\x21" + struct.pack("I", address))
self.status()
# Program
dat += "\xFF"*((block_size-len(dat)) % block_size)
for i in range(0, len(dat)/block_size):
dat += b"\xFF"*((block_size-len(dat)) % block_size)
for i in range(0, len(dat)//block_size):
ldat = dat[i*block_size:(i+1)*block_size]
print("programming %d with length %d" % (i, len(ldat)))
self._handle.controlWrite(0x21, DFU_DNLOAD, 2+i, 0, ldat)
@@ -105,17 +105,17 @@ class PandaDFU(object):
build_st(fn)
fn = os.path.join(BASEDIR, "board", fn)
with open(fn) as f:
with open(fn, "rb") as f:
code = f.read()
self.program_bootstub(code)
def reset(self):
# **** Reset ****
self._handle.controlWrite(0x21, DFU_DNLOAD, 0, 0, "\x21" + struct.pack("I", 0x8000000))
self._handle.controlWrite(0x21, DFU_DNLOAD, 0, 0, b"\x21" + struct.pack("I", 0x8000000))
self.status()
try:
self._handle.controlWrite(0x21, DFU_DNLOAD, 2, 0, "")
self._handle.controlWrite(0x21, DFU_DNLOAD, 2, 0, b"")
stat = str(self._handle.controlRead(0x21, DFU_GETSTATUS, 0, 0, 6))
except Exception:
pass