0

I've been working on a simple Linux firmware to load up a Ralink wifi card which requires the drivers rt2800usb. The firmware includes the file rt2800usb in the relevant place, starts the udev daemon and has a rule to match the card's attributes.

This is the rule I was initially using to match the card:

KERNEL=="wlan*", ATTRS{manufacturer}=="Ralink", NAME="wificard%E{SLOT}"

Although the rule matched the card's attributes it doesn't load the rt2800usb drivers for the card.

I've checked this using udevadm trigger --attr-match=manufacturer="Ralink" and I see the same thing, it picks up the device path, but doesn't load the driver.

There is one rule that seem to load the drivers, that's this:

udevadm trigger --verbose --parent-match=/sys/devices/pci0000\:00/0000\:00\:0f.5/usb1/1-2/1-2\:1.0/

However, as far as my understanding of udev is concerned, this rule would trigger for any device plugged into that particular USB slot. I'm trying to adapt this rule to work only for a Ralink card. I've tried adding in the --attr-match=manufacturer="Ralink" but the rule no longer matches.

I'd be really grateful if anyone could help me shed some light on this, in particular why do some udev matches launch the driver and others don't?

Also here's the output of udevadm info --attribute-walk udevadm info --attribute-walk --path=/sys/devices/pci0000\:00/0000\:00\:0f.5/usb1/1-2/1-2\:1.0:

looking at device '/devices/pci0000:00/0000:00:0f.5/usb1/1-2/1-2:1.0':
KERNEL=="1-2:1.0"
SUBSYSTEM=="usb"
DRIVER=="rt2800usb"
ATTR{bInterfaceClass}=="ff"
ATTR{bInterfaceSubClass}=="ff"
ATTR{bInterfaceProtocol}=="ff"
ATTR{bNumEndpoints}=="07"
ATTR{supports_autosuspend}=="0"
ATTR{bAlternateSetting}==" 0"
ATTR{bInterfaceNumber}=="00"
ATTR{interface}=="1.0"

looking at parent device '/devices/pci0000:00/0000:00:0f.5/usb1/1-2':
KERNELS=="1-2"
SUBSYSTEMS=="usb"
DRIVERS=="usb"
ATTRS{bDeviceSubClass}=="00"
ATTRS{bDeviceProtocol}=="00"
ATTRS{devpath}=="2"
ATTRS{idVendor}=="148f"
ATTRS{speed}=="480"
ATTRS{bNumInterfaces}==" 1"
ATTRS{bConfigurationValue}=="1"
ATTRS{bMaxPacketSize0}=="64"
ATTRS{busnum}=="1"
ATTRS{devnum}=="2"
ATTRS{configuration}==""
ATTRS{bMaxPower}=="450mA"
ATTRS{authorized}=="1"
ATTRS{bmAttributes}=="80"
ATTRS{bNumConfigurations}=="1"
ATTRS{maxchild}=="0"
ATTRS{bcdDevice}=="0101"
ATTRS{avoid_reset_quirk}=="0"
ATTRS{quirks}=="0x0"
ATTRS{serial}=="1.0"
ATTRS{version}==" 2.00"
ATTRS{urbnum}=="2719"
ATTRS{ltm_capable}=="no"
ATTRS{manufacturer}=="Ralink"
ATTRS{removable}=="unknown"
ATTRS{idProduct}=="5370"
ATTRS{bDeviceClass}=="00"
ATTRS{product}=="802.11 n WLAN"

looking at parent device '/devices/pci0000:00/0000:00:0f.5/usb1':
KERNELS=="usb1"
SUBSYSTEMS=="usb"
DRIVERS=="usb"
ATTRS{bDeviceSubClass}=="00"
ATTRS{bDeviceProtocol}=="00"
ATTRS{devpath}=="0"
ATTRS{idVendor}=="1d6b"
ATTRS{speed}=="480"
ATTRS{bNumInterfaces}==" 1"
ATTRS{bConfigurationValue}=="1"
ATTRS{bMaxPacketSize0}=="64"
ATTRS{authorized_default}=="1"
ATTRS{busnum}=="1"
ATTRS{devnum}=="1"
ATTRS{configuration}==""
ATTRS{bMaxPower}=="0mA"
ATTRS{authorized}=="1"
ATTRS{bmAttributes}=="e0"
ATTRS{bNumConfigurations}=="1"
ATTRS{maxchild}=="4"
ATTRS{bcdDevice}=="0312"
ATTRS{avoid_reset_quirk}=="0"
ATTRS{quirks}=="0x0"
ATTRS{serial}=="0000:00:0f.5"
ATTRS{version}==" 2.00"
ATTRS{urbnum}=="40"
ATTRS{ltm_capable}=="no"
ATTRS{manufacturer}=="Linux 3.12.9 ehci_hcd"
ATTRS{removable}=="unknown"
ATTRS{idProduct}=="0002"
ATTRS{bDeviceClass}=="09"
ATTRS{product}=="EHCI Host Controller"

looking at parent device '/devices/pci0000:00/0000:00:0f.5':
KERNELS=="0000:00:0f.5"
SUBSYSTEMS=="pci"
DRIVERS=="ehci-pci"
ATTRS{irq}=="12"
ATTRS{subsystem_vendor}=="0x1022"
ATTRS{broken_parity_status}=="0"
ATTRS{class}=="0x0c0320"
ATTRS{companion}==""
ATTRS{consistent_dma_mask_bits}=="32"
ATTRS{dma_mask_bits}=="32"
ATTRS{local_cpus}=="1"
ATTRS{device}=="0x2095"
ATTRS{uframe_periodic_max}=="100"
ATTRS{enable}=="1"
ATTRS{msi_bus}==""
ATTRS{local_cpulist}=="0"
ATTRS{vendor}=="0x1022"
ATTRS{subsystem_device}=="0x2095"

looking at parent device '/devices/pci0000:00':
KERNELS=="pci0000:00"
SUBSYSTEMS==""
DRIVERS==""
James
  • 3,957
  • 4
  • 37
  • 82
  • 2
    If you indeed have a USB-connected peripheral, why don't you want to match the USB VID/PID? Also, this seems like it probably should be on the unix/linux site rather than here. – Chris Stratton Apr 30 '14 at 19:37
  • When I trigger from vendor or product ID the `rt2800usb` module doesn't get loaded. When I trigger from the device path the module does get loaded. I am looking for a rule that's specific to the Ralink card and ensures the module is loaded. – James May 01 '14 at 12:31
  • That would be the VID / PID rule, you need to debug why it does not work. Possibly the device changes identity shortly after initial connection? – Chris Stratton May 01 '14 at 12:48
  • Since when is it udev's job to load drivers ? – Grapsus May 06 '14 at 10:00

1 Answers1

3

1)

ACTION=="add", SUBSYSTEM=="net", KERNEL=="wlan*", ATTR{flags}=="0x1002", DRIVERS=="rt2800usb"

2)

ACTION=="add", SUBSYSTEM=="compat_firmware"

1) This rule detected the insertion of USB adapter but not linked. I use this rule for restart networking, udhcpd and hostapd (for master mode). Restart net service causes firmware load and wlan get IP adress ;-)

2) I use driver compiled from Compat Driver, load of firmare sucess with:

SUBSYSTEM=="compat_firmware", ACTION=="add", RUN+="compat_firmware.sh"

code of "compat_firmware.sh"
#!/bin/sh -e

FIRMWARE_DIRS="/lib/firmware/updates/$(uname -r) /lib/firmware/updates \
               /lib/firmware/$(uname -r) /lib/firmware"

err() {
        echo "$@" >&2
        logger -t "${0##*/}[$$]" "$@" 2>/dev/null || true
}

if [ ! -e /sys$DEVPATH/loading ]; then
        err "udev firmware loader misses sysfs directory"
        exit 1
fi

for DIR in $FIRMWARE_DIRS; do
        [ -e "$DIR/$FIRMWARE" ] || continue
        echo 1 > /sys$DEVPATH/loading
        cat "$DIR/$FIRMWARE" > /sys$DEVPATH/data
        echo 0 > /sys$DEVPATH/loading
        exit 0
done

echo -1 > /sys$DEVPATH/loading
err "Cannot find  firmware file '$FIRMWARE'"
mkdir -p /dev/.udev/firmware-missing
file=$(echo "$FIRMWARE" | sed 's:/:\\x2f:g')
ln -s -f "$DEVPATH" /dev/.udev/firmware-missing/$file
exit 1

Sorry for my English

See me in G+ GustavoReyes71

Gustavo
  • 31
  • 4