记一次ubuntu蓝牙鼠标问题处理-linux内核编译

京东新搞的华硕天选笔记本,刷成ubuntu后蓝牙鼠标一直连接不上,后来发现蓝牙本身就搜索不出任何设备,但是ubuntu蓝牙管理模块显示正常,执行 dmesg | grep -i bluetooth 命令只有如下报错

1
Bluetooth: hci0: Failed to read codec capabilities (-22)

虽然不清楚这个报错具体是因为什么,也许和这个报错也没什么关系。但是既然搜索不到,估计大概也许可能确定是驱动出了问题

查看蓝牙设备信息

1
lsusb 
image-20241214205336013

注意看厂商和设备码:0489:e123

当前ubuntu内核版本:6.8.0-49-generic

到linux内核源码 drivers/bluetooth/btusb.c 找找是否存在 0489:e123

结果是没有,所以系统并没有识别到这个usb设备。

在最新内核tag检索设备码 https://github.com/torvalds/linux/blob/v6.12/drivers/bluetooth/btusb.c

结果是没有,瞬间塌方了。正打算随便写到蓝牙配置里时,发现master分支存在设备码0489, e123, 同时发现对应的patch。按照提示说明,蓝牙设备型号是RTL8852BE

image-20241214211606055

所以需要做得就是下载内核源码,增加蓝牙驱动配置,重新编译内核,这里选择了6.9.12内核作为升级内核版本

国内源地址:https://mirrors.tuna.tsinghua.edu.cn/kernel/v6.x/linux-6.9.12.tar.gz

1
2
3
4
wget https://mirrors.tuna.tsinghua.edu.cn/kernel/v6.x/linux-6.9.12.tar.gz
tar xf linux-6.9.12.tar.gz
cd linux-6.9.12.tar.gz
## 按照patch内容,修改btusb.c, 或者用patch命令,我这里直接修改的文件
image-20241214225553109

编译内核

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
##清理
make mrproper
make clean

## 复制配置过来
cp /boot/config-6.8.0-49-generic .config
## make menuconfig 看情况是否要修改配置,不需要不执行
## 编译安装
make -j 32
make modules -j32
make modules_install
make install
mkinitramfs -o /boot/initrd.img-6.9.12
update-initramfs -c -k 6.9.12
update-grub2
## 编译过程中报了个错,缺少对应的firmware,下载最新的复制
wget https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git/snapshot/linux-firmware-20241210.tar.gz
tar xf linux-firmware-20241210.tar.gz
cp linux-firmware-20241210/rtl_nic/* /lib/firmware/rtl_nic/
## 再次执行 make modules_install 和make install, 报错消失

重启,默认应该是从新的内核进入

1
reboot

重启后尝试搜索设备,此时设备可以搜索到了,蓝牙耳机和鼠标都正常连接,耳机声音正常,窃喜。但是鼠标无法使用,移动鼠标没反应,继续搞心态。

找到一篇帖子,说到可能是因为bluez版本底,需要升级

https://superuser.com/questions/1697648/lenovo-legion-m600-wireless-bluetooth-mouse-connected-and-paired-yet-not-working

按照这个说法,这是极少数设备的问题,而我刚好赶上了

image-20241214231321237

升级bluez

1
2
3
4
5
6
7
8
# 下载5.x最新版本bluez,解压
wget https://www.kernel.org/pub/linux/bluetooth/bluez-5.69.tar.gz
## 安装依赖
apt-get install libglib2.0-dev libdbus-glib-1-dev libical-dev libreadline6-dev
## 编译安装
./configure
make -j 32
make install

重启

1
reboot

重启后再次连接蓝牙鼠标,鼠标运行正常了,测试长时间不操作后鼠标能够重新唤醒,鼠标开关关闭再次打开能够连接上,速度很快。检查了/var/lib/bluetooth下的蓝牙鼠标info文件,interval速度应该是够了,如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[General]
Name=Legion M600 Mouse
Appearance=0x03c2
AddressType=public
SupportedTechnologies=LE;
Trusted=true
.....
忽略很长一段内容
.....
[ConnectionParameters]
MinInterval=6
MaxInterval=6
Latency=3
Timeout=300

又是折腾的一天

image-20241215000515757

image-20241215000837772