Linux内核编译初探—USB转网口驱动模块config文件配置方法

最近在调试USB转网口,涉及到Linux内核编译配置文件的更改,记录一下调试过程。

首先需要了解USB设备接入后系统的识别信息,打印内核日志:

root@MyDevice:/# dmesg | tail -20
[ 5364.325642] usb 1-1.1: new high-speed USB device number 5 using xhci-hcd
[ 5364.426138] usb 1-1.1: New USB device found, idVendor=0bda, idProduct=8152
[ 5364.426145] usb 1-1.1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 5364.426148] usb 1-1.1: Product: USB 10/100 LAN
[ 5364.426152] usb 1-1.1: Manufacturer: Realtek
[ 5364.426155] usb 1-1.1: SerialNumber: 00E04C3607A9

注意idProduct和Manufacturer内容,我用的这款USB转网口设备嵌入的是瑞昱的8152网口芯片。

进入Linux内核源码的kernel目录执行

make menuconfig

进入到图形化配置界面,依次键选[Device Drivers -> Network device support -> USB Network Adapters]

Linux内核编译初探—USB转网口驱动模块config文件配置方法_第1张图片

找到 Realtek RTL8152/RTL8153 Based USB Ethernet Adapters选项使能即可。

以上选项信息参考博文:https://www.eefocus.com/toradex/blog/16-12/401923_7db7d.html

然而,编译出的内核版本验证未成功,进入menuconfig图形界面发现勾选已失效(无法正常保存勾选),因此在内核源码目录下寻找config文件进行手动更改配置项

.../configs/.../normal_kernel.config

查看代码

...
CONFIG_USB_NET_DRIVERS=y
# CONFIG_USB_CATC is not set
# CONFIG_USB_KAWETH is not set
# CONFIG_USB_PEGASUS is not set
#CONFIG_USB_RTL8150 is not set
#CONFIG_USB_RTL8152 is not set
# CONFIG_USB_LAN78XX is not set
CONFIG_USB_USBNET=y
CONFIG_USB_NET_AX8817X=y
CONFIG_USB_NET_AX88179_178A=y
CONFIG_USB_NET_CDCETHER=y
# CONFIG_USB_NET_CDC_EEM is not set
...

将CONFIG_USB_RTL8150和CONFIG_USB_RTL8152设为使能,进入menuconfig查看相应配置项,已更新为勾选。

制作内核版本,烧写至设备后上电启动,dmesg查看USB接口信息:

[  471.409739] usb 1-1.1: new high-speed USB device number 4 using xhci-hcd
[  471.510346] usb 1-1.1: New USB device found, idVendor=0bda, idProduct=8152
[  471.510353] usb 1-1.1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[  471.510357] usb 1-1.1: Product: USB 10/100 LAN
[  471.510360] usb 1-1.1: Manufacturer: Realtek
[  471.510364] usb 1-1.1: SerialNumber: 00E04C3607A9
[  471.701309] usb 1-1.1: reset high-speed USB device number 4 using xhci-hcd
[  471.882926] r8152 1-1.1:1.0 eth1: v1.09.9

可以发现,多出了一行识别信息,r8152被识别为eth1(此时ifconfig发现新的网卡,但是没有IP等信息),使用udhcpc命令为eth1分配动态ip地址:

udhcpc -i eth1

ifconfig查看网络配置情况:

root@MyDevice:~# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0D:0D:D6:B6:21
          inet6 addr: fe80::20d:dff:fed6:b621/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:367 errors:0 dropped:0 overruns:0 frame:0
          TX packets:525 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:92887 (90.7 KiB)  TX bytes:74001 (72.2 KiB)
          Interrupt:30

eth0.10   Link encap:Ethernet  HWaddr 00:0D:0D:D6:B6:21
          inet addr:10.16.7.122  Bcast:10.16.7.255  Mask:255.255.255.0
          inet6 addr: 2001:10:16:8::60/64 Scope:Global
          inet6 addr: fe80::20d:dff:fed6:b621/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:97 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:18767 (18.3 KiB)

eth1      Link encap:Ethernet  HWaddr 00:E0:4C:36:07:A9
          inet addr:192.168.1.101  Bcast:192.168.1.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:20 errors:0 dropped:0 overruns:0 frame:0
          TX packets:13 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:4679 (4.5 KiB)  TX bytes:2086 (2.0 KiB)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:201 errors:0 dropped:0 overruns:0 frame:0
          TX packets:201 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:22516 (21.9 KiB)  TX bytes:22516 (21.9 KiB

发现eth1的IP地址生效,且与eth0.30在同一局域网,接着验证eth1的网络性能,发现无法ping通局域网中的其他设备。

route add default gw 192.168.1.1 eth1

进一步设置eth1的默认网关,再ping成功。t802:~# route add default gw 192.168.1.1 eth1

你可能感兴趣的:(Linux/Unix编程)