feat: initial bluetooth support (#9)

* Enable Bluetooth LE radio support
* Build our own bccmd which we need to setup/enable this BT chipset sadly
* Use our own tool we build to interface with the ubnt eeprom, so we can not rely on their custom kernel module
* Also fix HDDs not spinning down on shutdown, doing something similar to how unifi does it but a tad more generic.
This commit is contained in:
Chris Blake 2024-06-12 20:38:37 -05:00 committed by GitHub
parent fe3b4cd76f
commit 9ef1a72228
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 678 additions and 20 deletions

View file

@ -32,7 +32,10 @@ apt-get -o Dpkg::Options::="--force-confold" -y --allow-downgrades \
bsdextrautils git binutils ca-certificates e2fsprogs haveged parted curl \
locales console-common openssh-server less vim net-tools wireguard-tools \
ntpsec u-boot-tools wget initramfs-tools python3-flask gnupg libc-ares2 \
dfu-util
dfu-util bluez
# Enable bluetooth
systemctl enable bluetooth
# Locale gen
locale-gen

View file

@ -37,9 +37,9 @@ fi
# some modules. This is why some lines below are commented out.
# Build as normal, with our extra version set to a timestamp
make ${kernel_config}
make ${kernel_config}
make -j`getconf _NPROCESSORS_ONLN` EXTRAVERSION=-alpine-unvr # Build kernel and modules
#make -j`getconf _NPROCESSORS_ONLN` EXTRAVERSION=-alpine-unvr Image.gz # makes gzip image
#make -j`getconf _NPROCESSORS_ONLN` EXTRAVERSION=-alpine-unvr Image.gz # makes gzip image (we should just do this ourselves, skip using make)
make INSTALL_MOD_PATH=./modules-dir -j`getconf _NPROCESSORS_ONLN` EXTRAVERSION=-alpine-unvr modules_install # installs modules to dir
#mkimage -A arm64 -O linux -T kernel -C gzip -a 04080000 -e 04080000 -n "Linux-UNVR-NAS-$(date +%Y%m%d-%H%M%S)" -d ./arch/arm64/boot/Image.gz uImage

View file

@ -0,0 +1,55 @@
#!/bin/bash
set -e
scripts_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )"
. ${scripts_path}/vars.sh
# Exports baby
export PATH=${build_path}/toolchain/${toolchain_bin_path}:${PATH}
export GCC_COLORS=auto
export CROSS_COMPILE=${toolchain_cross_compile}
export ARCH=arm64
# Make our temp builddir for bluez so we can make bccmd
bluez_builddir=$(mktemp -d)
tar -xzf ${root_path}/downloads/${bluez_filename} -C ${bluez_builddir}
# Start with Bluez
cd ${bluez_builddir}/${bluez_repopath}
# If we have patches, apply them
if [[ -d ${root_path}/patches/bluez/ ]]; then
for file in ${root_path}/patches/bluez/*.patch; do
echo "Applying bluez patch ${file}"
patch -p1 < ${file}
done
fi
# Build bccmd from bluez
./bootstrap
./configure --disable-systemd \
--enable-deprecated \
--disable-library \
--disable-cups \
--disable-datafiles \
--disable-manpages \
--disable-pie \
--disable-client \
--disable-obex \
--disable-udev \
--build=x86_64-linux-gnu \
--host=aarch64-none-linux-gnu \
--target=aarch64-none-linux-gnu
make lib/bluetooth/hci.h lib/bluetooth/bluetooth.h lib/libbluetooth-internal.la tools/bccmd -j`getconf _NPROCESSORS_ONLN`
# Save our binary
mkdir -p ${build_path}/packages/bluez
mv ./tools/bccmd ${build_path}/packages/bluez/
# Build ubnteeprom (our own tool)
mkdir -p ${build_path}/packages/ubnteeprom
env GOOS=linux GOARCH=arm64 go build -ldflags="-s -w" -o ${build_path}/packages/ubnteeprom/ubnteeprom ${root_path}/tools/ubnteeprom/main.go
# Cleanup
cd - > /dev/null
rm -rf ${bluez_builddir}

View file

@ -35,8 +35,8 @@ if [[ -d ${root_path}/overlay/${fs_overlay_dir}/ ]]; then
fi
# Apply our part UUIDs to fstab
sed -i "s|BOOTUUIDPLACEHOLDER|$(blkid -o value -s UUID ${build_path}/boot.ext4)|g" ${build_path}/rootfs/etc/fstab
sed -i "s|ROOTUUIDPLACEHOLDER|$(blkid -o value -s UUID ${build_path}/rootfs.ext4)|g" ${build_path}/rootfs/etc/fstab
#sed -i "s|BOOTUUIDPLACEHOLDER|$(blkid -o value -s UUID ${build_path}/boot.ext4)|g" ${build_path}/rootfs/etc/fstab
#sed -i "s|ROOTUUIDPLACEHOLDER|$(blkid -o value -s UUID ${build_path}/rootfs.ext4)|g" ${build_path}/rootfs/etc/fstab
# Hostname
echo "${distrib_name}" > ${build_path}/rootfs/etc/hostname
@ -56,6 +56,18 @@ for file in libgrpc++.so.1 libgrpc.so.10 libprotobuf.so.23 \
cp -H ${build_path}/fw-extract/rootfs/usr/lib/aarch64-linux-gnu/${file} "${build_path}/rootfs/usr/lib/ubnt-fw/"
done
# Copy over bluetooth firmware files
mkdir -p "${build_path}/rootfs/lib/firmware"
cp -R "${build_path}/fw-extract/rootfs/lib/firmware/csr8x11" "${build_path}/rootfs/lib/firmware/" # LCD panel firmwares
# Install our bccmd we compiled (less we use from unifi the better)
cp -R "${build_path}/packages/bluez/bccmd" "${build_path}/rootfs/usr/bin"
chmod +x "${build_path}/rootfs/usr/bin/bccmd"
# Install our ubnteeprom tool
cp -R "${build_path}/packages/ubnteeprom/ubnteeprom" "${build_path}/rootfs/usr/bin"
chmod +x "${build_path}/rootfs/usr/bin/ubnteeprom"
# Kick off bash setup script within chroot
cp ${docker_scripts_path}/bootstrap/001-bootstrap ${build_path}/rootfs/bootstrap
chroot ${build_path}/rootfs /bootstrap