2022-08-16 11:11:49 +08:00
|
|
|
import os
|
2022-08-03 13:28:54 +08:00
|
|
|
import time
|
2019-12-10 02:54:48 +08:00
|
|
|
|
2023-01-27 12:54:11 +08:00
|
|
|
from panda import Panda, PandaDFU, McuType, BASEDIR
|
2017-07-30 22:59:14 +08:00
|
|
|
|
2019-12-10 02:54:48 +08:00
|
|
|
|
2023-03-23 12:38:37 +08:00
|
|
|
def check_signature(p):
|
|
|
|
assert not p.bootstub, "Flashed firmware not booting. Stuck in bootstub."
|
|
|
|
assert p.up_to_date()
|
|
|
|
|
2023-01-29 06:41:52 +08:00
|
|
|
# TODO: make more comprehensive bootstub tests and run on a few production ones + current
|
|
|
|
# TODO: also test release-signed app
|
2022-08-16 11:11:49 +08:00
|
|
|
def test_a_known_bootstub(p):
|
2023-01-27 12:54:11 +08:00
|
|
|
"""
|
|
|
|
Test that compiled app can work with known production bootstub
|
|
|
|
"""
|
|
|
|
known_bootstubs = {
|
2023-01-29 06:41:52 +08:00
|
|
|
# covers the two cases listed in Panda.connect
|
|
|
|
McuType.F4: [
|
|
|
|
# case A - no bcdDevice or panda type, has to assume F4
|
|
|
|
"bootstub_f4_first_dos_production.panda.bin",
|
|
|
|
|
|
|
|
# case B - just bcdDevice
|
|
|
|
"bootstub_f4_only_bcd.panda.bin",
|
|
|
|
],
|
|
|
|
McuType.H7: ["bootstub.panda_h7.bin"],
|
2023-01-27 12:54:11 +08:00
|
|
|
}
|
2022-08-16 11:11:49 +08:00
|
|
|
|
2023-01-29 06: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-16 11:11:49 +08:00
|
|
|
|
2023-01-29 06:41:52 +08:00
|
|
|
p.reset(enter_bootstub=True)
|
|
|
|
p.reset(enter_bootloader=True)
|
2022-08-16 11:11:49 +08:00
|
|
|
|
2023-04-17 05:43:58 +08:00
|
|
|
dfu_serial = p.get_dfu_serial()
|
2023-01-29 06:41:52 +08:00
|
|
|
assert Panda.wait_for_dfu(dfu_serial, timeout=30)
|
2022-08-16 11:11:49 +08:00
|
|
|
|
2023-01-29 06: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-22 11:05:21 +08:00
|
|
|
dfu.reset()
|
2023-01-29 06: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-16 11:11:49 +08:00
|
|
|
|
|
|
|
def test_b_recover(p):
|
2019-04-10 05:09:18 +08:00
|
|
|
assert p.recover(timeout=30)
|
2022-08-03 08:05:47 +08:00
|
|
|
check_signature(p)
|
2019-12-10 02:54:48 +08:00
|
|
|
|
2022-08-16 11:11:49 +08:00
|
|
|
def test_c_flash(p):
|
2022-08-03 13:28:54 +08:00
|
|
|
# test flash from bootstub
|
|
|
|
serial = p._serial
|
2022-11-04 08:24:28 +08:00
|
|
|
assert serial is not None
|
2022-08-03 13:28:54 +08:00
|
|
|
p.reset(enter_bootstub=True)
|
|
|
|
p.close()
|
|
|
|
time.sleep(2)
|
|
|
|
|
2023-01-14 08:17:20 +08:00
|
|
|
with Panda(serial) as np:
|
|
|
|
assert np.bootstub
|
|
|
|
assert np._serial == serial
|
|
|
|
np.flash()
|
2022-08-03 13:28:54 +08:00
|
|
|
|
|
|
|
p.reconnect()
|
|
|
|
p.reset()
|
|
|
|
check_signature(p)
|
|
|
|
|
|
|
|
# test flash from app
|
2017-07-30 22:59:14 +08:00
|
|
|
p.flash()
|
2022-08-03 08:05:47 +08:00
|
|
|
check_signature(p)
|