目前,在消费电子或商业电子领域,许多产品跑的是Android系统;而在工控等行业,应用linux,Ubuntu系统,也是十分普遍;当前很多主流的开发平台,如全志,瑞星微,三星,官方提供的多是Android系统;若产品需要跑linux或Ubuntu,则需要用户在官方提供的已有的支持之上,进行相应的移植支持;
比如linux,用户使用具体平台提供的uboot和kernel,然后把linux文件系统(一般是通过移植buildroot)移植到所需平台中;
下面的书写,作为工作的一个记录,与各位分享;
以下主要描述的是如何在linux中支持usb wifi RTL8723,即支持RTL8723BU的移植过程,而对于buildroot的移植过程,这里暂不表;
平台: 三星 S5P4418 (4核 A9)
开发板:G4418 (有兴趣的可查看这网站: http://www.graperain.cn/s5p4418/s5p4418-Development/)
内核: 3.4.39
(uboot,kernel,buildroot,RTL8723BU驱动源码,及交叉编译工具,开发板供应商都有提供)
以下为移植过程:
1、编译RTL8723BU源码,生成驱动文件
这里主要改动源码Makefile,指定用到的交叉编译工具和内核源码(这两者都是开发板供应商提供);
生成wlan.ko文件;
2、重新配置内核,让其支持80211 wext
内核的配置项为:CONFIG_CFG80211_WEXT
若此项不做配置,会出现类似的错误:用wireless工具列举时,报错
iwlist wlan0 scanning
wlan0 Interface doesn't support scanning.
3、buildroot中,配置支持wpa,wireless tools;重新生成linux的映像;
这样后,文件系统中就有wireless tools,wpa_supplicant等工具,无需另外添加;
4、经过1,2,3步骤后,重新更新kernel和linux文件系统,然后把生成的wlan.ko也放到开发板中;(可通过u盘,tf卡方式)
接着进行测试:
首先,手动加载wlan驱动: insmod wlan.ko
/lib/modules]# insmod wlan.ko
[ 121.643000] RTL871X: module init start
[ 121.647000] RTL871X: rtl8723bu v4.3.6.11_12942.20141204_BTCOEX20140507-4E40
[ 121.654000] RTL871X: build time: May 13 2015 17:19:00
[ 121.659000] RTL871X: rtl8723bu BT-Coex version = BTCOEX20140507-4E40
[ 121.815000]
[ 121.817000] 29 81 03 7C 01 08 21 00 40 07 05 35 10 00 00 00
[ 121.823000] 26 26 26 26 26 26 28 28 28 28 28 02 FF FF FF FF
[ 121.830000] FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
[ 121.837000] FF FF FF FF FF FF FF FF FF FF 2F 2F 2F 2E 2E 2E
[ 121.843000] 31 31 31 30 30 02 FF FF FF FF FF FF FF FF FF FF
[ 121.850000] FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
[ 121.856000] FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
[ 121.863000] FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
[ 121.870000] FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
[ 121.876000] FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
[ 121.883000] FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
[ 121.889000] FF FF FF FF FF FF FF FF 20 14 1F 00 00 00 FF FF
[ 121.896000] FF 28 20 11 00 00 00 FF 00 FF FF FF FF FF FF FF
[ 121.903000] FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
[ 121.909000] FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
[ 121.916000] FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
[ 121.922000] DA 0B 20 B7 E7 47 03 34 C3 D2 BE C2 18 09 03 52
[ 121.929000] 65 61 6C 74 65 6B 16 03 38 30 32 2E 31 31 6E 20
[ 121.936000] 57 4C 41 4E 20 41 64 61 70 74 65 72 00 FF FF FF
[ 121.942000] FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
[ 121.949000] FF FF FF FF FF FF FF 0F FF FF FF FF FF FF FF FF
[ 121.955000] FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
[ 121.962000] FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
[ 121.969000] FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
[ 121.975000] FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
[ 121.982000] FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
[ 121.989000] FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
[ 121.995000] FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
[ 122.002000] FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
[ 122.008000] FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
[ 122.015000] FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
[ 122.022000] FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
[ 122.031000] RTL871X: rtw_ndev_init(wlan0)
[ 122.035000] RTL871X: rtw_ndev_init(wlan1)
[ 122.040000] usbcore: registered new interface driver rtl8723bu
[ 122.047000] RTL871X: module init ret=0
查看网络情况:
/lib/modules]# ifconfig -a
eth0 Link encap:Ethernet HWaddr 72:F4:6C:A0:00:16
inet6 addr: fe80::70f4:6cff:fea0:16/64 Scope:Link
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:4 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:580 (580.0 B)
Interrupt:48
ip6tnl0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
NOARP MTU:1452 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
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:16436 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
sit0 Link encap:IPv6-in-IPv4
NOARP MTU:1480 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
wlan0 Link encap:Ethernet HWaddr 34:C3:D2:BE:C2:18
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
wlan1 Link encap:Ethernet HWaddr 36:C3:D2:BE:C2:18
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
上电wlan0,ifconfig wlan0 up
wlan0 Link encap:Ethernet HWaddr 34:C3:D2:BE:C2:18
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:76 errors:0 dropped:16 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
然后查看能搜索到的周边的wifi源:
iwlist wlan0 scanning
Cell 02 - Address: A0:63:91:DB:B6:AB
Channel:1
Frequency:2.412 GHz (Channel 1)
Quality=65/70 Signal level=-45 dBm
Encryption key:on
ESSID:"abc"
Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 18 Mb/s
24 Mb/s; 36 Mb/s; 54 Mb/s
Bit Rates:6 Mb/s; 9 Mb/s; 12 Mb/s; 48 Mb/s
Mode:Master
Extra:tsf=000000000ffa9085
Extra: Last beacon: 34ms ago
IE: Unknown: 0003747978
IE: Unknown: 010882848B962430486C
IE: Unknown: 030101
IE: Unknown: 2A0104
IE: Unknown: 2F0104
IE: IEEE 802.11i/WPA2 Version 1
Group Cipher : CCMP
Pairwise Ciphers (1) : CCMP
Authentication Suites (1) : PSK
IE: Unknown: 32040C121860
IE: Unknown: 0B050B00560000
IE: Unknown: 2D1AAD1917FFFFFF0000000000000000000000000000000000000000
IE: Unknown: 3D1601001700000000000000000000000000000000000000
IE: Unknown: 4A0E14000A002C01C800140005001900
IE: Unknown: 7F080100080000000040
IE: Unknown: DD810050F204104A0001101044000102103B00010310470010C1ADAADF8324644B14524BA52E1A59731021000D4E4554474541522C20496E632E10230007523633303076321024000752363330307632104200033637
IE: Unknown: DD09001018020B001C0000
IE: Unknown: DD180050F2020101880003A4000027A400004243BC0062326600
至此,可以看到wifi模块已经是工作起来,可以搜到周围的wifif源;
5、接下来,进行wifi的连接操作
首先,在开发板文件系统的/etc下,创建配置文件:
/etc]# cat wpa_supplicant.conf
ctrl_interface=/var/run/wpa_supplicant
ap_scan=1
network={
ssid="abc" (备注,此处的abc,即为需要连接的wifi的名称)
scan_ssid=1
key_mgmt=WPA-EAP WPA-PSK IEEE8021X NONE
pairwise=TKIP CCMP
group=CCMP TKIP WEP104 WEP40
psk="abc@@" (备注,此处的字符,即可要连接的wifi的密码)
}
然后在/run下,创建文件夹:
/run]# mkdir -p /var/run/wpa_supplicant
接着用以下命令,进行wifi的连接:
wpa_supplicant -Dwext -iwlan0 -c/etc/wpa_supplicant.conf &
/]# Successfully initialized wpa_supplicant
rfkill: Cannot open RFKILL control device
[ 758.237000] RTL871X: RTW_ADAPTIVITY_EN_AUTO, chplan:0x20, Regulation:3,3
[ 758.244000] RTL871X: RTW_ADAPTIVITY_MODE_NORMAL
[ 758.770000] RTL871X: nolinked power save leave
wlan0: Trying to associate with a0:63:91:db:b6:ab (SSID='tyx' freq=2412 [ 760.899000] RTL871X: rtw_set_802_11_connect(wlan0) fw_state=0x00000008
MHz)
[ 761.005000] RTL871X: start auth
[ 761.010000] RTL871X: auth success, start assoc
[ 761.018000] RTL871X: assoc success
[ 761.022000] ADDRCONF(NETDEV_CHANGE): wlan0: link becomes ready
wlan0: Associated with a0:63:91:db:b6:ab[ 761.030000] RTL871X: send eapol packet
[ 761.124000] RTL871X: send eapol packet
wlan0: WPA: Key negotiation completed with a0:63:91:db:b6:ab [PTK=CCMP GTK=CCMP]
wlan0: CTRL-EVENT-CONNECTED - Connection to a0:63:91:db:b6:ab completed [id=0 id_str=]
[ 761.162000] RTL871X: set pairwise key camid:4, addr:a0:63:91:db:b6:ab, kid:0, type:AES
[ 761.173000] RTL871X: set group key camid:5, addr:a0:63:91:db:b6:ab, kid:1, type:AES
从打印看到,连接成功;
6、获取ip,让开发板能够通过wifi上网;
方法1:手动设置
ifconfig wlan0 192.168.1.30
route add default gw 192.168.1.1(添加网关)
echo "nameserver 192.168.1.1" >>/etc/resolv.conf (改动resolv.conf文件)
以上操作后,尝试ping 网关和外网(www.baidu.com),都能成功;
方法2:自动获取ip
udhcpc -i wlan0 (这样操作后,开发板获取都ip,可以连接外网)
至此,wifi的移植和测试已经完成;
而为了方便,我们可以把以上的连接wifi的那部分操作,做成一个脚本,省去一些麻烦;如下:
在开发板文件系统中,创建脚本文件wapstart,内容如下:
#!/bin/sh
wldevname=$1
wlessidname=$2
wlkeyvar=$3
insmod /lib/modules/wlan.ko
mkdir -p /var/run/wpa_supplicant
echo "ctrl_interface=/var/run/wpa_supplicant" >/tmp/wpa_supplicant.conf
echo "network={" >>/tmp/wpa_supplicant.conf
echo "ssid=\"$wlessidname\"" >>/tmp/wpa_supplicant.conf
echo "key_mgmt=WPA-EAP WPA-PSK IEEE8021X NONE" >>/tmp/wpa_supplicant.conf
echo "pairwise=CCMP TKIP" >>/tmp/wpa_supplicant.conf
echo "group=CCMP TKIP WEP104 WEP40" >>/tmp/wpa_supplicant.conf
echo "psk=\"$wlkeyvar\"" >>/tmp/wpa_supplicant.conf
echo "}" >>/tmp/wpa_supplicant.conf
wpa_supplicant -Dwext -i$wldevname -c/tmp/wpa_supplicant.conf &
运行此脚本的命令为:
wpastart wlan0 abc abc@@ (备注,abc为wifi名称,abc@@为wifi密码)
这样即可完成wifi的连接操作;
以上所用的wifi模块为usb接口,所用开发板的平台为G4418; 若需要在其它平台支持,如全志,瑞星微等,移植的过程也是类似的;有需要的可以自行尝试;