2022-08-15 20:11:49 -07:00
|
|
|
import os
|
2022-08-02 22:28:54 -07:00
|
|
|
import time
|
2019-12-09 10:54:48 -08:00
|
|
|
|
2022-08-15 20:11:49 -07:00
|
|
|
from panda import Panda, PandaDFU, MCU_TYPE_H7, BASEDIR
|
|
|
|
|
from .helpers import test_all_pandas, panda_connect_and_init, check_signature
|
2017-07-30 07:59:14 -07:00
|
|
|
|
2019-12-09 10:54:48 -08:00
|
|
|
|
2019-08-28 12:57:42 -07:00
|
|
|
@test_all_pandas
|
2022-08-02 17:05:47 -07:00
|
|
|
@panda_connect_and_init(full_reset=False)
|
2022-08-15 20:11:49 -07:00
|
|
|
def test_a_known_bootstub(p):
|
|
|
|
|
# Test that compiled app can work with known production bootstub
|
2022-11-03 17:24:28 -07:00
|
|
|
KNOWN_H7_BOOTSTUB_FN = os.path.join(BASEDIR, "tests", "hitl", "known_bootstub", "bootstub.panda_h7.bin")
|
|
|
|
|
KNOWN_BOOTSTUB_FN = os.path.join(BASEDIR, "tests", "hitl", "known_bootstub", "bootstub.panda.bin")
|
2022-08-15 20:11:49 -07:00
|
|
|
|
|
|
|
|
p.reset(enter_bootstub=True)
|
|
|
|
|
p.reset(enter_bootloader=True)
|
|
|
|
|
|
|
|
|
|
dfu_serial = PandaDFU.st_serial_to_dfu_serial(p._serial, p._mcu_type)
|
|
|
|
|
assert Panda.wait_for_dfu(dfu_serial, timeout=30)
|
|
|
|
|
|
|
|
|
|
dfu = PandaDFU(dfu_serial)
|
|
|
|
|
fn = KNOWN_H7_BOOTSTUB_FN if p._mcu_type == MCU_TYPE_H7 else KNOWN_BOOTSTUB_FN
|
|
|
|
|
with open(fn, "rb") as f:
|
|
|
|
|
code = f.read()
|
|
|
|
|
|
|
|
|
|
dfu.program_bootstub(code)
|
|
|
|
|
p.connect(True, True)
|
|
|
|
|
p.flash()
|
|
|
|
|
check_signature(p)
|
|
|
|
|
|
|
|
|
|
@test_all_pandas
|
|
|
|
|
@panda_connect_and_init(full_reset=False)
|
|
|
|
|
def test_b_recover(p):
|
2019-04-09 14:09:18 -07:00
|
|
|
assert p.recover(timeout=30)
|
2022-08-02 17:05:47 -07:00
|
|
|
check_signature(p)
|
2019-12-09 10:54:48 -08:00
|
|
|
|
2019-08-28 12:57:42 -07:00
|
|
|
@test_all_pandas
|
2022-08-02 17:05:47 -07:00
|
|
|
@panda_connect_and_init(full_reset=False)
|
2022-08-15 20:11:49 -07:00
|
|
|
def test_c_flash(p):
|
2022-08-02 22:28:54 -07:00
|
|
|
# test flash from bootstub
|
|
|
|
|
serial = p._serial
|
2022-11-03 17:24:28 -07:00
|
|
|
assert serial is not None
|
2022-08-02 22:28:54 -07:00
|
|
|
p.reset(enter_bootstub=True)
|
|
|
|
|
p.close()
|
|
|
|
|
time.sleep(2)
|
|
|
|
|
|
|
|
|
|
np = Panda(serial)
|
|
|
|
|
assert np.bootstub
|
|
|
|
|
assert np._serial == serial
|
|
|
|
|
np.flash()
|
|
|
|
|
np.close()
|
|
|
|
|
|
|
|
|
|
p.reconnect()
|
|
|
|
|
p.reset()
|
|
|
|
|
check_signature(p)
|
|
|
|
|
|
|
|
|
|
# test flash from app
|
2017-07-30 07:59:14 -07:00
|
|
|
p.flash()
|
2022-08-02 17:05:47 -07:00
|
|
|
check_signature(p)
|