panda/python/update.py

45 lines
1009 B
Python
Raw Permalink Normal View History

2019-09-24 18:50:53 -06:00
#!/usr/bin/env python3
2017-08-28 11:42:23 -06:00
import os
import time
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"
2017-08-28 11:42:23 -06:00
panda = None
panda_dfu = None
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...")
2017-08-28 11:42:23 -06:00
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())
2019-09-24 19:07:05 -06:00
print("%s should be %s" % (version, repo_version))
2017-08-28 11:42:23 -06:00
assert(version.startswith(repo_version))
if __name__ == "__main__":
ensure_st_up_to_date()