之前适配的intel8265模块有点小贵,这里再适配另一款wifi模块RTL8821。经验在上一篇文章可以参考基于龙芯2K1000适配WIFI模块(型号:Intel 8265NGW),这里主要记录一些新问题。并且将此模块的蓝牙功能驱动一下。
1 wifi功能
首先确保模块及电路是没有问题的,用命令查看一下,RTL8821AE能被识别:
[loongson@localhost ~]$ lspci -v
04:00.0 USB controller: Renesas Technology Corp. uPD720201 USB 3.0 Host Controller (rev 03) (prog-if 30 [XHCI])
Flags: bus master, fast devsel, latency 0, IRQ 138
Memory at 40400000 (64-bit, non-prefetchable) [size=8K]
Capabilities: <access denied>
Kernel driver in use: xhci_hcd
08:00.0 Network controller: Realtek Semiconductor Co., Ltd. RTL8821AE 802.11ac PCIe Wireless Network Adapter
Subsystem: Realtek Semiconductor Co., Ltd. Device 2162
Flags: bus master, fast devsel, latency 0, IRQ 42
I/O ports at 6000 [size=256]
Memory at 40300000 (64-bit, non-prefetchable) [size=16K]
Capabilities: <access denied>
1.1 linux3.10
环境:pmon+linux3.10+loongnix1.0
正如适配Intel 8265NGW模块文章写道,需要改动的不多,主要在内核里选中以下参数就可以使用了,不做过多描述:
Device Drivers > Network device support > Wireless LAN > Realtek rtlwifi family of devices > Realtek RTL8821AE/RTL8812AE Wireless Network Adapter
1.2 linux4.19
环境:uboot+linux4.19+buildroot
内核选上:
Device Drivers > Network device support > Wireless LAN > Realtek rtlwifi family of devices > Realtek RTL8821AE/RTL8812AE Wireless Network Adapter
问题:
[ 3.516805] pci 0000:08:00.0: [10ec:8821] type 00 class 0x028000
[ 3.553800] rtl8821ae: Using firmware rtlwifi/rtl8821aefw_29.bin
[ 3.559951] rtl8821ae 0000:08:00.0: Direct firmware load for rtlwifi/rtl8821aefw_29.bin failed with error -2
[ 3.569869] rtl8821ae: Using firmware rtlwifi/rtl8821aefw_wowlan.bin
[ 3.569916] rtl8821ae 0000:08:00.0: Direct firmware load for rtlwifi/rtl8821aefw.bin failed with error -2
[ 3.576351] rtl8821ae 0000:08:00.0: Direct firmware load for rtlwifi/rtl8821aefw_wowlan.bin failed with error -2
[ 3.585882] rtlwifi: Loading alternative firmware rtlwifi/rtl8821aefw.bin
[ 3.613334] rtl8821ae 0000:08:00.0: Direct firmware load for rtlwifi/rtl8821aefw.bin failed with error -2
[ 3.623117] rtlwifi: Loading alternative firmware rtlwifi/rtl8821aefw.bin
还是老问题,缺少固件。这里呢,省事的方法,就是按适配intel 8265那样直接加个固件。但是呢,这种方式移植性不大好。
方法1:固件编进内核
还是简叙以下做法:
内核:
Device Drivers > Generic Driver Options > Firmware loader >
添加:rtlwifi/rtl8821aefw_29.bin
这个会从ubuntu中load固件,编译显示为:
MK_FW firmware/rtlwifi/rtl8821aefw_29.bin.gen.S
AS firmware/rtlwifi/rtl8821aefw_29.bin.gen.o
更新内核启动后:
# ifconfig -a
wlan0 Link encap:Ethernet HWaddr 90:DE:80:0D:C6:92
UP 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)
方法2:加载用户空间驱动
1、内核修改
改为:
疑问:内核加载用户层的固件在那个目录下呢?
内核函数drivers/base/firmware_loader/main.c做了说明,在以下4个任意目录可以了:
static const char * const fw_path[] = {
fw_path_para,
"/lib/firmware/updates/" UTS_RELEASE, //#define UTS_RELEASE "4.19.161+"
"/lib/firmware/updates",
"/lib/firmware/" UTS_RELEASE,
"/lib/firmware"
};
2、buildroot修改
buildroot选择:
Target packages > Hardware handling > Firmware > WiFi firmware
[*] Intel iwlwifi 8265 //使8265模块 wifi能用,单纯RTL8821不需要选此项
[*] Realtek 88xx
Target packages > Hardware handling > Firmware > Bluetooth firmware
[*] Intel Wireless Bluetooth //使8265模块 蓝牙能用,单纯RTL8821不需要选此项
启动:
[ 67.610715] iwlwifi 0000:08:00.0: loaded firmware version 36.9f0a2d68.0 op_mode iwlmvm
[ 67.627500] iwlwifi 0000:08:00.0: Detected Intel(R) Dual Band Wireless AC 8265, REV=0x230
[ 67.712574] iwlwifi 0000:08:00.0: base HW address: 84:5c:f3:26:e9:31
编完更新,内核和固件就可以用了,恩,就是这么简单。
发现1:wifi固件加载貌似是周期轮询的,60秒左右一次。
# [ 66.741710] Bluetooth: hci0: Failed to load Intel firmware file (-11)
[ 66.748863] cfg80211: failed to load regulatory.db
[ 66.838347] iwlwifi 0000:08:00.0: Direct firmware load for iwlwifi-8265-35.ucode failed with error -2
[ 66.847665] iwlwifi 0000:08:00.0: Falling back to syfs fallback for: iwlwifi-8265-35.ucode //从8265-35开始加载,恰好固件库里没有8265-35
[ 95.344391] usb 2-2: USB disconnect, device number 2
[ 128.181612] iwlwifi 0000:08:00.0: Direct firmware load for iwlwifi-8265-34.ucode failed with error -2
[ 128.190987] iwlwifi 0000:08:00.0: Falling back to syfs fallback for: iwlwifi-8265-34.ucode
发现2:intel 8265NGW模块驱动是从8265-35开始加载的,但是正好固件库没有这个,按顺序要到第二次循环才加载上8265-34。验证一下。
执行:cp /lib/firmware/iwlwifi-8265-36.ucode /lib/firmware/iwlwifi-8265-35.ucode
[ 67.610715] iwlwifi 0000:08:00.0: loaded firmware version 36.9f0a2d68.0 op_mode iwlmvm
[ 67.627500] iwlwifi 0000:08:00.0: Detected Intel(R) Dual Band Wireless AC 8265, REV=0x230
[ 67.712574] iwlwifi 0000:08:00.0: base HW address: 84:5c:f3:26:e9:31
发现3:蓝牙固件加载是启动时候加载的
# hciconfig hci0 up
[ 70.975989] Bluetooth: hci0: Bootloader revision 0.0 build 26 week 38 2015
[ 70.984973] Bluetooth: hci0: Device revision is 16
[ 70.989824] Bluetooth: hci0: Secure boot is enabled
[ 70.994865] Bluetooth: hci0: OTP lock is enabled
[ 70.999574] Bluetooth: hci0: API lock is enabled
[ 71.004279] Bluetooth: hci0: Debug lock is disabled
[ 71.009245] Bluetooth: hci0: Minimum firmware build 1 week 10 2014
[ 71.153604] Bluetooth: hci0: Found device firmware: intel/ibt-12-16.sfi
[ 75.954954] Bluetooth: hci0: Waiting for firmware download to complete
[ 75.961650] Bluetooth: hci0: Firmware loaded in 4870698 usecs
[ 75.967734] Bluetooth: hci0: Waiting for device to boot
[ 75.980958] Bluetooth: hci0: Device booted in 12987 usecs
[ 75.989040] Bluetooth: hci0: Found Intel DDC parameters: intel/ibt-12-16.ddc
[ 76.001966] Bluetooth: hci0: Applying Intel DDC parameters completed
wifi使用
搜索wifi:
# ifconfig wlan0 up
# ifconfig
wlan0 Link encap:Ethernet HWaddr 90:DE:80:0D:C6:92
UP 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)
# iwlist wlan0 scan
wlan0 Scan completed :
Cell 01 - Address: 32:B3:17:9A:13:03
Channel:1
Frequency:2.412 GHz (Channel 1)
Quality=50/70 Signal level=-60 dBm
Encryption key:on
ESSID:"HUAWEI P40 Pro"
Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 6 Mb/s; 9 Mb/s
11 Mb/s; 12 Mb/s; 18 Mb/s
Bit Rates:24 Mb/s; 36 Mb/s; 48 Mb/s; 54 Mb/s
Mode:Master
Extra:tsf=000000017887a733
Extra: Last beacon: 6ms ago
IE: Unknown: 000E485541574549205034302050726F
......
####联网:
# iwconfig wlan0 essid "USTC-WW" key "3132333435"
# ifconfig wlan0 up
# [ 33.354528] wlan0: authenticate with d8:49:0b:b4:bb:90
[ 33.368038] wlan0: send auth to d8:49:0b:b4:bb:90 (try 1/3)
[ 33.380880] wlan0: authenticated
[ 33.384200] iwlwifi 0000:08:00.0 wlan0: disabling HE/HT/VHT due to WEP/TKIP use
[ 33.391799] wlan0: associate with d8:49:0b:b4:bb:90 (try 1/3)
[ 33.408333] wlan0: RX AssocResp from d8:49:0b:b4:bb:90 (capab=0x1031 status=0 aid=1)
[ 33.418203] wlan0: associated
udhcpc -i wlan0
udhcpc: started, v1.29.3
udhcpc: sending discover
udhcpc: sending select for 10.100.2.42
udhcpc: lease of 10.100.2.42 obtained, lease time 3600
deleting routers
adding dns 202.102.192.68
adding dns 114.114.114.114
问题1:调试要么先设置密码,然后再启动网卡!要么up之后设置密码还要down和up一遍才能分配到mac地址等信息。
问题2:一定要接小天线,否则信号不好也分配不到mac,如果分配mac失败,请记得用iwlist wlan0 scan检查一下
问题3:确保wifi名称和密码是否输入错误,这里就是调试输入了错误的密码,当时做了一堆无用功,对报错log一顿乱搜
# iwconfig wlan0 essid "USTC-WW" key "313233343536" //密码错了
Error for wireless request "Set Encode" (8B2A) :
SET failed on device wlan0 ; Invalid argument.
2 蓝牙功能
确保蓝牙接口正常:
lsusb:
Bus 002 Device 003: ID 0930:022f Toshiba Corp.
2.1 linux3.10
环境:pmon+linux3.10+loongnix1.0
内核选中:
CONFIG_BT=y
CONFIG_BT_RFCOMM=y
CONFIG_BT_RFCOMM_TTY=y
CONFIG_BT_HCIBTUSB=y
问题:
Failed to open RFKILL control device
解决:
Networking support > RF switch subsystem support
使用:
使用之前必须执行hciconfig hci0 up启动蓝牙设备
这里有个很好的蓝牙调试参考链接:
Bluetooth (简体中文)
[root@localhost loongson]# bluetoothctl
[NEW] Controller 90:DE:80:0D:C6:93 localhost.localdomain [default]
[NEW] Device 6C:AB:31:D7:BE:0E iPhone
[bluetooth]# default-agent
No agent is registered
[bluetooth]# power on
Changing power on succeeded
[bluetooth]# scan on
Discovery started
[CHG] Controller 90:DE:80:0D:C6:93 Discovering: yes
[NEW] Device 7E:43:74:A7:FB:EB 7E-43-74-A7-FB-EB
...
[CHG] Device 78:7B:79:D7:1D:8E RSSI: -56
[bluetooth]# scan off
[CHG] Device 70:66:55:9B:FB:8C RSSI is nil
...
[CHG] Device 7E:43:74:A7:FB:EB RSSI is nil
Discovery stopped
[CHG] Controller 90:DE:80:0D:C6:93 Discovering: no
[bluetooth]# pair 6C:AB:31:D7:BE:0E
Attempting to pair with 6C:AB:31:D7:BE:0E
Failed to pair: org.bluez.Error.AlreadyExists
[bluetooth]# trust 6C:AB:31:D7:BE:0E
[CHG] Device 6C:AB:31:D7:BE:0E Trusted: yes
Changing 6C:AB:31:D7:BE:0E trust succeeded
[bluetooth]# connect 6C:AB:31:D7:BE:0E
Attempting to connect to 6C:AB:31:D7:BE:0E
[CHG] Device 6C:AB:31:D7:BE:0E Connected: yes
Connection successful
2.2 linux4.19
环境:uboot+linux4.19+buildroot
内核:
RTL8821模块蓝牙不需要额外的固件,直接按照linux3.10选中配置参数即可。
intel 8265模模块需要蓝牙固件,可以编进内核,也可以用加载用户空间的固件,这里不再赘述。
buildroot:
选中以下参数:
BR2_PACKAGE_DBUS_GLIB=y
BR2_PACKAGE_LIBUSB=y
BR2_PACKAGE_BLUEZ5_UTILS=y
BR2_PACKAGE_BLUEZ5_UTILS_CLIENT=y
BR2_PACKAGE_BLUEZ5_UTILS_DEPRECATED=y
BR2_PACKAGE_UTIL_LINUX_RFKILL=y
更新之后,系统启动之后还需要执行:
1、启动bluetoothd
/usr/libexec/bluetooth/bluetoothd -n &
2、启动蓝牙
hciconfig hci0 up
3、连接调试
bluetoothctl
常用的几个命令如下:
具体可以查阅Bluetooth (简体中文)
power on
scan on
scan off
trust xx:xx:xx:xx:xx:xx
pair xx:xx:xx:xx:xx:xx
connect xx:xx:xx:xx:xx:xx
问题1:第一步必须先执行power on否则执行其他指令会失败,如下:
[bluetooth]# discoverable on
Failed to set discoverable on: org.bluez.Error.Failed
[bluetooth]# power on
Changing power on succeeded
[CHG] Controller 84:5C:F3:26:E9:35 Powered: yes
[bluetooth]# discoverable on
Changing discoverable on succeeded
[CHG] Controller 84:5C:F3:26:E9:35 Discoverable: yes
问题2:已配对成功过,如果是初次配对是显示成功的信息,这里只要trust就行了
[bluetooth]# pair 0C:83:9A:B6:9C:8C
Attempting to pair with 0C:83:9A:B6:9C:8C
Failed to pair: org.bluez.Error.AlreadyExists
[bluetooth]# trust 0C:83:9A:B6:9C:8C
[CHG] Device 0C:83:9A:B6:9C:8C Trusted: yes
Changing 0C:83:9A:B6:9C:8C trust succeeded
问题3:到这里基本上就可以和手机配对了,但是总是连接不上。
[bluetooth]# connect 0C:83:9A:B6:9C:8C
Attempting to connect to 0C:83:9A:B6:9C:8C
bluetoothd[1402]: a2dp-source profile connect failed for 0C:83:9A:B6:9C:8C: Protocol not available
Failed to connect: org.bluez.Error.Failed
这个问题耗了我很长时间,大多都说要支持pulseaudio。这里附上一个让能连接手机蓝牙的解决方案参考:linux 蓝牙开发调试(rtl8821cs模块)
借助 blue-alsa工具:
最终能连上我手机的步骤:
1、hciconfig hci0 up
2、/usr/libexec/bluetooth/bluetoothd -n &
3、bluealsa -p a2dp-sink &
4、bluetoothctl
power on
scan on
scan off
trust xx:xx:xx:xx:xx:xx
pair xx:xx:xx:xx:xx:xx
connect xx:xx:xx:xx:xx:xx
结果如下:
[bluetooth]# connect 6C:AB:31:D7:BE:0E
Attempting to connect to 6C:AB:31:D7:BE:0E
[CHG] Device 6C:AB:31:D7:BE:0E Connected: yes
Connection successful
[iPhone]# bluetoothd[1434]: Can't open input device: No such file or directory (2)
bluetoothd[1434]: AVRCP: failed to init uinput for 6C:AB:31:D7:BE:0E
[CHG] Device 6C:AB:31:D7:BE:0E ServicesResolved: yes

学海无涯!!!