(UPDATED) Preliminary support for Bluetooth in Debian Rock960

Deleted because i fixed the issue., see next post…

Hi,

Finally i have achieved to upload the firmware via UART H4 interface and the interface hci0 now is working.

I list what we have to do to implement it in the Debian release:

1-Compile tool to upload firmware.

Our module is the AP6356S which is a wireless/bluetooth combo, the wireless is set up correctly but not the bluetooth, we have to upload the firmware via UART h4 protocol.

The rtk_hciattach or hciattach utiliy are not working in this device even changing to H4 protocol i didn’t achieve it if someone can do it is welcome :wink:

So looking for how Android setup this module i see broadcom has a propietary utility to upload the firmware but there is an opensource tool included in some Android sources:

brcm_patchram_plus

So we can compile this utility easily with:

gcc brcm_patchram_plus.c -o brcm_patchram_plus

2-Download firmware.

Once compiled we have to download the firmware, after few attempts i found one that seems stable download it:

bcm4356a2.hcd

The we have to upload it and IMPORTANT not stop the process after the firmware is uploaded.

If we stop the process the driver go down and we have to reboot the system, i didn’t find a solution for this issue.

We copy the firmware to our path:

cp bcm4356a2.hcd /system/vendor/firmware/

3-Upload firmware.

And then upload it:

   ` root@linaro-alip:/home/linaro# ./brcm_patchram_plus -d --enable_hci --no2bytes --use_baudrate_for_download --tosleep 200000 --baudrate 1500000 --patchram /system/vendor/firmware/bcm4356a2.hcd /dev/ttyS0

    option patchram with arg /home/linaro/bcm4356a2.hcd
    option no2bytes
    option baudrate with arg 4000000
    option use_baudrate_for_download
    option bd_addr with arg 90:E7:C4:F3:F7:09
    option enable_hci
    option scopcm with arg 0,4,0,0,0,1,0,3,0,0
    /dev/ttyS0 
    writing
    01 03 0c 00 
    received 7
    04 0e 04 01 03 0c 00 
    writing
    01 18 fc 06 00 00 00 09 3d 00 
    received 7
    04 0e 04 01 18 fc 00 
    Done setting baudrate
    writing
    01 2e fc 00 
    received 7
    04 0e 04 01 2e fc 00 
    writing
    01 4c fc 8b 00 f0 21 00 01 06 00 ea 44 72 42 04 
    1a c1 5e 00 ef 63 15 83 a4 ef 63 15 83 a4 37 02 
    56 02 56 02 57 02 57 02 58 02 58 02 59 02 59 02 
    5a 02 5a 02 5b 02 5b 02 5c 02 5c 02 5d 02 5d 02 
    5e 02 5e 02 5f 02 5f 02 60 02 60 02 61 02 61 02 
    62 02 62 02 63 02 63 02 64 02 64 02 65 02 65 02 
    66 02 66 02 67 02 67 02 68 02 68 02 69 02 69 28 
    1f 0a fd 04 00 ff ff ff ff 40 06 00 ac 1f 00 a2 
    54 43 02 0a 00 87 f0 21 00 00 00 00 00 00 00 
    received 7
    04 0e 04 01 4c fc 00 
    writing
    01 4c fc cc 87 f0 21 00 41 22 00 42 43 4d 34 33 
    35 36 20 33 37 2e 34 4d 48 7a 20 41 4d 50 41 4b 
    20 41 50 36 33 35 36 2d 30 30 35 35 00 c0 84 00 
    a8 0a 20 00 ff ff ff ff 06 00 00 00 84 01 64 00 
    ff 00 00 00 33 00 00 00 8c 00 32 00 00 f0 ff 0f 
    00 10 11 01 78 00 32 00 ff ff ff ff b9 b8 b9 b9 
    fc 00 64 00 ff 00 00 00 20 00 00 00 04 01 64 00 
    ff 00 00 00 10 00 00 00 08 01 64 00 ff 00 00 00 
    10 00 00 00 68 00 32 00 ff ff 00 00 b9 38 00 00 
    7c 00 32 00 ff ff ff ff bb b8 bb b8 58 1b 20 00 
    ff ff ff ff 00 00 00 00 59 1b 20 00 ff ff 00 00 
    01 00 00 00 68 04 00 10 00 00 00 0a 08 00 08 1c 
    20 00 12 00 00 00 c4 18 00 fc 00 64 00 20 00 00 
    received 7
    04 0e 04 01 4c fc 00 
    writing
    01 4c fc cc 4f f1 21 00 00 04 01 64 00 10 00 00 
    00 08 01 64 00 90 00 00 00 69 02 00 0a 01 6f 21 
    00 02 33 19 05 cf 00 00 00 78 14 7f 5a 00 aa 00 
    80 0a 92 00 00 00 00 14 00 00 00 00 00 00 02 14 
    1e 00 b2 09 00 04 00 00 a2 00 00 00 00 00 1a 24 
    00 02 01 08 08 0c 00 08 01 04 02 00 03 fc 04 f8 
    05 f4 06 f0 07 0c 00 08 01 04 02 00 03 fc 04 f8 
    05 f4 06 f0 07 1a 24 00 04 01 08 08 0c 00 08 01 
    04 02 00 03 fc 04 f8 05 f4 06 f0 07 0c 00 08 01 
    04 02 00 03 fc 04 f8 05 f4 06 f0 07 d8 32 00 02 
    08 12 00 00 00 0f 00 00 00 0d 00 00 00 0b 00 00 
    00 09 00 00 00 07 00 00 00 05 00 00 00 03 00 00 
    00 03 00 00 00 02 00 00 00 01 00 00 00 00 00 00 
    received 7
    04 0e 04 01 4c fc 00
    ...more and more....
    writing
    01 03 0c 00 
    received 7
    04 0e 04 01 03 0c 00 
    writing
    01 18 fc 06 00 00 60 e3 16 00 
    received 7
    04 0e 04 01 18 fc 00 
    Done setting baudrate
    Done setting line discpline` 

