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

388 lines
12 KiB
Bash
Raw Normal View History

2026-08-13 11:28:40 +08:00
#!/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"
2026-11-11 08:50:43 +08:00
MODULE_BUILD_DIR="${SRC}/output/.tmp"
2026-08-13 11:28:40 +08:00
# ==============================================================================
# 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"
2026-08-25 10:02:36 +08:00
TAHOE_V4L2="${TAHOE_V4L2:-yes}"
2026-08-13 11:28:40 +08:00
# ==============================================================================
# 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
2026-11-11 08:50:43 +08:00
aml_log error "TAHOE" "aml-comp not found: ${aml_comp_path}"
2026-08-13 11:28:40 +08:00
exit 1
fi
local source_dir="${aml_comp_path}/hardware/amlogic/video_encoder"
if [[ ! -d "${source_dir}" ]]; then
2026-11-11 08:50:43 +08:00
aml_log error "TAHOE" "Source directory not found: ${source_dir}"
2026-08-13 11:28:40 +08:00
exit 1
fi
2026-11-11 08:50:43 +08:00
aml_log debug "TAHOE" "Copying source from ${source_dir} to ${build_dir}"
2026-08-13 11:28:40 +08:00
# 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
2026-11-11 08:50:43 +08:00
aml_log info "TAHOE" "Copying firmware file..."
2026-08-13 11:28:40 +08:00
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}/"
2026-11-11 08:50:43 +08:00
aml_log debug "TAHOE" "Firmware installed: ${firmware_dst_dir}/${TAHOE_FIRMWARE_FILE}"
2026-08-13 11:28:40 +08:00
else
2026-11-11 08:50:43 +08:00
aml_log error "TAHOE" "Firmware file not found: ${firmware_src}"
2026-08-13 11:28:40 +08:00
fi
# Copy kernel module to proper location
2026-11-11 08:50:43 +08:00
aml_log info "TAHOE" "Copying ko files to ${kernel_version}..."
2026-08-13 11:28:40 +08:00
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}"
2026-11-11 08:50:43 +08:00
aml_log info "TAHOE" "Module installed: ${dst_dir}/tahoe.ko"
2026-08-13 11:28:40 +08:00
if [ "$LOAD_METHOD" = "conf" ]; then
2026-11-11 08:50:43 +08:00
aml_log info "TAHOE" "Generate modules-load.d configs to ${install_dir}/etc/modules-load.d ..."
2026-08-13 11:28:40 +08:00
# 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}"
2026-11-11 08:50:43 +08:00
aml_log info "TAHOE" "Starting tahoe driver build..."
2026-08-13 11:28:40 +08:00
# Check source directory
if [[ ! -d "${build_dir}" ]]; then
2026-11-11 08:50:43 +08:00
aml_log error "TAHOE" "Build directory not found: ${build_dir}"
2026-08-13 11:28:40 +08:00
return 1
fi
2026-08-25 10:02:36 +08:00
local tahoe_dir="tahoe"
if [ "$TAHOE_V4L2" = "yes" ]; then
tahoe_dir="tahoe_v4l"
fi
2026-08-13 11:28:40 +08:00
# Check tahoe source
2026-08-25 10:02:36 +08:00
local tahoe_source_dir="${build_dir}/${tahoe_dir}"
2026-08-13 11:28:40 +08:00
if [[ ! -d "${tahoe_source_dir}" ]]; then
2026-11-11 08:50:43 +08:00
aml_log error "TAHOE" "Tahoe source directory not found: ${tahoe_source_dir}"
2026-08-13 11:28:40 +08:00
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
2026-11-11 08:50:43 +08:00
aml_log error "TAHOE" "aml-comp not found: ${aml_comp_path}"
2026-08-13 11:28:40 +08:00
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
2026-11-11 08:50:43 +08:00
aml_log error "TAHOE" "Kernel build directory not found. Expected at: ${kernel_build_dir}"
2026-08-13 11:28:40 +08:00
return 1
fi
local kernel_version=$(make -s -C "${kernel_build_dir}" kernelrelease 2>/dev/null || echo "")
if [[ -z "${kernel_version}" ]]; then
2026-11-11 08:50:43 +08:00
aml_log warn "TAHOE" "Could not determine kernel version from ${kernel_build_dir}"
2026-08-13 11:28:40 +08:00
kernel_version="${KERNEL_VERSION}"
fi
2026-11-11 08:50:43 +08:00
aml_log info "TAHOE" "Building tahoe driver for kernel ${kernel_version}..."
2026-08-13 11:28:40 +08:00
# amlbian_checkout_toolchain
# Add specific compilation flags for a9 boards
2026-11-11 08:50:43 +08:00
if [[ "${BOARD}" == *"a9"* ]] || [[ "${BOARD}" == *"c5"* ]]; then
aml_log info "TAHOE" "Adding -DDOS_REGISTERS_V3 flag for a9 board"
2026-08-13 11:28:40 +08:00
export KERNEL_CC="${KERNEL_CC} -DDOS_REGISTERS_V3"
EXTRA_CFLAGS+=" -DDOS_REGISTERS_V3"
fi
2026-11-11 08:50:43 +08:00
aml_log info "TAHOE" "Building tahoe driver..."
2026-08-13 11:28:40 +08:00
# Create symbolic link as done in tahoe_6.12.bb
# Ensure common_drivers/drivers directory exists
mkdir -p "${STAGING_KERNEL_DIR}/common_drivers/drivers"
2026-08-25 10:02:36 +08:00
ln -sf "${build_dir}/${tahoe_dir}" "${STAGING_KERNEL_DIR}/common_drivers/drivers/" 2>/dev/null || true
2026-08-13 11:28:40 +08:00
# 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 || {
2026-11-11 08:50:43 +08:00
aml_log error "TAHOE" "Build failed"
2026-08-13 11:28:40 +08:00
# Clean up symbolic link
2026-08-25 10:02:36 +08:00
rm -f "${STAGING_KERNEL_DIR}/common_drivers/drivers/${tahoe_dir}" 2>/dev/null || true
2026-08-13 11:28:40 +08:00
return 1
}
# Clean up symbolic link
2026-08-25 10:02:36 +08:00
rm -f "${STAGING_KERNEL_DIR}/common_drivers/drivers/${tahoe_dir}" 2>/dev/null || true
2026-08-13 11:28:40 +08:00
# Install module
2026-11-11 08:50:43 +08:00
aml_log info "TAHOE" "Installing tahoe driver..."
2026-08-13 11:28:40 +08:00
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 || {
2026-11-11 08:50:43 +08:00
aml_log error "TAHOE" "Install failed"
2026-08-13 11:28:40 +08:00
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 <build@amlbian.com>"
local description="Amlogic Tahoe video encoder driver for kernel ${KERNEL_VERSION}"
2026-11-11 08:50:43 +08:00
aml_log info "TAHOE" "Creating Debian package for ${pkg_name} ${version}..."
2026-08-13 11:28:40 +08:00
# 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
2026-11-11 08:50:43 +08:00
aml_log debug "TAHOE" "Copied installed files to ${deb_dir}"
2026-08-13 11:28:40 +08:00
else
2026-11-11 08:50:43 +08:00
aml_log error "TAHOE" "No installed files found in ${install_dir}"
return 1
2026-08-13 11:28:40 +08:00
fi
local aml_comp_path="$(amlbian_get_aml_comp_dir)"
if [[ -z "${aml_comp_path}" ]] || [[ ! -d "${aml_comp_path}" ]]; then
2026-11-11 08:50:43 +08:00
aml_log error "TAHOE" "aml-comp not found: ${aml_comp_path}"
2026-08-13 11:28:40 +08:00
exit 1
fi
local kernel_build_dir="${aml_comp_path}/kernel/aml-${KERNEL_VERSION}/build"
if [[ ! -d "${kernel_build_dir}" ]]; then
2026-11-11 08:50:43 +08:00
aml_log error "TAHOE" "Kernel build directory not found. Expected at: ${kernel_build_dir}"
2026-08-13 11:28:40 +08:00
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"
2026-11-11 08:50:43 +08:00
aml_log info "TAHOE" "Building Debian package..."
2026-08-13 11:28:40 +08:00
# 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
2026-11-11 08:50:43 +08:00
aml_log error "TAHOE" "Failed to build Debian package"
2026-08-13 11:28:40 +08:00
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
2026-11-11 08:50:43 +08:00
aml_log info "[SKIP] >> tahoe-encoder disable in BUILD_UNITS"
2026-08-13 11:28:40 +08:00
return
fi
if ! is_feature_contains "$MEDIA_ENCODER_HW_CONFIG" "TAHOE"; then
2026-11-11 08:50:43 +08:00
aml_log info "[SKIP] >> TAHOE disable in MEDIA_ENCODER_HW_CONFIG"
2026-08-13 11:28:40 +08:00
return
fi
2026-11-11 08:50:43 +08:00
aml_log info "AMLOGIC: Building tahoe encoder driver ${KERNEL_VERSION} ${BOARD}"
2026-08-13 11:28:40 +08:00
# Define all directory paths (in .tmp directory)
2026-11-11 08:50:43 +08:00
local build_root="${MODULE_BUILD_DIR}/tahoe-build-${ARCH:-arm64}"
2026-08-13 11:28:40 +08:00
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}"
2026-11-11 08:50:43 +08:00
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"
2026-08-13 11:28:40 +08:00
# Prepare source code
__tahoe_prepare_source "${build_dir}"
# Build
if ! __tahoe_build "${build_dir}" "${install_dir}"; then
2026-11-11 08:50:43 +08:00
aml_log error "AMLOGIC: Tahoe encoder build failed"
2026-08-13 11:28:40 +08:00
return 1
fi
2026-11-11 08:50:43 +08:00
aml_log info "AMLOGIC: Creating Debian package..."
2026-08-13 11:28:40 +08:00
__tahoe_create_deb "${build_dir}" "${install_dir}"
return 0
}
# ==============================================================================
# Section 5: Main
# ==============================================================================
2026-11-11 08:50:43 +08:00
aml_log info "AMLbian Tahoe Encoder Build Script" "Version: ${KERNEL_VERSION}, Board: ${BOARD}"
2026-08-13 11:28:40 +08:00
amlbian_build_tahoe
2026-11-11 08:50:43 +08:00
aml_log info "AMLOGIC: Tahoe encoder build completed" "${BUILD_DIR}/output"
2026-08-13 11:28:40 +08:00
# ==============================================================================
# End of build_tahoe.sh
2026-11-11 08:50:43 +08:00
# ==============================================================================