lp-dp 2023-05-25T03:10:00 for EON/C2

version: lp-dp v0.9.3 for EON/C2
date: 2023-05-25T03:10:00
commit: 409000e6091be63a423d23e7940d569fed28497e
This commit is contained in:
Vehicle Researcher
2023-05-25 03:02:58 +00:00
parent 6def7af391
commit 8f67934f80
144 changed files with 3630 additions and 26174 deletions
+12 -7
View File
@@ -14,7 +14,7 @@ from typing import Optional
from itertools import accumulate
from .base import BaseHandle
from .constants import McuType
from .constants import FW_PATH, McuType
from .dfu import PandaDFU
from .isotp import isotp_send, isotp_recv
from .spi import PandaSpiHandle, PandaSpiException
@@ -151,7 +151,7 @@ class Panda:
SAFETY_NOOUTPUT = 19
SAFETY_HONDA_BOSCH = 20
SAFETY_VOLKSWAGEN_PQ = 21
SAFETY_SUBARU_LEGACY = 22
SAFETY_SUBARU_PREGLOBAL = 22
SAFETY_HYUNDAI_LEGACY = 23
SAFETY_HYUNDAI_COMMUNITY = 24
SAFETY_STELLANTIS = 25
@@ -239,6 +239,8 @@ class Panda:
FLAG_GM_HW_CAM = 1
FLAG_GM_HW_CAM_LONG = 2
FLAG_FORD_LONG_CONTROL = 1
def __init__(self, serial: Optional[str] = None, claim: bool = True, disable_checks: bool = True):
self._connect_serial = serial
self._disable_checks = disable_checks
@@ -403,14 +405,16 @@ class Panda:
return []
def reset(self, enter_bootstub=False, enter_bootloader=False, reconnect=True):
# no response is expected since it resets right away
timeout = 5000 if isinstance(self._handle, PandaSpiHandle) else 15000
try:
if enter_bootloader:
self._handle.controlWrite(Panda.REQUEST_IN, 0xd1, 0, 0, b'')
self._handle.controlWrite(Panda.REQUEST_IN, 0xd1, 0, 0, b'', timeout=timeout)
else:
if enter_bootstub:
self._handle.controlWrite(Panda.REQUEST_IN, 0xd1, 1, 0, b'')
self._handle.controlWrite(Panda.REQUEST_IN, 0xd1, 1, 0, b'', timeout=timeout)
else:
self._handle.controlWrite(Panda.REQUEST_IN, 0xd8, 0, 0, b'')
self._handle.controlWrite(Panda.REQUEST_IN, 0xd8, 0, 0, b'', timeout=timeout)
except Exception:
pass
if not enter_bootloader and reconnect:
@@ -485,7 +489,7 @@ class Panda:
def flash(self, fn=None, code=None, reconnect=True):
if not fn:
fn = self._mcu_type.config.app_path
fn = os.path.join(FW_PATH, self._mcu_type.config.app_fn)
assert os.path.isfile(fn)
logging.debug("flash: main version is %s", self.get_version())
if not self.bootstub:
@@ -536,7 +540,8 @@ class Panda:
def up_to_date(self) -> bool:
current = self.get_signature()
expected = Panda.get_signature_from_firmware(self.get_mcu_type().config.app_path)
fn = os.path.join(FW_PATH, self.get_mcu_type().config.app_fn)
expected = Panda.get_signature_from_firmware(fn)
return (current == expected)
def call_control_api(self, msg):
+7 -7
View File
@@ -3,7 +3,7 @@ import enum
from typing import List, NamedTuple
BASEDIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "../")
FW_PATH = os.path.join(BASEDIR, "board/obj/")
class McuConfig(NamedTuple):
mcu: str
@@ -13,9 +13,9 @@ class McuConfig(NamedTuple):
sector_sizes: List[int]
serial_number_address: int
app_address: int
app_path: str
app_fn: str
bootstub_address: int
bootstub_path: str
bootstub_fn: str
Fx = (
0x1FFF7A10,
@@ -23,9 +23,9 @@ Fx = (
[0x4000 for _ in range(4)] + [0x10000] + [0x20000 for _ in range(11)],
0x1FFF79C0,
0x8004000,
os.path.join(BASEDIR, "board", "obj", "panda.bin.signed"),
"panda.bin.signed",
0x8000000,
os.path.join(BASEDIR, "board", "obj", "bootstub.panda.bin"),
"bootstub.panda.bin",
)
F2Config = McuConfig("STM32F2", 0x411, *Fx)
F4Config = McuConfig("STM32F4", 0x463, *Fx)
@@ -39,9 +39,9 @@ H7Config = McuConfig(
[0x20000 for _ in range(7)],
0x080FFFC0,
0x8020000,
os.path.join(BASEDIR, "board", "obj", "panda_h7.bin.signed"),
"panda_h7.bin.signed",
0x8000000,
os.path.join(BASEDIR, "board", "obj", "bootstub.panda_h7.bin"),
"bootstub.panda_h7.bin",
)
@enum.unique
+5 -4
View File
@@ -1,3 +1,4 @@
import os
import usb1
import struct
import binascii
@@ -6,7 +7,7 @@ from typing import List, Optional
from .base import BaseSTBootloaderHandle
from .spi import STBootloaderSPIHandle, PandaSpiException
from .usb import STBootloaderUSBHandle
from .constants import McuType
from .constants import FW_PATH, McuType
class PandaDFU:
@@ -110,10 +111,10 @@ class PandaDFU:
self._handle.erase_bootstub()
self._handle.erase_app()
self._handle.program(self._mcu_type.config.bootstub_address, code_bootstub)
self.reset()
def recover(self):
with open(self._mcu_type.config.bootstub_path, "rb") as f:
fn = os.path.join(FW_PATH, self._mcu_type.config.bootstub_fn)
with open(fn, "rb") as f:
code = f.read()
self.program_bootstub(code)
self.reset()
+18 -8
View File
@@ -58,7 +58,14 @@ class SpiDevice:
"""
Provides locked, thread-safe access to a panda's SPI interface.
"""
def __init__(self, speed):
# 50MHz is the max of the 845. older rev comma three
# may not support the full 50MHz
MAX_SPEED = 50000000
def __init__(self, speed=MAX_SPEED):
assert speed <= self.MAX_SPEED
if not os.path.exists(DEV_PATH):
raise PandaSpiUnavailable(f"SPI device not found: {DEV_PATH}")
if spidev is None:
@@ -87,9 +94,7 @@ class PandaSpiHandle(BaseHandle):
A class that mimics a libusb1 handle for panda SPI communications.
"""
def __init__(self):
# 50MHz is the max of the 845. older rev comma three
# may not support the full 50MHz
self.dev = SpiDevice(50000000)
self.dev = SpiDevice()
# helpers
def _calc_checksum(self, data: List[int]) -> int:
@@ -115,8 +120,11 @@ class PandaSpiHandle(BaseHandle):
logging.debug("starting transfer: endpoint=%d, max_rx_len=%d", endpoint, max_rx_len)
logging.debug("==============================================")
n = 0
start_time = time.monotonic()
exc = PandaSpiException()
for n in range(MAX_XFER_RETRY_COUNT):
while (time.monotonic() - start_time) < timeout*1e-3:
n += 1
logging.debug("\ntry #%d", n+1)
try:
logging.debug("- send header")
@@ -124,16 +132,18 @@ class PandaSpiHandle(BaseHandle):
packet += bytes([reduce(lambda x, y: x^y, packet) ^ CHECKSUM_START])
spi.xfer2(packet)
to = timeout - (time.monotonic() - start_time)*1e3
logging.debug("- waiting for header ACK")
self._wait_for_ack(spi, HACK, timeout, 0x11)
self._wait_for_ack(spi, HACK, int(to), 0x11)
# send data
logging.debug("- sending data")
packet = bytes([*data, self._calc_checksum(data)])
spi.xfer2(packet)
to = timeout - (time.monotonic() - start_time)*1e3
logging.debug("- waiting for data ACK")
self._wait_for_ack(spi, DACK, timeout, 0x13)
self._wait_for_ack(spi, DACK, int(to), 0x13)
# get response length, then response
response_len_bytes = bytes(spi.xfer2(b"\x00" * 2))
@@ -149,7 +159,7 @@ class PandaSpiHandle(BaseHandle):
return dat[:-1]
except PandaSpiException as e:
exc = e
logging.debug("SPI transfer failed, %d retries left", MAX_XFER_RETRY_COUNT - n - 1, exc_info=True)
logging.debug("SPI transfer failed, retrying", exc_info=True)
raise exc
# libusb1 functions