Udev 규칙은 거의 변하지 않습니다.

Udev 규칙은 거의 변하지 않습니다.

플러그를 꽂으면 두 개의 서로 다른 코어(예: /dev/ttyUSB0/dev/ttyUSB1. 하나는 구성 포트, 다른 하나는 데이터 포트라고 부르겠습니다. 구성에는 항상 데이터 앞에 첫 번째 번호가 할당됩니다.

포트를 심볼릭 링크하고 서로 다른 장치를 구별하는 udev 규칙을 만들려고 합니다. 불행히도 차별화 기능은 데이터 대 구성의 한 상위 항목과 장치 대 장치의 다른 상위 항목에 있는 것 같습니다.

데이터 측면에서 이전 구성을 활용하는 방법을 잘 모르겠습니다. 하드 코딩 없이 어떻게 이 작업을 수행할 수 있나요? 원하는 결과가 다음과 같다고 가정합니다.

/dev/device0_config
/dev/device0_data
/dev/device1_config
/dev/device1_data

attribute-walk장치를 연결하면 각각 다음 구성과 데이터 결과가 생성됩니다.

Udevadm info 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:14.0/usb3/3-2/3-2:1.0/ttyUSB1/tty/ttyUSB1':
    KERNEL=="ttyUSB1"
    SUBSYSTEM=="tty"
    DRIVER==""

  looking at parent device '/devices/pci0000:00/0000:00:14.0/usb3/3-2/3-2:1.0/ttyUSB1':
    KERNELS=="ttyUSB1"
    SUBSYSTEMS=="usb-serial"
    DRIVERS=="cp210x"
    ATTRS{port_number}=="0"

  looking at parent device '/devices/pci0000:00/0000:00:14.0/usb3/3-2/3-2:1.0':
    KERNELS=="3-2:1.0"
    SUBSYSTEMS=="usb"
    DRIVERS=="cp210x"
    ATTRS{supports_autosuspend}=="1"
    ATTRS{bNumEndpoints}=="02"
    ATTRS{bInterfaceProtocol}=="00"
    ATTRS{bInterfaceSubClass}=="00"
    ATTRS{bInterfaceClass}=="ff"
    ATTRS{interface}=="Enhanced Com Port"
    ATTRS{bInterfaceNumber}=="00"
    ATTRS{authorized}=="1"
    ATTRS{bAlternateSetting}==" 0"

  looking at parent device '/devices/pci0000:00/0000:00:14.0/usb3/3-2':
    KERNELS=="3-2"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{bConfigurationValue}=="1"
    ATTRS{bNumConfigurations}=="1"
    ATTRS{quirks}=="0x0"
    ATTRS{devnum}=="9"
    ATTRS{version}==" 2.00"
    ATTRS{bcdDevice}=="0100"
    ATTRS{bNumInterfaces}==" 2"
    ATTRS{bDeviceProtocol}=="00"
    ATTRS{speed}=="12"
    ATTRS{bMaxPacketSize0}=="64"
    ATTRS{urbnum}=="22"
    ATTRS{maxchild}=="0"
    ATTRS{product}=="CP2105 Dual USB to UART Bridge Controller"
    ATTRS{bmAttributes}=="80"
    ATTRS{bDeviceSubClass}=="00"
    ATTRS{bMaxPower}=="100mA"
    ATTRS{configuration}==""
    ATTRS{idProduct}=="ea70"
    ATTRS{idVendor}=="10c4"
    ATTRS{ltm_capable}=="no"
    ATTRS{busnum}=="3"
    ATTRS{removable}=="removable"
    ATTRS{avoid_reset_quirk}=="0"
    ATTRS{rx_lanes}=="1"
    ATTRS{manufacturer}=="Silicon Labs"
    ATTRS{authorized}=="1"
    ATTRS{bDeviceClass}=="00"
    ATTRS{serial}=="00E25BEB"
    ATTRS{tx_lanes}=="1"
    ATTRS{devpath}=="2"

  looking at parent device '/devices/pci0000:00/0000:00:14.0/usb3':
    KERNELS=="usb3"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{speed}=="480"
    ATTRS{bcdDevice}=="0515"
    ATTRS{authorized_default}=="1"
    ATTRS{busnum}=="3"
    ATTRS{interface_authorized_default}=="1"
    ATTRS{bConfigurationValue}=="1"
    ATTRS{version}==" 2.00"
    ATTRS{bMaxPacketSize0}=="64"
    ATTRS{bmAttributes}=="e0"
    ATTRS{bNumInterfaces}==" 1"
    ATTRS{bNumConfigurations}=="1"
    ATTRS{tx_lanes}=="1"
    ATTRS{avoid_reset_quirk}=="0"
    ATTRS{bDeviceClass}=="09"
    ATTRS{maxchild}=="12"
    ATTRS{bMaxPower}=="0mA"
    ATTRS{product}=="xHCI Host Controller"
    ATTRS{serial}=="0000:00:14.0"
    ATTRS{bDeviceProtocol}=="01"
    ATTRS{devnum}=="1"
    ATTRS{configuration}==""
    ATTRS{idVendor}=="1d6b"
    ATTRS{devpath}=="0"
    ATTRS{quirks}=="0x0"
    ATTRS{urbnum}=="144"
    ATTRS{removable}=="unknown"
    ATTRS{bDeviceSubClass}=="00"
    ATTRS{idProduct}=="0002"
    ATTRS{authorized}=="1"
    ATTRS{rx_lanes}=="1"
    ATTRS{ltm_capable}=="no"
    ATTRS{manufacturer}=="Linux 5.15.0-58-generic xhci-hcd"

  looking at parent device '/devices/pci0000:00/0000:00:14.0':
    KERNELS=="0000:00:14.0"
    SUBSYSTEMS=="pci"
    DRIVERS=="xhci_hcd"
    ATTRS{consistent_dma_mask_bits}=="64"
    ATTRS{enable}=="1"
    ATTRS{ari_enabled}=="0"
    ATTRS{local_cpulist}=="0-7"
    ATTRS{label}=="Onboard - Other"
    ATTRS{dbc}=="disabled"
    ATTRS{device}=="0xa0ed"
    ATTRS{local_cpus}=="ff"
    ATTRS{subsystem_device}=="0x3002"
    ATTRS{irq}=="147"
    ATTRS{vendor}=="0x8086"
    ATTRS{power_state}=="D0"
    ATTRS{d3cold_allowed}=="1"
    ATTRS{class}=="0x0c0330"
    ATTRS{index}=="6"
    ATTRS{driver_override}=="(null)"
    ATTRS{numa_node}=="-1"
    ATTRS{dma_mask_bits}=="64"
    ATTRS{msi_bus}=="1"
    ATTRS{subsystem_vendor}=="0x8086"
    ATTRS{broken_parity_status}=="0"
    ATTRS{revision}=="0x20"

  looking at parent device '/devices/pci0000:00':
    KERNELS=="pci0000:00"
    SUBSYSTEMS==""
    DRIVERS==""
    ATTRS{waiting_for_supplier}=="0"

그리고

Udevadm info 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:14.0/usb3/3-2/3-2:1.1/ttyUSB2/tty/ttyUSB2':
    KERNEL=="ttyUSB2"
    SUBSYSTEM=="tty"
    DRIVER==""

  looking at parent device '/devices/pci0000:00/0000:00:14.0/usb3/3-2/3-2:1.1/ttyUSB2':
    KERNELS=="ttyUSB2"
    SUBSYSTEMS=="usb-serial"
    DRIVERS=="cp210x"
    ATTRS{port_number}=="0"

  looking at parent device '/devices/pci0000:00/0000:00:14.0/usb3/3-2/3-2:1.1':
    KERNELS=="3-2:1.1"
    SUBSYSTEMS=="usb"
    DRIVERS=="cp210x"
    ATTRS{bNumEndpoints}=="02"
    ATTRS{authorized}=="1"
    ATTRS{bInterfaceProtocol}=="00"
    ATTRS{bInterfaceNumber}=="01"
    ATTRS{bInterfaceClass}=="ff"
    ATTRS{bInterfaceSubClass}=="00"
    ATTRS{bAlternateSetting}==" 0"
    ATTRS{interface}=="Standard Com Port"
    ATTRS{supports_autosuspend}=="1"

  looking at parent device '/devices/pci0000:00/0000:00:14.0/usb3/3-2':
    KERNELS=="3-2"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{devpath}=="2"
    ATTRS{authorized}=="1"
    ATTRS{manufacturer}=="Silicon Labs"
    ATTRS{speed}=="12"
    ATTRS{quirks}=="0x0"
    ATTRS{bMaxPower}=="100mA"
    ATTRS{bDeviceClass}=="00"
    ATTRS{serial}=="00E25BEB"
    ATTRS{removable}=="removable"
    ATTRS{configuration}==""
    ATTRS{bMaxPacketSize0}=="64"
    ATTRS{ltm_capable}=="no"
    ATTRS{bDeviceSubClass}=="00"
    ATTRS{bNumInterfaces}==" 2"
    ATTRS{bcdDevice}=="0100"
    ATTRS{busnum}=="3"
    ATTRS{bmAttributes}=="80"
    ATTRS{bNumConfigurations}=="1"
    ATTRS{avoid_reset_quirk}=="0"
    ATTRS{bConfigurationValue}=="1"
    ATTRS{product}=="CP2105 Dual USB to UART Bridge Controller"
    ATTRS{urbnum}=="22"
    ATTRS{maxchild}=="0"
    ATTRS{bDeviceProtocol}=="00"
    ATTRS{tx_lanes}=="1"
    ATTRS{idVendor}=="10c4"
    ATTRS{idProduct}=="ea70"
    ATTRS{rx_lanes}=="1"
    ATTRS{devnum}=="9"
    ATTRS{version}==" 2.00"

  looking at parent device '/devices/pci0000:00/0000:00:14.0/usb3':
    KERNELS=="usb3"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{bDeviceSubClass}=="00"
    ATTRS{bNumConfigurations}=="1"
    ATTRS{bConfigurationValue}=="1"
    ATTRS{product}=="xHCI Host Controller"
    ATTRS{bMaxPacketSize0}=="64"
    ATTRS{bNumInterfaces}==" 1"
    ATTRS{busnum}=="3"
    ATTRS{version}==" 2.00"
    ATTRS{tx_lanes}=="1"
    ATTRS{idVendor}=="1d6b"
    ATTRS{quirks}=="0x0"
    ATTRS{removable}=="unknown"
    ATTRS{authorized_default}=="1"
    ATTRS{devnum}=="1"
    ATTRS{devpath}=="0"
    ATTRS{speed}=="480"
    ATTRS{bcdDevice}=="0515"
    ATTRS{urbnum}=="144"
    ATTRS{rx_lanes}=="1"
    ATTRS{bDeviceProtocol}=="01"
    ATTRS{configuration}==""
    ATTRS{serial}=="0000:00:14.0"
    ATTRS{interface_authorized_default}=="1"
    ATTRS{bDeviceClass}=="09"
    ATTRS{maxchild}=="12"
    ATTRS{manufacturer}=="Linux 5.15.0-58-generic xhci-hcd"
    ATTRS{bmAttributes}=="e0"
    ATTRS{idProduct}=="0002"
    ATTRS{avoid_reset_quirk}=="0"
    ATTRS{bMaxPower}=="0mA"
    ATTRS{ltm_capable}=="no"
    ATTRS{authorized}=="1"

  looking at parent device '/devices/pci0000:00/0000:00:14.0':
    KERNELS=="0000:00:14.0"
    SUBSYSTEMS=="pci"
    DRIVERS=="xhci_hcd"
    ATTRS{dma_mask_bits}=="64"
    ATTRS{broken_parity_status}=="0"
    ATTRS{driver_override}=="(null)"
    ATTRS{d3cold_allowed}=="1"
    ATTRS{revision}=="0x20"
    ATTRS{irq}=="147"
    ATTRS{power_state}=="D0"
    ATTRS{device}=="0xa0ed"
    ATTRS{label}=="Onboard - Other"
    ATTRS{dbc}=="disabled"
    ATTRS{enable}=="1"
    ATTRS{index}=="6"
    ATTRS{local_cpulist}=="0-7"
    ATTRS{subsystem_vendor}=="0x8086"
    ATTRS{local_cpus}=="ff"
    ATTRS{subsystem_device}=="0x3002"
    ATTRS{msi_bus}=="1"
    ATTRS{consistent_dma_mask_bits}=="64"
    ATTRS{vendor}=="0x8086"
    ATTRS{numa_node}=="-1"
    ATTRS{class}=="0x0c0330"
    ATTRS{ari_enabled}=="0"

  looking at parent device '/devices/pci0000:00':
    KERNELS=="pci0000:00"
    SUBSYSTEMS==""
    DRIVERS==""
    ATTRS{waiting_for_supplier}=="0"

ATTRS{serial}==...사용할 수 있는 장치를 구별하려면looking at parent device '/devices/pci0000:00/0000:00:14.0/usb3/3-2':

관련 정보