Rtl8761b bluetooth driver fix

Thanks for the updates and assistance.

I’ll be buggered if I can get it to work though.

Which directory does the firmware go into, in what form and how? I have 2 files, rtl8761b_config and rtl8761b_fw and thought that they went into /usr/lib/kernel-overlays/base/lib/firmware/rtl_bt but this directory seems to be read only.

I also tried to follow the steps manually and noted that when running the command insmod /storage/btrtl.ko ir returned an error insmod: ERROR: could not insert module /storage/btrtl.ko: File exists

Does the firmware go inside /storage/.config/firmware/rtl_bt?

Yes

mkdir -p /storage/.config/firmware/rtl_bt
copy firmware into /storage/.config/firmware/rtl_bt

At first, you must disable btrtl,btusb autoloaded.
Otherwise insmod will return error: could not insert module /storage/btrtl.ko: File exists.
Because built-in btrtl.ko has registered into kernel.

# cat /storage/.config/modprobe.d/disable-btrtl.conf
blacklist btusb
blacklist btrtl

# reboot -f 

Then reboot -f immediately.

vi /storage/.config/autostart.sh and reboot -f again .
or insmod by manual

# install modified module  btrtl.ko 
insmod /storage/btrtl.ko
modprobe btusb

# waiting for hci ready
sleep 4

# disable built-in bluetooth 4.2
rfkill list |grep `hciconfig -a |grep UART|cut -f1 -d:`|cut -f1 -d:|xargs -n1 rfkill block

systemctl restart bluetooth.service

I see, the source is complete different. Would be nice if you can create a “backport” to include both device types in one driver. We look forward to merge a provided PR to include it in CE :wink:

I just can’t get it to work.

After following the first part an then rebooting, if I then go through the process manually, when I run insmod /storage/btrtl.ko it returns the error insmod: ERROR: could not insert module /storage/btrtl.ko: Unknown symbol in module

Nothing prevents any existing BT module from being disabled.

Check dmesg for any more errors after insmod.

I get these errors

[ 63.586999@3] btrtl: Unknown symbol bt_info (err 0)
[ 63.587045@3] btrtl: Unknown symbol bt_err (err 0)
[ 63.587097@3] btrtl: Unknown symbol __hci_cmd_sync (err 0)

Then this kernel module was not build properly in CE build environment.

I have compiled a btrtl.ko. Download from here directly:

wget https://github.com/cdliyi/rtl8761b-fix-patch-for-kernel4.9/releases/download/0.1/btrtl.ko

After disable btrtl,btusb autoloaded :

CoreELEC:~ # uname -a
Linux CoreELEC 4.9.113 #1 SMP PREEMPT Tue Apr 13 00:32:58 UTC 2021 aarch64 GNU/Linux

CoreELEC:~ # lsb_release -a
CoreELEC (official): 19.1-Matrix_nightly_20210413

CoreELEC:~ # lsmod |grep bt
btbcm                  16384  1 hci_uart
btqca                  16384  1 hci_uart
btintel                24576  1 hci_uart
bluetooth             425984  27 hci_uart,btintel,btqca,btbcm

insmod btrtl.ko by manual:


CoreELEC:~ # ls -lart *.ko
-rw-r--r--    1 root     root         12000 Apr 13 20:09 btrtl.ko

CoreELEC:~ # file btrtl.ko 
btrtl.ko: ELF 64-bit LSB relocatable, ARM aarch64, version 1 (SYSV), BuildID[sha1]=e98beaf6ff502a7631a96083f87e6e386c597d25, not stripped

CoreELEC:~ # insmod /storage/btrtl.ko  <-- no error returned
CoreELEC:~ # modprobe btusb  
CoreELEC:~ # lsmod |grep bt
btusb                  45056  0
btrtl                  16384  1 btusb   <-- btrtl loaded successful
btbcm                  16384  2 hci_uart,btusb
btqca                  16384  1 hci_uart
btintel                24576  2 hci_uart,btusb
bluetooth             425984  46 btrtl,hci_uart,btintel,btqca,btbcm,btusb

CoreELEC:~ # dmesg |grep 8761
[  223.729794@0] Bluetooth: hci1: rtl: examining hci_ver=0a hci_rev=000b lmp_ver=0a lmp_subver=8761
[  223.729803@0] Bluetooth: hci1: rtl: loading rtl_bt/rtl8761b_config.bin
[  223.729908@0] bluetooth hci1: Direct firmware load for rtl_bt/rtl8761b_config.bin failed with error -2
[  223.729914@0] Bluetooth: hci1: Failed to load rtl_bt/rtl8761b_config.bin
[  223.729916@0] Bluetooth: hci1: rtl: loading rtl_bt/rtl8761b_fw.bin

Just ignore : failed with error -2, It's harmless.

CoreELEC:~ # hciconfig -a
hci1:   Type: Primary  Bus: USB
        BD Address: xx:xx:xx:xx:xx:xx  ACL MTU: 1021:5  SCO MTU: 255:11
        UP RUNNING PSCAN 
        RX bytes:1339 acl:0 sco:0 events:137 errors:0
        TX bytes:24396 acl:0 sco:0 commands:137 errors:0
        Features: 0xff 0xff 0xff 0xfe 0xdb 0xfd 0x7b 0x87
        Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3 
        Link policy: RSWITCH HOLD SNIFF PARK 
        Link mode: SLAVE ACCEPT 
        Name: 'CoreELEC #2'
        Class: 0x0c0000
        Service Classes: Rendering, Capturing
        Device Class: Miscellaneous, 
        HCI Version: 5.1 (0xa)  Revision: 0xd99
        LMP Version: 5.1 (0xa)  Subversion: 0x646b
        Manufacturer: Realtek Semiconductor Corporation (93)

Thanks for the update.

Unfortunately I get the same results.

My output:

CoreELEC:~ # uname -a
Linux CoreELEC 4.9.113 #1 SMP PREEMPT Tue Apr 13 00:32:58 UTC 2021 aarch64 GNU/Linux

CoreELEC:~ # lsb_release -a
CoreELEC (official): 19.1-Matrix_nightly_20210413

CoreELEC:~ # lsmod |grep bt
btusb               45056    0
btrtl                  16384    1 btusb
btbcm              16384    1 btusb
btintel              24576    1 btusb
bluetooth         425984  11 btrtl,btintel,btbcm,btusb

Yours shows hci_uart, mine shows btusb and it would seem that btusb and btrtl are not being blacklisted?

I’ve triple checked everything and it all looks the same as far as the setup is concerned.

Can someone try this module: https://drive.google.com/file/d/1YkSjy5engqKiVkQnVsxCb7yO-pR-xfra/view?usp=sharing

It should support both revisions a and b (with correct fw and config files).
Please check and post dmesg | paste result.

patch: https://drive.google.com/file/d/10qMDu7KtKK48qZiCpLfLzsmXrpba-sOz/view?usp=sharing

Working:

CoreELEC:~ # dmesg
[   32.577138@2] usb 1-1.3: new full-speed USB device number 4 using xhci-hcd
[   32.701935@2] usb 1-1.3: New USB device found, idVendor=0bda, idProduct=8771
[   32.701937@2] usb 1-1.3: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[   32.701939@2] usb 1-1.3: Product: Bluetooth Radio
[   32.701941@2] usb 1-1.3: Manufacturer: Realtek
[   32.701942@2] usb 1-1.3: SerialNumber: 00E04C239987
[   32.713556@2] usb 1-1.3: Unsupported device
[   32.713757@2] usb 1-1.3: Unsupported device
[   32.737378@3] Bluetooth: Core ver 2.22
[   32.737430@3] NET: Registered protocol family 31
[   32.737431@3] Bluetooth: HCI device and connection manager initialized
[   32.737439@3] Bluetooth: HCI socket layer initialized
[   32.737442@3] Bluetooth: L2CAP socket layer initialized
[   32.737465@3] Bluetooth: SCO socket layer initialized
[   32.744732@5] usbcore: registered new interface driver btusb
[   32.745657@1] Bluetooth: hci0: rtl: examining hci_ver=0a hci_rev=000b lmp_ver=0a lmp_subver=8761
[   32.745664@1] peter btrtl_setup_realtek, RTL_ROM_LMP_8761A rev 0xb
[   32.745666@1] peter btrtl_setup_realtek, RTL_ROM_LMP_8761A rev b
[   32.745668@1] peter btrtl_setup_rtl8723b, RTL_ROM_LMP_8761A rev 0xb
[   32.745669@1] peter btrtl_setup_rtl8723b, cfg_name rtl_bt/rtl8761b_config.bin
[   32.745671@1] Bluetooth: hci0: rtl: loading rtl_bt/rtl8761b_config.bin
[   32.753551@1] Bluetooth: hci0: rtl: loading rtl_bt/rtl8761b_fw.bin
[   32.754660@1] Bluetooth: hci0: rom_version status=0 version=1
[   32.754711@1] Bluetooth: cfg_sz 25, total size 23485
1 Like

This patch is perfect
http://ix.io/2VWC

1 Like

the module from vpeter seems to work, bu CE can’t find the BT-dongle
I manually "modprobe -r"d btsub and btrtl (blacklisting them seems not to work)
then insmod insmod ./btrtl_rev_a_and_b.ko

the rfkill does also not work, because hciconfig -a gives:

CoreELEC:~/.config/firmware # hciconfig -a
hci0:   Type: Primary  Bus: USB
        BD Address: 00:00:00:00:00:00  ACL MTU: 0:0  SCO MTU: 0:0
        DOWN 
        RX bytes:0 acl:0 sco:0 events:0 errors:0
        TX bytes:0 acl:0 sco:0 commands:1 errors:1
        Features: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
        Packet type: DM1 DH1 HV1 
        Link policy: 
        Link mode: SLAVE ACCEPT 

after systemctl restart bluetooth.service CE load the fw correctly. At least it seems to, but it is not found by CE in CE-Settings

[  440.338951@0] Bluetooth: hci0 command 0xfc20 tx timeout
[  448.468438@0] Bluetooth: hci0: download fw command failed (-110)
[  742.418617@1] usbcore: deregistering interface driver btusb
[  792.733802@0] usbcore: registered new interface driver btusb
[  794.742098@3] Bluetooth: hci0 command 0x1001 tx timeout
[  802.806509@0] Bluetooth: hci0: HCI_OP_READ_LOCAL_VERSION failed (-110)
[  905.806486@2] usb 1-1.2: USB disconnect, device number 5
[  908.102307@2] usb 1-1.2: new full-speed USB device number 6 using xhci-hcd
[  908.227192@2] usb 1-1.2: New USB device found, idVendor=0bda, idProduct=8771
[  908.227200@2] usb 1-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[  908.227205@2] usb 1-1.2: Product: Bluetooth Radio
[  908.227210@2] usb 1-1.2: Manufacturer: Realtek
[  908.227215@2] usb 1-1.2: SerialNumber: 00E04C239987
[  908.240369@1] hci0: rtl: examining hci_ver=0a hci_rev=000b lmp_ver=0a lmp_subver=8761
[  908.240382@1] peter btrtl_setup_realtek, RTL_ROM_LMP_8761A rev 0xb
[  908.240389@1] peter btrtl_setup_realtek, RTL_ROM_LMP_8761A rev b
[  908.240393@1] peter btrtl_setup_rtl8723b, RTL_ROM_LMP_8761A rev 0xb
[  908.240398@1] peter btrtl_setup_rtl8723b, cfg_name rtl_bt/rtl8761b_config.bin
[  908.240401@1] hci0: rtl: loading rtl_bt/rtl8761b_config.bin
[  908.242785@1] hci0: rtl: loading rtl_bt/rtl8761b_fw.bin
[  908.246395@1] hci0: rom_version status=0 version=1
[  908.246484@1] cfg_sz 25, total size 23485

