#!/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" MODULE_BUILD_DIR="${SRC}/output/.tmp" # ============================================================================== # 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 aml_log error "LINUX-UAPI-HEADERS" "aml-comp not found: ${aml_comp_path}" 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 aml_log error "LINUX-UAPI-HEADERS" "Kernel build directory not found. Expected at: ${kernel_build_dir}" return 1 fi display_alert "LINUX-UAPI-HEADERS" "Source prepared successfully" "success" return 0 } function __linux_uapi_headers_install { local install_dir="${1}" aml_log info "LINUX-UAPI-HEADERS" "Starting Linux UAPI headers installation..." local aml_comp_path="$(amlbian_get_aml_comp_dir)" if [[ -z "${aml_comp_path}" ]] || [[ ! -d "${aml_comp_path}" ]]; then aml_log error "LINUX-UAPI-HEADERS" "aml-comp not found: ${aml_comp_path}" exit 1 fi local STAGING_KERNEL_DIR="${aml_comp_path}/kernel/aml-${KERNEL_VERSION}" if [[ ! -d "${STAGING_KERNEL_DIR}" ]]; then aml_log error "LINUX-UAPI-HEADERS" "Kernel source directory not found: ${STAGING_KERNEL_DIR}" return 1 fi local includedir="${install_dir}/usr/include" mkdir -p "${includedir}/linux/amlogic" # 1. 安装 Amlogic 自定义头文件(有第二种路径尝试) aml_log info "LINUX-UAPI-HEADERS" "Installing Amlogic customized headers..." 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/" aml_log debug "LINUX-UAPI-HEADERS" "Copied Amlogic headers from ${aml_uapi_path}" else aml_log warn "LINUX-UAPI-HEADERS" "Amlogic headers not found at both locations" fi # 2. 安装额外头文件 (dma-heap.h, ion.h) aml_log info "LINUX-UAPI-HEADERS" "Installing extra headers..." 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/" aml_log debug "LINUX-UAPI-HEADERS" "Installed ${f}" else aml_log debug "LINUX-UAPI-HEADERS" "Skipping ${f} - already exists" fi else aml_log debug "LINUX-UAPI-HEADERS" "Header ${f} not found at ${uapi_path}" fi done # 3. 安装 DVB 额外头文件 aml_log info "LINUX-UAPI-HEADERS" "Installing DVB extra headers..." 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/" aml_log debug "LINUX-UAPI-HEADERS" "Installed DVB header ${f}" else aml_log debug "LINUX-UAPI-HEADERS" "DVB header ${f} not found" 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}" aml_log info "LINUX-UAPI-HEADERS" "Creating Debian package for ${pkg_name} ${version}..." # 创建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 aml_log debug "LINUX-UAPI-HEADERS" "Copied installed files to ${deb_dir}" else aml_log error "LINUX-UAPI-HEADERS" "No installed files found in ${install_dir}" return 1 fi # 创建control文件 cat > "${debian_dir}/control" <> linux-uapi-headers disable in BUILD_UNITS" return fi aml_log info "AMLOGIC: Building Linux UAPI headers ${KERNEL_VERSION} ${BOARD}" # Define all directory paths (in .tmp directory) local build_root="${MODULE_BUILD_DIR}/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}" aml_log debug "AMLOGIC: build_dir ${build_dir}" aml_log debug "AMLOGIC: install_dir ${install_dir}" aml_log debug "AMLOGIC: output_dir ${BUILD_DIR}/output" # 准备源代码 __linux_uapi_headers_prepare_source "${build_dir}" # 安装头文件 if ! __linux_uapi_headers_install "${install_dir}"; then aml_log error "AMLOGIC: Linux UAPI headers installation failed" return 1 fi aml_log info "AMLOGIC: Creating Debian package..." __linux_uapi_headers_create_deb "${build_dir}" "${install_dir}" return 0 } # ============================================================================== # Section 5: Main # ============================================================================== aml_log info "AMLIbian Linux UAPI Headers Build Script" "Version: ${KERNEL_VERSION}, Board: ${BOARD}" amlbian_build_linux_uapi_headers aml_log info "AMLOGIC: Linux UAPI headers build completed" "${OUTPUT_DIR}" # ============================================================================== # End of build-linux-uapi-headers.sh # ==============================================================================