2022-08-15 20:11:49 -07:00
|
|
|
import os
|
2022-08-02 22:28:54 -07:00
|
|
|
import time
|
2023-06-04 01:00:17 -07:00
|
|
|
import pytest
|
2019-12-09 10:54:48 -08:00
|
|
|
|
2023-01-26 20:54:11 -08:00
|
|
|
from panda import Panda, PandaDFU, McuType, BASEDIR
|
2017-07-30 07:59:14 -07:00
|
|
|
|
2019-12-09 10:54:48 -08:00
|
|
|
|
2023-03-22 21:38:37 -07:00
|
|
|
def check_signature(p):
|
|
|
|
|
assert not p.bootstub, "Flashed firmware not booting. Stuck in bootstub."
|
|
|
|
|
assert p.up_to_date()
|
|
|
|
|
|
2023-08-06 16:30:21 -07:00
|
|
|
|
|
|
|
|
def test_dfu(p):
|
|
|
|
|
app_mcu_type = p.get_mcu_type()
|
|
|
|
|
dfu_serial = p.get_dfu_serial()
|
|
|
|
|
|
|
|
|
|
p.reset(enter_bootstub=True)
|
|
|
|
|
p.reset(enter_bootloader=True)
|
|
|
|
|
assert Panda.wait_for_dfu(dfu_serial, timeout=19), "failed to enter DFU"
|
|
|
|
|
|
|
|
|
|
dfu = PandaDFU(dfu_serial)
|
|
|
|
|
assert dfu.get_mcu_type() == app_mcu_type
|
|
|
|
|
|
|
|
|
|
assert dfu_serial in PandaDFU.list()
|
|
|
|
|
|
|
|
|
|
dfu._handle.clear_status()
|
|
|
|
|
dfu.reset()
|
|
|
|
|
p.reconnect()
|
|
|
|
|
|
2023-01-28 14:41:52 -08:00
|
|
|
# TODO: make more comprehensive bootstub tests and run on a few production ones + current
|
|
|
|
|
# TODO: also test release-signed app
|
2024-01-18 17:44:32 -05:00
|
|
|
@pytest.mark.timeout(30)
|
2023-08-06 16:30:21 -07:00
|
|
|
def test_known_bootstub(p):
|
2023-01-26 20:54:11 -08:00
|
|
|
"""
|
|
|
|
|
Test that compiled app can work with known production bootstub
|
|
|
|
|
"""
|
|
|
|
|
known_bootstubs = {
|
2023-01-28 14:41:52 -08:00
|
|
|
McuType.H7: ["bootstub.panda_h7.bin"],
|
2023-01-26 20:54:11 -08:00
|
|
|
}
|
2022-08-15 20:11:49 -07:00
|
|
|
|
2023-01-28 14:41:52 -08:00
|
|
|
for kb in known_bootstubs[p.get_mcu_type()]:
|
|
|
|
|
app_ids = (p.get_mcu_type(), p.get_usb_serial())
|
|
|
|
|
assert None not in app_ids
|
2022-08-15 20:11:49 -07:00
|
|
|
|
2023-01-28 14:41:52 -08:00
|
|
|
p.reset(enter_bootstub=True)
|
|
|
|
|
p.reset(enter_bootloader=True)
|
2022-08-15 20:11:49 -07:00
|
|
|
|
2023-04-16 14:43:58 -07:00
|
|
|
dfu_serial = p.get_dfu_serial()
|
2023-01-28 14:41:52 -08:00
|
|
|
assert Panda.wait_for_dfu(dfu_serial, timeout=30)
|
2022-08-15 20:11:49 -07:00
|
|
|
|
2023-01-28 14:41:52 -08:00
|
|
|
dfu = PandaDFU(dfu_serial)
|
|
|
|
|
with open(os.path.join(BASEDIR, "tests/hitl/known_bootstub", kb), "rb") as f:
|
|
|
|
|
code = f.read()
|
|
|
|
|
|
|
|
|
|
dfu.program_bootstub(code)
|
2023-05-21 20:05:21 -07:00
|
|
|
dfu.reset()
|
2023-01-28 14:41:52 -08:00
|
|
|
|
|
|
|
|
p.connect(claim=False, wait=True)
|
|
|
|
|
|
|
|
|
|
# check for MCU or serial mismatch
|
|
|
|
|
with Panda(p._serial, claim=False) as np:
|
|
|
|
|
bootstub_ids = (np.get_mcu_type(), np.get_usb_serial())
|
|
|
|
|
assert app_ids == bootstub_ids
|
|
|
|
|
|
|
|
|
|
# ensure we can flash app and it jumps to app
|
|
|
|
|
p.flash()
|
|
|
|
|
check_signature(p)
|
|
|
|
|
assert not p.bootstub
|
2022-08-15 20:11:49 -07:00
|
|
|
|
2024-01-18 17:44:32 -05:00
|
|
|
@pytest.mark.timeout(25)
|
2023-08-06 16:30:21 -07:00
|
|
|
def test_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
|
|
|
|
2024-01-18 17:44:32 -05:00
|
|
|
@pytest.mark.timeout(25)
|
2023-08-06 16:30:21 -07:00
|
|
|
def test_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)
|
|
|
|
|
|
2023-01-13 16:17:20 -08:00
|
|
|
with Panda(serial) as np:
|
|
|
|
|
assert np.bootstub
|
|
|
|
|
assert np._serial == serial
|
|
|
|
|
np.flash()
|
2022-08-02 22:28:54 -07:00
|
|
|
|
|
|
|
|
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)
|