Udev

From CyanogenMod Wiki
Jump to: navigation, search

Contents

Setup

udev is an event driven daemon for device management in Linux. After connecting a device it is responsible for setting ownership, group and access rights of devices such as phones connected via USB. Configuring udev via rules stored in files is needed to allow users to access devices when using adb or fastboot. Below you can find examples of such udev rules.

These rules can be put in /lib/udev/rules.d/11-android.rules. If your device is not listed, or you want to know how to do this manually, see the instructions below.

Manually create udev rules

You will need to find the Vendor ID and Product ID for the device in four different modes (technically, you only need to find it for three modes): Normal, Debug, Recovery, and Fastboot. To find these ID numbers, boot the device into the appropriate mode and run lsusb from term with the device connected via USB. you should see something similar to the following:

patrick@pandora:~$ lsusb
Bus 005 Device 002: ID 413c:8126 Dell Computer Corp. Wireless 355 Bluetooth
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 020: ID 0bb4:0c91 High Tech Computer Corp. 
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

The line you are interested in is - in this example - the line containing the reference to HTC

Bus 001 Device 020: ID 0bb4:0c91 High Tech Computer Corp. 

The numbers we want are 0bb4 and 0c91, which are the vendor ID and product ID respectively. The vendor ID *should* be the same for all four modes (but it might not be, so pay attention). The product ID *will* be different for three of the four modes. Debug mode and Recovery mode *will* have the same product ID.

Please note that debug mode is found in settings » applications » development » USB debugging. Even though adb only works in debug mode, you *must* include normal mode for the udev rules work work correctly. Make sure you run lsusb in both 'normal' and 'debug' modes.

Now, following an example from below, insert your product ID and vendor ID in the appropriate places and put that in /lib/udev/rules.d/11-android.rules. you may need to run sudo restart udev for the changes to take effect.

udev file rules

File Location

According to Ubuntu 10.10 /lib/udev/rules.d/README: Rule files not installed by the OS should be in /etc/udev/rules.d (LinuxMint also)

File Numbers

The name you give a UDEV file should follow this convention(HIGHNUMBER=Override):

<priority ranking arbitrary number>-<your friendly name>.rules
  • Numbers less than 60 are non-persistent (define devices that should be forgotten when disconnected)
  • Numbers 60 - 69 are persistent but do not need helper binaries
  • Numbers 70 - 89 are persistent and can run binaries
  • Numbers 90+ exist to override rules below (run last)

Connected Devices

If you edit the rules file while a device is attached USB it will not be re-evaluated. You must disconnect and reconnect.

udev examples

HTC All Models

You can create a rule that defines all HTC Phones, All Modes. This is adapted from http://developer.android.com/guide/developing/device.html. Use root to create/modify /etc/udev/rules.d/51-android.rules. Put the following line in the file:

SUBSYSTEM=="usb", ATTRS{idVendor}=="0bb4", MODE="0660"

Instead of setting the OWNER you can also use a group (e.g. GROUP="plugdev") and add your user to that group.

Save the file, then chmod to all read:

chmod 0644 /etc/udev/rules.d/51-android.rules

HTC Hero (GSM)

SUBSYSTEMS=="usb", ATTRS{idVendor}=="0bb4", ATTRS{idProduct}=="0ff9", MODE="0660", OWNER="<your user name>" #Normal Hero
SUBSYSTEMS=="usb", ATTRS{idVendor}=="0bb4", ATTRS{idProduct}=="0c99", MODE="0660", OWNER="<your user name>" #Debug & Recovery Hero
SUBSYSTEMS=="usb", ATTRS{idVendor}=="0bb4", ATTRS{idProduct}=="0fff", MODE="0660", OWNER="<your user name>" #Fastboot Hero

HTC Hero (CDMA)

SUBSYSTEMS=="usb", ATTRS{idVendor}=="0bb4", ATTRS{idProduct}=="0ff9", MODE="0660", OWNER="<your user name>" #Normal Heroc
SUBSYSTEMS=="usb", ATTRS{idVendor}=="0bb4", ATTRS{idProduct}=="0c9a", MODE="0660", OWNER="<your user name>" #Debug & Recovery Heroc
SUBSYSTEMS=="usb", ATTRS{idVendor}=="0bb4", ATTRS{idProduct}=="0fff", MODE="0660", OWNER="<your user name>" #Fastboot Heroc

HTC Incredible

The Incredible has at least 3 hardware versions, either test each mode (normal, debug, fastboot, bootloader) with lsusb or add all
SUBSYSTEMS=="usb", ATTRS{idVendor}=="0bb4", ATTRS{idProduct}=="0ff9", MODE="0660", OWNER="<your user name>" #Normal dinc
SUBSYSTEMS=="usb", ATTRS{idVendor}=="0bb4", ATTRS{idProduct}=="0c9e", MODE="0660", OWNER="<your user name>" #Debug & Recovery dinc
SUBSYSTEMS=="usb", ATTRS{idVendor}=="0bb4", ATTRS{idProduct}=="0c8d", MODE="0660", OWNER="<your user name>" #Debug & Recovery dinc (hardware 0002)
SUBSYSTEMS=="usb", ATTRS{idVendor}=="0bb4", ATTRS{idProduct}=="0fff", MODE="0660", OWNER="<your user name>" #Fastboot dinc
SUBSYSTEMS=="usb", ATTRS{idVendor}=="0bb4", ATTRS{idProduct}=="0c94", MODE="0660", OWNER="<your user name>" #Bootloader dinc

HTC Slide

SUBSYSTEMS=="usb", ATTRS{idVendor}=="0bb4", ATTRS{idProduct}=="0ff9", MODE="0660", OWNER="<your user name>" #Normal slide
SUBSYSTEMS=="usb", ATTRS{idVendor}=="0bb4", ATTRS{idProduct}=="0e03", MODE="0660", OWNER="<your user name>" #Debug & Recovery slide
SUBSYSTEMS=="usb", ATTRS{idVendor}=="0bb4", ATTRS{idProduct}=="0fff", MODE="0660", OWNER="<your user name>" #Fastboot slide

HTC Evo Shift

SUBSYSTEMS=="usb", ATTRS{idVendor}=="0bb4", ATTRS{idProduct}=="0ff9", MODE="0660", OWNER="<your user name>" #Normal speedy
SUBSYSTEMS=="usb", ATTRS{idVendor}=="0bb4", ATTRS{idProduct}=="0ca5", MODE="0660", OWNER="<your user name>" #Debug & Recovery speedy
SUBSYSTEMS=="usb", ATTRS{idVendor}=="0bb4", ATTRS{idProduct}=="0fff", MODE="0660", OWNER="<your user name>" #Fastboot speedy

HTC Vision

SUBSYSTEMS=="usb", ATTRS{idVendor}=="0bb4", ATTRS{idProduct}=="0ff9", MODE="0660", OWNER="<your user name>" #Normal g2
SUBSYSTEMS=="usb", ATTRS{idVendor}=="0bb4", ATTRS{idProduct}=="0c91", MODE="0660", OWNER="<your user name>" #Debug & Recovery g2
SUBSYSTEMS=="usb", ATTRS{idVendor}=="0bb4", ATTRS{idProduct}=="0fff", MODE="0660", OWNER="<your user name>" #Fastboot g2

HTC Desire (Bravo)

SUBSYSTEMS=="usb", ATTRS{idVendor}=="0bb4", ATTRS{idProduct}=="0ff9", MODE="0660", GROUP="plugdev" # ADB
SUBSYSTEMS=="usb", ATTRS{idVendor}=="0bb4", ATTRS{idProduct}=="0c87", MODE="0660", GROUP="plugdev" # Recovery
SUBSYSTEMS=="usb", ATTRS{idVendor}=="0bb4", ATTRS{idProduct}=="0fff", MODE="0660", GROUP="plugdev" # Fastboot
SUBSYSTEMS=="usb", ATTRS{idVendor}=="0bb4", ATTRS{idProduct}=="0c94", MODE="0660", GROUP="plugdev" # ???

Nexus One

