Openwrt Udev Configure(3)

1      Scope of Document

This document describes how to write udev script, when enum usb device maybe produces several interfaces(/dev/ttyUSB*),

if we want to compatible serveral usb modules, udev script is very useful.when module insert or remove, spec udev script will

be called.example: this module have four port, we can enumerated to specific devices(/dev/ttyfdti1,/dev/ttyftdi1,/dev/ttyftdi2,/dev/ttyftdi3).

#add for ftdi usb-serial

ACTION=="add",KERNELS=="1-1.4:1.0",SUBSYSTEMS=="usb",DRIVERS=="ftdi_sio",SYMLINK+="ttyftdi0"

ACTION=="add",KERNELS=="1-1.4:1.1",SUBSYSTEMS=="usb",DRIVERS=="ftdi_sio",SYMLINK+="ttyftdi1"

ACTION=="add",KERNELS=="1-1.4:1.2",SUBSYSTEMS=="usb",DRIVERS=="ftdi_sio",SYMLINK+="ttyftdi2"

ACTION=="add",KERNELS=="1-1.4:1.3",SUBSYSTEMS=="usb",DRIVERS=="ftdi_sio",SYMLINK+="ttyftdi3"

 

#remove for ftdi usb-serial

ACTION=="remove",KERNELS=="1-1.4:1.0",SUBSYSTEMS=="usb",DRIVERS=="ftdi_sio",SYMLINK+="ttyftdi0"

ACTION=="remove",KERNELS=="1-1.4:1.1",SUBSYSTEMS=="usb",DRIVERS=="ftdi_sio",SYMLINK+="ttyftdi1"

ACTION=="remove",KERNELS=="1-1.4:1.2",SUBSYSTEMS=="usb",DRIVERS=="ftdi_sio",SYMLINK+="ttyftdi2"

ACTION=="remove",KERNELS=="1-1.4:1.3",SUBSYSTEMS=="usb",DRIVERS=="ftdi_sio",SYMLINK+="ttyftdi3"

 

2      Requiremen

2.1     Function Requirement

Custom private udev rules,compatible different hardware module.

2.2     Performance Requirement

NA

3      Hardware Overview

NA

                

4      Functional Description

4.1     Functional Block Diagram

NA

                     

5      Porting

5.1     System configure

Reference: https://wiki.archlinux.org/index.php/Udev_(简体中文)

          https://mirrors.edge.kernel.org/pub/linux/utils/kernel/hotplug/udev/udev.html

 

example1:

       when ec20 module be enumed, it can emum five device interfaces, /dev/tty20ec0,

/dev/tty20ec1,/dev/tty4g,/dev/tty20ec3,/dev/tty20ec4.attention to when enum /dev/tty4g interface, it will run /bin/ifup mobile script to diag-up.

If all internet access modules, its diag port was enumed to /dev/tty4g, we can compible all internet access modules in openwrt rootfs.

 

# add for ec20

ACTION=="add", ATTRS{modalias}=="usb:v2C7Cp0125d0318dcEFdsc02dp01icFFiscFFipFFin00", ATTRS{bInterfaceNumber}=="00", SYMLINK="tty20ec0"

ACTION=="add", ATTRS{modalias}=="usb:v2C7Cp0125d0318dcEFdsc02dp01icFFisc00ip00in01", ATTRS{bInterfaceNumber}=="01", SYMLINK="tty20ec1"

ACTION=="add", ATTRS{modalias}=="usb:v2C7Cp0125d0318dcEFdsc02dp01icFFisc00ip00in02", ATTRS{bInterfaceNumber}=="02", SYMLINK="tty4g",RUN="/sbin/ifup mobile"

ACTION=="add", ATTRS{modalias}=="usb:v2C7Cp0125d0318dcEFdsc02dp01icFFisc00ip00in03", ATTRS{bInterfaceNumber}=="03", SYMLINK="tty20ec3"

ACTION=="add", ATTRS{modalias}=="usb:v2C7Cp0125d0318dcEFdsc02dp01icFFiscFFipFFin04", ATTRS{bInterfaceNumber}=="04", SYMLINK="tty20ec4"

 

# remove for ec20

ACTION=="remove", ATTRS{modalias}=="usb:v2C7Cp0125d0318dcEFdsc02dp01icFFiscFFipFFin00", ATTRS{bInterfaceNumber}=="00", SYMLINK="tty20ec0"

ACTION=="remove", ATTRS{modalias}=="usb:v2C7Cp0125d0318dcEFdsc02dp01icFFisc00ip00in01", ATTRS{bInterfaceNumber}=="01", SYMLINK="tty20ec1"

ACTION=="remove", ATTRS{modalias}=="usb:v2C7Cp0125d0318dcEFdsc02dp01icFFisc00ip00in02", ATTRS{bInterfaceNumber}=="02", SYMLINK="tty4g",RUN="/sbin/ifdown mobile"

ACTION=="remove", ATTRS{modalias}=="usb:v2C7Cp0125d0318dcEFdsc02dp01icFFisc00ip00in03", ATTRS{bInterfaceNumber}=="03", SYMLINK="tty20ec3"

ACTION=="remove", ATTRS{modalias}=="usb:v2C7Cp0125d0318dcEFdsc02dp01icFFiscFFipFFin04", ATTRS{bInterfaceNumber}=="04", SYMLINK="tty20ec4"

 

Example2:
        if you have two usb-serial modules, and you want to distinguish between them, you can reference follow udev script methon:

       #add for ftdi usb-serial

ACTION=="add",KERNELS=="1-1.4:1.0",SUBSYSTEMS=="usb",DRIVERS=="ftdi_sio",SYMLINK+="ttyftdi0"

ACTION=="add",KERNELS=="1-1.4:1.1",SUBSYSTEMS=="usb",DRIVERS=="ftdi_sio",SYMLINK+="ttyftdi1"

ACTION=="add",KERNELS=="1-1.4:1.2",SUBSYSTEMS=="usb",DRIVERS=="ftdi_sio",SYMLINK+="ttyftdi2"

ACTION=="add",KERNELS=="1-1.4:1.3",SUBSYSTEMS=="usb",DRIVERS=="ftdi_sio",SYMLINK+="ttyftdi3"

 

#remove for ftdi usb-serial

ACTION=="remove",KERNELS=="1-1.4:1.0",SUBSYSTEMS=="usb",DRIVERS=="ftdi_sio",SYMLINK+="ttyftdi0"

ACTION=="remove",KERNELS=="1-1.4:1.1",SUBSYSTEMS=="usb",DRIVERS=="ftdi_sio",SYMLINK+="ttyftdi1"

ACTION=="remove",KERNELS=="1-1.4:1.2",SUBSYSTEMS=="usb",DRIVERS=="ftdi_sio",SYMLINK+="ttyftdi2"

ACTION=="remove",KERNELS=="1-1.4:1.3",SUBSYSTEMS=="usb",DRIVERS=="ftdi_sio",SYMLINK+="ttyftdi3"

posted @ 2019-01-09 15:27  嵌入式实操  阅读(926)  评论(0编辑  收藏  举报