如何修改linux内核,实现操作系统中的ethxx设备名修改

修改linux 中的ethxx 设备名

 

应用场景:

    有些公司想将模块换成合宙的模块,但是之前的模块出现的是USBxx 网卡,合宙的是ethxx ,这让就让应用程序改动应用程序,很是麻烦!

修改方法:

方法一  修改脚本 

       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*",

方法二  修改内核   

step 1:

For Linux Kernel Version newer than 2.6.30
File: [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. // NOTE net->name still not usable ...
  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 devices should always be named "wwan%d" */
  23. if ((dev->driver_info->flags & FLAG_WWAN) != 0)
  24. strcpy(net->name, "wwan%d");

    

  • step 2:
    为了禁止驱动将usb M0,M1加载为ttyUSB设备,需要将usb serial 驱动部分做如下修改:

For Linux Kernel Version newer than 2.6.30
File: [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
今日推荐