From 7b6e176368f68e1768eb7cd7e1a6b4eee4ce143d Mon Sep 17 00:00:00 2001 From: Firmware Batman Date: Sat, 29 Jul 2017 17:21:22 -0700 Subject: [PATCH] make new flasher the default for make --- board/build.mk | 19 +++++++----------- panda/__init__.py | 49 +++++++++++++++++++++++++++-------------------- 2 files changed, 35 insertions(+), 33 deletions(-) diff --git a/board/build.mk b/board/build.mk index 6114043..f29e897 100644 --- a/board/build.mk +++ b/board/build.mk @@ -16,10 +16,13 @@ endif DFU_UTIL = "dfu-util" # this no longer pushes the bootstub -all: obj/$(PROJ_NAME).bin - ./tools/enter_download_mode.py - $(DFU_UTIL) -a 0 -s 0x08004000 -D obj/$(PROJ_NAME).bin - $(DFU_UTIL) --reset-stm32 -a 0 -s 0x08000000 +flash: obj/$(PROJ_NAME).bin + python -c "from panda import Panda; Panda().flash('obj/$(PROJ_NAME).bin')" + +ota: obj/$(PROJ_NAME).bin + curl http://192.168.0.10/stupdate --upload-file $< + +bin: obj/$(PROJ_NAME).bin # this flashes everything recover: obj/bootstub.$(PROJ_NAME).bin obj/$(PROJ_NAME).bin @@ -27,14 +30,6 @@ recover: obj/bootstub.$(PROJ_NAME).bin obj/$(PROJ_NAME).bin $(DFU_UTIL) -a 0 -s 0x08004000 -D obj/$(PROJ_NAME).bin $(DFU_UTIL) -a 0 -s 0x08000000:leave -D obj/bootstub.$(PROJ_NAME).bin -flash: - python -c "from panda import Panda; Panda().flash()" - -ota: obj/$(PROJ_NAME).bin - curl http://192.168.0.10/stupdate --upload-file $< - -bin: obj/$(PROJ_NAME).bin - ifneq ($(wildcard ../.git/HEAD),) obj/gitversion.h: ../.git/HEAD ../.git/index echo "const uint8_t gitversion[] = \"$(shell git rev-parse HEAD)\";" > $@ diff --git a/panda/__init__.py b/panda/__init__.py index e221722..6928412 100644 --- a/panda/__init__.py +++ b/panda/__init__.py @@ -100,7 +100,7 @@ class Panda(object): self._handle.close() self._handle = None - def connect(self, claim=True): + def connect(self, claim=True, wait=False): if self._handle != None: self.close() @@ -109,22 +109,28 @@ class Panda(object): print("opening WIFI device") else: context = usb1.USBContext() - self._handle = None - for device in context.getDeviceList(skip_on_error=True): - #print(device) - if device.getVendorID() == 0xbbaa and device.getProductID() in [0xddcc, 0xddee]: - if self._serial is None or device.getSerialNumber() == self._serial: - print("opening device", device.getSerialNumber()) - self.bootstub = device.getProductID() == 0xddee - self.legacy = (device.getbcdDevice() != 0x2300) - self._handle = device.open() - if claim: - self._handle.claimInterface(0) - #self._handle.setInterfaceAltSetting(0, 0) #Issue in USB stack - break + while 1: + try: + for device in context.getDeviceList(skip_on_error=True): + #print(device) + if device.getVendorID() == 0xbbaa and device.getProductID() in [0xddcc, 0xddee]: + if self._serial is None or device.getSerialNumber() == self._serial: + print("opening device", device.getSerialNumber()) + self.bootstub = device.getProductID() == 0xddee + self.legacy = (device.getbcdDevice() != 0x2300) + self._handle = device.open() + if claim: + self._handle.claimInterface(0) + #self._handle.setInterfaceAltSetting(0, 0) #Issue in USB stack + break + except Exception as e: + print("exception", e) + if wait == False or self._handle != None: + break assert(self._handle != None) + print("connected") def reset(self, enter_bootstub=False, enter_bootloader=False): # reset @@ -138,19 +144,20 @@ class Panda(object): self._handle.controlWrite(Panda.REQUEST_IN, 0xd8, 0, 0, b'') except Exception: pass - time.sleep(1.0) if not enter_bootloader: - self.connect() + self.connect(wait=True) - def flash(self): + def flash(self, fn=None): if not self.bootstub: self.reset(enter_bootstub=True) - assert(self.bootstub) - ret = os.system("cd %s && make clean && make -f %s bin" % (os.path.join(BASEDIR, "board"), "Makefile.legacy" if self.legacy else "Makefile")) - # TODO: build and detect legacy - with open(os.path.join(BASEDIR, "board", "obj", "code.bin" if self.legacy else "panda.bin")) as f: + if fn is None: + ret = os.system("cd %s && make clean && make -f %s bin" % (os.path.join(BASEDIR, "board"), + "Makefile.legacy" if self.legacy else "Makefile")) + fn = os.path.join(BASEDIR, "board", "obj", "code.bin" if self.legacy else "panda.bin") + + with open(fn) as f: dat = f.read() # confirm flasher is present