From 6b54f3ce1cf6c7e215f313314ad57a6bf0f58478 Mon Sep 17 00:00:00 2001 From: Erovia Date: Tue, 12 May 2020 21:59:09 +0200 Subject: [PATCH] CLI: Tune doctor's udev rule checking to match #8750 --- lib/python/qmk/cli/doctor.py | 50 +++++++++++++++++++++++++++++------- tmk_core/avr.mk | 2 +- 2 files changed, 42 insertions(+), 10 deletions(-) diff --git a/lib/python/qmk/cli/doctor.py b/lib/python/qmk/cli/doctor.py index 3c4624837..636e49dab 100755 --- a/lib/python/qmk/cli/doctor.py +++ b/lib/python/qmk/cli/doctor.py @@ -27,9 +27,24 @@ ESSENTIAL_BINARIES = { ESSENTIAL_SUBMODULES = ['lib/chibios', 'lib/lufa'] -def _udev_rule(vid, pid=None): +def _udev_rule(vid, pid=None, *args): """ Helper function that return udev rules """ + rule = "" + if pid: + rule = 'SUBSYSTEMS=="usb", ATTRS{idVendor}=="%s", ATTRS{idProduct}=="%s", TAG+="uaccess", RUN{builtin}+="uaccess"' % (vid, pid) + else: + rule = 'SUBSYSTEMS=="usb", ATTRS{idVendor}=="%s", TAG+="uaccess", RUN{builtin}+="uaccess"' % vid + if args: + rule = ', '.join([rule, *args]) + return rule + + +def _deprecated_udev_rule(vid, pid=None): + """ Helper function that return udev rules + + Note: these are no longer the recommended rules, this is just used to check for them + """ if pid: return 'SUBSYSTEMS=="usb", ATTRS{idVendor}=="%s", ATTRS{idProduct}=="%s", MODE:="0666"' % (vid, pid) else: @@ -128,10 +143,24 @@ def check_udev_rules(): udev_dir = Path("/etc/udev/rules.d/") desired_rules = { 'dfu': {_udev_rule("03eb", "2ff4"), _udev_rule("03eb", "2ffb"), _udev_rule("03eb", "2ff0")}, - 'tmk': {_udev_rule("feed")}, - 'input_club': {_udev_rule("1c11")}, + 'input_club': {_udev_rule("1c11", "b007")}, 'stm32': {_udev_rule("1eaf", "0003"), _udev_rule("0483", "df11")}, - 'caterina': {'ATTRS{idVendor}=="2a03", ENV{ID_MM_DEVICE_IGNORE}="1"', 'ATTRS{idVendor}=="2341", ENV{ID_MM_DEVICE_IGNORE}="1"'}, + 'bootloadhid': {_udev_rule("16c0", "05df")}, + 'caterina': { + _udev_rule("2341", "0036", 'ENV{ID_MM_DEVICE_IGNORE}="1"'), + _udev_rule("1b4f", "9205", 'ENV{ID_MM_DEVICE_IGNORE}="1"'), + _udev_rule("1b4f", "9203", 'ENV{ID_MM_DEVICE_IGNORE}="1"'), + _udev_rule("2a03", "0036", 'ENV{ID_MM_DEVICE_IGNORE}="1"') + } + } + + # These rules are no longer recommended, only use them to check for their presence. + deprecated_rules = { + 'dfu': {_deprecated_udev_rule("03eb", "2ff4"), _deprecated_udev_rule("03eb", "2ffb"), _deprecated_udev_rule("03eb", "2ff0")}, + 'input_club': {_deprecated_udev_rule("1c11")}, + 'stm32': {_deprecated_udev_rule("1eaf", "0003"), _deprecated_udev_rule("0483", "df11")}, + 'bootloadhid': {_deprecated_udev_rule("16c0", "05df")}, + 'caterina': {'ATTRS{idVendor}=="2a03", ENV{ID_MM_DEVICE_IGNORE}="1"', 'ATTRS{idVendor}=="2341", ENV{ID_MM_DEVICE_IGNORE}="1"'} } if udev_dir.exists(): @@ -147,12 +176,15 @@ def check_udev_rules(): # Check if the desired rules are among the currently present rules for bootloader, rules in desired_rules.items(): + # For caterina, check if ModemManager is running + if bootloader == "caterina": + if check_modem_manager(): + ok = False + cli.log.warn("{bg_yellow}Detected ModemManager without the necessary udev rules. Please either disable it or set the appropriate udev rules if you are using a Pro Micro.") if not rules.issubset(current_rules): - # If the rules for catalina are not present, check if ModemManager is running - if bootloader == "caterina": - if check_modem_manager(): - ok = False - cli.log.warn("{bg_yellow}Detected ModemManager without udev rules. Please either disable it or set the appropriate udev rules if you are using a Pro Micro.") + deprecated_rule = deprecated_rules.get(bootloader) + if deprecated_rule and deprecated_rule.issubset(current_rules): + cli.log.warn("{bg_yellow}Found old, deprecated udev rules for '%s' boards. The new rules on https://docs.qmk.fm/#/faq_build?id=linux-udev-rules offer better security with the same functionality.", bootloader) else: cli.log.warn("{bg_yellow}Missing udev rules for '%s' boards. You'll need to use `sudo` in order to flash them.", bootloader) diff --git a/tmk_core/avr.mk b/tmk_core/avr.mk index 9118e497d..04ae16224 100644 --- a/tmk_core/avr.mk +++ b/tmk_core/avr.mk @@ -169,7 +169,7 @@ define EXEC_AVRDUDE USB=`comm -13 $$TMP1 $$TMP2 | $(GREP) -o '/dev/tty.*'`; \ mv $$TMP2 $$TMP1; \ done; \ - rm $$TMP2 $$TMP1; \ + rm $$TMP1; \ echo ""; \ echo "Device $$USB has appeared; assuming it is the controller."; \ if $(GREP) -q -s 'MINGW\|MSYS' /proc/version; then \