CE19-nighly from 10042021 on a N2-device
Thx in advance

Edit:
it seems the same lsmod difference like @Compent has

CoreELEC:~ # lsmod | grep bt
btusb                  45056  0
btbcm                  16384  1 btusb
btintel                24576  1 btusb
btrtl                  16384  1 btusb
bluetooth             425984  27 btrtl,btintel,btbcm,btusb

After a reboot, if I physically unplug and re-attach the dongle, the end of dmesg shows this:

[  216.756813@3] usb 1-1.2: USB disconnect, device number 7
[  219.051724@3] usb 1-1.2: new full-speed USB device number 8 using xhci-hcd
[  219.176802@3] usb 1-1.2: New USB device found, idVendor=0bda, idProduct=8771
[  219.176817@3] usb 1-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[  219.176824@3] usb 1-1.2: Product: Bluetooth Radio
[  219.176831@3] usb 1-1.2: Manufacturer: Realtek
[  219.176837@3] usb 1-1.2: SerialNumber: 00E04C239987
[  219.192259@3] Bluetooth: hci0: rtl: examining hci_ver=0a hci_rev=000b lmp_ver=0a lmp_subver=8761
[  219.192275@3] Bluetooth: hci0: rtl: loading rtl_bt/rtl8761a_config.bin
[  219.192458@3] bluetooth hci0: Direct firmware load for rtl_bt/rtl8761a_config.bin failed with error -2
[  219.192468@3] Bluetooth: hci0: Failed to load rtl_bt/rtl8761a_config.bin
[  219.192473@3] Bluetooth: hci0: rtl: loading rtl_bt/rtl8761a_fw.bin
[  219.194206@3] Bluetooth: hci0: rom_version status=0 version=1
[  219.194245@3] Bluetooth: cfg_sz 0, total size 20204
[  221.287797@3] Bluetooth: hci0 command 0xfc20 tx timeout
[  229.383731@3] Bluetooth: hci0: download fw command failed (-110)

This would seem to indicate that rtl8761a_fw.bin is being referenced and not rtl8761b_fw.bin

It seems odd that if we are all following the same paths that we get differing results, with the only fundamental differences likely being the boxes that we have,

update .tar for a test: https://drive.google.com/file/d/1I8VP5X2PrC8OvwCwbAZY2vIGo6Ay1HeI/view?usp=sharing

Remove any autostart.sh or other hacks for this bt device. Also remove firmware from /storage/.config/firmware because it is included in image itself.

If it works good. If not post links

dmesg | paste
journalctl -l  | paste
1 Like

It didn’t work after the initial update but then I rebooted and it works perfectly.

Thanks very much to all that made it happen :grin:

1 Like

It works! Audio over BT is OK.

But after disconnecting the BT-device, I have a freezing picture and no sound in Live-TV. Haven’t tested video streams.
Will report back tomorrow. My wife is occupying the TV :wink:
Thx

After a good day of use, things are rock solid.

Here is my bug-report.
I don’t know, if it is BT and/or rtl8761b related or a Kodi bug:
N2 with vpeters testbuild, rtl8761b BT-dongle, CE19

Connecting and disconnecting BT device over CE-settings seems fine.
After conecting, everything plays fine, but after disconnecting (turning off) my BT-device (JBL Go2), I have a freezing pic and NO sound at all while Live-TV and e.g. amazon streams. CE showed “disconnected device” before.

If this does not fit here, please let me know or separate this post. I can also file a bug report on github, if you want

I played 2 Live-TV channels over BT, then I turned off the device and tried to play another channel, which did not work.

debug-log: File-Upload.net - Datei nicht gefunden

CoreELEC:~ # dmesg | paste
http://ix.io/2W8m
CoreELEC:~ # journalctl -l | paste
http://ix.io/2W8n
Thx

Edit:
there is another user reporting “no sound” after disconnecting. Unfortunately without any log

Latest nightly image includes this driver support ootb:
CoreELEC-Amlogic-ng.arm-19.1-Matrix_nightly_20210415.tar