Linuxカーネルを変更してオペレーティングシステムのethxxデバイス名を変更する方法

Linuxでethxxデバイス名を変更します

 

アプリケーションシナリオ:

    一部の企業はモジュールを賀州モジュールに交換したいと考えていますが、前のモジュールはUSBxxネットワークカードを示し、賀州モジュールはethxxであったため、アプリケーションがアプリケーションを変更することになり、非常に面倒でした。

変更方法:

方法1はスクリプトを変更します 

       1.找到文件/etc/udev/rules.d/70-persistent-net.rules幹SUBSYSTEM == "net"、ACTION == "add"、DRIVERS == "?*"、ATTR {address} == " ac:00:00:c9:1e:c5 "、ATTR {dev_id} ==" 0x0 "、ATTR {type} ==" 1 "、KERNEL ==" eth * "改成SUBSYSTEM ==" net "、ACTION == "add"、DRIVERS == "?*"、ATTR {address} == "ac:00:00:c9:1e:c5"、ATTR {dev_id} == "0x0"、ATTR {type} == "1"、KERNEL == "usb *"、

方法2はカーネルを変更します   

ステップ1:

2.6.30より新しいLinuxカーネルバージョンの場合
ファイル:[
KERNEL ] / drivers / net / usb / usbnet.c



 
  1. usbnet_probe(struct usb_interface * udev、const struct usb_device_id * prod)
  2. {
  3. net-> netdev_ops =&usbnet_netdev_ops;
  4. net-> watchdog_timeo = TX_TIMEOUT_JIFFIES;
  5. net-> ethtool_ops =&usbnet_ethtool_ops;
  6. / allow device-specific bind/init procedures
  7. //注net-> nameはまだ使用できません..。
  8. if(info-> bind){
  9. status = info->bind (dev, udev);
  10. if(status <0)
  11. goto out1;
  12. // heuristic: "usb%d" for links we know are two-host,
  13. // else "eth%d" when there's reasonable doubt. userspace
  14. // can rename the link if it knows better.
  15. if ((dev->driver_info->flags & FLAG_ETHER) != 0 &&
  16. ((dev->driver_info->flags & FLAG_POINTTOPOINT) == 0 ||
  17. (net->dev_addr [0] & 0x02) == 0))
  18. strcpy (net->name, "eth%d"); /**** 请将此处修改为 strcpy(net-> name、 "usb%d"); * /
  19. /* WLAN devices should always be named "wlan%d" */
  20. if((dev-> driver_info-> flags&FLAG_WLAN)!= 0)
  21. strcpy(net-> name、 "wlan%d");
  22. / * WWANデバイスには常に「wwan%d」という名前を付ける必要があります* /
  23. if((dev-> driver_info-> flags&FLAG_WWAN)!= 0)
  24. strcpy(net-> name、 "wwan%d");

    

  • ステップ2:
    ドライバーがusb M0およびM1をttyUSBデバイスとしてロードすることを禁止するには、usbシリアルドライバーを次のように変更する必要があります。

2.6.30
ファイルより新しいLinuxカーネルバージョンの場合:[KERNEL] /drivers/usb/serial/option.c



 
  1. static int option_probe(struct usb_serial *serial,
  2. const struct usb_device_id *id)
  3. {
  4. struct usb_interface_descriptor *iface_desc =
  5. &serial->interface->cur_altsetting->desc;
  6. struct usb_device_descriptor *dev_desc = &serial->dev->descriptor;
  7.  
  8. /* Never bind to the CD-Rom emulation interface */
  9. if (iface_desc->bInterfaceClass == 0x08)
  10. i return -ENODEV;
  11. //+add by airm2m for Air72x
  12. if(dev_desc->idVendor == cpu_to_le16(0x1286) &&
  13. dev_desc->idProduct == cpu_to_le16(0x4e3d) &&
  14. iface_desc->bInterfaceNumber <= 1)
  15. return -ENODEV;
  16. //-add by airm2m for Air72x
  17. /*
  18. * Don't bind reserved interfaces (like network ones) which often have
  19. * the same class/subclass/protocol as the serial interfaces. Look at
  20. * the Windows driver .INF files for reserved interface numbers.
  21. */
  22. if (is_blacklisted(
  23. iface_desc->bInterfaceNumber,
  24. OPTION_BLACKLIST_RESERVED_IF,
  25. (const struct option_blacklist_info *) id->driver_info))
  26. return -ENODEV;

使用方法2

おすすめ

転載: blog.csdn.net/star871016/article/details/108835713