#!/usr/bin/env bash # # SPDX-License-Identifier: GPL-2.0 # # Copyright (c) 2026 AMLOGIC # # Tahoe video encoder driver build script for AMLbian # This script builds tahoe video encoder driver for 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="6.12" ARCH="${ARCH:-arm64}" CROSS_COMPILE="${CROSS_COMPILE:-aarch64-linux-gnu-}" # LOAD_METHOD value: conf script LOAD_METHOD="${LOAD_METHOD:-conf}" # Tahoe encoder configuration TAHOE_FIRMWARE_FILE="fw.bin" TAHOE_V4L2="${TAHOE_V4L2:-yes}" # ============================================================================== # Section 3: Tahoe Encoder Build Functions # ============================================================================== # Prepare tahoe source code function __tahoe_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 "TAHOE" "aml-comp not found: ${aml_comp_path}" exit 1 fi local source_dir="${aml_comp_path}/hardware/amlogic/video_encoder" if [[ ! -d "${source_dir}" ]]; then aml_log error "TAHOE" "Source directory not found: ${source_dir}" exit 1 fi aml_log debug "TAHOE" "Copying source from ${source_dir} to ${build_dir}" # Clean build directory rm -rf "${build_dir}" mkdir -p "${build_dir}" # Copy source code to build directory cp -r "${source_dir}"/* "${build_dir}/" display_alert "TAHOE" "Source prepared successfully" "success" } # Additional installation steps function __tahoe_install_append { local install_dir="${1}" local kernel_version="${2}" local build_dir="${3}" # Copy firmware file aml_log info "TAHOE" "Copying firmware file..." local firmware_src="${build_dir}/firmware/${TAHOE_FIRMWARE_FILE}" if [[ -f "${firmware_src}" ]]; then local firmware_dst_dir="${install_dir}/lib/firmware/encoder" mkdir -p "${firmware_dst_dir}" install -m 0666 "${firmware_src}" "${firmware_dst_dir}/" aml_log debug "TAHOE" "Firmware installed: ${firmware_dst_dir}/${TAHOE_FIRMWARE_FILE}" else aml_log error "TAHOE" "Firmware file not found: ${firmware_src}" fi # Copy kernel module to proper location aml_log info "TAHOE" "Copying ko files to ${kernel_version}..." local tmp_dir="${install_dir}/lib/modules/tmp_dir" mkdir -p "${tmp_dir}" local cur_dir="${install_dir}/lib/modules/${kernel_version}" cd "${cur_dir}" find -name "*.ko" -exec cp {} ${tmp_dir}/ \; rm -rf "${cur_dir}" local dst_dir="${install_dir}/lib/modules/${kernel_version}/video_encoder" mkdir -p "${dst_dir}" cp -r "${tmp_dir}"/* "${dst_dir}" rm -rf "${tmp_dir}" aml_log info "TAHOE" "Module installed: ${dst_dir}/tahoe.ko" if [ "$LOAD_METHOD" = "conf" ]; then aml_log info "TAHOE" "Generate modules-load.d configs to ${install_dir}/etc/modules-load.d ..." # Generate modules-load.d configs local modules_load_dir="${install_dir}/etc/modules-load.d" mkdir -p "${modules_load_dir}" for ko_file in "${dst_dir}"/*.ko; do [[ -e "${ko_file}" ]] || continue module_name=$(basename "${ko_file}" .ko) echo "${module_name}" > "${modules_load_dir}/${module_name}.conf" done fi return 0 } # Build tahoe driver function __tahoe_build { local build_dir="${1}" local install_dir="${2}" aml_log info "TAHOE" "Starting tahoe driver build..." # Check source directory if [[ ! -d "${build_dir}" ]]; then aml_log error "TAHOE" "Build directory not found: ${build_dir}" return 1 fi local tahoe_dir="tahoe" if [ "$TAHOE_V4L2" = "yes" ]; then tahoe_dir="tahoe_v4l" fi # Check tahoe source local tahoe_source_dir="${build_dir}/${tahoe_dir}" if [[ ! -d "${tahoe_source_dir}" ]]; then aml_log error "TAHOE" "Tahoe source directory not found: ${tahoe_source_dir}" return 1 fi # Enter build directory cd "${build_dir}" # Set build environment ARCH="${ARCH:-arm64}" CROSS_COMPILE="${CROSS_COMPILE:-aarch64-linux-gnu-}" # Find kernel build directory local aml_comp_path="$(amlbian_get_aml_comp_dir)" if [[ -z "${aml_comp_path}" ]] || [[ ! -d "${aml_comp_path}" ]]; then aml_log error "TAHOE" "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 "TAHOE" "Kernel build directory not found. Expected at: ${kernel_build_dir}" return 1 fi local kernel_version=$(make -s -C "${kernel_build_dir}" kernelrelease 2>/dev/null || echo "") if [[ -z "${kernel_version}" ]]; then aml_log warn "TAHOE" "Could not determine kernel version from ${kernel_build_dir}" kernel_version="${KERNEL_VERSION}" fi aml_log info "TAHOE" "Building tahoe driver for kernel ${kernel_version}..." # amlbian_checkout_toolchain # Add specific compilation flags for a9 boards if [[ "${BOARD}" == *"a9"* ]] || [[ "${BOARD}" == *"c5"* ]]; then aml_log info "TAHOE" "Adding -DDOS_REGISTERS_V3 flag for a9 board" export KERNEL_CC="${KERNEL_CC} -DDOS_REGISTERS_V3" EXTRA_CFLAGS+=" -DDOS_REGISTERS_V3" fi aml_log info "TAHOE" "Building tahoe driver..." # Create symbolic link as done in tahoe_6.12.bb # Ensure common_drivers/drivers directory exists mkdir -p "${STAGING_KERNEL_DIR}/common_drivers/drivers" ln -sf "${build_dir}/${tahoe_dir}" "${STAGING_KERNEL_DIR}/common_drivers/drivers/" 2>/dev/null || true # Build tahoe module make -C "${kernel_build_dir}" \ M="${tahoe_source_dir}" \ KERNEL_SRC="${STAGING_KERNEL_DIR}" \ ARCH="${ARCH}" \ CROSS_COMPILE="${CROSS_COMPILE}" \ KERNEL_CC="${KERNEL_CC}" \ EXTRA_CFLAGS="${EXTRA_CFLAGS}" \ V=1 \ modules \ -j$(nproc) \ 2>&1 | tee make.log || { aml_log error "TAHOE" "Build failed" # Clean up symbolic link rm -f "${STAGING_KERNEL_DIR}/common_drivers/drivers/${tahoe_dir}" 2>/dev/null || true return 1 } # Clean up symbolic link rm -f "${STAGING_KERNEL_DIR}/common_drivers/drivers/${tahoe_dir}" 2>/dev/null || true # Install module aml_log info "TAHOE" "Installing tahoe driver..." make -C "${kernel_build_dir}" \ M="${tahoe_source_dir}" \ KERNEL_SRC="${STAGING_KERNEL_DIR}" \ ARCH="${ARCH}" \ CROSS_COMPILE="${CROSS_COMPILE}" \ INSTALL_MOD_PATH="${install_dir}" \ INSTALL_MOD_STRIP=1 \ modules_install \ 2>/dev/null | tee install.log || { aml_log error "TAHOE" "Install failed" return 1 } # Additional installation steps __tahoe_install_append "${install_dir}" "${kernel_version}" "${build_dir}" display_alert "TAHOE" "Build tahoe driver completed successfully" "success" return 0 } # Create Debian package function __tahoe_create_deb { local build_dir="${1}" local install_dir="${2}" # Set necessary variables local pkg_name="tahoe-encoder" local version="${DEB_VERSION}" local architecture="${ARCH:-arm64}" local maintainer="Amlbian Builder " local description="Amlogic Tahoe video encoder driver for kernel ${KERNEL_VERSION}" aml_log info "TAHOE" "Creating Debian package for ${pkg_name} ${version}..." # Create Debian package control files local deb_dir="${build_dir}/deb/${pkg_name}-${version}" local debian_dir="${deb_dir}/DEBIAN" mkdir -p "${debian_dir}" # Copy installed directory contents to debian-root if [[ -d "${install_dir}" ]] && [[ "$(ls -A "${install_dir}")" ]]; then cp -r "${install_dir}"/* "${deb_dir}/" 2>/dev/null || true aml_log debug "TAHOE" "Copied installed files to ${deb_dir}" else aml_log error "TAHOE" "No installed files found in ${install_dir}" return 1 fi local aml_comp_path="$(amlbian_get_aml_comp_dir)" if [[ -z "${aml_comp_path}" ]] || [[ ! -d "${aml_comp_path}" ]]; then aml_log error "TAHOE" "aml-comp not found: ${aml_comp_path}" exit 1 fi local kernel_build_dir="${aml_comp_path}/kernel/aml-${KERNEL_VERSION}/build" if [[ ! -d "${kernel_build_dir}" ]]; then aml_log error "TAHOE" "Kernel build directory not found. Expected at: ${kernel_build_dir}" return 1 fi local kernel_version=$(make -s -C "${kernel_build_dir}" kernelrelease 2>/dev/null || echo "") # Create control file cat > "${debian_dir}/control" < "${debian_dir}/postinst" </dev/null 2>&1; then depmod -a "${kernel_version:-}" || true fi fi EOF chmod 755 "${debian_dir}/postinst" aml_log info "TAHOE" "Building Debian package..." # Build Debian package cd "${build_dir}/deb" dpkg-deb --build "${pkg_name}-${version}" local deb_file="${pkg_name}-${version}.deb" if [[ -f "${deb_file}" ]]; then local output_dir="${BUILD_DIR}/output" mkdir -p "${output_dir}" mv "${deb_file}" "${output_dir}/linux-${pkg_name}-${BOARD}-amlbian_${version}_${architecture}.deb" display_alert "TAHOE" "Debian package created: ${output_dir}/linux-${pkg_name}-${BOARD}-amlbian_${version}_${architecture}.deb" "success" else aml_log error "TAHOE" "Failed to build Debian package" return 1 fi return 0 } # Main tahoe build function function amlbian_build_tahoe { if ! is_unit_enabled "media-modules" && ! is_unit_enabled "tahoe-encoder"; then aml_log info "[SKIP] >> tahoe-encoder disable in BUILD_UNITS" return fi if ! is_feature_contains "$MEDIA_ENCODER_HW_CONFIG" "TAHOE"; then aml_log info "[SKIP] >> TAHOE disable in MEDIA_ENCODER_HW_CONFIG" return fi aml_log info "AMLOGIC: Building tahoe encoder driver ${KERNEL_VERSION} ${BOARD}" # Define all directory paths (in .tmp directory) local build_root="${MODULE_BUILD_DIR}/tahoe-build-${ARCH:-arm64}" local build_dir="${build_root}/build" # Build directory with source code local install_dir="${build_root}/install" # Install directory rm -rf "${build_root}" # Create directories 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" # Prepare source code __tahoe_prepare_source "${build_dir}" # Build if ! __tahoe_build "${build_dir}" "${install_dir}"; then aml_log error "AMLOGIC: Tahoe encoder build failed" return 1 fi aml_log info "AMLOGIC: Creating Debian package..." __tahoe_create_deb "${build_dir}" "${install_dir}" return 0 } # ============================================================================== # Section 5: Main # ============================================================================== aml_log info "AMLbian Tahoe Encoder Build Script" "Version: ${KERNEL_VERSION}, Board: ${BOARD}" amlbian_build_tahoe aml_log info "AMLOGIC: Tahoe encoder build completed" "${BUILD_DIR}/output" # ============================================================================== # End of build_tahoe.sh # ==============================================================================