#!/usr/bin/env bash # # SPDX-License-Identifier: GPL-2.0 # # Copyright (c) 2026 AMLOGIC # # Linux UAPI headers build script for AMLbian # This script installs Linux UAPI headers for different Amlogic chipsets set -e # Get script directory SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" AMLBIAN_DIR="$(dirname "${SCRIPT_DIR}")" BUILD_DIR="${AMLBIAN_DIR}/../build" # Source common functions if [[ -f "${AMLBIAN_DIR}/lib/function-common.sh" ]]; then source "${AMLBIAN_DIR}/lib/function-common.sh" fi # ============================================================================== # Section 2: Default Configuration # ============================================================================== KERNEL_VERSION="${KERNEL_VERSION:-6.12}" BOARD="${BOARD:-s6-bq201}" DEB_VERSION="1.0" # ============================================================================== # Section 4: Linux UAPI Headers Build Functions # ============================================================================== function __linux_uapi_headers_prepare_source { local build_dir="${1}" local aml_comp_path="$(amlbian_get_aml_comp_dir)" if [[ -z "${aml_comp_path}" ]] || [[ ! -d "${aml_comp_path}" ]]; then display_alert "LINUX-UAPI-HEADERS" "aml-comp not found: ${aml_comp_path}" "err" exit 1 fi # 查找内核构建目录 local kernel_build_dir="${aml_comp_path}/kernel/aml-${KERNEL_VERSION}/build" local STAGING_KERNEL_DIR="${aml_comp_path}/kernel/aml-${KERNEL_VERSION}" if [[ ! -d "${kernel_build_dir}" ]]; then display_alert "LINUX-UAPI-HEADERS" "Kernel build directory not found. Expected at: ${kernel_build_dir}" "err" return 1 fi display_alert "LINUX-UAPI-HEADERS" "Source prepared successfully" "success" return 0 } function __linux_uapi_headers_install { local install_dir="${1}" display_alert "LINUX-UAPI-HEADERS" "Starting Linux UAPI headers installation..." "info" local aml_comp_path="$(amlbian_get_aml_comp_dir)" if [[ -z "${aml_comp_path}" ]] || [[ ! -d "${aml_comp_path}" ]]; then display_alert "LINUX-UAPI-HEADERS" "aml-comp not found: ${aml_comp_path}" "err" exit 1 fi local STAGING_KERNEL_DIR="${aml_comp_path}/kernel/aml-${KERNEL_VERSION}" if [[ ! -d "${STAGING_KERNEL_DIR}" ]]; then display_alert "LINUX-UAPI-HEADERS" "Kernel source directory not found: ${STAGING_KERNEL_DIR}" "err" return 1 fi local includedir="${install_dir}/usr/include" mkdir -p "${includedir}/linux/amlogic" # 1. 安装 Amlogic 自定义头文件(有第二种路径尝试) display_alert "LINUX-UAPI-HEADERS" "Installing Amlogic customized headers..." "info" local aml_uapi_path="${STAGING_KERNEL_DIR}/common_drivers/include/uapi/amlogic" if [[ -d "${aml_uapi_path}" ]]; then cp -af "${aml_uapi_path}" "${includedir}/linux/" display_alert "LINUX-UAPI-HEADERS" "Copied Amlogic headers from ${aml_uapi_path}" "info" else display_alert "LINUX-UAPI-HEADERS" "Amlogic headers not found at both locations" "warn" fi # 2. 安装额外头文件 (dma-heap.h, ion.h) display_alert "LINUX-UAPI-HEADERS" "Installing extra headers..." "info" local uapi_path="${STAGING_KERNEL_DIR}/include/uapi/linux/" for f in dma-heap.h ion.h; do if [[ -f "${uapi_path}${f}" ]]; then # 简化处理:只检查目标目录是否已存在 if [[ ! -e "${includedir}/linux/${f}" ]]; then install -m 0644 "${uapi_path}${f}" "${includedir}/linux/" display_alert "LINUX-UAPI-HEADERS" "Installed ${f}" "info" else display_alert "LINUX-UAPI-HEADERS" "Skipping ${f} - already exists" "info" fi else display_alert "LINUX-UAPI-HEADERS" "Header ${f} not found at ${uapi_path}" "debug" fi done # 3. 安装 DVB 额外头文件 display_alert "LINUX-UAPI-HEADERS" "Installing DVB extra headers..." "info" for f in aml_ca_ext.h aml_dmx_ext.h aml_fe_ext.h; do if [[ -f "${uapi_path}/dvb/${f}" ]]; then install -m 0644 "${uapi_path}/dvb/${f}" "${includedir}/linux/amlogic/" display_alert "LINUX-UAPI-HEADERS" "Installed DVB header ${f}" "info" else display_alert "LINUX-UAPI-HEADERS" "DVB header ${f} not found" "debug" fi done display_alert "LINUX-UAPI-HEADERS" "Installation completed" "success" return 0 } function __linux_uapi_headers_create_deb { local build_dir="${1}" local install_dir="${2}" # 设置必要的变量 local pkg_name="linux-uapi-headers" local version="${DEB_VERSION}" local architecture="${ARCH:-arm64}" local maintainer="Amlbian Builder " local description="Linux UAPI headers for kernel ${KERNEL_VERSION}" display_alert "LINUX-UAPI-HEADERS" "Creating Debian package for ${pkg_name} ${version}..." "info" # 创建Debian包控制文件 local deb_dir="${build_dir}/deb/${pkg_name}-${version}" local debian_dir="${deb_dir}/DEBIAN" mkdir -p "${debian_dir}" # 将安装目录的内容复制到debian-root if [[ -d "${install_dir}" ]] && [[ "$(ls -A "${install_dir}")" ]]; then cp -r "${install_dir}"/* "${deb_dir}/" 2>/dev/null || true display_alert "LINUX-UAPI-HEADERS" "Copied installed files to ${deb_dir}" "info" else display_alert "LINUX-UAPI-HEADERS" "No installed files found in ${install_dir}" "warn" return 0 fi # 创建control文件 cat > "${debian_dir}/control" <> linux-uapi-headers disable in BUILD_UNITS" "" "info" return fi display_alert "AMLOGIC: Building Linux UAPI headers ${KERNEL_VERSION} ${BOARD}" "info" # Define all directory paths (in .tmp directory) local build_root="${BUILD_DIR}/.tmp/linux-uapi-headers-build-${ARCH:-arm64}" local build_dir="${build_root}/build" # Build directory local install_dir="${build_root}/install" # Install directory rm -rf "${build_root}" # 创建目录 mkdir -p "${build_dir}" "${install_dir}" display_alert "AMLOGIC: build_dir ${build_dir}" "info" display_alert "AMLOGIC: install_dir ${install_dir}" "info" display_alert "AMLOGIC: output_dir ${BUILD_DIR}/output" "info" # 准备源代码 __linux_uapi_headers_prepare_source "${build_dir}" # 安装头文件 if ! __linux_uapi_headers_install "${install_dir}"; then display_alert "AMLOGIC: Linux UAPI headers installation failed" "err" return 1 fi display_alert "AMLOGIC: Creating Debian package..." "info" __linux_uapi_headers_create_deb "${build_dir}" "${install_dir}" return 0 } # ============================================================================== # Section 5: Main # ============================================================================== display_alert "AMLIbian Linux UAPI Headers Build Script" "Version: ${KERNEL_VERSION}, Board: ${BOARD}" "info" amlbian_build_linux_uapi_headers display_alert "AMLOGIC: Linux UAPI headers build completed" "${OUTPUT_DIR}" "info" # ============================================================================== # End of build-linux-uapi-headers.sh # ==============================================================================