| 1 |
#!/usr/bin/env python |
| 2 |
# -*- coding: UTF-8 -*- |
| 3 |
# |
| 4 |
# Copyright 2016-2018 Martin Olejar |
| 5 |
# Copyright 2019-2024 NXP |
| 6 |
# |
| 7 |
# SPDX-License-Identifier: BSD-3-Clause |
| 8 |
|
| 9 |
"""USB Mboot interface implementation.""" |
| 10 |
|
| 11 |
from ...mboot.protocol.bulk_protocol import MbootBulkProtocol |
| 12 |
from ...utils.interfaces.device.usb_device import UsbDevice |
| 13 |
|
| 14 |
USB_DEVICES = { |
| 15 |
# NAME | VID | PID |
| 16 |
"MKL27": (0x15A2, 0x0073), |
| 17 |
"LPC55": (0x1FC9, 0x0021), |
| 18 |
"IMXRT": (0x1FC9, 0x0135), |
| 19 |
"MXRT10": (0x15A2, 0x0073), # this is ID of flash-loader for RT101x |
| 20 |
"MXRT20": (0x15A2, 0x0073), # this is ID of flash-loader for RT102x |
| 21 |
"MXRT50": (0x15A2, 0x0073), # this is ID of flash-loader for RT105x |
| 22 |
"MXRT60": (0x15A2, 0x0073), # this is ID of flash-loader for RT106x |
| 23 |
"LPC55xx": (0x1FC9, 0x0020), |
| 24 |
"LPC551x": (0x1FC9, 0x0022), |
| 25 |
"RT6xx": (0x1FC9, 0x0021), |
| 26 |
"RT5xx_A": (0x1FC9, 0x0020), |
| 27 |
"RT5xx_B": (0x1FC9, 0x0023), |
| 28 |
"RT5xx_C": (0x1FC9, 0x0023), |
| 29 |
"RT5xx": (0x1FC9, 0x0023), |
| 30 |
"RT6xxM": (0x1FC9, 0x0024), |
| 31 |
"LPC553x": (0x1FC9, 0x0025), |
| 32 |
"MCXN9xx": (0x1FC9, 0x014F), |
| 33 |
"MCXA1xx": (0x1FC9, 0x0155), |
| 34 |
"MCXN23x": (0x1FC9, 0x0158), |
| 35 |
} |
| 36 |
|
| 37 |
|
| 38 |
class MbootUSBInterface(MbootBulkProtocol): |
| 39 |
"""USB interface.""" |
| 40 |
|
| 41 |
identifier = "usb" |
| 42 |
device: UsbDevice |
| 43 |
usb_devices = USB_DEVICES |
| 44 |
|
| 45 |
def __init__(self, device: UsbDevice) -> None: |
| 46 |
"""Initialize the MbootUSBInterface object. |
| 47 |
|
| 48 |
:param device: The device instance |
| 49 |
""" |
| 50 |
assert isinstance(device, UsbDevice) |
| 51 |
super().__init__(device=device) |
| 52 |
|
| 53 |
@property |
| 54 |
def name(self) -> str: |
| 55 |
"""Get the name of the device.""" |
| 56 |
assert isinstance(self.device, UsbDevice) |
| 57 |
for name, value in self.usb_devices.items(): |
| 58 |
if value[0] == self.device.vid and value[1] == self.device.pid: |
| 59 |
return name |
| 60 |
return "Unknown" |