应用场景:
有些公司想将模块换成合宙的模块,但是之前的模块出现的是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
- usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod)
{net->netdev_ops = &usbnet_netdev_ops;net->watchdog_timeo = TX_TIMEOUT_JIFFIES;net->ethtool_ops = &usbnet_ethtool_ops;/ allow device-specific bind/init procedures// NOTE net->name still not usable ...if (info->bind) {status = info->bind (dev, udev);if (status < 0)goto out1;// heuristic: "usb%d" for links we know are two-host,// else "eth%d" when there's reasonable doubt. userspace// can rename the link if it knows better.if ((dev->driver_info->flags & FLAG_ETHER) != 0 &&((dev->driver_info->flags & FLAG_POINTTOPOINT) == 0 ||(net->dev_addr [0] & 0x02) == 0))strcpy (net->name, "eth%d"); /**** 请将此处修改为strcpy (net->name, "usb%d"); *//* WLAN devices should always be named "wlan%d" */if ((dev->driver_info->flags & FLAG_WLAN) != 0)strcpy(net->name, "wlan%d");/* WWAN devices should always be named "wwan%d" */if ((dev->driver_info->flags & FLAG_WWAN) != 0)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
static int option_probe(struct usb_serial *serial,const struct usb_device_id *id){struct usb_interface_descriptor *iface_desc =&serial->interface->cur_altsetting->desc;struct usb_device_descriptor *dev_desc = &serial->dev->descriptor;/* Never bind to the CD-Rom emulation interface */if (iface_desc->bInterfaceClass == 0x08)i return -ENODEV;//+add by airm2m for Air72xif(dev_desc->idVendor == cpu_to_le16(0x1286) &&dev_desc->idProduct == cpu_to_le16(0x4e3d) &&iface_desc->bInterfaceNumber <= 1)return -ENODEV;//-add by airm2m for Air72x/** Don't bind reserved interfaces (like network ones) which often have* the same class/subclass/protocol as the serial interfaces. Look at* the Windows driver .INF files for reserved interface numbers.*/if (is_blacklisted(iface_desc->bInterfaceNumber,OPTION_BLACKLIST_RESERVED_IF,(const struct option_blacklist_info *) id->driver_info))return -ENODEV;
优先推荐使用方法2
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!