This will keep the utility up and we can’t stop it or we will loose the hci0 interface.

4-Setup interface.

After this we have our hci0 interface up.

` root@linaro-alip:/home/linaro# hciconfig 
hci0:	Type: Primary  Bus: UART
	BD Address: CC:4B:73:04:2F:21  ACL MTU: 1021:8  SCO MTU: 64:1
	UP RUNNING PSCAN 
	RX bytes:16817 acl:207 sco:0 events:507 errors:0
	TX bytes:12458 acl:188 sco:3 commands:300 errors:0` 

And bluetoothctl working as well:

root@linaro-alip:/home/linaro# bluetoothctl [NEW] Controller CC:4B:73:04:2F:21 linaro-alip [default]
[NEW] Device 04:FE:A1:E4:F0:60 JBL Clip 2
[bluetooth]# connect 04:FE:A1:E4:F0:60
Attempting to connect to 04:FE:A1:E4:F0:60
[NEW] Device 78:0C:B8:88:80:64 debian
[CHG] Device 04:FE:A1:E4:F0:60 Connected: yes
[CHG] Device 04:FE:A1:E4:F0:60 UUIDs: 00001101-0000-1000-8000-00805f9b34fb
[CHG] Device 04:FE:A1:E4:F0:60 UUIDs: 00001108-0000-1000-8000-00805f9b34fb
[CHG] Device 04:FE:A1:E4:F0:60 UUIDs: 0000110a-0000-1000-8000-00805f9b34fb
[CHG] Device 04:FE:A1:E4:F0:60 UUIDs: 0000110b-0000-1000-8000-00805f9b34fb
[CHG] Device 04:FE:A1:E4:F0:60 UUIDs: 0000110c-0000-1000-8000-00805f9b34fb
[CHG] Device 04:FE:A1:E4:F0:60 UUIDs: 0000110d-0000-1000-8000-00805f9b34fb
[CHG] Device 04:FE:A1:E4:F0:60 UUIDs: 0000110e-0000-1000-8000-00805f9b34fb
[CHG] Device 04:FE:A1:E4:F0:60 UUIDs: 0000111e-0000-1000-8000-00805f9b34fb
[CHG] Device 04:FE:A1:E4:F0:60 UUIDs: 00001200-0000-1000-8000-00805f9b34fb
[JBL Clip 2]#`

