USB Bluetooth with Ubuntu Core
Ubuntu Core is great for its small footprint, security updates and other features, but some hardware support can be challenging. Such was the case in our attempt to get a Bluetooth USB adapter working. But, we have a solution! We started with the Plugable USB BT4LE which has the Broadcom BCM20702 chipset. We used this in a hardware device that has a Raspberry Pi CM3+ module, thus it did not have integrated Bluetooth or WiFi hardware.
Configuring Ubuntu Core: the Bluetooth Firmware Problem
Ubuntu Core has a limited set of firmware included. When we first plugged in the Plugable adapter, dmesg showed the failure:
bluetooth hci0: Direct firmware load for brcm/BCM20702A1-0a5c-21e8.hcd failed with error -2
Consequently, we set out looking for the firmware.
Get the firmware to install on Ubuntu Core
Plugable has a firmware file for their USB dongle. You can retrieve it here:
curl https://s3.amazonaws.com/plugable/bin/fw-0a5c_21e8.hcd -o fw-0a5c_21e8.hcd
Copy this file to your Ubuntu Core device. E.g. (your address and login will be different):
scp fw-0a5c_21e8.hcd -o fw-0a5c_21e8.hcd firstname.lastname@example.org:
The kernel expects to load the firmware from /lib/firmware, but this is mounted as read-only (squashfs) in Core. Thus, you must use an alternate path. Fortunately, the Linux kernel allows for this case with firmware search paths. The path that we will add is searched first, followed by the other standard search paths, such as /lib/firmware.
We decide to use the following location for the kernel path, and we enable the search path for the firmware:
sudo mkdir -p /etc/writable/firmware/brcm echo -n “/etc/writable/firmware” >/sys/module/firmware_class/parameters/path
Note that brcm is not needed in the kernel path since it is added at the kernel level. Now, copy the Broadcom BCM20702 firmware to that directory using both supported firmware variants (see the Plugable documentation page).
sudo cp fw-0a5c_21e8.hcd /etc/writable/firmware/brcm/BCM20702A0-0a5c-21e8.hcd sudo cp fw-0a5c_21e8.hcd /etc/writable/firmware/brcm/BCM20702A1-0a5c-21e8.hcd
Note: Given the error message above, it is likely that only the latter one is needed, but this firmware supports both the A0 and A1 version of the Broadcom chip, so we are now ready for either.
Now insert the Plugable or other compatible Bluetooth adapter.
‘dmesg’ should show that the error message is gone.
BlueZ is a Bluetooth implementation for Linux that is available as a snap:
$ snap install bluez $ snap connections bluez Interface Plug Slot Notes bluetooth-control bluez:bluetooth-control - - bluez bluez:client bluez:service - home bluez:home - - network-control bluez:network-control - - uhid bluez:uhid :uhid -
Now, let’s connect BlueZ to the Bluetooth device, and restart BlueZ.
$ snap connect bluez:bluetooth-control $ snap restart bluez
Now we can test with bluetoothctl.
$ sudo bluetoothctl [NEW] Controller 5C:F3:70:9C:BE:E8 tallypoint-37e4cd [default] Agent registered [bluetooth]# power on [CHG] Controller 5C:F3:70:9C:BE:E8 Class: 0x00100000 Changing power on succeeded [CHG] Controller 5C:F3:70:9C:BE:E8 Powered: yes [bluetooth]# scan on Discovery started [CHG] Controller 5C:F3:70:9C:BE:E8 Discovering: yes [NEW] Device 4D:9C:1C:54:78:C9 4D-9C-1C-54-78-C9 [NEW] Device 3C:22:FB:27:AE:59 3C-22-FB-27-AE-59 [NEW] Device 34:81:F4:1C:D1:06 QSI 1.5" [NEW] Device 79:44:CD:27:70:FE 79-44-CD-27-70-FE [NEW] Device D8:1C:6E:A8:A0:5C D8-1C-6E-A8-A0-5C [NEW] Device 4A:14:FF:9B:DC:31 4A-14-FF-9B-DC-31 [NEW] Device E2:02:00:0A:41:40 Kontakt [bluetooth]# info E2:02:00:0A:41:40 Device E2:02:00:0A:41:40 (random) Name: Kontakt Alias: Kontakt Paired: no Trusted: no Blocked: no Connected: no LegacyPairing: no ManufacturerData Key: 0x004c ManufacturerData Value: 02 15 f7 82 6d a6 4f a2 4e 98 80 24 bc 5b 71 e0 ....m.O.N..$.[q. 89 3e 07 6d b9 a7 bf .>.m... ServiceData Key: 0000d00d-0000-1000-8000-00805f9b34fb ServiceData Value: 41 62 4a 33 34 31 07 AbJ341.
The Kontakt device above is a BLE beacon.
Putting it all together
Next, you will want all of this to work the next time you boot the Pi device! It is possible to add the firmware search path to startup scripts on the Pi. But, the kernel search path document gives us another option: adding the path to the boot arguments. Edit /boot/uboot/cmdline.txt to add the following variable:
And reboot. If all has gone well, you will now have a working USB Bluetooth adapter in Ubuntu Core!