Skip to content

Instantly share code, notes, and snippets.

@nyaray
Forked from ericr3r/add bluez to Nerves
Last active November 9, 2018 21:40
Show Gist options
  • Save nyaray/acf8ea41a639d1529e43afa23488ccdf to your computer and use it in GitHub Desktop.
Save nyaray/acf8ea41a639d1529e43afa23488ccdf to your computer and use it in GitHub Desktop.

Adding bluez to Nerves

This might get tricky...

Quote notes

It's a start, basically you need to get to the point where btuart can run, that means the rpi firmware can be loaded and hciconfig and other tools can be run

Patches

add the following bluez patches to Nerves system, reachable through raspberrypi/linux#1314 (available at https://gist.github.com/nyaray/5d76432af70025b77f1d17ff8c781470)

first, mkdir -p patches/bluez5_utils in your system repo root directory.

  • patches/bluez5_utils/0001-bcm43xx-Add-bcm43xx-3wire-variant.patch
  • patches/bluez5_utils/0002-bcm43xx-The-UART-speed-must-be-reset-after-the-firmw.patch
  • patches/bluez5_utils/0003-Increase-firmware-load-timeout-to-30s.patch
  • patches/bluez5_utils/0004-Move-the-43xx-firmware-into-lib-firmware.patch

update nerves_defconfig to include bluez and patches

-BR2_GLOBAL_PATCH_DIR="${BR2_EXTERNAL_NERVES_PATH}/patches"
+BR2_GLOBAL_PATCH_DIR="${BR2_EXTERNAL_NERVES_PATH}/patches ${NERVES_DEFCONFIG_DIR}/patches"
+BR2_PACKAGE_BLUEZ5_UTILS=y
+BR2_PACKAGE_BLUEZ5_UTILS_CLIENT=y
+BR2_PACKAGE_BLUEZ5_UTILS_DEPRECATED=y

update linux-4.14.defconfig

+CONFIG_BT=y
+CONFIG_BT_HCIBTUSB=y
+CONFIG_BT_HCIUART=y
+CONFIG_BT_HCIUART_H4=y
+CONFIG_BT_HCIUART_BCSP=y
+CONFIG_BT_HCIBCM203X=m

the btuart script

btuart is a script normally on the rpi, looks like I didn't include a version in the patches, you'll want to check out the one on the pi for the logic. Bluez runs hciattach initially but determining the correct parameters depends a lot on the system

more context: raspberrypi/firmware#860

the script should be at /usr/bin/btuart

#!/bin/bash

HCIATTACH=/usr/bin/hciattach
SERIAL=`grep Serial /proc/cpuinfo | cut -c19-`
B1=`echo $SERIAL | cut -c3-4`
B2=`echo $SERIAL | cut -c5-6`
B3=`echo $SERIAL | cut -c7-8`
BDADDR=`printf b8:27:eb:%02x:%02x:%02x $((0x$B1 ^ 0xaa)) $((0x$B2 ^ 0xaa)) $((0x$B3 ^ 0xaa))`

if [ "$(cat /proc/device-tree/aliases/uart0)" = "$(cat /proc/device-tree/aliases/serial1)" ] ; then
	if [ "$(wc -c /proc/device-tree/soc/gpio@7e200000/uart0_pins/brcm\,pins | cut -f 1 -d ' ')" = "16" ] ; then
		$HCIATTACH /dev/serial1 bcm43xx 3000000 flow - $BDADDR
	else
		$HCIATTACH /dev/serial1 bcm43xx 921600 noflow - $BDADDR
	fi
else
	$HCIATTACH /dev/serial1 bcm43xx 460800 noflow - $BDADDR
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment