def update_panda(): with open(os.path.join(BASEDIR, "VERSION")) as f: repo_version = f.read() repo_version += "-EON" if os.path.isfile('/EON') else "-DEV" panda = None panda_dfu = None cloudlog.info("Connecting to panda") while True: # break on normal mode Panda panda_list = Panda.list() if len(panda_list) > 0: cloudlog.info("Panda found, connecting") panda = Panda(panda_list[0]) break # flash on DFU mode Panda panda_dfu = PandaDFU.list() if len(panda_dfu) > 0: cloudlog.info("Panda in DFU mode found, flashing recovery") panda_dfu = PandaDFU(panda_dfu[0]) panda_dfu.recover() print "waiting for board..." time.sleep(1) current_version = "bootstub" if panda.bootstub else str( panda.get_version()) cloudlog.info("Panda connected, version: %s, expected %s" % (current_version, repo_version)) if panda.bootstub or not current_version.startswith(repo_version): cloudlog.info("Panda firmware out of date, update required") signed_fn = os.path.join(BASEDIR, "board", "obj", "panda.bin.signed") if os.path.exists(signed_fn): cloudlog.info("Flashing signed firmware") panda.flash(fn=signed_fn) else: cloudlog.info("Building and flashing unsigned firmware") panda.flash() cloudlog.info("Done flashing") if panda.bootstub: cloudlog.info( "Flashed firmware not booting, flashing development bootloader") panda.recover() cloudlog.info("Done flashing bootloader") if panda.bootstub: cloudlog.info("Panda still not booting, exiting") raise AssertionError version = str(panda.get_version()) if not version.startswith(repo_version): cloudlog.info("Version mismatch after flashing, exiting") raise AssertionError
def update_panda(): panda = None panda_dfu = None cloudlog.info("Connecting to panda") while True: # break on normal mode Panda panda_list = Panda.list() if len(panda_list) > 0: cloudlog.info("Panda found, connecting") panda = Panda(panda_list[0]) break # flash on DFU mode Panda panda_dfu = PandaDFU.list() if len(panda_dfu) > 0: cloudlog.info("Panda in DFU mode found, flashing recovery") panda_dfu = PandaDFU(panda_dfu[0]) panda_dfu.recover() time.sleep(1) fw_fn = get_firmware_fn() fw_signature = get_expected_signature(fw_fn) try: serial = panda.get_serial()[0].decode("utf-8") except Exception: serial = None panda_version = "bootstub" if panda.bootstub else panda.get_version() panda_signature = b"" if panda.bootstub else panda.get_signature() cloudlog.warning( "Panda %s connected, version: %s, signature %s, expected %s" % ( serial, panda_version, panda_signature.hex(), fw_signature.hex(), )) if panda.bootstub or panda_signature != fw_signature: cloudlog.info("Panda firmware out of date, update required") panda.flash(fw_fn) cloudlog.info("Done flashing") if panda.bootstub: cloudlog.info( "Flashed firmware not booting, flashing development bootloader") panda.recover() cloudlog.info("Done flashing bootloader") if panda.bootstub: cloudlog.info("Panda still not booting, exiting") raise AssertionError panda_signature = panda.get_signature() if panda_signature != fw_signature: cloudlog.info("Version mismatch after flashing, exiting") raise AssertionError
def update_panda(): repo_version = get_expected_version() panda = None panda_dfu = None cloudlog.info("Connecting to panda") while True: # break on normal mode Panda panda_list = Panda.list() if len(panda_list) > 0: cloudlog.info("Panda found, connecting") panda = Panda(panda_list[0]) break # flash on DFU mode Panda panda_dfu = PandaDFU.list() if len(panda_dfu) > 0: cloudlog.info("Panda in DFU mode found, flashing recovery") panda_dfu = PandaDFU(panda_dfu[0]) panda_dfu.recover() print("waiting for board...") time.sleep(1) try: serial = panda.get_serial()[0].decode("utf-8") except Exception: serial = None current_version = "bootstub" if panda.bootstub else panda.get_version() cloudlog.warning("Panda %s connected, version: %s, expected %s" % (serial, current_version, repo_version)) if panda.bootstub or not current_version.startswith(repo_version): cloudlog.info("Panda firmware out of date, update required") signed_fn = os.path.join(BASEDIR, "board", "obj", "panda.bin.signed") if os.path.exists(signed_fn): cloudlog.info("Flashing signed firmware") panda.flash(fn=signed_fn) else: cloudlog.info("Building and flashing unsigned firmware") panda.flash() cloudlog.info("Done flashing") if panda.bootstub: cloudlog.info("Flashed firmware not booting, flashing development bootloader") panda.recover() cloudlog.info("Done flashing bootloader") if panda.bootstub: cloudlog.info("Panda still not booting, exiting") raise AssertionError version = panda.get_version() if not version.startswith(repo_version): cloudlog.info("Version mismatch after flashing, exiting") raise AssertionError
def main() -> NoReturn: first_run = True params = Params() while True: try: params.delete("PandaSignatures") # Flash all Pandas in DFU mode for p in PandaDFU.list(): cloudlog.info(f"Panda in DFU mode found, flashing recovery {p}") PandaDFU(p).recover() time.sleep(1) panda_serials = Panda.list() if len(panda_serials) == 0: continue cloudlog.info(f"{len(panda_serials)} panda(s) found, connecting - {panda_serials}") # Flash pandas pandas = [] for serial in panda_serials: pandas.append(flash_panda(serial)) # check health for lost heartbeat for panda in pandas: health = panda.health() if health["heartbeat_lost"]: params.put_bool("PandaHeartbeatLost", True) cloudlog.event("heartbeat lost", deviceState=health, serial=panda.get_usb_serial()) if first_run: cloudlog.info(f"Resetting panda {panda.get_usb_serial()}") panda.reset() # sort pandas to have deterministic order pandas.sort(key=cmp_to_key(panda_sort_cmp)) panda_serials = list(map(lambda p: p.get_usb_serial(), pandas)) # log panda fw versions params.put("PandaSignatures", b','.join(p.get_signature() for p in pandas)) # close all pandas for p in pandas: p.close() except (usb1.USBErrorNoDevice, usb1.USBErrorPipe): # a panda was disconnected while setting everything up. let's try again cloudlog.exception("Panda USB exception while setting up") continue first_run = False # run boardd with all connected serials as arguments os.environ['MANAGER_DAEMON'] = 'boardd' os.chdir(os.path.join(BASEDIR, "selfdrive/boardd")) subprocess.run(["./boardd", *panda_serials], check=True)
def ensure_st_up_to_date(): from panda import Panda, PandaDFU, BASEDIR with open(os.path.join(BASEDIR, "VERSION")) as f: repo_version = f.read() repo_version += "-EON" if os.path.isfile('/EON') else "-DEV" panda = None panda_dfu = None should_flash_recover = False while 1: # break on normal mode Panda panda_list = Panda.list() if len(panda_list) > 0: panda = Panda(panda_list[0]) break # flash on DFU mode Panda panda_dfu = PandaDFU.list() if len(panda_dfu) > 0: panda_dfu = PandaDFU(panda_dfu[0]) panda_dfu.recover() print("waiting for board...") time.sleep(1) if panda.bootstub or not panda.get_version().startswith(repo_version): panda.flash() if panda.bootstub: panda.recover() assert (not panda.bootstub) version = str(panda.get_version()) print("%s should be %s" % (version, repo_version)) assert (version.startswith(repo_version))
FW_FX_FN = "panda.bin" is_mcu_h7 = False if __name__ == "__main__": cur_dir = os.path.dirname(os.path.realpath(__file__)) # Open manifest manifest_fn = os.path.join(cur_dir, 'latest.json') with open(manifest_fn) as manifest: latest = json.load(manifest) # Open zip file zip_fn = os.path.join(cur_dir, latest['version'] + '.zip') with zipfile.ZipFile(zip_fn) as zip_file: # Wait for panda to connect while not PandaDFU.list(): print("Waiting for panda in DFU mode") if Panda.list(): print("Panda found. Putting in DFU Mode") panda = Panda() panda.reset(enter_bootstub=True) panda.reset(enter_bootloader=True) time.sleep(0.5) # Flash bootstub panda_dfu = PandaDFU(None) is_mcu_h7 = panda_dfu._mcu_type == MCU_TYPE_H7 fn = BOOTSTUB_H7_FN if is_mcu_h7 else BOOTSTUB_FX_FN print(f"Detected MCU type {panda_dfu._mcu_type}, flashing {fn}")
if __name__ == "__main__": if jungle: serials = PandaJungle.list() else: serials = Panda.list() num_senders = len(serials) if num_senders == 0: print("No senders found. Exiting") sys.exit(1) else: print("%d senders found. Starting broadcast" % num_senders) if "FLASH" in os.environ: for s in PandaDFU.list(): PandaDFU(s).recover() time.sleep(1) for s in serials: Panda(s).recover() Panda(s).flash() pool = Pool(num_senders, initializer=initializer) pool.map_async(send_thread, serials) while True: try: time.sleep(10) except KeyboardInterrupt: pool.terminate()