fix: clean up legacy aic_btusb configuration

Sanitize obsolete modprobe and udev rules during upgrades, unload the removed module when possible, and expand Bluetooth diagnostics for stale configuration. Continues the cleanup for #44 and #53.
This commit is contained in:
Shen Mintao
2026-07-14 17:30:03 +08:00
parent 7dc7569312
commit 6b8cb98e96
2 changed files with 88 additions and 9 deletions
+46 -9
View File
@@ -43,7 +43,7 @@ echo ""
# 3. 检查已加载的模块
echo "3. 已加载的相关模块 (期望: aic_load_fw + btusb):"
lsmod | grep -E "aic_load_fw|aicwf|btusb|bluetooth" || echo " 未找到相关模块"
lsmod | grep -E "aic_load_fw|aicwf|aic_btusb|btusb|bluetooth" || echo " 未找到相关模块"
echo ""
# 4. 检查 HCI 设备
@@ -61,15 +61,52 @@ echo "6. RF-Kill 状态:"
rfkill list bluetooth 2>/dev/null || echo " 无法获取 rfkill 信息"
echo ""
# 7. 检查残留的旧 modprobe 配置 (issue #53)
# 7. 检查残留的旧 aic_btusb 配置 (issue #53)
echo "7. 残留旧配置检查:"
if [ -f /etc/modprobe.d/aic8800-bt.conf ]; then
echo " ⚠️ 发现 /etc/modprobe.d/aic8800-bt.conf —— 这是早期版本残留, 应删除"
echo " 该文件 softdep / alias 到不再存在的 aic_btusb, 会导致 btusb 接管设备"
echo " 但固件未上传, 表现为 hci0 HCI_Reset 超时 (-110)"
echo " 修复: sudo rm /etc/modprobe.d/aic8800-bt.conf && sudo update-initramfs -u (若用 initramfs)"
legacy_refs_found=false
mapfile -t legacy_modprobe_files < <(
grep -RIlE '^[[:space:]]*(softdep|alias)[^#]*aic_btusb([[:space:]]|$)' \
/etc/modprobe.d /run/modprobe.d /usr/local/lib/modprobe.d /usr/lib/modprobe.d /lib/modprobe.d \
2>/dev/null || true
)
mapfile -t legacy_udev_files < <(
grep -RIl 'aic_btusb/new_id' \
/etc/udev/rules.d /run/udev/rules.d /usr/lib/udev/rules.d /lib/udev/rules.d \
2>/dev/null || true
)
for legacy_file in "${legacy_modprobe_files[@]}"; do
echo " ⚠️ 发现旧 modprobe 指令: $legacy_file"
legacy_refs_found=true
done
for legacy_file in "${legacy_udev_files[@]}"; do
echo " ⚠️ 发现旧 udev 绑定规则: $legacy_file"
legacy_refs_found=true
done
if lsmod | awk '{print $1}' | grep -qx 'aic_btusb'; then
echo " ⚠️ 旧 aic_btusb 模块当前仍已加载"
legacy_refs_found=true
fi
if modinfo -n aic_btusb >/dev/null 2>&1; then
echo " ⚠️ 系统中仍存在 aic_btusb 模块: $(modinfo -n aic_btusb 2>/dev/null)"
legacy_refs_found=true
fi
if [ "$legacy_refs_found" = true ]; then
echo " 这些残留会尝试加载已删除的模块, 并干扰标准 btusb 的自动加载/绑定顺序。"
echo " 修复: 拉取最新 bluetooth 分支后重新运行 sudo ./install.sh"
if command -v update-initramfs >/dev/null 2>&1; then
echo " 然后执行: sudo update-initramfs -u"
elif command -v dracut >/dev/null 2>&1; then
echo " 然后执行: sudo dracut -f"
elif command -v mkinitcpio >/dev/null 2>&1; then
echo " 然后执行: sudo mkinitcpio -P"
fi
else
echo " /etc/modprobe.d/aic8800-bt.conf 不存在 (正常)"
echo " 未发现活动的 aic_btusb 配置、规则或模块 (正常)"
fi
echo ""
@@ -89,7 +126,7 @@ fi
if dmesg | grep -iE "hci0:.*command (0x|tx) timed out|hci0.*opcode.*0x0c03" | tail -5 | grep -q .; then
echo "⚠️ 检测到 HCI 命令超时 (HCI_Reset/-110)"
echo " 常见原因:"
echo " a) /etc/modprobe.d/aic8800-bt.conf 残留 (见第 7 项)"
echo " a) 旧 aic_btusb 配置或 udev 规则残留 (见第 7 项)"
echo " b) aic_load_fw 没有先把蓝牙固件 patch 上传到芯片"
echo " c) usb_modeswitch 没把 1111:1111 切换到真实 VID:PID"
echo " 排查: 看上面第 5 项日志, 应能看到 fw_patch_table_8800d80 / fw_adid 字样"
+42
View File
@@ -323,6 +323,46 @@ check_kernel_build_tree() {
# Firmware Installation
#############################################################################
cleanup_legacy_bluetooth_config() {
local legacy_conf="/etc/modprobe.d/aic8800-bt.conf"
local legacy_udev="/etc/udev/rules.d/90-aic8800-mode-switch.rules"
local changed=false
if [ -f "$legacy_conf" ] && grep -Eq '^[[:space:]]*(softdep|alias)[^#]*aic_btusb([[:space:]]|$)' "$legacy_conf"; then
print_info "Removing obsolete aic_btusb directives from $legacy_conf..."
if [ ! -f "${legacy_conf}.aic8800-backup" ]; then
cp -a "$legacy_conf" "${legacy_conf}.aic8800-backup" >> "$LOG_FILE" 2>&1
fi
sed -i -E '/^[[:space:]]*(softdep|alias)[^#]*aic_btusb([[:space:]]|$)/d' "$legacy_conf"
if ! grep -Eq '^[[:space:]]*[^#[:space:]]' "$legacy_conf"; then
rm -f "$legacy_conf"
fi
changed=true
fi
if [ -f "$legacy_udev" ] && grep -q 'aic_btusb/new_id' "$legacy_udev"; then
print_info "Removing obsolete aic_btusb binding rules from $legacy_udev..."
if [ ! -f "${legacy_udev}.aic8800-backup" ]; then
cp -a "$legacy_udev" "${legacy_udev}.aic8800-backup" >> "$LOG_FILE" 2>&1
fi
sed -i '/aic_btusb\/new_id/d' "$legacy_udev"
changed=true
fi
if lsmod | awk '{print $1}' | grep -qx 'aic_btusb'; then
print_info "Unloading obsolete aic_btusb module..."
if modprobe -r aic_btusb >> "$LOG_FILE" 2>&1; then
changed=true
else
print_warning "aic_btusb is still in use; reboot or replug the adapter after installation."
fi
fi
if [ "$changed" = true ]; then
print_success "Legacy Bluetooth configuration cleaned up."
fi
}
install_firmware() {
print_step "Installing firmware..."
@@ -334,6 +374,8 @@ install_firmware() {
exit 1
fi
cleanup_legacy_bluetooth_config
# Remove old firmware versions
if [ -d "/lib/firmware" ] && [ -n "$(find /lib/firmware -maxdepth 1 -name 'aic8800*' -type d 2>/dev/null)" ]; then
print_info "Removing existing firmware..."