Skip to contentSkip to conversation

Run hotplug scripts after device node is created?

DISCUSSION Stefan Schweizer 5 participants 16 messages Aug 22, 2005 – Aug 23, 2005

lore
Share & tools
lore
#0 lore raw

Hi,

I use a hotplug script to download the firmware to my hp printer. This is needed for HP Laserjet 1000,1005 and 1020. The procedure is just cat firmware > /dev/usb/lp*

The problem is that /dev/usb/lp* has to exist for the script to work. In earlier udev versions I just added "sleep 20" to the script to be sure that the device node exists. With the last version of udev this seems to be no longer possiblee because udev waits for the hotplug script to exit before creating the device node :(

How can I make sure that the hotplug script is run after usblp is loaded and after the device is created?

Is there some hotplug-way to find out which device-node I am supposed to load the firmware into?

Regards,
Stefan

-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#1 lore raw
Quoted 9 lines · Stefan Schweizer

I use a hotplug script to download the firmware to my hp printer. This is needed for HP Laserjet 1000,1005 and 1020. The procedure is just cat firmware > /dev/usb/lp*

The problem is that /dev/usb/lp* has to exist for the script to work. In earlier udev versions I just added "sleep 20" to the script to be sure that the device node exists. With the last version of udev this seems to be no longer possiblee because udev waits for the hotplug script to exit before creating the device node :(

No, only PROGRAM and IMPORT runs before the node is created.

Quoted 2 lines

How can I make sure that the hotplug script is run after usblp is loaded and after the device is created?

RUN runs definitely after the node handling is finished.

Quoted 2 lines

Is there some hotplug-way to find out which device-node I am supposed to load the firmware into?

Don't understand the question.

And what udev version is it?
What does:
cat /proc/sys/kernel/hotplug
print?

Kay

-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#2 lore raw
In reply to Stefan Schweizer
Quoted 11 lines · Kay Sievers
Quoted 9 lines · Stefan Schweizer

I use a hotplug script to download the firmware to my hp printer. This is needed for HP Laserjet 1000,1005 and 1020. The procedure is just cat firmware > /dev/usb/lp*

The problem is that /dev/usb/lp* has to exist for the script to work. In earlier udev versions I just added "sleep 20" to the script to be sure that the device node exists. With the last version of udev this seems to be no longer possiblee because udev waits for the hotplug script to exit before creating the device node :(

Quoted 7 lines

No, only PROGRAM and IMPORT runs before the node is created.

Quoted 2 lines

How can I make sure that the hotplug script is run after usblp is loaded and after the device is created?

RUN runs definitely after the node handling is finished.

I don't use either of those ..

this is just a plain old hotplug script with /etc/hotplug/usb/hplj.usermap:
hplj1005 0x0003 0x03f0 0x1317 0x0000 0x0000 0x00 0x00 0x00 0x00 0x00 0x00 0x00000000
/etc/hotplug/usb/hplj1005
waiting and catting the firmware into the device node.

Quoted 4 lines
Quoted 2 lines

Is there some hotplug-way to find out which device-node I am supposed to load the firmware into?

Don't understand the question.

currently the script is scanning all devices for a supported one .. is there some variable in a hotplug script to read out the device node?

Quoted 1 line

And what udev version is it?

udev-068

Quoted 3 lines

What does:
cat /proc/sys/kernel/hotplug
print?

/sbin/udevsend

thanks,
Stefan

-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#3 lore raw
In reply to Stefan Schweizer
Quoted 2 lines · Stefan Schweizer

this is just a plain old hotplug script with
/etc/hotplug/usb/hplj.usermap:

Don't. Support for maps will be probably killed *soon*.

Quoted 2 lines

currently the script is scanning all devices for a supported one .. is there some variable in a hotplug script to read out the device node?

udev can provide it on the command line.

Signature · 13 lines
ciao,
Marco


-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Linux-hotplug-devel mailing list  http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
#4 lore raw
In reply to Stefan Schweizer
Quoted 19 lines · Stefan Schweizer
Quoted 11 lines · Kay Sievers
Quoted 9 lines · Stefan Schweizer

I use a hotplug script to download the firmware to my hp printer. This is needed for HP Laserjet 1000,1005 and 1020. The procedure is just cat firmware > /dev/usb/lp*

The problem is that /dev/usb/lp* has to exist for the script to work. In earlier udev versions I just added "sleep 20" to the script to be sure that the device node exists. With the last version of udev this seems to be no longer possiblee because udev waits for the hotplug script to exit before creating the device node :(

Quoted 7 lines

No, only PROGRAM and IMPORT runs before the node is created.

Quoted 2 lines

How can I make sure that the hotplug script is run after usblp is loaded and after the device is created?

RUN runs definitely after the node handling is finished.

Quoted 8 lines

I don't use either of those ..

this is just a plain old hotplug script with /etc/hotplug/usb/hplj.usermap:
hplj1005 0x0003 0x03f0 0x1317 0x0000 0x0000 0x00 0x00 0x00 0x00 0x00 0x00 0x00000000
/etc/hotplug/usb/hplj1005
waiting and catting the firmware into the device node.

Somewhere in your rules is a:
RUN+="/sbin/udev_run_hotplugd"

right? If not, /etc/hotplug.d/ is not called.

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

Is there some hotplug-way to find out which device-node I am supposed to load the firmware into?

Don't understand the question.

currently the script is scanning all devices for a supported one .. is there some variable in a hotplug script to read out the device node?

Sure. DEVNAME.

Kay

-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#5 lore raw
In reply to Stefan Schweizer
Quoted 5 lines · Marco d'Itri
Quoted 2 lines · Stefan Schweizer

this is just a plain old hotplug script with
/etc/hotplug/usb/hplj.usermap:

Don't. Support for maps will be probably killed *soon*.

what am I supposed to be using now?

Quoted 3 lines
Quoted 2 lines

currently the script is scanning all devices for a supported one .. is there some variable in a hotplug script to read out the device node?

udev can provide it on the command line.

How can I use the cmdline?

Stefan

-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#6 lore raw
In reply to Stefan Schweizer
Quoted 8 lines · Kay Sievers
Quoted 6 lines · Stefan Schweizer

this is just a plain old hotplug script with /etc/hotplug/usb/hplj.usermap:
hplj1005 0x0003 0x03f0 0x1317 0x0000 0x0000 0x00 0x00 0x00 0x00 0x00 0x00 0x00000000
/etc/hotplug/usb/hplj1005
waiting and catting the firmware into the device node.

Quoted 4 lines

Somewhere in your rules is a:
RUN+="/sbin/udev_run_hotplugd"

right? If not, /etc/hotplug.d/ is not called.

Yes, right ..it is obviously default in Gentoo.

- Stefan

-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#7 lore raw
In reply to Stefan Schweizer
Quoted 4 lines · Stefan Schweizer
Quoted 3 lines
Quoted 2 lines

this is just a plain old hotplug script with
/etc/hotplug/usb/hplj.usermap:

Don't. Support for maps will be probably killed *soon*.

what am I supposed to be using now?

A udev RUN rule.

Quoted 4 lines
Quoted 3 lines
Quoted 2 lines

currently the script is scanning all devices for a supported one .. is there some variable in a hotplug script to read out the device node?

udev can provide it on the command line.

How can I use the cmdline?

udev.conf(5).

Signature · 13 lines
ciao,
Marco


-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Linux-hotplug-devel mailing list  http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
#8 lore raw
In reply to Stefan Schweizer
Quoted 5 lines · [email protected] (Marco d'Itri) writes:
Quoted 2 lines · Stefan Schweizer

this is just a plain old hotplug script with
/etc/hotplug/usb/hplj.usermap:

Don't. Support for maps will be probably killed *soon*.

What should we do then? Write an udev rule per device ids? This would end up in a huge number of rules, can udev manage that without performance cost?
Wouldn't it be better to add some kind of map support in udev?

Signature · 15 lines
Olivier Blin
Mandriva
Mandrakesoft becomes Mandriva



-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Linux-hotplug-devel mailing list  http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
#9 lore raw
In reply to Stefan Schweizer
Quoted 1 line · Olivier Blin

What should we do then? Write an udev rule per device ids?

Yes, or match on some other appropriate value.

Quoted 2 lines

This would end up in a huge number of rules, can udev manage that without performance cost?

I doubt that the number or rules would be high.

Quoted 1 line

Wouldn't it be better to add some kind of map support in udev?

No.

Signature · 13 lines
ciao,
Marco


-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Linux-hotplug-devel mailing list  http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
#10 lore raw
In reply to Stefan Schweizer
Quoted 8 lines · On Tue, 23 Aug 2005 14:27:09 +0200 Marco d'Itri wrote:
Quoted 1 line · Olivier Blin

What should we do then? Write an udev rule per device ids?

Yes, or match on some other appropriate value.

Quoted 2 lines

This would end up in a huge number of rules, can udev manage that without performance cost?

I doubt that the number or rules would be high.

$ grep -v '^#' /etc/hotplug/usb/libsane.usermap | wc -l
210
$ grep -v '^#' /etc/hotplug/usb/usbcam.usermap | wc -l 
372

These are basically just a bunch of USB vendor/device IDs, and it is likely that most devices don't have any reliable attributes which would allow to match a group of them with a single rule.

#11 lore raw
In reply to Stefan Schweizer
Quoted 7 lines · Sergey Vlasov
Quoted 5 lines · On Tue, 23 Aug 2005 14:27:09 +0200 Marco d'Itri wrote:
Quoted 1 line · Olivier Blin

What should we do then? Write an udev rule per device ids?

Yes, or match on some other appropriate value.

Quoted 8 lines
Quoted 3 lines
Quoted 2 lines

This would end up in a huge number of rules, can udev manage that without performance cost?

I doubt that the number or rules would be high.

$ grep -v '^#' /etc/hotplug/usb/libsane.usermap | wc -l
210
$ grep -v '^#' /etc/hotplug/usb/usbcam.usermap | wc -l 
372

Same on Mandriva (mostly gphoto devices):

$ grep -v '^#' /etc/hotplug/usb.*map | wc -l
936
Quoted 3 lines

These are basically just a bunch of USB vendor/device IDs, and it is likely that most devices don't have any reliable attributes which would allow to match a group of them with a single rule.

Right, it means as many rules as devices.

Signature · 15 lines
Olivier Blin
Mandriva
Mandrakesoft becomes Mandriva



-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Linux-hotplug-devel mailing list  http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
#12 lore raw
In reply to Stefan Schweizer
Quoted 4 lines · Kay Sievers
Quoted 2 lines

currently the script is scanning all devices for a supported one .. is there some variable in a hotplug script to read out the device node?

Sure. DEVNAME.

thank you .. but I do not seem to be able to access DEVNAME :(

Any better idea than again guessing and sleeping?

relevant part of udev.conf:

SUBSYSTEM="usb", ACTION="add", ENV{PRODUCT}="3f0/0517*", RUN+="/etc/hotplug/hplj-udev"
SUBSYSTEM="usb", ACTION="add", ENV{PRODUCT}="3f0/1317*", RUN+="/etc/hotplug/hplj-udev"
SUBSYSTEM="usb", ACTION="add", ENV{PRODUCT}="3f0/2B17*", RUN+="/etc/hotplug/hplj-udev"
SUBSYSTEM="usb", KERNEL="lp*", ACTION="add", NAME="usb/%k", SYMLINK+="usb%k", GROUP="lp"
#BUS="usb", KERNEL="lp[0-9]*", NAME="usb/%k", GROUP="lp"

env of the script:
SUBSYSTEM=usb DEVPATH=/devices/pci0000:00/0000:00:0f.5/usb2/2-2/2-2.1/2-2.1:1.0 PATH=/sbin:/bin:/usr/sbin:/usr/bin
ACTION­d MODALIAS=usb:v03F0p1317d0120dc00dsc00dp00ic07isc01ip02 PWD=/
UDEVD_EVENT=1
SHLVL=1
HOME=/
DEVICE=/proc/bus/usb/002/017
INTERFACE=7/1/2
PRODUCT?0/1317/120
TYPE=0/0/0
PHYSDEVBUS=usb
SEQNUM†3
_=/bin/env

-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#13 lore raw
In reply to Stefan Schweizer
Quoted 31 lines · Stefan Schweizer
Quoted 4 lines · Kay Sievers
Quoted 2 lines

currently the script is scanning all devices for a supported one .. is there some variable in a hotplug script to read out the device node?

Sure. DEVNAME.

thank you .. but I do not seem to be able to access DEVNAME :(

Any better idea than again guessing and sleeping?

relevant part of udev.conf:

SUBSYSTEM="usb", ACTION="add", ENV{PRODUCT}="3f0/0517*", RUN+="/etc/hotplug/hplj-udev"
SUBSYSTEM="usb", ACTION="add", ENV{PRODUCT}="3f0/1317*", RUN+="/etc/hotplug/hplj-udev"
SUBSYSTEM="usb", ACTION="add", ENV{PRODUCT}="3f0/2B17*", RUN+="/etc/hotplug/hplj-udev"
SUBSYSTEM="usb", KERNEL="lp*", ACTION="add", NAME="usb/%k", SYMLINK+="usb%k", GROUP="lp"
#BUS="usb", KERNEL="lp[0-9]*", NAME="usb/%k", GROUP="lp"

env of the script:
SUBSYSTEM=usb DEVPATH=/devices/pci0000:00/0000:00:0f.5/usb2/2-2/2-2.1/2-2.1:1.0 PATH=/sbin:/bin:/usr/sbin:/usr/bin
ACTION­d MODALIAS=usb:v03F0p1317d0120dc00dsc00dp00ic07isc01ip02 PWD=/
UDEVD_EVENT=1
SHLVL=1

Quoted 8 lines

HOME=/
DEVICE=/proc/bus/usb/002/017
INTERFACE=7/1/2
PRODUCT?0/1317/120
TYPE=0/0/0
PHYSDEVBUS=usb
SEQNUM†3
_=/bin/env

You are catching the event for the "raw" usb device here. I don't know what device you need to upload the firmware too, but "raw" usb devices don't have a device node in the current kernel only an interface in /proc. You may need to catch the event for the printer interface, not sure.

Run "udevmonitor" while connecting the printer, it will show you all events. And "udevmonitor --env" will print the whole environment, where you can possibly see the DEVNAME.

Good luck,
Kay

-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#14 lore raw
In reply to Stefan Schweizer
Quoted 8 lines · Kay Sievers

You are catching the event for the "raw" usb device here. I don't know what device you need to upload the firmware too, but "raw" usb devices don't have a device node in the current kernel only an interface in /proc. You may need to catch the event for the printer interface, not sure.

Run "udevmonitor" while connecting the printer, it will show you all events. And "udevmonitor --env" will print the whole environment, where you can possibly see the DEVNAME.

Thanks you very much, I got it working!

rules look like:
SUBSYSTEM=="usb", KERNEL=="lp*", ACTION=="add", SYSFS{idVendor}=="03f0", SYSFS{idProduct}=="0517", RUN+="/etc/hotplug/hplj-udev 1000" SUBSYSTEM=="usb", KERNEL=="lp*", ACTION=="add", SYSFS{idVendor}=="03f0", SYSFS{idProduct}=="1317", RUN+="/etc/hotplug/hplj-udev 1005" SUBSYSTEM=="usb", KERNEL=="lp*", ACTION=="add", SYSFS{idVendor}=="03f0", SYSFS{idProduct}=="2B17", RUN+="/etc/hotplug/hplj-udev 1020"

and the script is attached for those interested.
Comments? Improvements? Is /etc/hotplug a good dir for udev-run-scripts?

Regrads

#15 lore raw
In reply to Stefan Schweizer
Quoted 1 line · Stefan Schweizer

Comments? Improvements? Is /etc/hotplug a good dir for udev-run-scripts?

I suggest you use /lib/hotplug/ or /sbin/.

Signature · 13 lines
ciao,
Marco


-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Linux-hotplug-devel mailing list  http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel