You are not logged in.

#1 2008-12-31 12:38:13

synthead
Member
Registered: 2006-05-09
Posts: 1,337

[solved] udev rule refuses to respond to my device

So I have an M-Audio Transit USB sound card.  It uses volatile memory for its firmware, and after every hotplug, you have to upload a binary using a program called madfuload.  Well, I own this package in the AUR, and I something broke supposedly a month ago, and I'd like to fix it.

The tricky bugger is that the card gets a new device ID on every hotplug, and madfuload wants to know what the device is to upload a binary.  So I made this udev rule:

ACTION=="add", ATTR{idVendor}=="0763", ATTR{idProduct}=="2806", RUN+="/usr/sbin/madfuload -3 -f /usr/share/usb/maudio/ma006100.bin -D /dev/bus/usb/001/$(lsusb | awk -F':| ' '/763:2806/{print $4}')"

If I run the command in this rule as root, it works all the time regardless of if I reconnect the card or not.  It works, awesome.  But not within the udev rule.

Here's what udevadm has to say about it:

[max@pwn usbdev1.15]$ udevadm info -a -p /devices/pci0000:00/0000:00:1d.0/usb1/1-1

Udevinfo 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/pci0000:00/0000:00:1d.0/usb1/1-1':
    KERNEL=="1-1"
    SUBSYSTEM=="usb"
    DRIVER=="usb"
    ATTR{configuration}==""
    ATTR{bNumInterfaces}==" 1"
    ATTR{bConfigurationValue}=="1"
    ATTR{bmAttributes}=="40"
    ATTR{bMaxPower}=="200mA"
    ATTR{urbnum}=="10"
    ATTR{idVendor}=="0763"
    ATTR{idProduct}=="2806"
    ATTR{bcdDevice}=="0100"
    ATTR{bDeviceClass}=="fe"
    ATTR{bDeviceSubClass}=="01"
    ATTR{bDeviceProtocol}=="00"
    ATTR{bNumConfigurations}=="1"
    ATTR{bMaxPacketSize0}=="64"
    ATTR{speed}=="12"
    ATTR{busnum}=="1"
    ATTR{devnum}=="17"
    ATTR{version}==" 1.00"
    ATTR{maxchild}=="0"
    ATTR{quirks}=="0x0"
    ATTR{authorized}=="1"
    ATTR{manufacturer}=="Unknown"
    ATTR{product}=="Unknown"

  looking at parent device '/devices/pci0000:00/0000:00:1d.0/usb1':
    KERNELS=="usb1"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{configuration}==""
    ATTRS{bNumInterfaces}==" 1"
    ATTRS{bConfigurationValue}=="1"
    ATTRS{bmAttributes}=="e0"
    ATTRS{bMaxPower}=="  0mA"
    ATTRS{urbnum}=="343"
    ATTRS{idVendor}=="1d6b"
    ATTRS{idProduct}=="0001"
    ATTRS{bcdDevice}=="0206"
    ATTRS{bDeviceClass}=="09"
    ATTRS{bDeviceSubClass}=="00"
    ATTRS{bDeviceProtocol}=="00"
    ATTRS{bNumConfigurations}=="1"
    ATTRS{bMaxPacketSize0}=="64"
    ATTRS{speed}=="12"
    ATTRS{busnum}=="1"
    ATTRS{devnum}=="1"
    ATTRS{version}==" 1.10"
    ATTRS{maxchild}=="2"
    ATTRS{quirks}=="0x0"
    ATTRS{authorized}=="1"
    ATTRS{manufacturer}=="Linux 2.6.27-ARCH uhci_hcd"
    ATTRS{product}=="UHCI Host Controller"
    ATTRS{serial}=="0000:00:1d.0"
    ATTRS{authorized_default}=="1"

  looking at parent device '/devices/pci0000:00/0000:00:1d.0':
    KERNELS=="0000:00:1d.0"
    SUBSYSTEMS=="pci"
    DRIVERS=="uhci_hcd"
    ATTRS{vendor}=="0x8086"
    ATTRS{device}=="0x27c8"
    ATTRS{subsystem_vendor}=="0x107b"
    ATTRS{subsystem_device}=="0x0681"
    ATTRS{class}=="0x0c0300"
    ATTRS{irq}=="23"
    ATTRS{local_cpus}=="ffff"
    ATTRS{local_cpulist}=="0-15"
    ATTRS{modalias}=="pci:v00008086d000027C8sv0000107Bsd00000681bc0Csc03i00"
    ATTRS{broken_parity_status}=="0"
    ATTRS{msi_bus}==""

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

So the information is correct.  What's the deal?

Last edited by synthead (2009-02-27 07:54:28)

Offline

#2 2009-01-02 05:54:45

synthead
Member
Registered: 2006-05-09
Posts: 1,337

Re: [solved] udev rule refuses to respond to my device

If I replace

/usr/sbin/madfuload -3 -f /usr/share/usb/maudio/ma006100.bin -D /dev/bus/usb/001/$(lsusb | awk -F':| ' '/763:2806/{print $4}')

with something generic like plaympeg something.mp3, galculator, etc., it doesn't launch any programs.  What am I doing wrong?

Offline

#3 2009-01-02 10:06:20

azleifel
Member
Registered: 2007-10-28
Posts: 486

Re: [solved] udev rule refuses to respond to my device

This is not my area of expertise but I suspect that it has something to do with the limited environment that a program gets when it is run from udev (take a squint at http://www.reactivated.net/writing_udev … ternal-run, particularly the last paragraph).  What I have found is that it is possible to use sh to run programs from a udev rule, e.g.

# Set root:scanner group and permissions in /proc/bus/usb
# ATTRS{idVendor}=="04b8", ATTRS{idProduct}=="0116", RUN+="/bin/sh -c '/bin/chown root:scanner /proc/$name;/bin/chmod 0664 /proc/$name'"

Try it at your own risk!

Offline

#4 2009-01-16 19:34:41

synthead
Member
Registered: 2006-05-09
Posts: 1,337

Re: [solved] udev rule refuses to respond to my device

GREAT!  Clever!  I will fire up my laptop and try this.  I'll let you know what happens!  If it works, you will make a lot of people happy through a working AUR package big_smile

Offline

#5 2009-01-21 20:50:36

synthead
Member
Registered: 2006-05-09
Posts: 1,337

Re: [solved] udev rule refuses to respond to my device

Okay, so this is really confusing me.  I can't get this to work no matter what I do.  I decided to write a script to simplify things, and it works when ran, but the udev rule still doesn't function.  I've tried to house my command with /bin/sh -c 'stuff' but it didn't help anything.

This is my udev script (I'm only trying to get the Transit to work right now):

/etc/udev/rules.d/madfuload.rules

# madfuload.rules - udev rules for loading firmware into M-Audio DFU devices

# DEVPATH=="/*.0" selects interface 0 only
# (some udev versions don't work with SYSFS{bInterfaceNumber})

# Audiophile
ACTION=="add", SUBSYSTEM=="usb", DEVPATH=="/*.0", ENV{PRODUCT}=="763/2803/*", RUN+="/bin/sh -c '/usr/sbin/madfuload -l -n -f /usr/share/usb/maudio/ma003101.bin'"
# MobilePre
ACTION=="add", SUBSYSTEM=="usb", DEVPATH=="/*.0", ENV{PRODUCT}=="763/2804/*", RUN+="/bin/sh -c '/usr/sbin/madfuload -l -3 -f /usr/share/usb/maudio/ma004103.bin'"
# Sonica
ACTION=="add", SUBSYSTEM=="usb", DEVPATH=="/*.0", ENV{PRODUCT}=="763/2805/*", RUN+="/bin/sh -c '/usr/sbin/madfuload -l -n -f /usr/share/usb/maudio/ma005101.bin'"
# Transit
ACTION=="add", SUBSYSTEM=="usb", DEVPATH=="/*.0", ENV{PRODUCT}=="763/2806/*", RUN+="/usr/sbin/madfuload.auto ma006100.bin"

# Ozone
ACTION=="add", SUBSYSTEM=="usb", DEVPATH=="/*.0", ENV{PRODUCT}=="763/2808/*", RUN+="/bin/sh -c '/usr/sbin/madfuload -l -3 -f /usr/share/usb/maudio/ma008100.bin'"

# vim: ft=conf

This is the script I wrote.  I've tried to add a sleep command to see if the problem was simply the device not settling, but it didn't help.  This script works 100%: if I run /usr/sbin/madfuload.auto ma006100.bin as root, bam, the sound card comes to life and will play audio.

/usr/sbin/madfuload.auto

#!/bin/bash

#sleep 0.5

/usr/sbin/madfuload -3 -f /usr/share/usb/maudio/$1 -D /dev/bus/usb/$(lsusb | awk '/763:2806/{print $2}')/$(lsusb | awk -F':| ' '/763:2806/{print $4}')

So what am I doing wrong? sad

Offline

#6 2009-01-21 22:51:18

azleifel
Member
Registered: 2007-10-28
Posts: 486

Re: [solved] udev rule refuses to respond to my device

ACTION=="add", SUBSYSTEM=="usb", DEVPATH=="/*.0", ENV{PRODUCT}=="763/2806/*", RUN+="/usr/sbin/madfuload.auto ma006100.bin"

Until somebody who knows about these things comes along, I would say that it may not be possible to pass a parameter to a batch file like that.  Does it work if the ma006100.bin file name is hard-coded into the batch file?

In the meantime, if I add

ATTRS{idVendor}=="04b8", ATTRS{idProduct}=="0116", RUN+="/bin/sh -c '/usr/bin/aplay /home/david/Documents/Sounds/carskid.wav'"

to my udev rules then I get audio notification when I switch on my scanner.

Edit: And so does

ATTRS{idVendor}=="04b8", ATTRS{idProduct}=="0116", RUN+="/bin/sh -c '/home/david/announce.bat /home/david/Documents/Sounds/carskid.wav'"

where announce.bat contains

#!/bin/bash

/usr/bin/aplay $1

Last edited by azleifel (2009-01-21 22:56:01)

Offline

#7 2009-01-26 08:49:18

synthead
Member
Registered: 2006-05-09
Posts: 1,337

Re: [solved] udev rule refuses to respond to my device

Okay, here's what I got now.  It's still not working.  I made a formal script, and it runs just fine.  If I run /bin/sh -c '/usr/sbin/madfuload.auto transit' from a root shell, it flashes the firmware.  So I'm not sure what the problem is.

/usr/sbin/madfuload.auto

#!/bin/bash

if [[ $1 = "audiophile" ]]; then MADPRODUCT="Audiophile"; MADFIRMWARE="ma003101.bin"; MADID="2803"; fi
if [[ $1 = "mobilepre" ]]; then MADPRODUCT="MobilePre"; MADFIRMWARE="ma004103.bin"; MADID="2804"; fi
if [[ $1 = "sonica" ]]; then MADPRODUCT="Sonica"; MADFIRMWARE="ma005101.bin"; MADID="2805"; fi
if [[ $1 = "transit" ]]; then MADPRODUCT="Transit"; MADFIRMWARE="ma006100.bin"; MADID="2806"; fi
if [[ $1 = "ozone" ]]; then MADPRODUCT="Ozone"; MADFIRMWARE="ma008100.bin"; MADID="2808"; fi

if [ -z $MADPRODUCT ]; then
echo "Usage: madfuload.auto [ audiophile | mobilepre | sonica | transit | ozone ]";
echo "Discovers path of specific M-Audio hardware and flashes firmware automatically"; exit 1; fi

MADBUS="$(lsusb | awk '/763:'$MADID'/{print $2}')"
MADDEVICE="$(lsusb | awk -F':| ' '/763:'$MADID'/{print $4}')"

if [ -z $MADBUS ] || [ -z $MADDEVICE ]; then echo "Unflashed M-Audio $MADPRODUCT not found!"; exit 1; fi
echo "Unflashed M-Audio $MADPRODUCT found on /dev/bus/usb/$MADBUS/$MADDEVICE!"
if [[ $(id -u) != "0" ]]; then echo "Must be superuser to flash firmware to this device."; exit 1; fi
echo "Flashing $MADFIRMWARE to device..."

/usr/sbin/madfuload -3 -f /usr/share/usb/maudio/$MADFIRMWARE -D /dev/bus/usb/$MADBUS/$MADDEVICE >& /dev/null

/etc/udev/rules.d/madfuload.rules

# madfuload.rules - udev rules for loading firmware into M-Audio DFU devices

# DEVPATH=="/*.0" selects interface 0 only
# (some udev versions don't work with SYSFS{bInterfaceNumber})

# Audiophile
ACTION=="add", SUBSYSTEM=="usb", DEVPATH=="/*.0", ENV{PRODUCT}=="763/2803/*", RUN+="/bin/sh -c '/usr/sbin/madfuload.auto audiophile'"
# MobilePre
ACTION=="add", SUBSYSTEM=="usb", DEVPATH=="/*.0", ENV{PRODUCT}=="763/2804/*", RUN+="/bin/sh -c '/usr/sbin/madfuload.auto mobilepre'"
# Sonica
ACTION=="add", SUBSYSTEM=="usb", DEVPATH=="/*.0", ENV{PRODUCT}=="763/2805/*", RUN+="/bin/sh -c '/usr/sbin/madfuload.auto sonica'"
# Transit
ACTION=="add", SUBSYSTEM=="usb", DEVPATH=="/*.0", ENV{PRODUCT}=="763/2806/*", RUN+="/bin/sh -c '/usr/sbin/madfuload.auto transit'"
# Ozone
ACTION=="add", SUBSYSTEM=="usb", DEVPATH=="/*.0", ENV{PRODUCT}=="763/2808/*", RUN+="/bin/sh -c '/usr/sbin/madfuload.auto ozone'"

# vim: ft=conf

Last edited by synthead (2009-01-26 09:54:11)

Offline

#8 2009-01-26 09:16:26

synthead
Member
Registered: 2006-05-09
Posts: 1,337

Re: [solved] udev rule refuses to respond to my device

I added a sleep 10 line to my script to debug it and it looks like madfuload.auto is being ran (as seen in top).  If I run aplay, it'll play a sound too.  But when I try to run the madfuload.auto command (that works at a terminal) ... nothing.

Last edited by synthead (2009-01-26 09:56:08)

Offline

#9 2009-01-26 09:28:09

synthead
Member
Registered: 2006-05-09
Posts: 1,337

Re: [solved] udev rule refuses to respond to my device

Does this have to do with permissions somehow?  The device will only flash when madfuload is ran as root.

Offline

#10 2009-01-26 17:48:04

azleifel
Member
Registered: 2007-10-28
Posts: 486

Re: [solved] udev rule refuses to respond to my device

I'm regretting ever replying to this ;-)  There's a comment by shimage on the madfuload AUR page that refers to an ubuntu forums thread at http://ubuntuforums.org/showthread.php?t=846621 with modifications to the udev rules.  Something like

ACTION=="add", SUBSYSTEM=="usb", SYSFS{idVendor}=="0763", SYSFS{idProduct}=="2804", RUN+="/usr/local/sbin/madfuload -l -3 -f /usr/local/share/usb/maudio/ma004103.bin -D $env{DEVNAME}"

seems to make more sense than using lsusb and awk to get the device node.  In addition, looking at the original udev rules that come with madfuload, I see that the wait-related switches differ for different devices,

# Audiophile
ACTION=="add", SUBSYSTEM=="usb", DEVPATH=="/*.0", ENV{PRODUCT}=="763/2803/*", RUN+="/usr/sbin/madfuload -l -n -f /usr/share/usb/maudio/ma003101.bin"
# MobilePre
ACTION=="add", SUBSYSTEM=="usb", DEVPATH=="/*.0", ENV{PRODUCT}=="763/2804/*", RUN+="/usr/sbin/madfuload -l -3 -f /usr/share/usb/maudio/ma004103.bin"

etc.

Offline

#11 2009-01-27 09:06:47

synthead
Member
Registered: 2006-05-09
Posts: 1,337

Re: [solved] udev rule refuses to respond to my device

That's what I needed!  The package is fixed!  Thank you so much!

Offline

Board footer

Powered by FluxBB