Udev rule is not being applied

2019-09-10 17:05发布

问题:

I am running a Linux chroot environment on an Android device and I am attempting to communicate with an Atmel atmega2560 based (Arduino Mega derived) microcontroller. Doing "ls -ld /dev/ttyACM0" shows the following permissions for the modem:

crw------- 1 root root 166, 0 Feb 11 22:28 /dev/ttyACM0

"lsusb" tells me:

Bus 003 Devices: ID 03eb:204b Atmel Corp. LUFA USB to Serial Adpater Project

"udevadm info --attribute-walk --name=ttyACM0" says:

Udevadm info starts with the device specified by the devpath and then
walks up the chain of parent devices. It prints for every device
found, all possible attributes in the udev rules key format.
A rule to match, can be composed by the attributes of the device
and the attributes from one single parent device.

  looking at device '/devices/platform/sunxi_hcd_host0/usb3/3-1/3-1:1.0/tty/ttyACM0':
    KERNEL=="ttyACM0"
    SUBSYSTEM=="tty"
    DRIVER==""

  looking at parent device '/devices/platform/sunxi_hcd_host0/usb3/3-1/3-1:1.0':
    KERNELS=="3-1:1.0"
    SUBSYSTEMS=="usb"
    DRIVERS=="cdc_acm"
    ATTRS{bInterfaceClass}=="02"
    ATTRS{bmCapabilities}=="6"
    ATTRS{bInterfaceSubClass}=="02"
    ATTRS{bInterfaceProtocol}=="01"
    ATTRS{bNumEndpoints}=="01"
    ATTRS{supports_autosuspend}=="1"
    ATTRS{bAlternateSetting}==" 0"
    ATTRS{bInterfaceNumber}=="00"

  looking at parent device '/devices/platform/sunxi_hcd_host0/usb3/3-1':
    KERNELS=="3-1"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{bDeviceSubClass}=="00"
    ATTRS{bDeviceProtocol}=="00"
    ATTRS{devpath}=="1"
    ATTRS{idVendor}=="03eb"
    ATTRS{speed}=="12"
    ATTRS{bNumInterfaces}==" 2"
    ATTRS{bConfigurationValue}=="1"
    ATTRS{bMaxPacketSize0}=="8"
    ATTRS{busnum}=="3"
    ATTRS{devnum}=="20"
    ATTRS{configuration}==""
    ATTRS{bMaxPower}=="200mA"
    ATTRS{authorized}=="1"
    ATTRS{bmAttributes}=="c0"
    ATTRS{bNumConfigurations}=="1"
    ATTRS{maxchild}=="0"
    ATTRS{bcdDevice}=="8888"
    ATTRS{avoid_reset_quirk}=="0"
    ATTRS{quirks}=="0x0"
    ATTRS{serial}=="55330343534351415012"
    ATTRS{version}==" 1.10"
    ATTRS{urbnum}=="12"
    ATTRS{manufacturer}=="RRD (www.ru"
    ATTRS{removable}=="unknown"
    ATTRS{idProduct}=="204b"
    ATTRS{bDeviceClass}=="02"
    ATTRS{product}=="RUMBA - ATmega 2560 co"

  looking at parent device '/devices/platform/sunxi_hcd_host0/usb3':
    KERNELS=="usb3"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{bDeviceSubClass}=="00"
    ATTRS{bDeviceProtocol}=="00"
    ATTRS{devpath}=="0"
    ATTRS{idVendor}=="1d6b"
    ATTRS{speed}=="12"
    ATTRS{bNumInterfaces}==" 1"
    ATTRS{bConfigurationValue}=="1"
    ATTRS{bMaxPacketSize0}=="64"
    ATTRS{authorized_default}=="1"
    ATTRS{busnum}=="3"
    ATTRS{devnum}=="1"
    ATTRS{configuration}==""
    ATTRS{bMaxPower}=="  0mA"
    ATTRS{authorized}=="1"
    ATTRS{bmAttributes}=="e0"
    ATTRS{bNumConfigurations}=="1"
    ATTRS{maxchild}=="1"
    ATTRS{bcdDevice}=="0304"
    ATTRS{avoid_reset_quirk}=="0"
    ATTRS{quirks}=="0x0"
    ATTRS{serial}=="sunxi_hcd_host0"
    ATTRS{version}==" 1.10"
    ATTRS{urbnum}=="777"
    ATTRS{manufacturer}=="Linux 3.4.39 sunxi_hcd-hcd"
    ATTRS{removable}=="unknown"
    ATTRS{idProduct}=="0001"
    ATTRS{bDeviceClass}=="09"
    ATTRS{product}=="sunxi_hcd host driver"

  looking at parent device '/devices/platform/sunxi_hcd_host0':
    KERNELS=="sunxi_hcd_host0"
    SUBSYSTEMS=="platform"
    DRIVERS=="sunxi_hcd_host0"

  looking at parent device '/devices/platform':
    KERNELS=="platform"
    SUBSYSTEMS==""
    DRIVERS==""

Therefore, I created the file '/etc/udev/rules.d/99-arduino.rules' which contains:

SUBSYSTEMS=="usb", ATTRS{idVendor}=="03eb", ATTRS{idProduct}=="204b", MODE:="0666"

In an attempt to allow read/write permission for my user. I cannot just run my application with root permission, I need ownership of ttyACM* (note I have also tried OWNER="myusername" instead of MODE:="0666").

回答1:

It turns out I just needed to do "service udev restart" and all of the sudden it started working. Previously I tried "udevadm control --reload-rules", "udevadm control --reload", "udevadm control trigger", and restarting the system, none of which worked.