2023-01-27 12:54:11 +08:00
|
|
|
import os
|
|
|
|
import enum
|
2024-02-25 05:56:28 +08:00
|
|
|
from typing import NamedTuple
|
2023-01-27 12:54:11 +08:00
|
|
|
|
|
|
|
BASEDIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "../")
|
2023-05-22 12:19:19 +08:00
|
|
|
FW_PATH = os.path.join(BASEDIR, "board/obj/")
|
2023-01-27 12:54:11 +08:00
|
|
|
|
2023-07-18 15:03:17 +08:00
|
|
|
USBPACKET_MAX_SIZE = 0x40
|
|
|
|
|
2023-01-27 12:54:11 +08:00
|
|
|
class McuConfig(NamedTuple):
|
|
|
|
mcu: str
|
2023-01-28 16:32:07 +08:00
|
|
|
mcu_idcode: int
|
2024-02-25 05:56:28 +08:00
|
|
|
sector_sizes: list[int]
|
2023-10-01 14:19:06 +08:00
|
|
|
sector_count: int # total sector count, used for MCU identification in DFU mode
|
2023-03-07 13:52:08 +08:00
|
|
|
uid_address: int
|
2023-01-27 12:54:11 +08:00
|
|
|
block_size: int
|
|
|
|
serial_number_address: int
|
|
|
|
app_address: int
|
2023-05-22 12:19:19 +08:00
|
|
|
app_fn: str
|
2023-01-27 12:54:11 +08:00
|
|
|
bootstub_address: int
|
2023-05-22 12:19:19 +08:00
|
|
|
bootstub_fn: str
|
2023-01-27 12:54:11 +08:00
|
|
|
|
2023-09-15 03:49:59 +08:00
|
|
|
def sector_address(self, i):
|
|
|
|
# assume bootstub is in sector 0
|
|
|
|
return self.bootstub_address + sum(self.sector_sizes[:i])
|
|
|
|
|
2024-02-17 14:58:01 +08:00
|
|
|
F4Config = McuConfig(
|
|
|
|
"STM32F4",
|
|
|
|
0x463,
|
|
|
|
[0x4000 for _ in range(4)] + [0x10000] + [0x20000 for _ in range(11)],
|
|
|
|
16,
|
2023-03-07 13:52:08 +08:00
|
|
|
0x1FFF7A10,
|
2023-01-27 12:54:11 +08:00
|
|
|
0x800,
|
|
|
|
0x1FFF79C0,
|
|
|
|
0x8004000,
|
2023-05-22 12:19:19 +08:00
|
|
|
"panda.bin.signed",
|
2023-01-27 12:54:11 +08:00
|
|
|
0x8000000,
|
2023-05-22 12:19:19 +08:00
|
|
|
"bootstub.panda.bin",
|
2023-01-27 12:54:11 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
H7Config = McuConfig(
|
|
|
|
"STM32H7",
|
2023-01-28 16:32:07 +08:00
|
|
|
0x483,
|
2023-09-15 03:58:56 +08:00
|
|
|
[0x20000 for _ in range(7)],
|
2023-10-01 14:19:06 +08:00
|
|
|
8,
|
2023-03-07 13:52:08 +08:00
|
|
|
0x1FF1E800,
|
2023-01-27 12:54:11 +08:00
|
|
|
0x400,
|
|
|
|
# there is an 8th sector, but we use that for the provisioning chunk, so don't program over that!
|
|
|
|
0x080FFFC0,
|
|
|
|
0x8020000,
|
2023-05-22 12:19:19 +08:00
|
|
|
"panda_h7.bin.signed",
|
2023-01-27 12:54:11 +08:00
|
|
|
0x8000000,
|
2023-05-22 12:19:19 +08:00
|
|
|
"bootstub.panda_h7.bin",
|
2023-01-27 12:54:11 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
@enum.unique
|
|
|
|
class McuType(enum.Enum):
|
|
|
|
F4 = F4Config
|
|
|
|
H7 = H7Config
|
|
|
|
|
|
|
|
@property
|
|
|
|
def config(self):
|
|
|
|
return self.value
|
2023-03-07 13:52:08 +08:00
|
|
|
|
|
|
|
MCU_TYPE_BY_IDCODE = {m.config.mcu_idcode: m for m in McuType}
|