Tiny Core Linux

Tiny Core Base => TCB Talk => Topic started by: vbs on January 16, 2016, 08:41:51 AM

Title: udev rule for USB device at boot time
Post by: vbs on January 16, 2016, 08: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!
Title: Re: udev rule for USB device at boot time
Post by: Rich on January 16, 2016, 09:13:49 AM
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.
Title: Re: udev rule for USB device at boot time
Post by: curaga on January 16, 2016, 11:21:26 AM
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.
Title: Re: udev rule for USB device at boot time
Post by: vbs on January 23, 2016, 09:41:42 AM
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!