コード例 #1
0
ファイル: pandad.py プロジェクト: ooohal9000/6.4dudes
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 プロジェクト: beenfhb/open-pilot
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
コード例 #4
0
ファイル: pandad.py プロジェクト: neon-dev/openpilot
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 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
コード例 #6
0
ファイル: update.py プロジェクト: two70/raspberry-pilot
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))
コード例 #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
ファイル: 1_program.py プロジェクト: dagelf/panda-1
def test_flash():
    p = Panda()
    p.flash()
コード例 #9
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!")
コード例 #10
0
ファイル: flash_release.py プロジェクト: n2aws/panda
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!")
コード例 #11
0
ファイル: 1_program.py プロジェクト: shola/openpilot
def test_flash(serial=None):
  p = Panda(serial=serial)
  p.flash()
コード例 #12
0
ファイル: 1_program.py プロジェクト: n2aws/panda
def test_flash():
  p = Panda()
  p.flash()