Skip to content

Commit

Permalink
CLI: Tune doctor's udev rule checking to match qmk#8750
Browse files Browse the repository at this point in the history
  • Loading branch information
Erovia authored and skullydazed committed May 15, 2020
1 parent c3aaed8 commit 6b54f3c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 10 deletions.
50 changes: 41 additions & 9 deletions lib/python/qmk/cli/doctor.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,24 @@
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:
Expand Down Expand Up @@ -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():
Expand All @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion tmk_core/avr.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down

0 comments on commit 6b54f3c

Please sign in to comment.