WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: udev rule for USB device at boot time  (Read 5014 times)

Offline vbs

  • Newbie
  • *
  • Posts: 21
udev rule for USB device at boot time
« on: January 16, 2016, 11:41:51 AM »
I have a Raspi2 using piCore6 6.1beta1. Also I have a USB device (CO2 sensor) which is permanently connected to the Pi as a HID. Now I have the following udev-rule to assign permissions to a group and to create a symlink:

Code: [Select]
ACTION=="remove", GOTO="co2mini_end"

SUBSYSTEMS=="usb", KERNEL=="hidraw*", ATTRS{idVendor}=="04d9", ATTRS{idProduct}=="a052", GROUP="plugdev", MODE="0660", SYMLINK+="co2mini%n", GOTO="co2mini_end"

LABEL="co2mini_end"

This is working fine when I connect the USB device at runtime. Then the udev rule is executed and I get my symlink and permissions for group "plugdev". But the problem is that the udev does not seem to fire at boot time when the USB device is connected already. Then I only have it as /dev/hidraw0 but the symlink does not get created and also the permissions are not set.

Could please help me out what the problem could be that the rule is not executed at boot time?

Thanks guys!

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11704
Re: udev rule for USB device at boot time
« Reply #1 on: January 16, 2016, 12:13:49 PM »
Hi vbs
Maybe executing a command like this will help:
Code: [Select]
udevadm trigger --attr-match=subsystem=usb
Quote
SUBSYSTEMS=="usb", KERNEL=="hidraw*", .....
I think  SUBSYSTEMS  should be  SUBSYSTEM.

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11050
Re: udev rule for USB device at boot time
« Reply #2 on: January 16, 2016, 02:21:26 PM »
If your rule is in the backup, it's too late for the coldplug. If you remaster it into the initrd it will be there in time.
The only barriers that can stop you are the ones you create yourself.

Offline vbs

  • Newbie
  • *
  • Posts: 21
Re: udev rule for USB device at boot time
« Reply #3 on: January 23, 2016, 12:41:42 PM »
Guys, sorry for my late reply, something got in my way.

But I finally have it working now: Since remastering initrd seemed too hard I went with Rich's advice and called "udevadm trigger" after boot. There still was one tricky part for me: I had to trigger "hidraw" instead of "usb" to get the right device.

So this is my udev rule now:
Code: [Select]
KERNEL=="hidraw*", ATTRS{idVendor}=="04d9", ATTRS{idProduct}=="a052", GROUP="plugdev", MODE="0660", SYMLINK+="co2mini%n"

And I am calling this now in bootlocal.sh
Code: [Select]
udevadm trigger --subsystem-match=hidraw

So it seems to be working now! Thanks guys!