Merge pull request #6194 from jepler/revamp-duplicate-usb-check
Improve the USB vid:pid duplicate checker
This commit is contained in:
commit
fcde108d03
@ -1,6 +1,7 @@
|
|||||||
LD_FILE = boards/samd51x20-bootloader-external-flash.ld
|
LD_FILE = boards/samd51x20-bootloader-external-flash.ld
|
||||||
USB_VID = 0x1b4f
|
USB_VID = 0x1b4f
|
||||||
USB_PID = 0x0020 # Used by uf2 bootloader
|
# Used by uf2 bootloader
|
||||||
|
USB_PID = 0x0020
|
||||||
USB_PRODUCT = "SparkFun MicroMod SAMD51 Processor"
|
USB_PRODUCT = "SparkFun MicroMod SAMD51 Processor"
|
||||||
USB_MANUFACTURER = "SparkFun Electronics"
|
USB_MANUFACTURER = "SparkFun Electronics"
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
LD_FILE = boards/samd51x20-bootloader-external-flash.ld
|
LD_FILE = boards/samd51x20-bootloader-external-flash.ld
|
||||||
USB_VID = 0x1b4f
|
USB_VID = 0x1b4f
|
||||||
USB_PID = 0x0016 # Used by uf2 bootloader
|
# Used by uf2 bootloader
|
||||||
|
USB_PID = 0x0016
|
||||||
USB_PRODUCT = "SparkFun SAMD51 Thing+"
|
USB_PRODUCT = "SparkFun SAMD51 Thing+"
|
||||||
USB_MANUFACTURER = "SparkFun Electronics"
|
USB_MANUFACTURER = "SparkFun Electronics"
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
USB_VID = 0x2b04
|
USB_VID = 0x2b04
|
||||||
USB_PID = 0xc00e # argon is 0xc00c
|
# argon is 0xc00c
|
||||||
|
USB_PID = 0xc00e
|
||||||
USB_PRODUCT = "Xenon"
|
USB_PRODUCT = "Xenon"
|
||||||
USB_MANUFACTURER = "Particle"
|
USB_MANUFACTURER = "Particle"
|
||||||
|
|
||||||
|
@ -24,58 +24,41 @@
|
|||||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
# THE SOFTWARE.
|
# THE SOFTWARE.
|
||||||
|
|
||||||
|
from collections import defaultdict
|
||||||
import argparse
|
import argparse
|
||||||
import pathlib
|
import pathlib
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
DEFAULT_IGNORELIST = [
|
DEFAULT_CLUSTERLIST = {
|
||||||
"circuitplayground_express",
|
"0x04D8:0xEC44": ["pycubed", "pycubed_mram", "pycubed_mram_v05", "pycubed_v05"],
|
||||||
"circuitplayground_express_crickit",
|
"0x1B4F:0x8D24": ["sparkfun_qwiic_micro_no_flash", "sparkfun_qwiic_micro_with_flash"],
|
||||||
"circuitplayground_express_displayio",
|
"0x1D50:0x6153": [
|
||||||
"pycubed",
|
"jpconstantineau_pykey18",
|
||||||
"pycubed_mram",
|
"jpconstantineau_pykey44",
|
||||||
"pycubed_v05",
|
"jpconstantineau_pykey60",
|
||||||
"pycubed_mram_v05",
|
"jpconstantineau_pykey87",
|
||||||
"pygamer",
|
],
|
||||||
"pygamer_advance",
|
"0x239A:0x8019": [
|
||||||
"trinket_m0",
|
"circuitplayground_express",
|
||||||
"trinket_m0_haxpress",
|
"circuitplayground_express_crickit",
|
||||||
"sparkfun_qwiic_micro_with_flash",
|
"circuitplayground_express_displayio",
|
||||||
"sparkfun_qwiic_micro_no_flash",
|
],
|
||||||
"feather_m0_express",
|
"0x239A:0x801F": ["trinket_m0_haxpress", "trinket_m0"],
|
||||||
"feather_m0_supersized",
|
"0x239A:0x8021": ["metro_m4_express", "cp32-m4"],
|
||||||
"cp32-m4",
|
"0x239A:0x8023": ["feather_m0_express", "feather_m0_supersized"],
|
||||||
"metro_m4_express",
|
"0x239A:0x80A6": ["espressif_esp32s2_devkitc_1_n4r2", "espressif_saola_1_wrover"],
|
||||||
"unexpectedmaker_feathers2",
|
"0x239A:0x80AC": ["unexpectedmaker_feathers2", "unexpectedmaker_feathers2_prerelease"],
|
||||||
"unexpectedmaker_feathers2_prerelease",
|
"0x239A:0x80C8": ["espressif_kaluga_1", "espressif_kaluga_1.3"],
|
||||||
"espressif_kaluga_1",
|
"0x303A:0x7003": [
|
||||||
"espressif_kaluga_1.3",
|
"espressif_esp32s3_devkitc_1_n8",
|
||||||
"espressif_esp32s2_devkitc_1_n4",
|
"espressif_esp32s3_devkitc_1_n8r2",
|
||||||
"espressif_esp32s2_devkitc_1_n4r2",
|
"espressif_esp32s3_devkitc_1_n8r8",
|
||||||
"espressif_esp32s3_devkitc_1_n8",
|
],
|
||||||
"espressif_esp32s3_devkitc_1_n8r2",
|
"0x303A:0x7009": ["espressif_esp32s2_devkitc_1_n4", "espressif_esp32s2_devkitc_1_n4r2"],
|
||||||
"espressif_esp32s3_devkitc_1_n8r8",
|
}
|
||||||
"espressif_saola_1_wrover",
|
|
||||||
"jpconstantineau_pykey18",
|
|
||||||
"jpconstantineau_pykey44",
|
|
||||||
"jpconstantineau_pykey60",
|
|
||||||
"jpconstantineau_pykey87",
|
|
||||||
]
|
|
||||||
|
|
||||||
cli_parser = argparse.ArgumentParser(description="USB VID/PID Duplicate Checker")
|
cli_parser = argparse.ArgumentParser(description="USB VID/PID Duplicate Checker")
|
||||||
cli_parser.add_argument(
|
|
||||||
"--ignorelist",
|
|
||||||
dest="ignorelist",
|
|
||||||
nargs="?",
|
|
||||||
action="store",
|
|
||||||
default=DEFAULT_IGNORELIST,
|
|
||||||
help=(
|
|
||||||
"Board names to ignore duplicate VID/PID combinations. Pass an empty "
|
|
||||||
"string to disable all duplicate ignoring. Defaults are: "
|
|
||||||
f"{', '.join(DEFAULT_IGNORELIST)}"
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def configboard_files():
|
def configboard_files():
|
||||||
@ -88,48 +71,49 @@ def configboard_files():
|
|||||||
return working_dir.glob("ports/**/boards/**/mpconfigboard.mk")
|
return working_dir.glob("ports/**/boards/**/mpconfigboard.mk")
|
||||||
|
|
||||||
|
|
||||||
def check_vid_pid(files, ignorelist):
|
def check_vid_pid(files, clusterlist):
|
||||||
"""Compiles a list of USB VID & PID values for all boards, and checks
|
"""Compiles a list of USB VID & PID values for all boards, and checks
|
||||||
for duplicates. Exits with ``sys.exit()`` (non-zero exit code)
|
for duplicates. Exits with ``sys.exit()`` (non-zero exit code)
|
||||||
if duplicates are found, and lists the duplicates.
|
if duplicates are found, and lists the duplicates.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
duplicates_found = False
|
vid_pattern = re.compile(r"^USB_VID\s*=\s*(.*)", flags=re.M)
|
||||||
|
pid_pattern = re.compile(r"^USB_PID\s*=\s*(.*)", flags=re.M)
|
||||||
usb_ids = {}
|
usb_pattern = re.compile(r"^CIRCUITPY_USB\s*=\s*0$|^IDF_TARGET = esp32c3$", flags=re.M)
|
||||||
|
|
||||||
vid_pattern = re.compile(r"^USB_VID\s*\=\s*(.*)", flags=re.M)
|
|
||||||
pid_pattern = re.compile(r"^USB_PID\s*\=\s*(.*)", flags=re.M)
|
|
||||||
|
|
||||||
|
usb_ids = defaultdict(set)
|
||||||
for board_config in files:
|
for board_config in files:
|
||||||
src_text = board_config.read_text()
|
src_text = board_config.read_text()
|
||||||
|
|
||||||
usb_vid = vid_pattern.search(src_text)
|
usb_vid = vid_pattern.search(src_text)
|
||||||
usb_pid = pid_pattern.search(src_text)
|
usb_pid = pid_pattern.search(src_text)
|
||||||
|
non_usb = usb_pattern.search(src_text)
|
||||||
board_name = board_config.parts[-2]
|
board_name = board_config.parts[-2]
|
||||||
|
|
||||||
board_ignorelisted = False
|
|
||||||
if board_name in ignorelist:
|
|
||||||
board_ignorelisted = True
|
|
||||||
board_name += " (ignorelisted)"
|
|
||||||
|
|
||||||
if usb_vid and usb_pid:
|
if usb_vid and usb_pid:
|
||||||
id_group = f"{usb_vid.group(1)}:{usb_pid.group(1)}"
|
id_group = f"0x{int(usb_vid.group(1), 16):04X}:0x{int(usb_pid.group(1), 16):04X}"
|
||||||
if id_group not in usb_ids:
|
elif non_usb:
|
||||||
usb_ids[id_group] = {"boards": [board_name], "duplicate": False}
|
continue
|
||||||
|
else:
|
||||||
|
raise SystemExit(f"Could not parse {board_config}")
|
||||||
|
|
||||||
|
usb_ids[id_group].add(board_name)
|
||||||
|
|
||||||
|
duplicates = []
|
||||||
|
for key, boards in usb_ids.items():
|
||||||
|
if len(boards) == 1:
|
||||||
|
continue
|
||||||
|
|
||||||
|
# It is a cluster
|
||||||
|
cluster = set(clusterlist.get(key, []))
|
||||||
|
if cluster != boards:
|
||||||
|
if key == "":
|
||||||
|
duplicates.append(f"- Non-USB:\n" f" Boards: {', '.join(sorted(boards))}")
|
||||||
else:
|
else:
|
||||||
usb_ids[id_group]["boards"].append(board_name)
|
duplicates.append(f"- VID/PID: {key}\n" f" Boards: {', '.join(sorted(boards))}")
|
||||||
if not board_ignorelisted:
|
|
||||||
usb_ids[id_group]["duplicate"] = True
|
|
||||||
duplicates_found = True
|
|
||||||
|
|
||||||
if duplicates_found:
|
|
||||||
duplicates = ""
|
|
||||||
for key, value in usb_ids.items():
|
|
||||||
if value["duplicate"]:
|
|
||||||
duplicates += f"- VID/PID: {key}\n" f" Boards: {', '.join(value['boards'])}\n"
|
|
||||||
|
|
||||||
|
if duplicates:
|
||||||
|
duplicates = "\n".join(duplicates)
|
||||||
duplicate_message = (
|
duplicate_message = (
|
||||||
f"Duplicate VID/PID usage found!\n{duplicates}\n"
|
f"Duplicate VID/PID usage found!\n{duplicates}\n"
|
||||||
f"If you are open source maker, then you can request a PID from http://pid.codes\n"
|
f"If you are open source maker, then you can request a PID from http://pid.codes\n"
|
||||||
@ -144,7 +128,6 @@ if __name__ == "__main__":
|
|||||||
arguments = cli_parser.parse_args()
|
arguments = cli_parser.parse_args()
|
||||||
|
|
||||||
print("Running USB VID/PID Duplicate Checker...")
|
print("Running USB VID/PID Duplicate Checker...")
|
||||||
print(f"Ignoring the following boards: {', '.join(arguments.ignorelist)}", end="\n\n")
|
|
||||||
|
|
||||||
board_files = configboard_files()
|
board_files = configboard_files()
|
||||||
check_vid_pid(board_files, arguments.ignorelist)
|
check_vid_pid(board_files, DEFAULT_CLUSTERLIST)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user