예제 #1
0
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
예제 #2
0
def flash_panda(panda_serial: str) -> Panda:
    panda = Panda(panda_serial)

    fw_signature = get_expected_signature(panda)

    panda_version = "bootstub" if panda.bootstub else panda.get_version()
    panda_signature = b"" if panda.bootstub else panda.get_signature()
    cloudlog.warning(
        f"Panda {panda_serial} connected, version: {panda_version}, signature {panda_signature.hex()[:16]}, expected {fw_signature.hex()[:16]}"
    )

    if panda.bootstub or panda_signature != fw_signature:
        cloudlog.info("Panda firmware out of date, update required")
        panda.flash()
        cloudlog.info("Done flashing")

    if panda.bootstub:
        bootstub_version = panda.get_version()
        cloudlog.info(
            f"Flashed firmware not booting, flashing development bootloader. Bootstub version: {bootstub_version}"
        )
        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

    return panda
예제 #3
0
파일: pandad.py 프로젝트: eric-abb/auto
def update_panda() -> 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_signature = get_expected_signature()

  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()
    cloudlog.info("Done flashing")

  if panda.bootstub:
    bootstub_version = panda.get_version()
    cloudlog.info(f"Flashed firmware not booting, flashing development bootloader. Bootstub version: {bootstub_version}")
    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

  return panda
예제 #4
0
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
예제 #5
0
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))
예제 #6
0
def flash_panda(panda_serial: str) -> Panda:
    panda = Panda(panda_serial)

    fw_signature = get_expected_signature(panda)

    panda_version = "bootstub" if panda.bootstub else panda.get_version()
    panda_signature = b"" if panda.bootstub else panda.get_signature()
    cloudlog.warning(
        f"Panda {panda_serial} connected, version: {panda_version}, signature {panda_signature.hex()[:16]}, expected {fw_signature.hex()[:16]}"
    )

    if panda.bootstub or panda_signature != fw_signature:
        cloudlog.info("Panda firmware out of date, update required")
        panda.flash()
        cloudlog.info("Done flashing")

    if panda.bootstub:
        spinner = Spinner()
        spinner.update("Restoring panda")
        panda.recover()
        spinner.close()

    if panda.bootstub:
        spinner = Spinner()
        spinner.update("Restoring panda")
        try:
            if panda.get_mcu_type() == MCU_TYPE_H7:
                subprocess.run(
                    "cd /data/openpilot/panda/board; ./recover_h7.sh",
                    capture_output=True,
                    shell=True)
            else:
                subprocess.run("cd /data/openpilot/panda/board; ./recover.sh",
                               capture_output=True,
                               shell=True)
            panda.reset()
            panda.reconnect()
        finally:
            spinner.close()

    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

    return panda
예제 #7
0
def flash_release(path=None, st_serial=None):
    from panda import Panda, PandaDFU
    from zipfile import ZipFile

    def status(x):
        print("\033[1;32;40m" + x + "\033[00m")

    if st_serial is not None:
        # look for Panda
        panda_list = Panda.list()
        if len(panda_list) == 0:
            raise Exception(
                "panda not found, make sure it's connected and your user can access it"
            )
        elif len(panda_list) > 1:
            raise Exception("Please only connect one panda")
        st_serial = panda_list[0]
        print("Using panda with serial %s" % st_serial)

    if path is None:
        print(
            "Fetching latest firmware from github.com/commaai/panda-artifacts")
        r = requests.get(
            "https://raw.githubusercontent.com/commaai/panda-artifacts/master/latest.json"
        )
        url = json.loads(r.text)['url']
        r = requests.get(url)
        print("Fetching firmware from %s" % url)
        path = io.BytesIO(r.content)

    zf = ZipFile(path)
    zf.printdir()

    version = zf.read("version").decode()
    status("0. Preparing to flash " + str(version))

    code_bootstub = zf.read("bootstub.panda.bin")
    code_panda = zf.read("panda.bin")

    # enter DFU mode
    status("1. Entering DFU mode")
    panda = Panda(st_serial)
    panda.reset(enter_bootstub=True)
    panda.reset(enter_bootloader=True)
    time.sleep(1)

    # program bootstub
    status("2. Programming bootstub")
    dfu = PandaDFU(PandaDFU.st_serial_to_dfu_serial(st_serial))
    dfu.program_bootstub(code_bootstub)
    time.sleep(1)

    # flash main code
    status("3. Flashing main code")
    panda = Panda(st_serial)
    panda.flash(code=code_panda)
    panda.close()

    # check for connection
    status("4. Verifying version")
    panda = Panda(st_serial)
    my_version = panda.get_version()
    print("dongle id: %s" % panda.get_serial()[0])
    print(my_version, "should be", version)
    assert (str(version) == str(my_version))

    # done!
    status("6. Success!")
