forked from Evaneee/armbian-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bluetooth-hciattach.sh
69 lines (55 loc) · 2.53 KB
/
bluetooth-hciattach.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#
# SPDX-License-Identifier: GPL-2.0
# Copyright (c) 2023 Ricardo Pardini <[email protected]>
# This file is a part of the Armbian Build Framework https://github.com/armbian/build/
#
# Some boards needs a special treatment for bluetooth, running hciattach manually.
# To use, enable_extension bluetooth-hciattach, and set BLUETOOTH_HCIATTACH_PARAMS and BLUETOOTH_HCIATTACH_RKFILL_NUM.
function extension_prepare_config__bluetooth_hciattach() {
display_alert "${EXTENSION} ${BOARD}" "initializing config" "info"
# Bomb if BLUETOOTH_HCIATTACH_PARAMS is not set.
if [[ -z "${BLUETOOTH_HCIATTACH_PARAMS}" ]]; then
exit_with_error "${EXTENSION} ${BOARD} - BLUETOOTH_HCIATTACH_PARAMS is not set - please set in the board file."
fi
# Default BLUETOOTH_HCIATTACH_RKFILL_NUM to 0 if not set.
if [[ -z "${BLUETOOTH_HCIATTACH_RKFILL_NUM}" ]]; then
declare -g BLUETOOTH_HCIATTACH_RKFILL_NUM=0
fi
}
# Add bluetooth packages to the image (not rootfs cache)
function post_family_config__bluetooth_hciattach_add_bluetooth_packages() {
display_alert "${EXTENSION} ${BOARD}" "adding bluetooth packages to image" "info"
add_packages_to_image rfkill bluetooth bluez bluez-tools
}
# Deploy the script and the systemd service in the BSP. It'll be enabled below in the image.
function post_family_tweaks_bsp__bluetooth_hciattach_add_systemd_service() {
display_alert "${EXTENSION} ${BOARD}" "adding bluetooth hciattach service to BSP" "info"
: "${destination:?destination is not set}"
declare script_dir="/usr/local/sbin"
run_host_command_logged mkdir -pv "${destination}${script_dir}"
declare script_path="${script_dir}/bluetooth-hciattach.sh"
cat <<- BT_HCIATTACH_SCRIPT > "${destination}${script_path}"
#!/bin/bash
rfkill unblock ${BLUETOOTH_HCIATTACH_RKFILL_NUM}
hciattach -n ${BLUETOOTH_HCIATTACH_PARAMS}
BT_HCIATTACH_SCRIPT
run_host_command_logged chmod -v +x "${destination}${script_path}" # Make it executable
cat <<- BT_HCIATTACH_SYSTEMD_SERVICE > "$destination"/lib/systemd/system/bluetooth-hciattach.service
[Unit]
Description=${BOARD} Bluetooth HCIAttach fix
After=network.target
StartLimitIntervalSec=0
[Service]
Type=simple
ExecStart=${script_path}
[Install]
WantedBy=multi-user.target
BT_HCIATTACH_SYSTEMD_SERVICE
return 0
}
# Enable the service created in the BSP above.
function post_family_tweaks__bluetooth_hciattach_enable_bt_service_in_image() {
display_alert "${EXTENSION} ${BOARD}" "enabling bluetooth hciattach service in the image" "info"
chroot_sdcard systemctl --no-reload enable "bluetooth-hciattach.service"
return 0
}