Files
BPI-CM9-Linux/amlbian/scripts/bt/build-bt.sh
T

648 lines
23 KiB
Bash
Raw Normal View History

2026-08-13 11:28:40 +08:00
#!/usr/bin/env bash
# SPDX-License-Identifier: (GPL-2.0-only OR MIT)
# Copyright (C) 2026 Amlogic, Inc. All rights reserved
################################################################################
2026-11-11 08:50:43 +08:00
# Amlbian Bluetooth Driver Compilation Package
2026-08-13 11:28:40 +08:00
#
2026-11-11 08:50:43 +08:00
# Purpose: Build W2/W2L/W1U bluetooth kernel modules with Hook support and aml-comp integration
2026-08-13 11:28:40 +08:00
# Provides: Bluetooth driver kernel module, firmware installation
2026-11-11 08:50:43 +08:00
# Based on Yocto recipes: aml-bt-w2l_1.0.bb, aml-bt-w1u_1.0.bb
2026-08-13 11:28:40 +08:00
################################################################################
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}")")"
2026-11-11 08:50:43 +08:00
MODULE_BUILD_DIR="${SRC}/output/.tmp"
2026-08-13 11:28:40 +08:00
# Source ADLA build script if it exists
HCIATTACH_SCRIPT="${SCRIPT_DIR}/build-hciattach.sh"
if [[ -f "${HCIATTACH_SCRIPT}" ]]; then
2026-11-11 08:50:43 +08:00
aml_log info "Loading hciattach build script" "${HCIATTACH_SCRIPT}"
2026-08-13 11:28:40 +08:00
source "${HCIATTACH_SCRIPT}"
else
2026-11-11 08:50:43 +08:00
aml_log warn "hciattach build script not found" "${HCIATTACH_SCRIPT}"
2026-08-13 11:28:40 +08:00
fi
# ==============================================================================
# Shared Helper Functions
# ==============================================================================
# ------------------------------------------------------------------------------
# Step 1: Package Information Definition
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Step 2: Build Directory Structure Setup
# ------------------------------------------------------------------------------
# Create layered build directory structure
# Parameters:
# $1 - base name (e.g. "${PKG_NAME}_${PKG_VERSION}_${PKG_ARCH}")
2026-11-11 08:50:43 +08:00
# Sets: MODULE_BUILD_DIR, BASE_BUILD_DIR, SOURCE_DIR, BUILD_DIR, INSTALL_DIR, PATCH_DIR,
2026-08-13 11:28:40 +08:00
# DEB_PACKAGE_DIR, DEBIAN_DIR, MODULE_DIR, FIRMWARE_DIR, BUILD_LOG
function _bt_common_create_build_dirs() {
local base_name="$1"
2026-11-11 08:50:43 +08:00
mkdir -p "${MODULE_BUILD_DIR}"
2026-08-13 11:28:40 +08:00
# 基础构建目录
2026-11-11 08:50:43 +08:00
BASE_BUILD_DIR="${MODULE_BUILD_DIR}/${base_name}"
2026-08-13 11:28:40 +08:00
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"
# 获取内核版本
local KERNEL_VERSION=$(make -s -C "${KERNEL_BUILD_DIR}" kernelrelease 2>/dev/null || echo "unknown-$(date +%Y%m%d)")
# 安装目录的子目录
DEBIAN_DIR="${INSTALL_DIR}/DEBIAN"
MODULE_DIR="${INSTALL_DIR}/lib/modules/${KERNEL_VERSION}/kernel/drivers/amlogic/bt"
FIRMWARE_DIR="${INSTALL_DIR}/lib/firmware/aml"
mkdir -p "${DEBIAN_DIR}"
mkdir -p "${MODULE_DIR}"
mkdir -p "${FIRMWARE_DIR}"
}
# Display build directory info
# Parameters:
# $1 - log prefix
function _bt_common_display_build_info() {
local log_prefix="$1"
local KERNEL_VERSION=$(make -s -C "${KERNEL_BUILD_DIR}" kernelrelease 2>/dev/null || echo "unknown-$(date +%Y%m%d)")
2026-11-11 08:50:43 +08:00
aml_log info "${log_prefix} Source dir: ${SOURCE_DIR}"
aml_log info "${log_prefix} Build dir: ${BUILD_DIR}"
aml_log info "${log_prefix} Install dir: ${INSTALL_DIR}"
aml_log info "${log_prefix} Patch dir: ${PATCH_DIR}"
aml_log info "${log_prefix} Deb package dir: ${DEB_PACKAGE_DIR}"
aml_log info "${log_prefix} Build log: ${BUILD_LOG}"
aml_log info "${log_prefix} Module dir: ${MODULE_DIR}"
aml_log info "${log_prefix} Firmware dir: ${FIRMWARE_DIR}"
aml_log info "${log_prefix} Kernel version: ${KERNEL_VERSION}"
2026-08-13 11:28:40 +08:00
}
# ------------------------------------------------------------------------------
# Step 3: Source File Validation and Copying
# ------------------------------------------------------------------------------
# Validate and copy source files
# Parameters:
# $1 - source directory path
# $2 - component name (for logging)
function _bt_common_validate_and_copy_sources() {
local src_dir="$1"
local component="$2"
# Check if source directory exists
if [[ ! -d "${src_dir}" ]]; then
2026-11-11 08:50:43 +08:00
aml_log error "COMPILE-${component} Bluetooth driver source code not found" "${src_dir}"
2026-08-13 11:28:40 +08:00
exit 1
fi
# Copy source to source directory
2026-11-11 08:50:43 +08:00
aml_log info "COMPILE-${component} Copying source files to source directory"
2026-08-13 11:28:40 +08:00
echo "Copying source files to source directory at $(date)" > "${BUILD_LOG}"
cp -r "${src_dir}/"* "${SOURCE_DIR}/" 2>&1 >> "${BUILD_LOG}"
}
# ------------------------------------------------------------------------------
# Step 8: Debian Package Building
# ------------------------------------------------------------------------------
# Build Debian package from install directory
# Parameters:
# $1 - log prefix (e.g. "COMPILE-BT-W2L")
# $2 - output deb filename (without path)
# Sets: OUTPUT_DEB
function _bt_common_build_deb_package() {
local log_prefix="$1"
local output_deb_name="$2"
local KERNEL_VERSION=$(make -s -C "${KERNEL_BUILD_DIR}" kernelrelease 2>/dev/null || echo "unknown-$(date +%Y%m%d)")
# 将install目录内容拷贝到deb目录
2026-11-11 08:50:43 +08:00
aml_log info "${log_prefix} Copying install directory to deb package directory"
2026-08-13 11:28:40 +08:00
echo "Copying install directory to deb package directory at $(date)" >> "${BUILD_LOG}"
cp -r "${INSTALL_DIR}/"* "${DEB_PACKAGE_DIR}/" 2>&1 >> "${BUILD_LOG}"
# 基于deb目录打包
2026-11-11 08:50:43 +08:00
aml_log info "${log_prefix} Building Debian package"
2026-08-13 11:28:40 +08:00
echo "Building Debian package at $(date)" >> "${BUILD_LOG}"
dpkg-deb --build "${DEB_PACKAGE_DIR}" 2>&1 >> "${BUILD_LOG}"
if [[ $? -ne 0 ]]; then
2026-11-11 08:50:43 +08:00
aml_log error "${log_prefix} Package build failed"
2026-08-13 11:28:40 +08:00
exit 1
fi
# Move to output directory
OUTPUT_DEB="${SRC}/output/${output_deb_name}"
mkdir -p "$(dirname "${OUTPUT_DEB}")"
mv "${DEB_PACKAGE_DIR}.deb" "${OUTPUT_DEB}"
2026-11-11 08:50:43 +08:00
aml_log info "${log_prefix} Package built successfully ${output_deb_name}"
aml_log info "${log_prefix} Build directory preserved ${BASE_BUILD_DIR}"
2026-08-13 11:28:40 +08:00
}
# ==============================================================================
# Generic Bluetooth Driver Build Functions
# ==============================================================================
# Initialize package metadata for Bluetooth driver
# Parameters:
# $1 - driver type (w2l or w2)
function _bt_init_package_info() {
local driver_type="$1"
PKG_MAINTAINER="Armbian Build <build@armbian.com>"
PKG_DESCRIPTION="Amlogic ${driver_type^^} bluetooth driver"
PKG_NAME="aml-bt-${driver_type}"
PKG_VERSION="1.0"
PKG_ARCH="${ARCH:-arm64}"
COMPONENT="bt-${driver_type}"
# Cross compilation settings
CROSS_COMPILE="${CROSS_COMPILE:-aarch64-linux-gnu-}"
# Driver configuration
DRIVER_NAME="${driver_type}_bt"
DRIVER_MODULE="${DRIVER_NAME}.ko"
# Source directory for bluetooth driver
2026-08-25 10:02:36 +08:00
BT_SRC_DIR="${BASE_DIR}/aml-comp/hardware/bluetooth/amlogic/${driver_type}"
2026-08-13 11:28:40 +08:00
# Firmware source directory
2026-08-25 10:02:36 +08:00
BT_FIRMWARE_DIR="${BASE_DIR}/aml-comp/hardware/bluetooth/amlogic/${driver_type}"
2026-08-13 11:28:40 +08:00
# Kernel directories
KERNEL_BUILD_DIR="${BASE_DIR}/aml-comp/kernel/aml-6.12/build"
STAGING_KERNEL_DIR="${BASE_DIR}/aml-comp/kernel/aml-6.12"
}
2026-11-11 08:50:43 +08:00
# Initialize package metadata for W1U Bluetooth driver
function _bt_w1u_init_package_info() {
PKG_MAINTAINER="Armbian Build <build@armbian.com>"
PKG_DESCRIPTION="Amlogic W1U bluetooth driver"
PKG_NAME="aml-bt-w1u"
PKG_VERSION="1.0"
PKG_ARCH="${ARCH:-arm64}"
COMPONENT="bt-w1u"
# Cross compilation settings
CROSS_COMPILE="${CROSS_COMPILE:-aarch64-linux-gnu-}"
# Driver configuration
DRIVER_NAME="w1u_bt"
DRIVER_MODULE="${DRIVER_NAME}.ko"
# Source directory for bluetooth driver
BT_SRC_DIR="${BASE_DIR}/aml-comp/hardware/bluetooth/amlogic/w1u"
# Firmware source directory
BT_FIRMWARE_DIR="${BASE_DIR}/aml-comp/hardware/bluetooth/amlogic/w1u"
# Kernel directories
KERNEL_BUILD_DIR="${BASE_DIR}/aml-comp/kernel/aml-6.12/build"
STAGING_KERNEL_DIR="${BASE_DIR}/aml-comp/kernel/aml-6.12"
# W1U WiFi dependency path for Module.symvers
W1U_WIFI_SYMVERS="${MODULE_BUILD_DIR}/aml-wifi-w1u_1.0_${PKG_ARCH}/source/project_w1u/vmac/Module.symvers"
}
2026-08-13 11:28:40 +08:00
# Validate kernel build environment
# Parameters:
# $1 - driver type (w2l or w2)
# $2 - temporary directory path
function _bt_validate_kernel_env() {
local driver_type="$1"
local tmp_dir="$2"
# Check for kernel headers
if [[ ! -d "${KERNEL_BUILD_DIR}" ]]; then
2026-11-11 08:50:43 +08:00
aml_log error "COMPILE-${COMPONENT} Kernel build directory not found" "${KERNEL_BUILD_DIR}"
2026-08-13 11:28:40 +08:00
exit 1
fi
# Get wifi driver Module.symvers path
local WIFI_MODULE_SYMS="${tmp_dir}/aml-wifi-${driver_type}_1.0_${PKG_ARCH}/source/aml_drv/Module.symvers"
# Check if wifi driver Module.symvers exists
if [[ ! -f "${WIFI_MODULE_SYMS}" ]]; then
2026-11-11 08:50:43 +08:00
aml_log warn "COMPILE-${COMPONENT} Wifi driver Module.symvers not found" "${WIFI_MODULE_SYMS}"
aml_log info "COMPILE-${COMPONENT} Building wifi driver first..."
2026-08-13 11:28:40 +08:00
if [[ ! -f "${WIFI_MODULE_SYMS}" ]]; then
2026-11-11 08:50:43 +08:00
aml_log error "COMPILE-${COMPONENT} Failed to build wifi driver or Module.symvers not found"
2026-08-13 11:28:40 +08:00
exit 1
fi
fi
2026-11-11 08:50:43 +08:00
aml_log info "COMPILE-${COMPONENT} Using wifi Module.symvers" "${WIFI_MODULE_SYMS}"
2026-08-13 11:28:40 +08:00
# Return the path to wifi Module.symvers
echo "${WIFI_MODULE_SYMS}"
}
2026-11-11 08:50:43 +08:00
# Validate kernel build environment for W1U BT
function _bt_w1u_validate_kernel_env() {
# Check for kernel headers
if [[ ! -d "${KERNEL_BUILD_DIR}" ]]; then
aml_log error "COMPILE-${COMPONENT} Kernel build directory not found ${KERNEL_BUILD_DIR}"
exit 1
fi
# Check W1U WiFi Module.symvers dependency
if [[ ! -f "${W1U_WIFI_SYMVERS}" ]]; then
aml_log error "COMPILE-${COMPONENT} W1U WiFi Module.symvers not found ${W1U_WIFI_SYMVERS}"
aml_log error "COMPILE-${COMPONENT} Please build aml-wifi-w1u first"
exit 1
fi
aml_log info "COMPILE-${COMPONENT} Using W1U WiFi Module.symvers ${W1U_WIFI_SYMVERS}"
echo "${W1U_WIFI_SYMVERS}"
}
2026-08-13 11:28:40 +08:00
# Build bluetooth kernel module
# Parameters:
# $1 - source directory path
# $2 - path to wifi driver Module.symvers
function _bt_build_module() {
local src_dir="$1"
local wifi_module_syms="$2"
2026-11-11 08:50:43 +08:00
aml_log info "COMPILE-${COMPONENT} Building ${DRIVER_NAME} kernel module"
2026-08-13 11:28:40 +08:00
# Change to source directory
cd "${src_dir}"
# Based on Yocto recipe: EXTRA_OEMAKE='-C ${S}/aml_bt/${driver_type} M=${S}/aml_bt/${driver_type} KERNEL_SRC=${STAGING_KERNEL_DIR} ARCH=${ARCH} CROSS_COMPILE=${CROSS_COMPILE}'
make -C "${KERNEL_BUILD_DIR}" \
M="${src_dir}" \
KBUILD_EXTRA_SYMBOLS="${wifi_module_syms}" \
KERNEL_SRC="${STAGING_KERNEL_DIR}" \
ARCH="${PKG_ARCH}" \
CROSS_COMPILE="${CROSS_COMPILE}" \
modules
# Check if module was built
if [[ ! -f "${src_dir}/${DRIVER_MODULE}" ]]; then
2026-11-11 08:50:43 +08:00
aml_log error "COMPILE-${COMPONENT} Module build failed. Could not find ${DRIVER_MODULE}"
2026-08-13 11:28:40 +08:00
exit 1
fi
2026-11-11 08:50:43 +08:00
aml_log info "COMPILE-${COMPONENT} Module built successfully: ${DRIVER_MODULE}"
2026-08-13 11:28:40 +08:00
# 在BUILD_DIR中保存编译结果(备份)
2026-11-11 08:50:43 +08:00
aml_log info "COMPILE-${COMPONENT} Saving build result to build directory"
mkdir -p "${BUILD_DIR}/modules"
cp -f "${src_dir}/${DRIVER_MODULE}" "${BUILD_DIR}/modules/"
}
# Build W1U bluetooth kernel module
# Parameters:
# $1 - source directory path
# $2 - path to W1U WiFi Module.symvers
function _bt_w1u_build_module() {
local src_dir="$1"
local wifi_module_syms="$2"
aml_log info "COMPILE-${COMPONENT} Building ${DRIVER_NAME} kernel module"
# Change to source directory
cd "${src_dir}"
# Based on Yocto recipe: EXTRA_OEMAKE='-C ${S} M=${S} KERNEL_SRC=${STAGING_KERNEL_DIR} ARCH=${ARCH} CROSS_COMPILE=${CROSS_COMPILE} EXTRA_SYMBOLS_USB_PATH=...'
make -C "${KERNEL_BUILD_DIR}" \
M="${src_dir}" \
KERNEL_SRC="${STAGING_KERNEL_DIR}" \
ARCH="${PKG_ARCH}" \
CROSS_COMPILE="${CROSS_COMPILE}" \
KBUILD_EXTRA_SYMBOLS="${wifi_module_syms}"
# Check if module was built
if [[ ! -f "${src_dir}/${DRIVER_MODULE}" ]]; then
aml_log error "COMPILE-${COMPONENT} Module build failed. Could not find ${DRIVER_MODULE}"
exit 1
fi
aml_log info "COMPILE-${COMPONENT} Module built successfully: ${DRIVER_MODULE}"
# 在BUILD_DIR中保存编译结果(备份)
aml_log info "COMPILE-${COMPONENT} Saving build result to build directory"
2026-08-13 11:28:40 +08:00
mkdir -p "${BUILD_DIR}/modules"
cp -f "${src_dir}/${DRIVER_MODULE}" "${BUILD_DIR}/modules/"
}
# Install module and firmware files
# Parameters:
# $1 - source directory path
# $2 - driver type (w2l or w2)
function _bt_install_files() {
local src_dir="$1"
local driver_type="$2"
# Install module to INSTALL_DIR(用于打包)
2026-11-11 08:50:43 +08:00
aml_log info "COMPILE-${COMPONENT} Installing module to install directory ${MODULE_DIR}"
2026-08-13 11:28:40 +08:00
install -m 0666 "${src_dir}/${DRIVER_MODULE}" "${MODULE_DIR}/"
# Install firmware files to INSTALL_DIR
# Firmware source: ${S}/aml_bt/firmware/${driver_type}_bt_15p4_fw_*.bin
2026-11-11 08:50:43 +08:00
aml_log info "COMPILE-${COMPONENT} Installing firmware files to install directory ${FIRMWARE_DIR}"
2026-08-13 11:28:40 +08:00
if [[ -d "${BT_FIRMWARE_DIR}" ]]; then
if [[ "${driver_type}" == "w2l" ]]; then
install -m 0666 ${BT_FIRMWARE_DIR}/${driver_type}_bt_15p4_fw_*.bin "${FIRMWARE_DIR}/" 2>/dev/null || true
else
install -m 0666 ${BT_FIRMWARE_DIR}/${driver_type}_bt_*fw*.bin "${FIRMWARE_DIR}/" 2>/dev/null || true
fi
fi
}
2026-11-11 08:50:43 +08:00
# Install W1U module and firmware files
# Parameters:
# $1 - source directory path
function _bt_w1u_install_files() {
local src_dir="$1"
# Install module to INSTALL_DIR(用于打包)
aml_log info "COMPILE-${COMPONENT} Installing module to install directory ${MODULE_DIR}"
install -m 0666 "${src_dir}/${DRIVER_MODULE}" "${MODULE_DIR}/"
# Install firmware files to INSTALL_DIR
aml_log info "COMPILE-${COMPONENT} Installing firmware files to install directory ${FIRMWARE_DIR}"
install -m 0666 ${src_dir}/w1u_bt_fw_*.bin "${FIRMWARE_DIR}/" 2>/dev/null || true
}
2026-08-13 11:28:40 +08:00
# Create Debian control file
# Parameters:
# $1 - driver type (w2l or w2)
function _bt_create_control_file() {
local driver_type="$1"
local KERNEL_VERSION=$(make -s -C "${KERNEL_BUILD_DIR}" kernelrelease 2>/dev/null || echo "unknown-$(date +%Y%m%d)")
2026-11-11 08:50:43 +08:00
aml_log info "COMPILE-${COMPONENT} Creating control file DEBIAN/control"
2026-08-13 11:28:40 +08:00
cat > "${DEBIAN_DIR}/control" << EOF
Package: ${PKG_NAME}
Version: ${PKG_VERSION}
Architecture: ${PKG_ARCH}
Maintainer: ${PKG_MAINTAINER}
Depends: aml-wifi-${driver_type}
Section: kernel
Priority: optional
Description: ${PKG_DESCRIPTION}
This package provides the kernel module for Amlogic ${driver_type^^} bluetooth.
It includes the ${DRIVER_NAME} module for bluetooth functionality.
EOF
}
2026-11-11 08:50:43 +08:00
# Create Debian control file for W1U BT
function _bt_w1u_create_control_file() {
local KERNEL_VERSION=$(make -s -C "${KERNEL_BUILD_DIR}" kernelrelease 2>/dev/null || echo "unknown-$(date +%Y%m%d)")
aml_log info "COMPILE-${COMPONENT} Creating control file DEBIAN/control"
cat > "${DEBIAN_DIR}/control" << EOF
Package: ${PKG_NAME}
Version: ${PKG_VERSION}
Architecture: ${PKG_ARCH}
Maintainer: ${PKG_MAINTAINER}
Depends: aml-wifi-w1u
Section: kernel
Priority: optional
Description: ${PKG_DESCRIPTION}
This package provides the kernel module for Amlogic W1U bluetooth.
It includes the ${DRIVER_NAME} module for bluetooth functionality.
EOF
}
2026-08-13 11:28:40 +08:00
# Create post-installation script
# Parameters:
# $1 - driver type (w2l or w2)
function _bt_create_postinst() {
local driver_type="$1"
local KERNEL_VERSION="$2"
2026-11-11 08:50:43 +08:00
aml_log info "COMPILE-${COMPONENT} Creating post-installation script: DEBIAN/postinst"
2026-08-13 11:28:40 +08:00
cat > "${DEBIAN_DIR}/postinst" << EOF
#!/bin/bash
set -e
if [ "\$1" = "configure" ]; then
# run depmod only if /lib/modules/${KERNEL_VERSION} exists
if [ -d "/lib/modules/${KERNEL_VERSION}" ]; then
depmod -a "${KERNEL_VERSION}"
else
echo "Warning: /lib/modules/${KERNEL_VERSION} not found, skipping depmod"
fi
# try to load module but don't error
if modprobe -n ${driver_type}_bt 2>/dev/null; then
echo "Amlogic ${driver_type^^} bluetooth module can be loaded with 'modprobe ${driver_type}_bt'"
fi
fi
exit 0
EOF
chmod 755 "${DEBIAN_DIR}/postinst"
}
# Create pre-removal script
# Parameters:
# $1 - driver type (w2l or w2)
function _bt_create_prerm() {
local driver_type="$1"
2026-11-11 08:50:43 +08:00
aml_log info "COMPILE-${COMPONENT} Creating pre-removal script: DEBIAN/prerm"
2026-08-13 11:28:40 +08:00
cat > "${DEBIAN_DIR}/prerm" << EOF
#!/bin/bash
set -e
if [ "\$1" = "remove" ] || [ "\$1" = "deconfigure" ]; then
# Unload module if loaded
if lsmod | grep -q "${driver_type}_bt"; then
modprobe -r ${driver_type}_bt 2>/dev/null || true
fi
fi
exit 0
EOF
chmod 755 "${DEBIAN_DIR}/prerm"
}
# Generic Bluetooth driver package build function
# Parameters:
# $1 - driver type (w2l or w2)
function amlbian_build_bt_driver() {
local driver_type="$1"
set -e
# ---- Step 1: Version and Package Information ----
_bt_init_package_info "${driver_type}"
local KERNEL_VERSION=$(make -s -C "${KERNEL_BUILD_DIR}" kernelrelease 2>/dev/null || echo "unknown-$(date +%Y%m%d)")
2026-11-11 08:50:43 +08:00
aml_log info "COMPILE-${COMPONENT} Building ${driver_type^^} bluetooth driver version ${PKG_VERSION} for ${PKG_ARCH}"
aml_log info "COMPILE-${COMPONENT} Building ${driver_type^^} bluetooth driver for kernel ${KERNEL_VERSION}"
2026-08-13 11:28:40 +08:00
# ---- Step 2: Build Directory Setup ----
_bt_common_create_build_dirs "${PKG_NAME}_${PKG_VERSION}_${PKG_ARCH}"
_bt_common_display_build_info "COMPILE-${COMPONENT}"
# ---- Step 3: Source File Validation and Copying ----
_bt_common_validate_and_copy_sources "${BT_SRC_DIR}" "${COMPONENT}"
# Update source directory to the copied location
local SRC_DIR_COPY="${SOURCE_DIR}"
# ---- Step 4: Kernel Build Environment Validation ----
2026-11-11 08:50:43 +08:00
local wifi_module_syms=$(_bt_validate_kernel_env "${driver_type}" "${MODULE_BUILD_DIR}")
2026-08-13 11:28:40 +08:00
# ---- Step 5: Build Bluetooth Kernel Module ----
_bt_build_module "${SRC_DIR_COPY}" "${wifi_module_syms}"
# ---- Step 6: File Installation ----
_bt_install_files "${SRC_DIR_COPY}" "${driver_type}"
# ---- Step 7: Debian Packaging Scripts ----
_bt_create_control_file "${driver_type}"
_bt_create_postinst "${driver_type}" "${KERNEL_VERSION}"
_bt_create_prerm "${driver_type}"
# ---- Step 8: Build Debian Package ----
_bt_common_build_deb_package "COMPILE-${COMPONENT}" "${PKG_NAME}_${PKG_VERSION}_${KERNEL_VERSION}_${PKG_ARCH}.deb"
2026-11-11 08:50:43 +08:00
aml_log info "COMPILE-${COMPONENT} ${driver_type^^} bluetooth driver package build completed"
aml_log info "COMPILE-${COMPONENT} Build directories preserved:"
aml_log info "COMPILE-${COMPONENT} Source: ${SOURCE_DIR}"
aml_log info "COMPILE-${COMPONENT} Build: ${BUILD_DIR}"
aml_log info "COMPILE-${COMPONENT} Install: ${INSTALL_DIR}"
aml_log info "COMPILE-${COMPONENT} Patch: ${PATCH_DIR}"
aml_log info "COMPILE-${COMPONENT} Deb package: ${DEB_PACKAGE_DIR}"
return 0
}
# ------------------------------------------------------------------------------
# W1U Bluetooth Driver Build
# Entry point: amlbian_build_bt_w1u
# ------------------------------------------------------------------------------
function amlbian_build_bt_w1u() {
set -e
# ---- Step 1: Version and Package Information ----
_bt_w1u_init_package_info
local KERNEL_VERSION=$(make -s -C "${KERNEL_BUILD_DIR}" kernelrelease 2>/dev/null || echo "unknown-$(date +%Y%m%d)")
aml_log info "COMPILE-${COMPONENT} Building W1U bluetooth driver version ${PKG_VERSION} for ${PKG_ARCH}"
aml_log info "COMPILE-${COMPONENT} Building W1U bluetooth driver for kernel ${KERNEL_VERSION}"
# ---- Step 2: Build Directory Setup ----
_bt_common_create_build_dirs "${PKG_NAME}_${PKG_VERSION}_${PKG_ARCH}"
_bt_common_display_build_info "COMPILE-${COMPONENT}"
# ---- Step 3: Source File Validation and Copying ----
_bt_common_validate_and_copy_sources "${BT_SRC_DIR}" "${COMPONENT}"
# Update source directory to the copied location
local SRC_DIR_COPY="${SOURCE_DIR}"
# ---- Step 4: Kernel Build Environment Validation ----
local wifi_module_syms=$(_bt_w1u_validate_kernel_env)
# ---- Step 5: Build Bluetooth Kernel Module ----
_bt_w1u_build_module "${SRC_DIR_COPY}" "${wifi_module_syms}"
# ---- Step 6: File Installation ----
_bt_w1u_install_files "${SRC_DIR_COPY}"
# ---- Step 7: Debian Packaging Scripts ----
_bt_w1u_create_control_file
_bt_create_postinst "w1u" "${KERNEL_VERSION}"
_bt_create_prerm "w1u"
# ---- Step 8: Build Debian Package ----
_bt_common_build_deb_package "COMPILE-${COMPONENT}" "${PKG_NAME}_${PKG_VERSION}_${KERNEL_VERSION}_${PKG_ARCH}.deb"
aml_log info "COMPILE-${COMPONENT} W1U bluetooth driver package build completed"
aml_log info "COMPILE-${COMPONENT} Build directories preserved:"
aml_log info "COMPILE-${COMPONENT} Source: ${SOURCE_DIR}"
aml_log info "COMPILE-${COMPONENT} Build: ${BUILD_DIR}"
aml_log info "COMPILE-${COMPONENT} Install: ${INSTALL_DIR}"
aml_log info "COMPILE-${COMPONENT} Patch: ${PATCH_DIR}"
aml_log info "COMPILE-${COMPONENT} Deb package: ${DEB_PACKAGE_DIR}"
2026-08-13 11:28:40 +08:00
return 0
}
# ------------------------------------------------------------------------------
# Main Bluetooth Build Function
# ------------------------------------------------------------------------------
function amlbian_build_bt() {
if ! is_unit_enabled "bt"; then
echo "[SKIP] >> Bluetooth disable in BUILD_UNITS"
return
fi
# Build W2 Bluetooth driver
if [ "${BT_MODE:-}" = "w2" ]; then
2026-11-11 08:50:43 +08:00
aml_log info "Building W2 Bluetooth driver" "W2 enabled in BUILD_UNITS"
2026-08-13 11:28:40 +08:00
amlbian_build_bt_driver "w2"
else
2026-11-11 08:50:43 +08:00
aml_log info "Skipping W2 Bluetooth driver" "W2 disabled in BUILD_UNITS"
2026-08-13 11:28:40 +08:00
fi
# Build W2L Bluetooth driver
if [ "${BT_MODE:-}" = "w2l" ]; then
2026-11-11 08:50:43 +08:00
aml_log info "Building W2L Bluetooth driver" "W2L enabled in BUILD_UNITS"
2026-08-13 11:28:40 +08:00
amlbian_build_bt_driver "w2l"
else
2026-11-11 08:50:43 +08:00
aml_log info "Skipping W2L Bluetooth driver" "W2L disabled in BUILD_UNITS"
fi
# Build W1U Bluetooth driver
if [ "${BT_MODE:-}" = "w1u" ]; then
aml_log info "Building W1U Bluetooth driver" "W1U enabled in BUILD_UNITS"
amlbian_build_bt_w1u
else
aml_log info "Skipping W1U Bluetooth driver" "W1U disabled in BUILD_UNITS"
2026-08-13 11:28:40 +08:00
fi
# Build HCI Attach tool
if [ "${BT_HCIATTACH:-}" = "yes" ]; then
2026-11-11 08:50:43 +08:00
aml_log info "Building HCI Attach tool"
2026-08-13 11:28:40 +08:00
amlbian_build_hciattach
else
2026-11-11 08:50:43 +08:00
aml_log info "Skipping HCI Attach tool"
2026-08-13 11:28:40 +08:00
fi
}
# ==============================================================================
# Main Execution
# ==============================================================================
2026-11-11 08:50:43 +08:00
aml_log info "AMLbian Bt Build Script BT_MODE $BT_MODE BT_HCIATTACH $BT_HCIATTACH BT_BLUEZ $BT_BLUEZ" "Starting Bt build"
2026-08-13 11:28:40 +08:00
amlbian_build_bt
2026-11-11 08:50:43 +08:00
aml_log info "AMLOGIC: Bt build completed" "Check output directory for packages"