From 7cffb1f45b4565f5482546b938b72da3aa0169e8 Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Tue, 10 Jul 2018 01:14:07 +0200 Subject: [PATCH] Native bluetooth support (#91) * Add bluez * rpi firmware * add rpi support * Make packages from rpi * Fix build * Fix target * persistent * fix package * Auto enable * Fix parameter * Fix rpi * Fix done --- buildroot-external/Config.in | 1 + buildroot-external/configs/ova_defconfig | 2 ++ buildroot-external/configs/rpi0_w_defconfig | 3 ++ buildroot-external/configs/rpi2_defconfig | 2 ++ buildroot-external/configs/rpi3_64_defconfig | 5 +++- buildroot-external/configs/rpi3_defconfig | 5 +++- buildroot-external/configs/rpi_defconfig | 2 ++ .../package/bluetooth-bcm43xx/Config.in | 6 ++++ .../bluetooth-bcm43xx/bluetooth-bcm43xx | 18 ++++++++++++ .../bluetooth-bcm43xx/bluetooth-bcm43xx.mk | 29 +++++++++++++++++++ .../bluetooth-bcm43xx.service | 12 ++++++++ .../rootfs-overlay/etc/bluetooth/main.conf | 2 ++ .../var-lib-bluetooth.mount | 1 + .../hassos-hardware.target.wants/.empty | 0 .../hassos-hardware.target | 1 + .../lib/systemd/system/hassos-hardware.target | 3 ++ .../systemd/system/var-lib-bluetooth.mount | 14 +++++++++ 17 files changed, 104 insertions(+), 2 deletions(-) create mode 100644 buildroot-external/package/bluetooth-bcm43xx/Config.in create mode 100755 buildroot-external/package/bluetooth-bcm43xx/bluetooth-bcm43xx create mode 100644 buildroot-external/package/bluetooth-bcm43xx/bluetooth-bcm43xx.mk create mode 100644 buildroot-external/package/bluetooth-bcm43xx/bluetooth-bcm43xx.service create mode 100644 buildroot-external/rootfs-overlay/etc/bluetooth/main.conf create mode 120000 buildroot-external/rootfs-overlay/etc/systemd/system/hassos-bind.target.wants/var-lib-bluetooth.mount create mode 100644 buildroot-external/rootfs-overlay/etc/systemd/system/hassos-hardware.target.wants/.empty create mode 120000 buildroot-external/rootfs-overlay/etc/systemd/system/multi-user.target.wants/hassos-hardware.target create mode 100644 buildroot-external/rootfs-overlay/usr/lib/systemd/system/hassos-hardware.target create mode 100644 buildroot-external/rootfs-overlay/usr/lib/systemd/system/var-lib-bluetooth.mount diff --git a/buildroot-external/Config.in b/buildroot-external/Config.in index b8daf99ec..bec35c7c6 100644 --- a/buildroot-external/Config.in +++ b/buildroot-external/Config.in @@ -1,3 +1,4 @@ source "$BR2_EXTERNAL_HASSOS_PATH/package/hassos/Config.in" source "$BR2_EXTERNAL_HASSOS_PATH/package/libapparmor/Config.in" source "$BR2_EXTERNAL_HASSOS_PATH/package/apparmor/Config.in" +source "$BR2_EXTERNAL_HASSOS_PATH/package/bluetooth-bcm43xx/Config.in" diff --git a/buildroot-external/configs/ova_defconfig b/buildroot-external/configs/ova_defconfig index bccbe9e18..da869451e 100644 --- a/buildroot-external/configs/ova_defconfig +++ b/buildroot-external/configs/ova_defconfig @@ -40,6 +40,8 @@ BR2_PACKAGE_AVAHI=y # BR2_PACKAGE_AVAHI_AUTOIPD is not set BR2_PACKAGE_AVAHI_DAEMON=y BR2_PACKAGE_AVAHI_LIBDNSSD_COMPATIBILITY=y +BR2_PACKAGE_BLUEZ5_UTILS=y +BR2_PACKAGE_BLUEZ5_UTILS_CLIENT=y BR2_PACKAGE_DHCP=y BR2_PACKAGE_DHCP_CLIENT=y BR2_PACKAGE_DROPBEAR=y diff --git a/buildroot-external/configs/rpi0_w_defconfig b/buildroot-external/configs/rpi0_w_defconfig index e758e6e09..041900505 100644 --- a/buildroot-external/configs/rpi0_w_defconfig +++ b/buildroot-external/configs/rpi0_w_defconfig @@ -48,6 +48,8 @@ BR2_PACKAGE_AVAHI=y # BR2_PACKAGE_AVAHI_AUTOIPD is not set BR2_PACKAGE_AVAHI_DAEMON=y BR2_PACKAGE_AVAHI_LIBDNSSD_COMPATIBILITY=y +BR2_PACKAGE_BLUEZ5_UTILS=y +BR2_PACKAGE_BLUEZ5_UTILS_CLIENT=y BR2_PACKAGE_DHCP=y BR2_PACKAGE_DHCP_CLIENT=y BR2_PACKAGE_DROPBEAR=y @@ -94,3 +96,4 @@ BR2_PACKAGE_HASSOS_CLI_ARGS="--network=hassio --add-host hassio:172.30.32.2" BR2_PACKAGE_HASSOS_CLI_PROFILE="docker-default" BR2_PACKAGE_HASSOS_APPARMOR_DIR="supervisor/apparmor" BR2_PACKAGE_APPARMOR=y +BR2_PACKAGE_BLUETOOTH_BCM43XX=y diff --git a/buildroot-external/configs/rpi2_defconfig b/buildroot-external/configs/rpi2_defconfig index e2dae9c45..39925c381 100644 --- a/buildroot-external/configs/rpi2_defconfig +++ b/buildroot-external/configs/rpi2_defconfig @@ -47,6 +47,8 @@ BR2_PACKAGE_AVAHI=y # BR2_PACKAGE_AVAHI_AUTOIPD is not set BR2_PACKAGE_AVAHI_DAEMON=y BR2_PACKAGE_AVAHI_LIBDNSSD_COMPATIBILITY=y +BR2_PACKAGE_BLUEZ5_UTILS=y +BR2_PACKAGE_BLUEZ5_UTILS_CLIENT=y BR2_PACKAGE_DHCP=y BR2_PACKAGE_DHCP_CLIENT=y BR2_PACKAGE_DROPBEAR=y diff --git a/buildroot-external/configs/rpi3_64_defconfig b/buildroot-external/configs/rpi3_64_defconfig index b82e30ad0..283e36fe2 100644 --- a/buildroot-external/configs/rpi3_64_defconfig +++ b/buildroot-external/configs/rpi3_64_defconfig @@ -35,8 +35,8 @@ BR2_PACKAGE_JQ=y BR2_PACKAGE_E2FSPROGS=y BR2_PACKAGE_E2FSPROGS_RESIZE2FS=y BR2_PACKAGE_SQUASHFS=y -BR2_PACKAGE_RPI_WIFI_FIRMWARE=y BR2_PACKAGE_RPI_FIRMWARE=y +BR2_PACKAGE_RPI_WIFI_FIRMWARE=y BR2_PACKAGE_GPTFDISK=y BR2_PACKAGE_GPTFDISK_SGDISK=y BR2_PACKAGE_UBOOT_TOOLS=y @@ -48,6 +48,8 @@ BR2_PACKAGE_AVAHI=y # BR2_PACKAGE_AVAHI_AUTOIPD is not set BR2_PACKAGE_AVAHI_DAEMON=y BR2_PACKAGE_AVAHI_LIBDNSSD_COMPATIBILITY=y +BR2_PACKAGE_BLUEZ5_UTILS=y +BR2_PACKAGE_BLUEZ5_UTILS_CLIENT=y BR2_PACKAGE_DHCP=y BR2_PACKAGE_DHCP_CLIENT=y BR2_PACKAGE_DROPBEAR=y @@ -94,3 +96,4 @@ BR2_PACKAGE_HASSOS_CLI_ARGS="--network=hassio --add-host hassio:172.30.32.2" BR2_PACKAGE_HASSOS_CLI_PROFILE="docker-default" BR2_PACKAGE_HASSOS_APPARMOR_DIR="supervisor/apparmor" BR2_PACKAGE_APPARMOR=y +BR2_PACKAGE_BLUETOOTH_BCM43XX=y diff --git a/buildroot-external/configs/rpi3_defconfig b/buildroot-external/configs/rpi3_defconfig index 64cccbc6a..3c71b292f 100644 --- a/buildroot-external/configs/rpi3_defconfig +++ b/buildroot-external/configs/rpi3_defconfig @@ -35,8 +35,8 @@ BR2_PACKAGE_JQ=y BR2_PACKAGE_E2FSPROGS=y BR2_PACKAGE_E2FSPROGS_RESIZE2FS=y BR2_PACKAGE_SQUASHFS=y -BR2_PACKAGE_RPI_WIFI_FIRMWARE=y BR2_PACKAGE_RPI_FIRMWARE=y +BR2_PACKAGE_RPI_WIFI_FIRMWARE=y BR2_PACKAGE_GPTFDISK=y BR2_PACKAGE_GPTFDISK_SGDISK=y BR2_PACKAGE_UBOOT_TOOLS=y @@ -48,6 +48,8 @@ BR2_PACKAGE_AVAHI=y # BR2_PACKAGE_AVAHI_AUTOIPD is not set BR2_PACKAGE_AVAHI_DAEMON=y BR2_PACKAGE_AVAHI_LIBDNSSD_COMPATIBILITY=y +BR2_PACKAGE_BLUEZ5_UTILS=y +BR2_PACKAGE_BLUEZ5_UTILS_CLIENT=y BR2_PACKAGE_DHCP=y BR2_PACKAGE_DHCP_CLIENT=y BR2_PACKAGE_DROPBEAR=y @@ -94,3 +96,4 @@ BR2_PACKAGE_HASSOS_CLI_ARGS="--network=hassio --add-host hassio:172.30.32.2" BR2_PACKAGE_HASSOS_CLI_PROFILE="docker-default" BR2_PACKAGE_HASSOS_APPARMOR_DIR="supervisor/apparmor" BR2_PACKAGE_APPARMOR=y +BR2_PACKAGE_BLUETOOTH_BCM43XX=y diff --git a/buildroot-external/configs/rpi_defconfig b/buildroot-external/configs/rpi_defconfig index 6d7747271..ab9c2ccc7 100644 --- a/buildroot-external/configs/rpi_defconfig +++ b/buildroot-external/configs/rpi_defconfig @@ -47,6 +47,8 @@ BR2_PACKAGE_AVAHI=y # BR2_PACKAGE_AVAHI_AUTOIPD is not set BR2_PACKAGE_AVAHI_DAEMON=y BR2_PACKAGE_AVAHI_LIBDNSSD_COMPATIBILITY=y +BR2_PACKAGE_BLUEZ5_UTILS=y +BR2_PACKAGE_BLUEZ5_UTILS_CLIENT=y BR2_PACKAGE_DHCP=y BR2_PACKAGE_DHCP_CLIENT=y BR2_PACKAGE_DROPBEAR=y diff --git a/buildroot-external/package/bluetooth-bcm43xx/Config.in b/buildroot-external/package/bluetooth-bcm43xx/Config.in new file mode 100644 index 000000000..05add93bf --- /dev/null +++ b/buildroot-external/package/bluetooth-bcm43xx/Config.in @@ -0,0 +1,6 @@ +config BR2_PACKAGE_BLUETOOTH_BCM43XX + bool "bluetooth bcm43xx" + depends on BR2_PACKAGE_BLUEZ5_UTILS_CLIENT + select BR2_PACKAGE_BLUEZ5_UTILS_DEPRECATED + help + Install bluetooth for bcm43xx. diff --git a/buildroot-external/package/bluetooth-bcm43xx/bluetooth-bcm43xx b/buildroot-external/package/bluetooth-bcm43xx/bluetooth-bcm43xx new file mode 100755 index 000000000..f21193ef9 --- /dev/null +++ b/buildroot-external/package/bluetooth-bcm43xx/bluetooth-bcm43xx @@ -0,0 +1,18 @@ +#!/bin/sh + +HCIATTACH=/usr/bin/hciattach +SERIAL=`cat /proc/device-tree/serial-number | cut -c9-` +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 diff --git a/buildroot-external/package/bluetooth-bcm43xx/bluetooth-bcm43xx.mk b/buildroot-external/package/bluetooth-bcm43xx/bluetooth-bcm43xx.mk new file mode 100644 index 000000000..6ec348349 --- /dev/null +++ b/buildroot-external/package/bluetooth-bcm43xx/bluetooth-bcm43xx.mk @@ -0,0 +1,29 @@ +################################################################################ +# +# Bluetooth BCM43xx +# +################################################################################ + +BLUETOOTH_BCM43XX_VERSION = 1.0.0 +BLUETOOTH_BCM43XX_LICENSE = Apache License 2.0 +BLUETOOTH_BCM43XX_LICENSE_FILES = $(BR2_EXTERNAL_HASSOS_PATH)/../LICENSE +BLUETOOTH_BCM43XX_SITE = $(BR2_EXTERNAL_HASSOS_PATH)/package/bluetooth-bcm43xx +BLUETOOTH_BCM43XX_SITE_METHOD = local + +define BLUETOOTH_BCM43XX_BUILD_CMDS + curl -o $(@D)/BCM43430A1.hcd https://raw.githubusercontent.com/RPi-Distro/bluez-firmware/master/broadcom/BCM43430A1.hcd + curl -o $(@D)/BCM4345C0.hcd https://raw.githubusercontent.com/RPi-Distro/bluez-firmware/master/broadcom/BCM4345C0.hcd +endef + +define BLUETOOTH_BCM43XX_INSTALL_TARGET_CMDS + mkdir -p $(TARGET_DIR)/etc/systemd/system/hassos-hardware.wants + cp -f $(@D)/bluetooth-bcm43xx $(TARGET_DIR)/usr/sbin/ + cp -f $(@D)/bluetooth-bcm43xx.service $(TARGET_DIR)/usr/lib/systemd/system/ + ln -fs /usr/lib/systemd/system/bluetooth-bcm43xx.service $(TARGET_DIR)/etc/systemd/system/hassos-hardware.wants/ + + mkdir -p $(TARGET_DIR)/lib/firmware/brcm + cp -f $(@D)/BCM43430A1.hcd $(TARGET_DIR)/lib/firmware/brcm/ + cp -f $(@D)/BCM4345C0.hcd $(TARGET_DIR)/lib/firmware/brcm/ +endef + +$(eval $(generic-package)) diff --git a/buildroot-external/package/bluetooth-bcm43xx/bluetooth-bcm43xx.service b/buildroot-external/package/bluetooth-bcm43xx/bluetooth-bcm43xx.service new file mode 100644 index 000000000..d902f97e5 --- /dev/null +++ b/buildroot-external/package/bluetooth-bcm43xx/bluetooth-bcm43xx.service @@ -0,0 +1,12 @@ +[Unit] +Description=Bluetooth for BCM43xx +Before=bluetooth.service +After=dev-ttyAMA0.device +ConditionPathIsDirectory=/proc/device-tree/soc/gpio@7e200000/bt_pins + +[Service] +Type=forking +ExecStart=/usr/sbin/bluetooth-bcm43xx + +[Install] +WantedBy=hassos-hardware.target diff --git a/buildroot-external/rootfs-overlay/etc/bluetooth/main.conf b/buildroot-external/rootfs-overlay/etc/bluetooth/main.conf new file mode 100644 index 000000000..d3e19f7d2 --- /dev/null +++ b/buildroot-external/rootfs-overlay/etc/bluetooth/main.conf @@ -0,0 +1,2 @@ +[Policy] +AutoEnable=true diff --git a/buildroot-external/rootfs-overlay/etc/systemd/system/hassos-bind.target.wants/var-lib-bluetooth.mount b/buildroot-external/rootfs-overlay/etc/systemd/system/hassos-bind.target.wants/var-lib-bluetooth.mount new file mode 120000 index 000000000..d16b3e1f6 --- /dev/null +++ b/buildroot-external/rootfs-overlay/etc/systemd/system/hassos-bind.target.wants/var-lib-bluetooth.mount @@ -0,0 +1 @@ +/usr/lib/systemd/system/var-lib-bluetooth.mount \ No newline at end of file diff --git a/buildroot-external/rootfs-overlay/etc/systemd/system/hassos-hardware.target.wants/.empty b/buildroot-external/rootfs-overlay/etc/systemd/system/hassos-hardware.target.wants/.empty new file mode 100644 index 000000000..e69de29bb diff --git a/buildroot-external/rootfs-overlay/etc/systemd/system/multi-user.target.wants/hassos-hardware.target b/buildroot-external/rootfs-overlay/etc/systemd/system/multi-user.target.wants/hassos-hardware.target new file mode 120000 index 000000000..e14d96357 --- /dev/null +++ b/buildroot-external/rootfs-overlay/etc/systemd/system/multi-user.target.wants/hassos-hardware.target @@ -0,0 +1 @@ +/usr/lib/systemd/system/hassos-hardware.target \ No newline at end of file diff --git a/buildroot-external/rootfs-overlay/usr/lib/systemd/system/hassos-hardware.target b/buildroot-external/rootfs-overlay/usr/lib/systemd/system/hassos-hardware.target new file mode 100644 index 000000000..44001027e --- /dev/null +++ b/buildroot-external/rootfs-overlay/usr/lib/systemd/system/hassos-hardware.target @@ -0,0 +1,3 @@ +[Unit] +Description=HassOS hardware targets +Documentation=man:systemd.target(5) diff --git a/buildroot-external/rootfs-overlay/usr/lib/systemd/system/var-lib-bluetooth.mount b/buildroot-external/rootfs-overlay/usr/lib/systemd/system/var-lib-bluetooth.mount new file mode 100644 index 000000000..cd37d3a70 --- /dev/null +++ b/buildroot-external/rootfs-overlay/usr/lib/systemd/system/var-lib-bluetooth.mount @@ -0,0 +1,14 @@ +[Unit] +Description=Bluetooth persistent state +Requires=mnt-overlay.mount +After=mnt-overlay.mount +Before=bluetooth.service + +[Mount] +What=/mnt/overlay/var/lib/bluetooth +Where=/var/lib/bluetooth +Type=None +Options=bind + +[Install] +WantedBy=hassos-bind.target