SUBSYSTEMS=="usb", ATTRS{idVendor}=="18d1", ATTRS{idProduct}=="4e11", MODE="0660", OWNER="<your user name>" #Normal nexus one
SUBSYSTEMS=="usb", ATTRS{idVendor}=="18d1", ATTRS{idProduct}=="4e12", MODE="0660", OWNER="<your user name>" #Debug & Recovery nexus one
SUBSYSTEMS=="usb", ATTRS{idVendor}=="0bb4", ATTRS{idProduct}=="0fff", MODE="0660", OWNER="<your user name>" #Fastboot nexus

Nexus S

SUBSYSTEMS=="usb", ATTRS{idVendor}=="18d1", ATTRS{idProduct}=="4e21", MODE="0660", OWNER="<your user name>" #Normal nexus s
SUBSYSTEMS=="usb", ATTRS{idVendor}=="18d1", ATTRS{idProduct}=="4e22", MODE="0660", OWNER="<your user name>" #Debug & Recovery nexus s
SUBSYSTEMS=="usb", ATTRS{idVendor}=="18d1", ATTRS{idProduct}=="4e20", MODE="0660", OWNER="<your user name>" #Fastboot nexus s

MyTouch 4G

SUBSYSTEMS=="usb", ATTRS{idVendor}=="0bb4", ATTRS{idProduct}=="0ff9", MODE="0660", OWNER="<your user name>" #Normal g2
SUBSYSTEMS=="usb", ATTRS{idVendor}=="0bb4", ATTRS{idProduct}=="0c96", MODE="0660", OWNER="<your user name>" #Debug & Recovery g2
SUBSYSTEMS=="usb", ATTRS{idVendor}=="0bb4", ATTRS{idProduct}=="0fff", MODE="0660", OWNER="<your user name>" #Fastboot g2

Motorola (All models/Global)

SUBSYSTEM=="usb", ATTRS{idVendor}=="22b8", MODE="0666", OWNER="username"  #All Motorola

Motorola Droid

SUBSYSTEMS=="usb", ATTRS{idVendor}=="22b8", ATTRS{idProduct}=="41db", MODE="0660", OWNER="<your user name>" #Normal, Debug & Recovery droid

Motorola Droid 2 Global

SUBSYSTEMS=="usb", ATTRS{idVendor}=="22b8", ATTRS{idProduct}=="42b4", MODE="0666", OWNER="username" #Normal, Debug & Recovery droid
SUBSYSTEMS=="usb", ATTRS{idVendor}=="22b8", ATTRS{idProduct}=="42b3", MODE="0666", OWNER="username"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="22b8", ATTRS{idProduct}=="41de", MODE="0666", OWNER="username" 
SUBSYSTEMS=="usb", ATTRS{idVendor}=="22b8", ATTRS{idProduct}=="42ba", MODE="0666", OWNER="username" 
SUBSYSTEMS=="usb", ATTRS{idVendor}=="22b8", ATTRS{idProduct}=="42b5", MODE="0666", OWNER="username" 
#This is not the entire list

Motorola CLIQ XT/Quench

SUBSYSTEMS=="usb", ATTRS{idVendor}=="22b8", ATTRS{idProduct}=="2d66", MODE="0660", OWNER="<your user name>" #Normal cliqxt

Motorola Defy/MB525

SUBSYSTEMS=="usb", ATTRS{idVendor}=="22b8", ATTRS{idProduct}=="428c", MODE="0660", OWNER="<your user name>" #Debug

ZTE Blade

SUBSYSTEMS=="usb", ATTRS{idVendor}=="19d2", ATTRS{idProduct}=="1353", MODE="0660", OWNER="<your user name>" #Normal
SUBSYSTEMS=="usb", ATTRS{idVendor}=="19d2", ATTRS{idProduct}=="1351", MODE="0660", OWNER="<your user name>" #Debug
SUBSYSTEMS=="usb", ATTRS{idVendor}=="19d2", ATTRS{idProduct}=="1354", MODE="0660", OWNER="<your user name>" #Recovery

links

android developer's UDEV page

Personal tools