예제 #8
0
파일: get_version.py 프로젝트: s70160/panda
#!/usr/bin/env python3
from panda import Panda

if __name__ == "__main__":
    for p in Panda.list():
        pp = Panda(p)
        print("%s: %s" % (pp.get_serial()[0], pp.get_version()))
예제 #9
0
#!/usr/bin/env python3
import time
from panda import Panda

p1 = Panda('380016000551363338383037')
p2 = Panda('430026000951363338383037')

# this is a test, no safety
p1.set_safety_mode(Panda.SAFETY_ALLOUTPUT)
p2.set_safety_mode(Panda.SAFETY_ALLOUTPUT)

# get versions
print(p1.get_version())
print(p2.get_version())

# this sets bus 2 to actually be GMLAN
p2.set_gmlan(bus=2)

# send w bitbang then without
#iden = 123
iden = 18000
#dat = "\x01\x02"
dat = "\x01\x02\x03\x04\x05\x06\x07\x08"
while 1:
    iden += 1
    p1.set_gmlan(bus=None)
    p1.can_send(iden, dat, bus=3)
    #p1.set_gmlan(bus=2)
    #p1.can_send(iden, dat, bus=3)
    time.sleep(0.01)
    print(p2.can_recv())
예제 #10
0
def flash_release(path=None, st_serial=None):
    from panda import Panda, PandaDFU, ESPROM, CesantaFlasher
    from zipfile import ZipFile

    def status(x):
        print("\033[1;32;40m" + x + "\033[00m")

    if st_serial == None:
        # look for Panda
        panda_list = Panda.list()
        if len(panda_list) == 0:
            raise Exception(
                "panda not found, make sure it's connected and your user can access it"
            )
        elif len(panda_list) > 1:
            raise Exception("Please only connect one panda")
        st_serial = panda_list[0]
        print("Using panda with serial %s" % st_serial)

    if path == None:
        print(
            "Fetching latest firmware from github.com/commaai/panda-artifacts")
        r = requests.get(
            "https://raw.githubusercontent.com/commaai/panda-artifacts/master/latest.json"
        )
        url = json.loads(r.text)['url']
        r = requests.get(url)
        print("Fetching firmware from %s" % url)
        path = io.StringIO(r.content)

    zf = ZipFile(path)
    zf.printdir()

    version = zf.read("version")
    status("0. Preparing to flash " + version)

    code_bootstub = zf.read("bootstub.panda.bin")
    code_panda = zf.read("panda.bin")

    code_boot_15 = zf.read("boot_v1.5.bin")
    code_boot_15 = code_boot_15[0:2] + "\x00\x30" + code_boot_15[4:]

    code_user1 = zf.read("user1.bin")
    code_user2 = zf.read("user2.bin")

    # enter DFU mode
    status("1. Entering DFU mode")
    panda = Panda(st_serial)
    panda.enter_bootloader()
    time.sleep(1)

    # program bootstub
    status("2. Programming bootstub")
    dfu = PandaDFU(PandaDFU.st_serial_to_dfu_serial(st_serial))
    dfu.program_bootstub(code_bootstub)
    time.sleep(1)

    # flash main code
    status("3. Flashing main code")
    panda = Panda(st_serial)
    panda.flash(code=code_panda)
    panda.close()

    # flashing ESP
    if panda.is_white():
        status("4. Flashing ESP (slow!)")
        align = lambda x, sz=0x1000: x + "\xFF" * ((sz - len(x)) % sz)
        esp = ESPROM(st_serial)
        esp.connect()
        flasher = CesantaFlasher(esp, 230400)
        flasher.flash_write(0x0, align(code_boot_15), True)
        flasher.flash_write(0x1000, align(code_user1), True)
        flasher.flash_write(0x81000, align(code_user2), True)
        flasher.flash_write(0x3FE000, "\xFF" * 0x1000)
        flasher.boot_fw()
        del flasher
        del esp
        time.sleep(1)
    else:
        status("4. No ESP in non-white panda")

    # check for connection
    status("5. Verifying version")
    panda = Panda(st_serial)
    my_version = panda.get_version()
    print("dongle id: %s" % panda.get_serial()[0])
    print(my_version, "should be", version)
    assert (str(version) == str(my_version))

    # done!
    status("6. Success!")
