前言
走OTG网卡这一步,也是迫不得已的行为,但事情总是不会一帆风顺的。解决外接网卡的驱动问题,就是一个麻烦的事情。
设备
- 小米note
- rt5370网卡
系统
- MIUI 6 Linux kernel 3.4
可行的解决方式
- 换合适的手机支持你的外接网卡
- 换合适的网卡支持你的手机
- 重新刷你手机的内核,这个新的内核编译时包含了你外接网卡的驱动
- 自己编译外接网卡的驱动模块
讨论
- 前两种方式虽然可以解决,但就解决问题而言,不是最佳的方式。其实是在逃避问题。
- 第三种是可行的,网上也看到了相关教程,但风险无疑也是很大的,因此我打算最后在尝试。当然如果你本身对这方面比较精通,希望能不吝赐教。
- 我这里只谈一下,我的第四种尝试。
编译内核模块
- 在实践之前,我首先搜索了大量相关的教程,总体而言和我当年学习过的嵌入式开发,区别不大。网络上部分文章是给PC进行驱动模块的开发,也有给arm开发板进行的驱动模块开发,少部分是给android系统进行的驱动开发,我这里单独列出arm和android主要是因为两者还是有一定区别的,比如最明显的文件系统目录(我比较粗糙的理解,毕竟没有深入对比)。arm板而言还是和PC很类似的目录结构。
- 按照我的理解,我不得不假设,android中的驱动模块和arm开发板的驱动模块开发流程是一致的(下面的内容都以这文前提)。 说起来这个流程很简单。
内核头文件目录/内核源码目录 + 驱动源码 ->内核模块
- 不管是PC,还是arm开发板其实都是这个流程,给PC来开发是最简单的,arm 开发板一般则需要交叉编译。
- 我目前的情况是,在挂载的kali中,下载了一份很旧的网卡驱动,而我这个kali也有gcc环境,因此考虑是否可以直接在手机的kali中编译出需要的内核模块。理论上,这是完全可行的,但其实有很多不行的地方。首先我们都知道编译内核模块所需的内核头文件版本和你当前的内核版本应该是一致的,这一点就很难满足。我挂载的kali系统提示我它是linux kernel 3.4的,这是我手机的内核信息(为何不是kali的3.18?)。但kali 的软件源中根本没有对应的内核头文件版本。
- 就当是探索了,我安装了一个3.18的内核头文件(甚至后来还装了内核源文件)。又修改了驱动源码中Makefile的一些内容,但其实到一定的阶段就编译失败了,原因很多,我觉得一个原因可能是内核版本太高了,一些原先的数据结构,不一致了等。反正很难顺利的编译下去。
- 在实践的过程中,我其实是有疑惑的,我在插上外接网卡后,dmesg其实打印了识别的信息,但不知为什么就是在ifconfig中无法看到,
35842.063914] C0 [ kworker/0:2, 8829] BMS: adjust_soc: s 72 i 259584 v 4048380 ocv 4076326 rbatt 132 uuc 89880 cc 6086 r 2187080 t 305 f 2996000
[35843.963958] C0 [ AudioOut_2, 779] msm_dai_q6_mi2s_hw_params: dai id 1 dai_data->channels = 2
[35843.963963] C0 [ AudioOut_2, 779] sample_rate = 48000 i2s_cfg_minor_version = 0x1
[35843.963968] C0 [ AudioOut_2, 779] bit_width = 16 channel_mode = 0x2 mono_stereo = 0x1
[35843.963973] C0 [ AudioOut_2, 779] ws_src = 0x1 sample_rate = 48000 data_format = 0x0
[35843.963977] C0 [ AudioOut_2, 779] reserved = 0
[35843.977474] C0 [ AudioOut_2, 779] msm8974_sec_mi2s_startup: dai name msm-dai-q6-mi2s.1 f5272a08
[35843.977496] C0 [ AudioOut_2, 779] msm8974_sec_mi2s_startup: acquire mi2s rx resources
[35843.978643] C0 [ AudioOut_2, 779] msm8974_sec_mi2s_startup: acquire mi2s tx resources
[35843.979191] C0 [ AudioOut_2, 779] msm_dai_q6_mi2s_hw_params: dai id 1 dai_data->channels = 2
[35843.979197] C0 [ AudioOut_2, 779] sample_rate = 48000 i2s_cfg_minor_version = 0x1
[35843.979201] C0 [ AudioOut_2, 779] bit_width = 16 channel_mode = 0x1 mono_stereo = 0x1
[35843.979206] C0 [ AudioOut_2, 779] ws_src = 0x1 sample_rate = 48000 data_format = 0x0
[35843.979210] C0 [ AudioOut_2, 779] reserved = 0
[35844.743592] C0 [ MC_Thread, 1229] wlan: [1229:E :HDP] hdd_tx_rx_pkt_cnt_stat_timer_handler: Disable split scan
[35848.144587] C0 [ AudioOut_2, 779] msm8974_sec_mi2s_shutdown: free mi2s rx resources
[35848.145280] C0 [ AudioOut_2, 779] msm8974_sec_mi2s_shutdown: free mi2s tx resources
[35862.064191] C0 [ kworker/0:2, 8829] BMS: adjust_soc: s 72 i 125339 v 4054830 ocv 4076326 rbatt 132 uuc 89880 cc 7188 r 2187080 t 305 f 2996000
[35870.552180] C0 [ kworker/0:2, 8829] msm-dwc3 msm_dwc3: DWC3 exited from low power mode
[35870.552761] C0 [ kworker/0:2, 8829] switch_usb_to_host_mode: switch to host mode
[35870.554960] C0 [ kworker/0:2, 8829] xhci-hcd xhci-hcd: xHCI Host Controller
[35870.554996] C0 [ kworker/0:2, 8829] xhci-hcd xhci-hcd: new USB bus registered, assigned bus number 1
[35870.557212] C0 [ kworker/0:2, 8829] xhci-hcd xhci-hcd: irq 163, io mem 0xf9200000
[35870.561656] C0 [ kworker/0:2, 8829] usb usb1: New USB device found, idVendor=1d6b, idProduct=0002
[35870.561675] C0 [ kworker/0:2, 8829] usb usb1: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[35870.561691] C0 [ kworker/0:2, 8829] usb usb1: Product: xHCI Host Controller
[35870.561705] C0 [ kworker/0:2, 8829] usb usb1: Manufacturer: Linux 3.4.0-g8035498-01450-g5febb22 xhci-hcd
[35870.561719] C0 [ kworker/0:2, 8829] usb usb1: SerialNumber: xhci-hcd
[35870.562543] C0 [ kworker/0:2, 8829] xHCI xhci_add_endpoint called for root hub
[35870.562557] C0 [ kworker/0:2, 8829] xHCI xhci_check_bandwidth called for root hub
[35870.562988] C0 [ kworker/0:2, 8829] hub 1-0:1.0: USB hub found
[35870.563016] C0 [ kworker/0:2, 8829] hub 1-0:1.0: 1 port detected
[35870.563743] C0 [ kworker/0:2, 8829] xhci-hcd xhci-hcd: xHCI Host Controller
[35870.563769] C0 [ kworker/0:2, 8829] xhci-hcd xhci-hcd: new USB bus registered, assigned bus number 2
[35870.563869] C0 [ kworker/0:2, 8829] usb usb2: New USB device found, idVendor=1d6b, idProduct=0003
[35870.563885] C0 [ kworker/0:2, 8829] usb usb2: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[35870.563900] C0 [ kworker/0:2, 8829] usb usb2: Product: xHCI Host Controller
[35870.563913] C0 [ kworker/0:2, 8829] usb usb2: Manufacturer: Linux 3.4.0-g8035498-01450-g5febb22 xhci-hcd
[35870.563926] C0 [ kworker/0:2, 8829] usb usb2: SerialNumber: xhci-hcd
[35870.564556] C0 [ kworker/0:2, 8829] xHCI xhci_add_endpoint called for root hub
[35870.564569] C0 [ kworker/0:2, 8829] xHCI xhci_check_bandwidth called for root hub
[35870.565031] C0 [ kworker/0:2, 8829] hub 2-0:1.0: USB hub found
[35870.565060] C0 [ kworker/0:2, 8829] hub 2-0:1.0: 1 port detected
[35870.572421] C0 [ healthd, 257] qpnp_chg_usb_usbin_valid_irq_handler: usbin-valid triggered: 1 host_mode: 1
[35870.873600] C0 [ khubd, 65] usb 1-1: new high-speed USB device number 2 using xhci-hcd
[35870.913669] C0 [ khubd, 65] usb 1-1: New USB device found, idVendor=148f, idProduct=5370
[35870.913689] C0 [ khubd, 65] usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[35870.913705] C0 [ khubd, 65] usb 1-1: Product: 802.11 n WLAN
[35870.913718] C0 [ khubd, 65] usb 1-1: Manufacturer: TPlink
[35870.913731] C0 [ khubd, 65] usb 1-1: SerialNumber: 1.0
[35870.914752] C0 [ khubd, 65] usb 1-1: ep 0x81 - rounding interval to 32768 microframes, ep desc says 0 microframes
[35870.918267] C0 [ khubd, 65] usb 1-1: ep 0x1 - rounding interval to 32768 microframes, ep desc says 0 microframes
[35870.918660] C0 [ khubd, 65] usb 1-1: ep 0x2 - rounding interval to 32768 microframes, ep desc says 0 microframes
[35870.918687] C0 [ khubd, 65] usb 1-1: ep 0x3 - rounding interval to 32768 microframes, ep desc says 0 microframes
[35870.919064] C0 [ khubd, 65] usb 1-1: ep 0x4 - rounding interval to 32768 microframes, ep desc says 0 microframes
[35870.919458] C0 [ khubd, 65] usb 1-1: ep 0x5 - rounding interval to 32768 microframes, ep desc says 0 microframes
[35870.919483] C0 [ khubd, 65] usb 1-1: ep 0x6 - rounding interval to 32768 microframes, ep desc says 0 microframes
- 后来我也了解到,rt5370其实在kernel3.0后就有了支持。但不知道为何不能使用。希望大神赐教。
2015.8.10 20:19 续
- 逛论坛,发现在github上有内核的源文件,按照网上的说法,rt5370驱动已经在kernel 3.0时已加入了内核,目前小米使用的内核是3.4版本,通过查找,果然发现rt5370驱动在如下目录中,下一步考虑重新编译内核,将其添加到内核中。
/linux/tree/master/drivers/net/wireless/rt2x00