5-Whats working.

-Discoverable on.
-Scan on.
-Trust on.
-Pairing with different devices.
-Connecting.
-Set a spd service (serial with spdtool)
-Listen in that service and success connection with phone.
-Serial service uart protocol.
-Headphones, speakers tested and working :wink:

Now ive tested adding RFCOMM TTY functionality to the kernel and ive connected with a terminal app in android against the sdp service with success.

Speakers also has been tested and are working well at least JBL Clip with pulseaudio were automatically detected and added the new profile without configuring anything.
We can say the driver is very stable.
Well i hope you guys can add all this stuff in the Debian release, is nothing new just the way Android is doing it.

Best regards,
Sylkat

`

3 Likes

Very nice. We will definitely adding it in the release.

Good job, but this is the old way to do, Broadcom combos are now fully supported in the kernel (hci_bcm) without having to rely on any userspace trick thanks to Serial bus support.
You need to

  • have the firmware (patchram)
  • enable HCI_BCM, SERIAL_DEV_BUS and BT_HCI_UART_SERDEV.
  • Add bcm4356 as a child node of the UART (ttyS0)

https://patchwork.kernel.org/patch/10005171/
https://elixir.bootlin.com/linux/latest/source/Documentation/devicetree/bindings/net/broadcom-bluetooth.txt

1 Like

Well i think i make the things more complicated then.

Btw im trying to do it in the new way, i have some doubts about it.

In the kernel provided by 96rocks 4.4 i don’t see the options:
HCI_BCM, SERIAL_DEV_BUS, BT_HCI_UART_SERDEV.

Maybe we have to upgrade the kenel to a new version with this features included?

Also our hci_bcm.c is not updated to the last version so we dont have the last patches.

And finally i don’t understand the last point about add bcm4356 as a child node of the UART (ttyS0), can you elaborate how to do it please?

Really i am very new to this board just few days working with it, so just begin my work in it, for now i will download the new kernel to see if the patches are already applied and we can give support in the new way.

Thanks in advance,

Sylkat

1 Like

I have downloaded the last stable kernel 4.17.17 and still that patch is not included.

I see the patch is in status “Not applicable” and is archived can you confirm that?

Anyways to compile the new kernel for this board is not that easy, the kernel that rock96 brings is well optimized and with some drivers not free added to the tree like the MALI gpu and some more.

For me is really ok this approach because i spend already too much time researching this, if someone want to add the patchs to the 4.4 kernel tree of this board will be nice.

Regards,

Sylkat

Correct, serdev landed recently and is not supported by Linux 4.4, meaning that BT controller can not be detected automatically at boot time and bound to the hci_bcm driver. You can however force binding with btattach tool (e.g. btattach --bredr /dev/ttyS0 -P bcm), however this requests to have kernel built with BT_BCM config.

You can also use hciattach (bluez tool) to initialize controller from user-space and attach it to the the hci_h4 linux driver:

rfkill unblock bluetooth
hciattach /dev/ttyS0 bcm43xx

In case you use a recent kernel which includes ‘serial bus’ support, you can add bcm4356 device as a node of the rock960 device tree. Since the combo is behind uart0/ttyS0, it should be a ‘child’ node of the uart node. This is BTW what is done with the raspberry pi 3 which has similar BT controller [1]

Anyway using hciattach or brcm_patchram_plus is fine! I just wanted to highlight that a better solution exist with recent kernel.

[1] bcm2837-rpi-3-b.dts - arch/arm/boot/dts/bcm2837-rpi-3-b.dts - Linux source code (v5.15.12) - Bootlin

3 Likes

God, with hciattach even is not needed the firmware and is easier…

So finally the best method to setup is:

hciattach /dev/ttyS0 bcm43xx

Then Debian developers forget all my post just hciattach does the work.

Thanks Loic i really spend too much time and the solution was so simple XD

1 Like

Hi, @Kryz_nop_nop ,

Is this on kernel 4.4 or 4.17?

I’m trying it on kernel 4.4 with TB-96AIoT board. The hciattach method returns “bcm43xx_init” followed by “Initialization time out.”. I wonder whether to try your long method, change kernel 4.4, or switch to kernel 4.17.

Thanks.