예제 #11
0
파일: get_version.py 프로젝트: n2aws/panda
#!/usr/bin/env python
from panda import Panda

if __name__ == "__main__":
  for p in Panda.list():
    pp = Panda(p)
    print("%s: %s" % (pp.get_serial()[0], pp.get_version()))


예제 #12
0
def flash_release(path=None, st_serial=None):
  from panda import Panda, PandaDFU, ESPROM, CesantaFlasher
  from zipfile import ZipFile

  def status(x):
    print("\033[1;32;40m"+x+"\033[00m")

  if st_serial == None:
    # look for Panda
    panda_list = Panda.list()
    if len(panda_list) == 0:
      raise Exception("panda not found, make sure it's connected and your user can access it")
    elif len(panda_list) > 1:
      raise Exception("Please only connect one panda")
    st_serial = panda_list[0]
    print("Using panda with serial %s" % st_serial)

  if path == None:
    print("Fetching latest firmware from github.com/commaai/panda-artifacts")
    r = requests.get("https://raw.githubusercontent.com/commaai/panda-artifacts/master/latest.json")
    url = json.loads(r.text)['url']
    r = requests.get(url)
    print("Fetching firmware from %s" % url)
    path = StringIO.StringIO(r.content)

  zf = ZipFile(path)
  zf.printdir()

  version = zf.read("version")
  status("0. Preparing to flash "+version)

  code_bootstub = zf.read("bootstub.panda.bin")
  code_panda = zf.read("panda.bin")

  code_boot_15 = zf.read("boot_v1.5.bin")
  code_boot_15 = code_boot_15[0:2] + "\x00\x30" + code_boot_15[4:]

  code_user1 = zf.read("user1.bin")
  code_user2 = zf.read("user2.bin")

  # enter DFU mode
  status("1. Entering DFU mode")
  panda = Panda(st_serial)
  panda.enter_bootloader()
  time.sleep(1)

  # program bootstub
  status("2. Programming bootstub")
  dfu = PandaDFU(PandaDFU.st_serial_to_dfu_serial(st_serial))
  dfu.program_bootstub(code_bootstub)
  time.sleep(1)

  # flash main code
  status("3. Flashing main code")
  panda = Panda(st_serial)
  panda.flash(code=code_panda)
  panda.close()

  # flashing ESP
  status("4. Flashing ESP (slow!)")
  align = lambda x, sz=0x1000: x+"\xFF"*((sz-len(x)) % sz)
  esp = ESPROM(st_serial)
  esp.connect()
  flasher = CesantaFlasher(esp, 230400)
  flasher.flash_write(0x0, align(code_boot_15), True)
  flasher.flash_write(0x1000, align(code_user1), True)
  flasher.flash_write(0x81000, align(code_user2), True)
  flasher.flash_write(0x3FE000, "\xFF"*0x1000)
  flasher.boot_fw()
  del flasher
  del esp
  time.sleep(1)

  # check for connection
  status("5. Verifying version")
  panda = Panda(st_serial)
  my_version = panda.get_version()
  print("dongle id: %s" % panda.get_serial()[0])
  print(my_version, "should be", version)
  assert(str(version) == str(my_version))

  # done!
  status("6. Success!")