900 lines
35 KiB
Bash
900 lines
35 KiB
Bash
#!/usr/bin/env bash
|
|
# SPDX-License-Identifier: (GPL-2.0-only OR MIT)
|
|
# Copyright (C) 2026 Amlogic, Inc. All rights reserved
|
|
################################################################################
|
|
# Amlbian BlueZ5 Compilation Package
|
|
#
|
|
# Purpose: BlueZ5 compilation based on Yocto recipe bluez5_5.65.bb
|
|
# + meta-meson/recipes-connectivity/bluez/bluez5_%.bbappend
|
|
# + meta-meson/recipes-connectivity/bluez/bluez5_5.65.bbappend
|
|
# Based on Yocto recipe: poky/meta/recipes-connectivity/bluez5/bluez5_5.65.bb
|
|
#
|
|
# This script implements the base BlueZ5 5.65 recipe with complete bbappend modifications
|
|
# Optimized version based on build-bt.sh structure
|
|
################################################################################
|
|
|
|
set -e
|
|
|
|
# Get script directory
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
AMLBIAN_DIR="$(dirname "$(dirname "${SCRIPT_DIR}")")"
|
|
BASE_DIR="$(dirname "$(dirname "${AMLBIAN_DIR}")")"
|
|
|
|
# Source common functions
|
|
if [[ -f "${AMLBIAN_DIR}/lib/function-common.sh" ]]; then
|
|
source "${AMLBIAN_DIR}/lib/function-common.sh"
|
|
fi
|
|
|
|
# ==============================================================================
|
|
# Shared Helper Functions
|
|
# ==============================================================================
|
|
|
|
# ------------------------------------------------------------------------------
|
|
# Step 1: Package Information Definition
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Initialize BlueZ5 package metadata
|
|
function _bluez5_init_package_info() {
|
|
PKG_NAME="bluez"
|
|
PKG_VERSION="5.65"
|
|
COMPONENT="bluez5"
|
|
PKG_ARCH="${ARCH:-aarch64}"
|
|
|
|
PKG_MAINTAINER="Armbian Build <[email protected]>"
|
|
PKG_DESCRIPTION="BlueZ 5.65 Bluetooth stack with Amlogic modifications"
|
|
|
|
# Cross compilation settings
|
|
CROSS_COMPILE="${CROSS_COMPILE:-aarch64-linux-gnu-}"
|
|
|
|
# Source URL from bluez5_5.65.bb
|
|
KERNELORG_MIRROR="https://www.kernel.org/pub/linux/bluetooth"
|
|
SRC_URL="${KERNELORG_MIRROR}/bluez-${PKG_VERSION}.tar.xz"
|
|
SRC_SHA256="2565a4d48354b576e6ad92e25b54ed66808296581c8abb80587051f9993d96d4"
|
|
|
|
# Meta-meson files directory (from bbappend FILESEXTRAPATHS)
|
|
FILES_DIR="${SCRIPT_DIR}/files"
|
|
|
|
# TTY setting from bluez5_%.bbappend
|
|
TTY="${TTY:-ttyS1}"
|
|
|
|
# DISTRO_FEATURES - controls which features are enabled
|
|
DISTRO_FEATURES+=" systemd obexd aml-wifi bt-audio"
|
|
|
|
# MACHINE_EXTRA_RRECOMMENDS for RDEPENDS logic
|
|
MACHINE_EXTRA_RRECOMMENDS="${MACHINE_EXTRA_RRECOMMENDS:-}"
|
|
}
|
|
|
|
# ------------------------------------------------------------------------------
|
|
# Step 2: Build Directory Structure Setup
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Create layered build directory structure
|
|
# Parameters:
|
|
# $1 - base name (e.g. "${PKG_NAME}_${PKG_VERSION}_${PKG_ARCH}")
|
|
# Sets: TMP_DIR, BASE_BUILD_DIR, SOURCE_DIR, BUILD_DIR, INSTALL_DIR, PATCH_DIR,
|
|
# DEB_PACKAGE_DIR, DEBIAN_DIR, BUILD_LOG
|
|
function _bluez5_common_create_build_dirs() {
|
|
local base_name="$1"
|
|
|
|
TMP_DIR="${SRC}/.tmp"
|
|
mkdir -p "${TMP_DIR}"
|
|
|
|
# 基础构建目录
|
|
BASE_BUILD_DIR="${TMP_DIR}/${base_name}"
|
|
|
|
rm -rf ${BASE_BUILD_DIR}
|
|
|
|
# 分层目录
|
|
SOURCE_DIR="${BASE_BUILD_DIR}/source" # 源码目录
|
|
BUILD_DIR="${BASE_BUILD_DIR}/build" # 编译目录
|
|
INSTALL_DIR="${BASE_BUILD_DIR}/install" # 安装目录
|
|
PATCH_DIR="${BASE_BUILD_DIR}/patch" # 补丁目录
|
|
|
|
# 创建所有目录
|
|
mkdir -p "${SOURCE_DIR}"
|
|
mkdir -p "${BUILD_DIR}"
|
|
mkdir -p "${INSTALL_DIR}"
|
|
mkdir -p "${PATCH_DIR}"
|
|
|
|
# 在BUILD_DIR下创建deb/包名目录
|
|
DEB_PACKAGE_DIR="${BUILD_DIR}/deb/${base_name}"
|
|
mkdir -p "${DEB_PACKAGE_DIR}"
|
|
|
|
# 创建编译日志文件
|
|
BUILD_LOG="${BUILD_DIR}/build.log"
|
|
|
|
# 安装目录的子目录
|
|
DEBIAN_DIR="${INSTALL_DIR}/DEBIAN"
|
|
BIN_DIR="${INSTALL_DIR}/usr/bin/"
|
|
SYSTEMD_DIR="${INSTALL_DIR}/lib/systemd/system/"
|
|
ETC_DIR="${INSTALL_DIR}/etc/bluetooth/"
|
|
|
|
mkdir -p "${DEBIAN_DIR}"
|
|
mkdir -p "${BIN_DIR}"
|
|
mkdir -p "${SYSTEMD_DIR}"
|
|
mkdir -p "${ETC_DIR}"
|
|
}
|
|
|
|
# Display build directory info
|
|
# Parameters:
|
|
# $1 - log prefix
|
|
function _bluez5_common_display_build_info() {
|
|
local log_prefix="$1"
|
|
|
|
display_alert "${log_prefix} Source dir: ${SOURCE_DIR}" "info"
|
|
display_alert "${log_prefix} Build dir: ${BUILD_DIR}" "info"
|
|
display_alert "${log_prefix} Install dir: ${INSTALL_DIR}" "info"
|
|
display_alert "${log_prefix} Patch dir: ${PATCH_DIR}" "info"
|
|
display_alert "${log_prefix} Deb package dir: ${DEB_PACKAGE_DIR}" "info"
|
|
display_alert "${log_prefix} Build log: ${BUILD_LOG}" "info"
|
|
display_alert "${log_prefix} Bin dir: ${BIN_DIR}" "info"
|
|
display_alert "${log_prefix} Systemd dir: ${SYSTEMD_DIR}" "info"
|
|
display_alert "${log_prefix} Config dir: ${ETC_DIR}" "info"
|
|
}
|
|
|
|
# ------------------------------------------------------------------------------
|
|
# Step 3: Source Download and Extraction
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Download and extract BlueZ5 source code
|
|
function _bluez5_download_and_extract() {
|
|
display_alert "COMPILE-${COMPONENT} Step 1: Downloading BlueZ5 source code" "info"
|
|
|
|
cd "${BASE_BUILD_DIR}"
|
|
|
|
# Download source tarball
|
|
if [[ ! -f "bluez-${PKG_VERSION}.tar.xz" ]]; then
|
|
display_alert "COMPILE-${COMPONENT} Downloading from ${SRC_URL}" "info"
|
|
wget -q --show-progress -O "bluez-${PKG_VERSION}.tar.xz" "${SRC_URL}" 2>&1 >> "${BUILD_LOG}"
|
|
|
|
# Verify SHA256 checksum
|
|
local calculated_sha=$(sha256sum "bluez-${PKG_VERSION}.tar.xz" | cut -d' ' -f1)
|
|
if [[ "$calculated_sha" != "$SRC_SHA256" ]]; then
|
|
display_alert "COMPILE-${COMPONENT} SHA256 mismatch: expected $SRC_SHA256, got $calculated_sha" "error"
|
|
exit 1
|
|
fi
|
|
else
|
|
display_alert "COMPILE-${COMPONENT} Source tarball already exists, skipping download" "info"
|
|
fi
|
|
|
|
# Extract source
|
|
tar -xf "bluez-${PKG_VERSION}.tar.xz" -C "${SOURCE_DIR}" --strip-components=1
|
|
display_alert "COMPILE-${COMPONENT} Source extracted to ${SOURCE_DIR}" "info"
|
|
}
|
|
|
|
# ------------------------------------------------------------------------------
|
|
# Step 4: Apply Patches
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Apply base recipe patches from bluez5.inc
|
|
function _bluez5_apply_base_patches() {
|
|
display_alert "COMPILE-${COMPONENT} Step 2: Applying patches from bluez5.inc" "info"
|
|
|
|
cd "${SOURCE_DIR}"
|
|
|
|
# Patches defined in bluez5.inc SRC_URI
|
|
local patches=(
|
|
"0001-Allow-using-obexd-without-systemd-in-the-user-sessio.patch"
|
|
"0001-tests-add-a-target-for-building-tests-without-runnin.patch"
|
|
"0001-test-gatt-Fix-hung-issue.patch"
|
|
"CVE-2023-45866.patch"
|
|
"CVE-2023-27349.patch"
|
|
"CVE-2023-50229_CVE-2023-50230.patch"
|
|
)
|
|
|
|
# Patch directory from poky
|
|
local PATCH_DIR="${SCRIPT_DIR}/files"
|
|
|
|
# Apply patches
|
|
for patch in "${patches[@]}"; do
|
|
local patch_file="${PATCH_DIR}/${patch}"
|
|
|
|
if [[ -f "$patch_file" ]]; then
|
|
display_alert "COMPILE-${COMPONENT} Applying patch: $patch" "info"
|
|
|
|
# Try patch with -p1 first
|
|
if patch -p1 --dry-run < "$patch_file" &> /dev/null; then
|
|
patch -p1 < "$patch_file" >> "$BUILD_LOG" 2>&1
|
|
display_alert "COMPILE-${COMPONENT} Patch applied successfully with -p1" "info"
|
|
else
|
|
# Try with -p0
|
|
if patch -p0 --dry-run < "$patch_file" &> /dev/null; then
|
|
patch -p0 < "$patch_file" >> "$BUILD_LOG" 2>&1
|
|
display_alert "COMPILE-${COMPONENT} Patch applied successfully with -p0" "info"
|
|
else
|
|
display_alert "COMPILE-${COMPONENT} Failed to apply patch: $patch" "warn"
|
|
fi
|
|
fi
|
|
else
|
|
display_alert "COMPILE-${COMPONENT} Patch file not found: $patch_file" "warn"
|
|
fi
|
|
done
|
|
}
|
|
|
|
# Apply bbappend patches
|
|
function _bluez5_apply_bbappend_patches() {
|
|
display_alert "COMPILE-${COMPONENT} Step 3: Applying bbappend patches" "info"
|
|
|
|
cd "${SOURCE_DIR}"
|
|
local PATCH_DIR="${SCRIPT_DIR}/files"
|
|
|
|
# Apply default_agent patch from bluez5_%.bbappend
|
|
local default_agent_patch="${PATCH_DIR}/0000-bluez5-add-default_agent-3-5.patch"
|
|
if [[ -f "$default_agent_patch" ]]; then
|
|
display_alert "COMPILE-${COMPONENT} Applying default_agent patch" "info"
|
|
if patch -p1 --dry-run < "$default_agent_patch" &> /dev/null; then
|
|
patch -p1 < "$default_agent_patch" >> "$BUILD_LOG" 2>&1
|
|
display_alert "COMPILE-${COMPONENT} Default_agent patch applied successfully" "info"
|
|
else
|
|
display_alert "COMPILE-${COMPONENT} Failed to apply default_agent patch" "warn"
|
|
fi
|
|
fi
|
|
|
|
# Apply always-applied patches from bluez5_5.65.bbappend
|
|
local bbappend_patches_565=(
|
|
"0001-bluez-remove-bonded-check-in-hog-accept.patch"
|
|
"0002-bluez-fix-repeatedly-connect-and-disconnect.patch"
|
|
"0003-bluez-fix-rcu-reconnect.patch"
|
|
"0004-bluez-fix-pair-interrupt-error.patch"
|
|
)
|
|
|
|
for patch in "${bbappend_patches_565[@]}"; do
|
|
local patch_file="${PATCH_DIR}/${patch}"
|
|
|
|
if [[ -f "$patch_file" ]]; then
|
|
display_alert "COMPILE-${COMPONENT} Applying patch: $patch" "info"
|
|
|
|
if patch -p1 --dry-run < "$patch_file" &> /dev/null; then
|
|
patch -p1 < "$patch_file" >> "$BUILD_LOG" 2>&1
|
|
display_alert "COMPILE-${COMPONENT} Patch applied successfully with -p1" "info"
|
|
elif patch -p0 --dry-run < "$patch_file" &> /dev/null; then
|
|
patch -p0 < "$patch_file" >> "$BUILD_LOG" 2>&1
|
|
display_alert "COMPILE-${COMPONENT} Patch applied successfully with -p0" "info"
|
|
else
|
|
display_alert "COMPILE-${COMPONENT} Failed to apply patch: $patch" "warn"
|
|
fi
|
|
else
|
|
display_alert "COMPILE-${COMPONENT} Patch file not found: $patch_file" "warn"
|
|
fi
|
|
done
|
|
|
|
# Apply conditional patches based on DISTRO_FEATURES
|
|
# bt-qca support
|
|
if [[ "${DISTRO_FEATURES:-}" == *"bt-qca"* ]]; then
|
|
local qca_patch="${PATCH_DIR}/0001-bluez-hciattach-add-qca-support.patch"
|
|
if [[ -f "$qca_patch" ]]; then
|
|
display_alert "COMPILE-${COMPONENT} Applying bt-qca patch: 0001-bluez-hciattach-add-qca-support.patch" "info"
|
|
if patch -p1 --dry-run < "$qca_patch" &> /dev/null; then
|
|
patch -p1 < "$qca_patch" >> "$BUILD_LOG" 2>&1
|
|
display_alert "COMPILE-${COMPONENT} bt-qca patch applied successfully" "info"
|
|
else
|
|
display_alert "COMPILE-${COMPONENT} Failed to apply bt-qca patch" "warn"
|
|
fi
|
|
else
|
|
display_alert "COMPILE-${COMPONENT} bt-qca patch not found: $qca_patch" "warn"
|
|
fi
|
|
fi
|
|
|
|
# aml-wifi support
|
|
if [[ "${DISTRO_FEATURES:-}" == *"aml-wifi"* ]]; then
|
|
local aml_patches=(
|
|
"0001-bluez-hciattach-add-aml-support.patch"
|
|
"0001-BT-extract-amlbt-fw-log-1-1.patch"
|
|
)
|
|
for patch in "${aml_patches[@]}"; do
|
|
local patch_file="${PATCH_DIR}/${patch}"
|
|
if [[ -f "$patch_file" ]]; then
|
|
display_alert "COMPILE-${COMPONENT} Applying aml-wifi patch: $patch" "info"
|
|
if patch -p1 --dry-run < "$patch_file" &> /dev/null; then
|
|
patch -p1 < "$patch_file" >> "$BUILD_LOG" 2>&1
|
|
display_alert "COMPILE-${COMPONENT} Patch applied successfully" "info"
|
|
else
|
|
display_alert "COMPILE-${COMPONENT} Failed to apply patch: $patch" "warn"
|
|
fi
|
|
else
|
|
display_alert "COMPILE-${COMPONENT} Patch not found: $patch_file" "warn"
|
|
fi
|
|
done
|
|
fi
|
|
}
|
|
|
|
# Copy additional directories from bbappend
|
|
function _bluez5_copy_bbappend_directories() {
|
|
display_alert "COMPILE-${COMPONENT} Step 4: Copying bbappend directories" "info"
|
|
|
|
local FILES_DIR="${SCRIPT_DIR}/files"
|
|
|
|
# Copy client/ directory (from bluez5_%.bbappend do_compile:prepend)
|
|
local client_src="${FILES_DIR}/client"
|
|
if [[ -d "$client_src" ]]; then
|
|
display_alert "COMPILE-${COMPONENT} Copying client/ directory to source" "info"
|
|
cp -rf "${client_src}/"* "${SOURCE_DIR}/client/"
|
|
display_alert "COMPILE-${COMPONENT} Client files copied successfully" "info"
|
|
else
|
|
display_alert "COMPILE-${COMPONENT} Client directory not found: $client_src" "warn"
|
|
fi
|
|
|
|
# Copy tools/ directory (from bluez5_5.65.bbappend do_compile:prepend)
|
|
local tools_src="${FILES_DIR}/tools"
|
|
if [[ -d "$tools_src" ]]; then
|
|
display_alert "COMPILE-${COMPONENT} Copying tools/ directory to source" "info"
|
|
install -d "${SOURCE_DIR}/tools"
|
|
cp -rf "${tools_src}/"* "${SOURCE_DIR}/tools/"
|
|
display_alert "COMPILE-${COMPONENT} Tools files copied successfully" "info"
|
|
else
|
|
display_alert "COMPILE-${COMPONENT} Tools directory not found: $tools_src" "warn"
|
|
fi
|
|
|
|
# Copy monitor/ directory (from bluez5_5.65.bbappend do_compile:prepend, conditional on aml-wifi)
|
|
local monitor_src="${FILES_DIR}/monitor"
|
|
if [[ -d "$monitor_src" ]]; then
|
|
display_alert "COMPILE-${COMPONENT} Copying monitor/ directory to source (aml-wifi)" "info"
|
|
install -d "${SOURCE_DIR}/monitor"
|
|
cp -rf "${monitor_src}/"* "${SOURCE_DIR}/monitor/"
|
|
display_alert "COMPILE-${COMPONENT} Monitor files copied successfully" "info"
|
|
else
|
|
display_alert "COMPILE-${COMPONENT} Monitor directory not found: $monitor_src" "warn"
|
|
fi
|
|
}
|
|
|
|
# ------------------------------------------------------------------------------
|
|
# Step 5: Configure Build
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Configure BlueZ5 build
|
|
function _bluez5_configure_build() {
|
|
display_alert "COMPILE-${COMPONENT} Step 5: Configuring BlueZ build" "info"
|
|
|
|
cd "${SOURCE_DIR}"
|
|
|
|
# Clean previous build
|
|
if [[ -f "Makefile" ]]; then
|
|
display_alert "COMPILE-${COMPONENT} Clean build" "info"
|
|
make distclean >> "$BUILD_LOG" 2>&1 || true
|
|
fi
|
|
|
|
# 设置编译环境
|
|
: "${ARCH:=arm64}"
|
|
CROSS_COMPILE="${CROSS_COMPILE:-aarch64-linux-gnu-}"
|
|
|
|
export ARCH
|
|
export CROSS_COMPILE="${CROSS_COMPILE}"
|
|
|
|
autoreconf -fi
|
|
|
|
# Check if ROOTFS_TEMP exists, use it as sysroot, otherwise error
|
|
SYSROOT=""
|
|
|
|
if [[ -n "${ROOTFS_TEMP}" ]] && [[ -d "${ROOTFS_TEMP}" ]] && [[ -d "${ROOTFS_TEMP}/usr/lib/aarch64-linux-gnu" ]]; then
|
|
SYSROOT="${ROOTFS_TEMP}"
|
|
display_alert "COMPILE-${COMPONENT}" "Using ROOTFS_TEMP as sysroot: ${SYSROOT}" "info"
|
|
else
|
|
display_alert "COMPILE-${COMPONENT}" "ROOTFS_TEMP not found or invalid: ${ROOTFS_TEMP}" "err"
|
|
display_alert "COMPILE-${COMPONENT}" "ROOTFS_TEMP should be created by create_base_rootfs function" "err"
|
|
return 1
|
|
fi
|
|
|
|
mkdir -p $SYSROOT/usr/lib
|
|
|
|
# 软链接(关键)
|
|
ln -sf $SYSROOT/usr/lib/aarch64-linux-gnu/crti.o $SYSROOT/usr/lib/crti.o
|
|
ln -sf $SYSROOT/usr/lib/aarch64-linux-gnu/crtn.o $SYSROOT/usr/lib/crtn.o
|
|
ln -sf $SYSROOT/usr/lib/aarch64-linux-gnu/crt1.o $SYSROOT/usr/lib/crt1.o
|
|
|
|
# 构建所有配置选项
|
|
local all_configure_opts=()
|
|
|
|
# Base configure options from bluez5.inc
|
|
local base_opts=(
|
|
"--prefix=/usr"
|
|
"--sysconfdir=/etc"
|
|
"--localstatedir=/var"
|
|
"--mandir=/usr/share/man"
|
|
"--enable-test"
|
|
"--enable-datafiles"
|
|
"--enable-library"
|
|
"--without-zsh-completion-dir"
|
|
"--disable-manpages"
|
|
)
|
|
all_configure_opts+=("${base_opts[@]}")
|
|
|
|
# PACKAGECONFIG options (default from bluez5.inc)
|
|
local packagenconfig=(
|
|
"obex-profiles"
|
|
"readline"
|
|
"a2dp-profiles"
|
|
"avrcp-profiles"
|
|
"network-profiles"
|
|
"hid-profiles"
|
|
"hog-profiles"
|
|
"tools"
|
|
"deprecated"
|
|
"udev"
|
|
"systemd"
|
|
)
|
|
|
|
# Process PACKAGECONFIG options
|
|
for config in "${packagenconfig[@]}"; do
|
|
case "$config" in
|
|
"obex-profiles") all_configure_opts+=("--enable-obex") ;;
|
|
"readline") all_configure_opts+=("--enable-client") ;;
|
|
"systemd") all_configure_opts+=("--enable-systemd") ;;
|
|
"a2dp-profiles") all_configure_opts+=("--enable-a2dp") ;;
|
|
"avrcp-profiles") all_configure_opts+=("--enable-avrcp") ;;
|
|
"network-profiles") all_configure_opts+=("--enable-network") ;;
|
|
"hid-profiles") all_configure_opts+=("--enable-hid") ;;
|
|
"hog-profiles") all_configure_opts+=("--enable-hog") ;;
|
|
"tools") all_configure_opts+=("--enable-tools") ;;
|
|
"deprecated") all_configure_opts+=("--enable-deprecated") ;;
|
|
"udev") all_configure_opts+=("--enable-udev") ;;
|
|
esac
|
|
done
|
|
|
|
# Apply PACKAGECONFIG removals from bluez5_5.65.bbappend
|
|
# Remove a2dp-profiles and avrcp-profiles if bt-audio not in DISTRO_FEATURES
|
|
if [[ "${DISTRO_FEATURES:-}" != *"bt-audio"* ]]; then
|
|
# 从数组中移除对应的选项
|
|
for i in "${!all_configure_opts[@]}"; do
|
|
if [[ "${all_configure_opts[i]}" == "--enable-a2dp" ]] || [[ "${all_configure_opts[i]}" == "--enable-avrcp" ]]; then
|
|
unset 'all_configure_opts[i]'
|
|
fi
|
|
done
|
|
# 重新索引数组
|
|
all_configure_opts=("${all_configure_opts[@]}")
|
|
display_alert "COMPILE-${COMPONENT} Removed a2dp-profiles and avrcp-profiles (bt-audio not enabled)" "info"
|
|
fi
|
|
|
|
# Remove obex-profiles if obexd not in DISTRO_FEATURES
|
|
if [[ "${DISTRO_FEATURES:-}" != *"obexd"* ]]; then
|
|
for i in "${!all_configure_opts[@]}"; do
|
|
if [[ "${all_configure_opts[i]}" == "--enable-obex" ]]; then
|
|
unset 'all_configure_opts[i]'
|
|
fi
|
|
done
|
|
all_configure_opts=("${all_configure_opts[@]}")
|
|
display_alert "COMPILE-${COMPONENT} Removed obex-profiles (obexd not enabled)" "info"
|
|
fi
|
|
|
|
# Remove network-profiles if bt-network not in DISTRO_FEATURES
|
|
if [[ "${DISTRO_FEATURES:-}" != *"bt-network"* ]]; then
|
|
for i in "${!all_configure_opts[@]}"; do
|
|
if [[ "${all_configure_opts[i]}" == "--enable-network" ]]; then
|
|
unset 'all_configure_opts[i]'
|
|
fi
|
|
done
|
|
all_configure_opts=("${all_configure_opts[@]}")
|
|
display_alert "COMPILE-${COMPONENT} Removed network-profiles (bt-network not enabled)" "info"
|
|
fi
|
|
|
|
export PKG_CONFIG=/usr/bin/pkg-config
|
|
export PKG_CONFIG_SYSROOT_DIR="${SYSROOT}"
|
|
export PKG_CONFIG_LIBDIR="${SYSROOT}/usr/lib/aarch64-linux-gnu/pkgconfig:${SYSROOT}/usr/share/pkgconfig"
|
|
unset PKG_CONFIG_PATH
|
|
|
|
# Set up flags with sysroot
|
|
export CPPFLAGS="${CPPFLAGS} --sysroot=${SYSROOT}"
|
|
|
|
# Add standard library definitions to avoid C23 issues
|
|
export CFLAGS="${CFLAGS} --sysroot=${SYSROOT} -fPIC"
|
|
export CXXFLAGS="${CXXFLAGS} --sysroot=${SYSROOT} -fPIC"
|
|
|
|
# Add sysroot-specific include paths
|
|
local include_flags="-I${SYSROOT}/usr/include/aarch64-linux-gnu \
|
|
-I${SYSROOT}/usr/include/glib-2.0 \
|
|
-I${SYSROOT}/usr/lib/aarch64-linux-gnu/glib-2.0/include"
|
|
|
|
export CPPFLAGS="${CPPFLAGS} ${include_flags}"
|
|
export CFLAGS="${CFLAGS} ${include_flags}"
|
|
export CXXFLAGS="${CXXFLAGS} ${include_flags}"
|
|
export LIBS="${LIBS} -ltinfo"
|
|
|
|
# Add sysroot-specific library paths with required libraries
|
|
export LDFLAGS="${LDFLAGS} --sysroot=${SYSROOT} \
|
|
-L${SYSROOT}/usr/lib/aarch64-linux-gnu \
|
|
-L${SYSROOT}/lib/aarch64-linux-gnu \
|
|
-Wl,-rpath-link=${SYSROOT}/usr/lib/aarch64-linux-gnu \
|
|
-Wl,-rpath-link=${SYSROOT}/lib/aarch64-linux-gnu \
|
|
-lpcre2-8 -lm -lsystemd -lncurses -ltinfo"
|
|
|
|
# 处理 CONFIGURE_ARGS(如果有额外的配置参数)
|
|
local extra_args=""
|
|
if [[ -n "${CONFIGURE_ARGS:-}" ]]; then
|
|
extra_args="${CONFIGURE_ARGS}"
|
|
display_alert "COMPILE-${COMPONENT}" "Additional configure args: ${extra_args}" "info"
|
|
fi
|
|
|
|
# Run configure
|
|
display_alert "COMPILE-${COMPONENT} Configure options" "${all_configure_opts[*]} ${extra_args}" "info"
|
|
|
|
./configure \
|
|
"${all_configure_opts[@]}" \
|
|
--host=aarch64-linux-gnu \
|
|
--build=x86_64-linux-gnu \
|
|
--libdir=/usr/lib/aarch64-linux-gnu \
|
|
PKG_CONFIG=/usr/bin/pkg-config \
|
|
CC="${CROSS_COMPILE}gcc" \
|
|
CFLAGS="${CFLAGS}" \
|
|
LDFLAGS="${LDFLAGS}" \
|
|
${extra_args} \
|
|
2>&1 || {
|
|
display_alert "COMPILE-${COMPONENT} configure failed" "error"
|
|
return 1
|
|
}
|
|
|
|
display_alert "COMPILE-${COMPONENT} Configuration successful" "info"
|
|
}
|
|
|
|
# ------------------------------------------------------------------------------
|
|
# Step 6: Compile BlueZ5
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Compile BlueZ5
|
|
function _bluez5_compile() {
|
|
display_alert "COMPILE-${COMPONENT} Step 6: Compiling BlueZ" "info"
|
|
|
|
# Compile
|
|
display_alert "COMPILE-${COMPONENT} Building with $(nproc) parallel jobs LDFLAGS ${LDFLAGS} CFLAGS ${CFLAGS}" "info"
|
|
|
|
make CC="${CROSS_COMPILE}gcc" \
|
|
CFLAGS="${CFLAGS}" \
|
|
LDFLAGS="${LDFLAGS}" \
|
|
ARCH="${PKG_ARCH}" \
|
|
-j$(nproc) \
|
|
all 2>&1
|
|
|
|
if [[ $? -ne 0 ]]; then
|
|
display_alert "COMPILE-${COMPONENT} Compilation failed, check $BUILD_LOG" "error"
|
|
exit 1
|
|
fi
|
|
|
|
display_alert "COMPILE-${COMPONENT} Compilation successful" "info"
|
|
}
|
|
|
|
# ------------------------------------------------------------------------------
|
|
# Step 7: Install Files
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Install base recipe files
|
|
function _bluez5_install_base() {
|
|
display_alert "COMPILE-${COMPONENT} Step 7: Installing BlueZ (base recipe)" "info"
|
|
|
|
# Install to staging directory
|
|
mkdir -p "${INSTALL_DIR}"
|
|
|
|
make install DESTDIR="${INSTALL_DIR}" \
|
|
CC="${CROSS_COMPILE}gcc" \
|
|
CFLAGS="" \
|
|
LDFLAGS="" \
|
|
DBUS_CONFDIR="/etc" \
|
|
DBUS_SESSIONBUSDIR="/usr/share/dbus-1/services" \
|
|
DBUS_SYSTEMBUSDIR="/usr/share/dbus-1/system-services" \
|
|
SYSTEMD_SYSTEMUNITDIR="/lib/systemd/system" \
|
|
SYSTEMD_USERUNITDIR="/usr/lib/systemd/user" \
|
|
UDEV_DIR="/lib/udev" \
|
|
>> "$BUILD_LOG" 2>&1
|
|
}
|
|
|
|
# Install bbappend extra files
|
|
function _bluez5_install_bbappend_files() {
|
|
display_alert "COMPILE-${COMPONENT} Step 7b: Installing bbappend extra files" "info"
|
|
|
|
# Create necessary directories
|
|
install -d "${INSTALL_DIR}/usr/bin"
|
|
install -d "${INSTALL_DIR}/lib/systemd/system"
|
|
install -d "${INSTALL_DIR}/etc/bluetooth"
|
|
|
|
# Install default_agent binary
|
|
if [[ -f "${SOURCE_DIR}/client/default_agent" ]]; then
|
|
install -m 0755 "${SOURCE_DIR}/client/default_agent" "${INSTALL_DIR}/usr/bin/"
|
|
display_alert "COMPILE-${COMPONENT} Installed: default_agent -> /usr/bin/" "info"
|
|
else
|
|
display_alert "COMPILE-${COMPONENT} default_agent binary not found in build output" "warn"
|
|
fi
|
|
|
|
# Install bluez_tool.sh
|
|
local bluez_tool_src="${FILES_DIR}/bluez_tool.sh"
|
|
if [[ -f "$bluez_tool_src" ]]; then
|
|
install -m 0755 "$bluez_tool_src" "${INSTALL_DIR}/usr/bin/"
|
|
display_alert "COMPILE-${COMPONENT} Installed: bluez_tool.sh -> /usr/bin/" "info"
|
|
else
|
|
display_alert "COMPILE-${COMPONENT} bluez_tool.sh not found: $bluez_tool_src" "warn"
|
|
fi
|
|
|
|
# Install bluez.service
|
|
local bluez_service_src="${FILES_DIR}/bluez.service"
|
|
if [[ -f "$bluez_service_src" ]]; then
|
|
install -m 0644 "$bluez_service_src" "${INSTALL_DIR}/lib/systemd/system/"
|
|
display_alert "COMPILE-${COMPONENT} Installed: bluez.service -> /lib/systemd/system/" "info"
|
|
else
|
|
display_alert "COMPILE-${COMPONENT} bluez.service not found: $bluez_service_src" "warn"
|
|
fi
|
|
|
|
# Install main.conf
|
|
local main_conf_src="${FILES_DIR}/main.conf"
|
|
if [[ -f "$main_conf_src" ]]; then
|
|
install -m 0644 "$main_conf_src" "${INSTALL_DIR}/etc/bluetooth/"
|
|
display_alert "COMPILE-${COMPONENT} Installed: main.conf -> /etc/bluetooth/" "info"
|
|
else
|
|
display_alert "COMPILE-${COMPONENT} main.conf not found: $main_conf_src" "warn"
|
|
fi
|
|
|
|
# Modify main.conf based on DISTRO_FEATURES
|
|
local main_conf_installed="${INSTALL_DIR}/etc/bluetooth/main.conf"
|
|
if [[ -f "$main_conf_installed" ]]; then
|
|
# Determine Device type based on DISTRO_FEATURES
|
|
if [[ "${DISTRO_FEATURES:-}" == *"aml-wifi"* ]]; then
|
|
sed -i '/Debug/a Device=aml' "$main_conf_installed"
|
|
display_alert "COMPILE-${COMPONENT} main.conf: Device=aml (aml-wifi enabled)" "info"
|
|
elif [[ "${DISTRO_FEATURES:-}" == *"bt-qca"* ]]; then
|
|
sed -i '/Debug/a Device=qca' "$main_conf_installed"
|
|
display_alert "COMPILE-${COMPONENT} main.conf: Device=qca (bt-qca enabled)" "info"
|
|
elif [[ "${DISTRO_FEATURES:-}" == *"bt-bcm"* ]]; then
|
|
sed -i '/Debug/a Device=bcm' "$main_conf_installed"
|
|
display_alert "COMPILE-${COMPONENT} main.conf: Device=bcm (bt-bcm enabled)" "info"
|
|
else
|
|
sed -i '/Debug/a Device=rtk' "$main_conf_installed"
|
|
display_alert "COMPILE-${COMPONENT} main.conf: Device=rtk (default)" "info"
|
|
fi
|
|
|
|
# Add TTY setting
|
|
sed -i "/Debug/a TTY=/dev/${TTY}" "$main_conf_installed"
|
|
display_alert "COMPILE-${COMPONENT} main.conf: TTY=/dev/${TTY}" "info"
|
|
fi
|
|
|
|
# Modify bluetooth.service
|
|
local bluetooth_service_installed="${INSTALL_DIR}/lib/systemd/system/bluetooth.service"
|
|
if [[ -f "$bluetooth_service_installed" ]]; then
|
|
# Add EnvironmentFile before ExecStart
|
|
sed -i "/ExecStart/i EnvironmentFile=-/etc/aml-wifi-debug.d/bt.env" "$bluetooth_service_installed"
|
|
# Modify ExecStart to use $BLUETOOTHD_EXT_ARGS
|
|
sed -i 's|^ExecStart=/usr/libexec/bluetooth/bluetoothd.*|ExecStart=/usr/libexec/bluetooth/bluetoothd $BLUETOOTHD_EXT_ARGS|' "$bluetooth_service_installed"
|
|
display_alert "COMPILE-${COMPONENT} bluetooth.service: Added EnvironmentFile and modified ExecStart" "info"
|
|
fi
|
|
}
|
|
|
|
# Install NOINST_TOOLS
|
|
function _bluez5_install_noinst_tools() {
|
|
display_alert "COMPILE-${COMPONENT} Step 8: Installing NOINST_TOOLS" "info"
|
|
|
|
# NOINST_TOOLS definitions from bluez5_5.65.bb
|
|
local noinst_tools=(
|
|
"tools/bdaddr"
|
|
"tools/btinfo"
|
|
"tools/btsnoop"
|
|
"tools/btproxy"
|
|
)
|
|
|
|
for tool in "${noinst_tools[@]}"; do
|
|
if [[ -f "${SOURCE_DIR}/$tool" ]]; then
|
|
install -m 0755 "${SOURCE_DIR}/$tool" "${INSTALL_DIR}/usr/bin/"
|
|
display_alert "COMPILE-${COMPONENT} Installed NOINST_TOOL: $(basename "$tool") -> /usr/bin/" "info"
|
|
fi
|
|
done
|
|
}
|
|
|
|
# Install additional files from bluez5.inc
|
|
function _bluez5_install_additional_files() {
|
|
display_alert "COMPILE-${COMPONENT} Step 9: Installing additional files from bluez5.inc" "info"
|
|
|
|
# Create bluetooth config directory
|
|
mkdir -p "${INSTALL_DIR}/etc/bluetooth"
|
|
|
|
# Install network.conf if it exists
|
|
if [[ -f "${SOURCE_DIR}/profiles/network/network.conf" ]]; then
|
|
install -m 0644 "${SOURCE_DIR}/profiles/network/network.conf" "${INSTALL_DIR}/etc/bluetooth/"
|
|
display_alert "COMPILE-${COMPONENT} Installed: network.conf -> /etc/bluetooth/" "info"
|
|
fi
|
|
|
|
# Install input.conf if it exists
|
|
if [[ -f "${SOURCE_DIR}/profiles/input/input.conf" ]]; then
|
|
install -m 0644 "${SOURCE_DIR}/profiles/input/input.conf" "${INSTALL_DIR}/etc/bluetooth/"
|
|
display_alert "COMPILE-${COMPONENT} Installed: input.conf -> /etc/bluetooth/" "info"
|
|
fi
|
|
}
|
|
|
|
# ------------------------------------------------------------------------------
|
|
# Step 8: Create Debian Package
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Create Debian control file
|
|
function _bluez5_create_control_file() {
|
|
display_alert "COMPILE-${COMPONENT} Step 10: Creating Debian package" "info"
|
|
|
|
# Build RDEPENDS string based on bbappend logic
|
|
local rdepends="libc6, libdbus-1-3, libglib2.0-0"
|
|
|
|
# # Add amlogic-hciattach if aml-wifi enabled
|
|
# if [[ "${DISTRO_FEATURES:-}" == *"aml-wifi"* ]]; then
|
|
# rdepends="${rdepends}, amlogic-hciattach"
|
|
# display_alert "COMPILE-${COMPONENT} Added RDEPENDS: amlogic-hciattach (aml-wifi enabled)" "info"
|
|
# fi
|
|
|
|
# Add aml-wifi-common if MACHINE_EXTRA_RRECOMMENDS contains wifi modules
|
|
if [[ -n "$MACHINE_EXTRA_RRECOMMENDS" ]]; then
|
|
if echo "$MACHINE_EXTRA_RRECOMMENDS" | grep -q -E '\b(aml-wifi-w1|aml-wifi-w1u|aml-wifi-w2)\b'; then
|
|
rdepends="${rdepends}, aml-wifi-common"
|
|
display_alert "COMPILE-${COMPONENT} Added RDEPENDS: aml-wifi-common (MACHINE_EXTRA_RRECOMMENDS contains wifi modules)" "info"
|
|
fi
|
|
fi
|
|
|
|
# Create control file
|
|
display_alert "COMPILE-${COMPONENT} Creating control file DEBIAN/control" "info"
|
|
cat > "${DEBIAN_DIR}/control" << EOF
|
|
Package: ${PKG_NAME}
|
|
Version: ${PKG_VERSION}
|
|
Architecture: ${PKG_ARCH}
|
|
Maintainer: ${PKG_MAINTAINER}
|
|
Depends: ${rdepends}
|
|
Section: net
|
|
Priority: optional
|
|
Description: ${PKG_DESCRIPTION}
|
|
BlueZ is the official Linux Bluetooth protocol stack. It is an Open Source
|
|
project distributed under GNU General Public License (GPL).
|
|
.
|
|
This package contains BlueZ 5.65 with Amlogic-specific modifications:
|
|
- Amlogic wifi support (aml-wifi)
|
|
- Device-specific configuration (aml/qca/bcm/rtk)
|
|
- Additional tools and utilities
|
|
- Systemd service integration with bluez.service
|
|
.
|
|
Features enabled: ${DISTRO_FEATURES}
|
|
EOF
|
|
}
|
|
|
|
# Create post-installation script
|
|
function _bluez5_create_postinst() {
|
|
display_alert "COMPILE-${COMPONENT} Creating post-installation script: DEBIAN/postinst" "info"
|
|
cat > "${DEBIAN_DIR}/postinst" << EOF
|
|
#!/bin/bash
|
|
set -e
|
|
|
|
if [ "\$1" = "configure" ]; then
|
|
# Reload systemd daemon
|
|
if command -v systemctl >/dev/null 2>&1; then
|
|
systemctl daemon-reload 2>/dev/null || true
|
|
fi
|
|
|
|
# Create runtime directories
|
|
mkdir -p /var/lib/bluetooth
|
|
chmod 0755 /var/lib/bluetooth
|
|
|
|
# Set up bluez.service (from bbappend SYSTEMD_SERVICE)
|
|
if [ -f /lib/systemd/system/bluez.service ]; then
|
|
# Disable auto-enable as per bbappend SYSTEMD_AUTO_ENABLE
|
|
systemctl disable bluez.service 2>/dev/null || true
|
|
echo "BlueZ service (bluez.service) is installed but auto-enable is disabled"
|
|
echo "To enable manually: systemctl enable bluez.service"
|
|
fi
|
|
|
|
echo "BlueZ 5.65 (Amlogic modified) installed successfully"
|
|
echo "Configuration files are located in /etc/bluetooth/"
|
|
echo "Device type: \$(grep '^Device=' /etc/bluetooth/main.conf 2>/dev/null | cut -d= -f2 || echo 'not set')"
|
|
fi
|
|
|
|
exit 0
|
|
EOF
|
|
chmod 755 "${DEBIAN_DIR}/postinst"
|
|
}
|
|
|
|
# Create pre-removal script
|
|
function _bluez5_create_prerm() {
|
|
display_alert "COMPILE-${COMPONENT} Creating pre-removal script: DEBIAN/prerm" "info"
|
|
cat > "${DEBIAN_DIR}/prerm" << EOF
|
|
#!/bin/bash
|
|
set -e
|
|
|
|
if [ "\$1" = "remove" ] || [ "\$1" = "deconfigure" ]; then
|
|
# Stop bluetooth service
|
|
if command -v systemctl >/dev/null 2>&1; then
|
|
systemctl stop bluetooth 2>/dev/null || true
|
|
systemctl disable bluetooth 2>/dev/null || true
|
|
systemctl stop bluez.service 2>/dev/null || true
|
|
systemctl disable bluez.service 2>/dev/null || true
|
|
fi
|
|
fi
|
|
|
|
exit 0
|
|
EOF
|
|
chmod 755 "${DEBIAN_DIR}/prerm"
|
|
}
|
|
|
|
# Build Debian package
|
|
function _bluez5_build_deb_package() {
|
|
# 将install目录内容拷贝到deb目录
|
|
display_alert "COMPILE-${COMPONENT} Copying install directory to deb package directory" "info"
|
|
echo "Copying install directory to deb package directory at $(date)" >> "${BUILD_LOG}"
|
|
cp -r "${INSTALL_DIR}/"* "${DEB_PACKAGE_DIR}/" 2>&1 >> "${BUILD_LOG}"
|
|
|
|
# 基于deb目录打包
|
|
display_alert "COMPILE-${COMPONENT} Building Debian package" "info"
|
|
echo "Building Debian package at $(date)" >> "${BUILD_LOG}"
|
|
dpkg-deb --build "${DEB_PACKAGE_DIR}" 2>&1 >> "${BUILD_LOG}"
|
|
|
|
if [[ $? -ne 0 ]]; then
|
|
display_alert "COMPILE-${COMPONENT} Package build failed" "error"
|
|
exit 1
|
|
fi
|
|
# 移动生成的deb包到输出目录
|
|
OUTPUT_DEB="${SRC}/output/${PKG_NAME}_${PKG_VERSION}_${PKG_ARCH}.deb"
|
|
mkdir -p "$(dirname "${OUTPUT_DEB}")"
|
|
mv "${DEB_PACKAGE_DIR}.deb" "${OUTPUT_DEB}"
|
|
cp -r "${BASE_BUILD_DIR}" "${AMLBIAN_DIR}/.tmp"
|
|
chown -R --reference="${AMLBIAN_DIR}" "${AMLBIAN_DIR}/.tmp"
|
|
|
|
display_alert "COMPILE-${COMPONENT} BlueZ5 package built successfully: ${OUTPUT_DEB}" "info"
|
|
display_alert "COMPILE-${COMPONENT} Build directories preserved:" "info"
|
|
display_alert "COMPILE-${COMPONENT} Source: ${SOURCE_DIR}" "info"
|
|
display_alert "COMPILE-${COMPONENT} Build: ${BUILD_DIR}" "info"
|
|
display_alert "COMPILE-${COMPONENT} Install: ${INSTALL_DIR}" "info"
|
|
display_alert "COMPILE-${COMPONENT} Patch: ${PATCH_DIR}" "info"
|
|
display_alert "COMPILE-${COMPONENT} Deb package: ${DEB_PACKAGE_DIR}" "info"
|
|
}
|
|
|
|
# ==============================================================================
|
|
# Main BlueZ5 Build Function
|
|
# ==============================================================================
|
|
|
|
# Generic BlueZ5 package build function
|
|
function amlbian_build_bluez5App() {
|
|
set -e
|
|
|
|
# ---- Step 1: Version and Package Information ----
|
|
_bluez5_init_package_info
|
|
|
|
display_alert "COMPILE-${COMPONENT} Building BlueZ5 version ${PKG_VERSION} for ${PKG_ARCH}" "info"
|
|
display_alert "COMPILE-${COMPONENT} Features: ${DISTRO_FEATURES}" "info"
|
|
|
|
# ---- Step 2: Build Directory Setup ----
|
|
_bluez5_common_create_build_dirs "${PKG_NAME}_${PKG_VERSION}_${PKG_ARCH}"
|
|
_bluez5_common_display_build_info "COMPILE-${COMPONENT}"
|
|
|
|
# ---- Step 3: Source Download and Extraction ----
|
|
_bluez5_download_and_extract
|
|
|
|
# ---- Step 4: Apply Patches ----
|
|
_bluez5_apply_base_patches
|
|
_bluez5_apply_bbappend_patches
|
|
_bluez5_copy_bbappend_directories
|
|
|
|
# ---- Step 5: Configure Build ----
|
|
_bluez5_configure_build
|
|
|
|
# ---- Step 6: Compile BlueZ5 ----
|
|
_bluez5_compile
|
|
|
|
# ---- Step 7: Install Files ----
|
|
_bluez5_install_base
|
|
_bluez5_install_bbappend_files
|
|
_bluez5_install_noinst_tools
|
|
_bluez5_install_additional_files
|
|
|
|
# ---- Step 8: Debian Packaging Scripts ----
|
|
_bluez5_create_control_file
|
|
_bluez5_create_postinst
|
|
_bluez5_create_prerm
|
|
|
|
# ---- Step 9: Build Debian Package ----
|
|
_bluez5_build_deb_package
|
|
|
|
display_alert "COMPILE-${COMPONENT} BlueZ5 build completed. Successfully built for ${PKG_ARCH}" "success"
|
|
display_alert "COMPILE-${COMPONENT} Features: ${DISTRO_FEATURES}" "info"
|
|
|
|
return 0
|
|
}
|
|
|
|
function amlbian_build_bluez5() {
|
|
if ! is_unit_enabled "bt" || [ "${BT_BLUEZ:-}" != "yes" ]; then
|
|
echo "[SKIP] >> Bluetooth disabled in BUILD_UNITS or BT_BLUEZ not yes"
|
|
return
|
|
fi
|
|
|
|
amlbian_build_bluez5App
|
|
}
|
|
|
|
# ==============================================================================
|
|
# Main Execution
|
|
# ==============================================================================
|
|
|
|
display_alert "AMLbian bulez5 Build Script" "Starting Bt build" "info"
|
|
amlbian_build_bluez5
|
|
display_alert "AMLOGIC: bulez5 build completed" "Check output directory for packages" "info" |