384 lines
13 KiB
Bash
384 lines
13 KiB
Bash
#!/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"
|
|
|
|
# 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="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"
|
|
|
|
# ==============================================================================
|
|
# 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
|
|
display_alert "TAHOE" "aml-comp not found: ${aml_comp_path}" "err"
|
|
exit 1
|
|
fi
|
|
|
|
local source_dir="${aml_comp_path}/hardware/amlogic/video_encoder"
|
|
|
|
if [[ ! -d "${source_dir}" ]]; then
|
|
display_alert "TAHOE" "Source directory not found: ${source_dir}" "err"
|
|
exit 1
|
|
fi
|
|
|
|
display_alert "TAHOE" "Copying source from ${source_dir} to ${build_dir}" "info"
|
|
|
|
# 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
|
|
display_alert "TAHOE" "Copying firmware file..." "info"
|
|
|
|
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}/"
|
|
display_alert "TAHOE" "Firmware installed: ${firmware_dst_dir}/${TAHOE_FIRMWARE_FILE}" "info"
|
|
else
|
|
display_alert "TAHOE" "Firmware file not found: ${firmware_src}" "warn"
|
|
fi
|
|
|
|
# Copy kernel module to proper location
|
|
display_alert "TAHOE" "Copying ko files to ${kernel_version}..." "info"
|
|
|
|
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}"
|
|
|
|
display_alert "TAHOE" "Module installed: ${dst_dir}/tahoe.ko" "info"
|
|
|
|
if [ "$LOAD_METHOD" = "conf" ]; then
|
|
display_alert "TAHOE" "Generate modules-load.d configs to ${install_dir}/etc/modules-load.d ..." "info"
|
|
|
|
# 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}"
|
|
|
|
display_alert "TAHOE" "Starting tahoe driver build..." "info"
|
|
|
|
# Check source directory
|
|
if [[ ! -d "${build_dir}" ]]; then
|
|
display_alert "TAHOE" "Build directory not found: ${build_dir}" "err"
|
|
return 1
|
|
fi
|
|
|
|
# Check tahoe source
|
|
local tahoe_source_dir="${build_dir}/tahoe"
|
|
if [[ ! -d "${tahoe_source_dir}" ]]; then
|
|
display_alert "TAHOE" "Tahoe source directory not found: ${tahoe_source_dir}" "err"
|
|
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
|
|
display_alert "TAHOE" "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 "TAHOE" "Kernel build directory not found. Expected at: ${kernel_build_dir}" "err"
|
|
return 1
|
|
fi
|
|
|
|
local kernel_version=$(make -s -C "${kernel_build_dir}" kernelrelease 2>/dev/null || echo "")
|
|
if [[ -z "${kernel_version}" ]]; then
|
|
display_alert "TAHOE" "Could not determine kernel version from ${kernel_build_dir}" "warn"
|
|
kernel_version="${KERNEL_VERSION}"
|
|
fi
|
|
|
|
display_alert "TAHOE" "Building tahoe driver for kernel ${kernel_version}..." "info"
|
|
|
|
# amlbian_checkout_toolchain
|
|
|
|
# Add specific compilation flags for a9 boards
|
|
if [[ "${BOARD}" == *"a9"* ]]; then
|
|
display_alert "TAHOE" "Adding -DDOS_REGISTERS_V3 flag for a9 board" "info"
|
|
export KERNEL_CC="${KERNEL_CC} -DDOS_REGISTERS_V3"
|
|
EXTRA_CFLAGS+=" -DDOS_REGISTERS_V3"
|
|
fi
|
|
|
|
display_alert "TAHOE" "Building tahoe driver..." "info"
|
|
|
|
# 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" "${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 || {
|
|
display_alert "TAHOE" "Build failed" "err"
|
|
# Clean up symbolic link
|
|
rm -f "${STAGING_KERNEL_DIR}/common_drivers/drivers/tahoe" 2>/dev/null || true
|
|
return 1
|
|
}
|
|
|
|
# Clean up symbolic link
|
|
rm -f "${STAGING_KERNEL_DIR}/common_drivers/drivers/tahoe" 2>/dev/null || true
|
|
|
|
# Install module
|
|
display_alert "TAHOE" "Installing tahoe driver..." "info"
|
|
|
|
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 || {
|
|
display_alert "TAHOE" "Install failed" "err"
|
|
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 <[email protected]>"
|
|
local description="Amlogic Tahoe video encoder driver for kernel ${KERNEL_VERSION}"
|
|
|
|
display_alert "TAHOE" "Creating Debian package for ${pkg_name} ${version}..." "info"
|
|
|
|
# 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
|
|
display_alert "TAHOE" "Copied installed files to ${deb_dir}" "info"
|
|
else
|
|
display_alert "TAHOE" "No installed files found in ${install_dir}" "warn"
|
|
return 0
|
|
fi
|
|
|
|
local aml_comp_path="$(amlbian_get_aml_comp_dir)"
|
|
if [[ -z "${aml_comp_path}" ]] || [[ ! -d "${aml_comp_path}" ]]; then
|
|
display_alert "TAHOE" "aml-comp not found: ${aml_comp_path}" "err"
|
|
exit 1
|
|
fi
|
|
|
|
local kernel_build_dir="${aml_comp_path}/kernel/aml-${KERNEL_VERSION}/build"
|
|
|
|
if [[ ! -d "${kernel_build_dir}" ]]; then
|
|
display_alert "TAHOE" "Kernel build directory not found. Expected at: ${kernel_build_dir}" "err"
|
|
return 1
|
|
fi
|
|
|
|
local kernel_version=$(make -s -C "${kernel_build_dir}" kernelrelease 2>/dev/null || echo "")
|
|
|
|
# Create control file
|
|
cat > "${debian_dir}/control" <<EOF
|
|
Package: ${pkg_name}
|
|
Version: ${version}
|
|
Architecture: ${architecture}
|
|
Maintainer: ${maintainer}
|
|
Description: ${description}
|
|
This package provides Tahoe video encoder kernel driver for Amlogic hardware.
|
|
Depends:
|
|
Section: kernel
|
|
Priority: optional
|
|
EOF
|
|
|
|
# Create postinst script for module dependency update
|
|
cat > "${debian_dir}/postinst" <<EOF
|
|
#!/bin/sh
|
|
set -e
|
|
|
|
if [ "\$1" = "configure" ]; then
|
|
# Update module dependencies
|
|
if command -v depmod >/dev/null 2>&1; then
|
|
depmod -a "${kernel_version:-}" || true
|
|
fi
|
|
fi
|
|
EOF
|
|
|
|
chmod 755 "${debian_dir}/postinst"
|
|
|
|
display_alert "TAHOE" "Building Debian package..." "info"
|
|
|
|
# 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
|
|
display_alert "TAHOE" "Failed to build Debian package" "err"
|
|
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
|
|
display_alert "[SKIP] >> tahoe-encoder disable in BUILD_UNITS" "" "info"
|
|
return
|
|
fi
|
|
|
|
if ! is_feature_contains "$MEDIA_ENCODER_HW_CONFIG" "TAHOE"; then
|
|
display_alert "[SKIP] >> TAHOE disable in MEDIA_ENCODER_HW_CONFIG" "" "info"
|
|
return
|
|
fi
|
|
|
|
display_alert "AMLOGIC: Building tahoe encoder driver ${KERNEL_VERSION} ${BOARD}" "info"
|
|
|
|
# Define all directory paths (in .tmp directory)
|
|
local build_root="${BUILD_DIR}/.tmp/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}"
|
|
|
|
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"
|
|
|
|
# Prepare source code
|
|
__tahoe_prepare_source "${build_dir}"
|
|
|
|
# Build
|
|
if ! __tahoe_build "${build_dir}" "${install_dir}"; then
|
|
display_alert "AMLOGIC: Tahoe encoder build failed" "err"
|
|
return 1
|
|
fi
|
|
|
|
display_alert "AMLOGIC: Creating Debian package..." "info"
|
|
__tahoe_create_deb "${build_dir}" "${install_dir}"
|
|
|
|
return 0
|
|
}
|
|
|
|
# ==============================================================================
|
|
# Section 5: Main
|
|
# ==============================================================================
|
|
|
|
display_alert "AMLbian Tahoe Encoder Build Script" "Version: ${KERNEL_VERSION}, Board: ${BOARD}" "info"
|
|
|
|
amlbian_build_tahoe
|
|
|
|
display_alert "AMLOGIC: Tahoe encoder build completed" "${BUILD_DIR}/output" "info"
|
|
|
|
# ==============================================================================
|
|
# End of build_tahoe.sh
|
|
# ============================================================================== |