437 lines
15 KiB
Bash
437 lines
15 KiB
Bash
#!/usr/bin/env bash
|
|
#
|
|
# SPDX-License-Identifier: GPL-2.0
|
|
#
|
|
# Copyright (c) 2026 AMLOGIC
|
|
#
|
|
# HDMI Test build script for AMLbian
|
|
# This script builds hdmi-test application for Amlogic SoCs
|
|
# Based on build-mediactrlsrc.sh functionality
|
|
|
|
set -e
|
|
|
|
# Get script directory
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
AMLBIAN_DIR="$(dirname "$(dirname "${SCRIPT_DIR}")")"
|
|
BUILD_DIR="${SRC}"
|
|
|
|
# Source common functions
|
|
if [[ -f "${AMLBIAN_DIR}/lib/function-common.sh" ]]; then
|
|
source "${AMLBIAN_DIR}/lib/function-common.sh"
|
|
fi
|
|
|
|
# ==============================================================================
|
|
# Section 2: Default Configuration
|
|
# ==============================================================================
|
|
|
|
BOARD="${BOARD:-s6-bq201}"
|
|
HDMI_TEST_VERSION="${HDMI_TEST_VERSION:-1.0.0}"
|
|
: "${ARCH:=arm64}"
|
|
KERNEL_VERSION="${KERNEL_VERSION:-6.12}"
|
|
|
|
# ==============================================================================
|
|
# Section 4: HDMI Test Build Functions
|
|
# ==============================================================================
|
|
|
|
function __unset_hdmi_test_config {
|
|
# Clean up any environment variables set during build
|
|
unset CFLAGS
|
|
unset CXXFLAGS
|
|
unset LDFLAGS
|
|
}
|
|
|
|
function __hdmi_test_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 "HDMI-TEST" "aml-comp not found: ${aml_comp_path}" "err"
|
|
exit 1
|
|
fi
|
|
|
|
local source_dir="${aml_comp_path}/vendor/amlogic/linux_sample_app/aml-hdmi-test"
|
|
|
|
if [[ ! -d "${source_dir}" ]]; then
|
|
display_alert "HDMI-TEST" "Source directory not found: ${source_dir}" "err"
|
|
exit 1
|
|
fi
|
|
|
|
display_alert "HDMI-TEST" "Copying source from ${source_dir} to ${build_dir}" "info"
|
|
|
|
# 复制源代码到构建目录
|
|
cp -r "${source_dir}"/* "${build_dir}/" 2>/dev/null || true
|
|
|
|
# Check for necessary source files
|
|
if [[ ! -f "${build_dir}/Makefile" ]]; then
|
|
display_alert "HDMI-TEST" "Makefile not found in source" "err"
|
|
exit 1
|
|
fi
|
|
|
|
display_alert "HDMI-TEST" "Source prepared successfully" "success"
|
|
}
|
|
|
|
function __hdmi_test_build {
|
|
local build_dir="${1}"
|
|
|
|
display_alert "HDMI-TEST" "Starting hdmi-test build..." "info"
|
|
|
|
if [[ ! -d "${build_dir}" ]]; then
|
|
display_alert "HDMI-TEST" "Build directory not found: ${build_dir}" "err"
|
|
return 1
|
|
fi
|
|
|
|
# Get aml_comp_path again for include paths
|
|
local aml_comp_path="$(amlbian_get_aml_comp_dir)"
|
|
if [[ -z "${aml_comp_path}" ]] || [[ ! -d "${aml_comp_path}" ]]; then
|
|
display_alert "HDMI-TEST" "aml-comp not found: ${aml_comp_path}" "err"
|
|
return 1
|
|
fi
|
|
|
|
# Set build environment
|
|
: "${ARCH:=arm64}"
|
|
CROSS_COMPILE="${CROSS_COMPILE:-aarch64-linux-gnu-}"
|
|
|
|
export ARCH
|
|
export CROSS_COMPILE="${CROSS_COMPILE}"
|
|
|
|
if [[ -n "${ROOTFS_TEMP}" ]] && [[ -d "${ROOTFS_TEMP}" ]] && [[ -d "${ROOTFS_TEMP}/usr/lib/aarch64-linux-gnu" ]]; then
|
|
SYSROOT="${ROOTFS_TEMP}"
|
|
display_alert "HDMI-TEST" "Using ROOTFS_TEMP as sysroot: ${SYSROOT}" "info"
|
|
else
|
|
display_alert "HDMI-TEST" "ROOTFS_TEMP not found or invalid: ${ROOTFS_TEMP}" "err"
|
|
display_alert "HDMI-TEST" "ROOTFS_TEMP should be created by create_base_rootfs function" "err"
|
|
return 1
|
|
fi
|
|
|
|
export PKG_CONFIG=/usr/bin/pkg-config
|
|
export PKG_CONFIG_SYSROOT_DIR="${SYSROOT}"
|
|
export PKG_CONFIG_LIBDIR="${SYSROOT}/usr/lib/aarch64-linux-gnu/pkgconfig:${SYSROOT}/usr/share/pkgconfig"
|
|
unset PKG_CONFIG_PATH
|
|
|
|
# Set up flags with sysroot
|
|
export CPPFLAGS="${CPPFLAGS} --sysroot=${SYSROOT}"
|
|
export CFLAGS="${CFLAGS} --sysroot=${SYSROOT} -fPIC"
|
|
export CXXFLAGS="${CXXFLAGS} --sysroot=${SYSROOT} -fPIC"
|
|
export LDFLAGS="${LDFLAGS} --sysroot=${SYSROOT}"
|
|
|
|
local include_flags="-I${ROOTFS_TEMP}/usr/include/aarch64-linux-gnu \
|
|
-I${ROOTFS_TEMP}/usr/include/glib-2.0 \
|
|
-I${ROOTFS_TEMP}/usr/lib/aarch64-linux-gnu/glib-2.0/include"
|
|
|
|
export CPPFLAGS="${CPPFLAGS} ${include_flags}"
|
|
export CFLAGS="${CFLAGS} ${include_flags}"
|
|
export CXXFLAGS="${CXXFLAGS} ${include_flags}"
|
|
|
|
export LDFLAGS="${LDFLAGS} -L${ROOTFS_TEMP}/usr/lib/aarch64-linux-gnu -L${ROOTFS_TEMP}/usr/aarch64-linux-gnu/lib"
|
|
export LDFLAGS="${LDFLAGS} -Wl,-rpath-link,${ROOTFS_TEMP}/usr/lib/aarch64-linux-gnu"
|
|
|
|
cd "${build_dir}"
|
|
|
|
# Create output directory
|
|
local out_dir="${build_dir}/output"
|
|
mkdir -p "${out_dir}"
|
|
|
|
display_alert "HDMI-TEST" "Building using Makefile..." "info"
|
|
display_alert "HDMI-TEST" "CC=${CC}" "debug"
|
|
|
|
# Build flags
|
|
local current_cflags="${CFLAGS} -Wno-unused-result -Wno-unused-variable -Wno-unused-function -Os"
|
|
|
|
export CFLAGS="${current_cflags}"
|
|
export CXXFLAGS="${CXXFLAGS} ${current_cflags}"
|
|
|
|
export LDFLAGS="${LDFLAGS} -lamlv4l2src"
|
|
|
|
# Determine make targets based on mediactrlsrc feature
|
|
local make_targets="aml_hdmi_test"
|
|
local expected_bins=("aml_hdmi_test")
|
|
|
|
# Check if mediactrlsrc feature is enabled (passed from parent function)
|
|
# We'll check DISTRO_FEATURES directly here for simplicity
|
|
if is_feature_contains "$DISTRO_FEATURES" "mediactrlsrc"; then
|
|
make_targets="" # Build all targets (default)
|
|
expected_bins=("test_amlv4l2src" "aml_hdmi_test")
|
|
display_alert "HDMI-TEST" "mediactrlsrc enabled, building both test_amlv4l2src and aml_hdmi_test" "info"
|
|
else
|
|
make_targets="aml_hdmi_test"
|
|
expected_bins=("aml_hdmi_test")
|
|
display_alert "HDMI-TEST" "mediactrlsrc disabled, building only aml_hdmi_test" "info"
|
|
fi
|
|
|
|
# Run make with OUT_DIR pointing to our output directory
|
|
make OUT_DIR="${out_dir}" \
|
|
TARGET_DIR="${out_dir}" \
|
|
STAGING_DIR="${out_dir}" \
|
|
CC="${CC}" \
|
|
CFLAGS="${CFLAGS} -fPIC -Wall" \
|
|
LDFLAGS="${LDFLAGS}" \
|
|
${make_targets} \
|
|
-j$(nproc) \
|
|
2>&1 | tee "${out_dir}/make.log" || {
|
|
display_alert "HDMI-TEST" "Build failed" "err"
|
|
return 1
|
|
}
|
|
|
|
# Verify the binaries were created
|
|
local bins_created=0
|
|
|
|
for bin in "${expected_bins[@]}"; do
|
|
if [[ -f "${out_dir}/${bin}" ]]; then
|
|
display_alert "HDMI-TEST" "Binary created: ${out_dir}/${bin}" "info"
|
|
bins_created=$((bins_created + 1))
|
|
else
|
|
# Check in build directory
|
|
if [[ -f "${build_dir}/${bin}" ]]; then
|
|
cp "${build_dir}/${bin}" "${out_dir}/"
|
|
display_alert "HDMI-TEST" "Binary found and copied: ${build_dir}/${bin}" "info"
|
|
bins_created=$((bins_created + 1))
|
|
else
|
|
display_alert "HDMI-TEST" "Binary not found: ${bin}" "warn"
|
|
fi
|
|
fi
|
|
done
|
|
|
|
# Check for library
|
|
if [[ -f "${out_dir}/libamlv4l2adaptation.so" ]] || [[ -f "${build_dir}/libamlv4l2adaptation.so" ]]; then
|
|
display_alert "HDMI-TEST" "Library created: libamlv4l2adaptation.so" "info"
|
|
fi
|
|
|
|
if [[ ${bins_created} -gt 0 ]]; then
|
|
display_alert "HDMI-TEST" "Build completed successfully (${bins_created} binaries)" "success"
|
|
else
|
|
display_alert "HDMI-TEST" "No binaries were created" "err"
|
|
return 1
|
|
fi
|
|
|
|
return 0
|
|
}
|
|
|
|
function __hdmi_test_install {
|
|
local build_dir="${1}"
|
|
local install_dir="${2}"
|
|
|
|
display_alert "HDMI-TEST" "Installing hdmi-test..." "info"
|
|
|
|
local out_dir="${build_dir}/output"
|
|
|
|
if [[ ! -d "${out_dir}" ]]; then
|
|
display_alert "HDMI-TEST" "Output directory not found: ${out_dir}" "err"
|
|
return 1
|
|
fi
|
|
|
|
# Create installation directories
|
|
mkdir -p "${install_dir}/usr/bin"
|
|
mkdir -p "${install_dir}/usr/lib"
|
|
mkdir -p "${install_dir}/usr/include"
|
|
|
|
# Determine which binaries to install based on mediactrlsrc feature
|
|
local binaries_to_install=("aml_hdmi_test")
|
|
|
|
# Check if mediactrlsrc feature is enabled
|
|
if is_feature_contains "$DISTRO_FEATURES" "mediactrlsrc"; then
|
|
binaries_to_install=("test_amlv4l2src" "aml_hdmi_test")
|
|
display_alert "HDMI-TEST" "mediactrlsrc enabled, installing both test_amlv4l2src and aml_hdmi_test" "info"
|
|
else
|
|
binaries_to_install=("aml_hdmi_test")
|
|
display_alert "HDMI-TEST" "mediactrlsrc disabled, installing only aml_hdmi_test" "info"
|
|
fi
|
|
|
|
# Install binaries
|
|
display_alert "HDMI-TEST" "Installing binaries: ${binaries_to_install[*]}" "info"
|
|
|
|
for bin in "${binaries_to_install[@]}"; do
|
|
local bin_path="${out_dir}/${bin}"
|
|
if [[ ! -f "${bin_path}" ]]; then
|
|
bin_path="${build_dir}/${bin}"
|
|
fi
|
|
|
|
if [[ -f "${bin_path}" ]]; then
|
|
install -m 0755 "${bin_path}" "${install_dir}/usr/bin/"
|
|
display_alert "HDMI-TEST" "Installed ${bin} to ${install_dir}/usr/bin/" "debug"
|
|
else
|
|
display_alert "HDMI-TEST" "Binary not found: ${bin}" "warn"
|
|
fi
|
|
done
|
|
|
|
# Install library if exists
|
|
local lib_path="${out_dir}/libamlv4l2adaptation.so"
|
|
if [[ ! -f "${lib_path}" ]]; then
|
|
lib_path="${build_dir}/libamlv4l2adaptation.so"
|
|
fi
|
|
|
|
if [[ -f "${lib_path}" ]]; then
|
|
install -m 0644 "${lib_path}" "${install_dir}/usr/lib/"
|
|
display_alert "HDMI-TEST" "Installed libamlv4l2adaptation.so to ${install_dir}/usr/lib/" "debug"
|
|
fi
|
|
|
|
# Install headers
|
|
display_alert "HDMI-TEST" "Installing headers..." "info"
|
|
|
|
local headers=("amlv4l2src_adaptation.h")
|
|
for header in "${headers[@]}"; do
|
|
local header_path="${build_dir}/${header}"
|
|
if [[ -f "${header_path}" ]]; then
|
|
install -m 0644 "${header_path}" "${install_dir}/usr/include/"
|
|
display_alert "HDMI-TEST" "Installed ${header} to ${install_dir}/usr/include/" "debug"
|
|
fi
|
|
done
|
|
|
|
display_alert "HDMI-TEST" "Installation completed successfully" "success"
|
|
return 0
|
|
}
|
|
|
|
function __hdmi_test_create_deb {
|
|
local build_dir="${1}"
|
|
local install_dir="${2}"
|
|
|
|
# Package details
|
|
local pkg_name="hdmi-test"
|
|
local version="${HDMI_TEST_VERSION}"
|
|
local architecture="${ARCH:-arm64}"
|
|
local maintainer="Amlbian Builder <[email protected]>"
|
|
local description="Amlogic HDMI Test Application"
|
|
local description_long="This package provides HDMI test application for Amlogic platforms, based on v4l2src patch for media controller support."
|
|
|
|
display_alert "HDMI-TEST" "Creating Debian package for ${pkg_name} ${version}..." "info"
|
|
|
|
# Create Debian package directory structure
|
|
local deb_dir="${build_dir}/deb/${pkg_name}-${version}"
|
|
local debian_dir="${deb_dir}/DEBIAN"
|
|
|
|
mkdir -p "${debian_dir}"
|
|
|
|
# Copy installed files to package directory
|
|
if [[ -d "${install_dir}" ]] && [[ "$(ls -A "${install_dir}")" ]]; then
|
|
cp -r "${install_dir}"/* "${deb_dir}/" 2>/dev/null || true
|
|
display_alert "HDMI-TEST" "Copied installed files to ${deb_dir}" "info"
|
|
else
|
|
display_alert "HDMI-TEST" "No installed files found in ${install_dir}" "warning"
|
|
return 0
|
|
fi
|
|
|
|
# Create control file
|
|
cat > "${debian_dir}/control" <<EOF
|
|
Package: ${pkg_name}
|
|
Version: ${version}
|
|
Architecture: ${architecture}
|
|
Maintainer: ${maintainer}
|
|
Description: ${description}
|
|
${description_long}
|
|
Depends: libc6
|
|
Section: utils
|
|
Priority: optional
|
|
EOF
|
|
|
|
# Create postinst script for ldconfig
|
|
cat > "${debian_dir}/postinst" << 'POSTINST_EOF'
|
|
#!/bin/sh
|
|
set -e
|
|
|
|
if [ "$1" = "configure" ]; then
|
|
# Update ldconfig cache if library is installed
|
|
if [ -f /usr/lib/libamlv4l2adaptation.so ] && command -v ldconfig >/dev/null 2>&1; then
|
|
ldconfig
|
|
fi
|
|
fi
|
|
|
|
exit 0
|
|
POSTINST_EOF
|
|
|
|
chmod 755 "${debian_dir}/postinst"
|
|
|
|
# Create prerm script
|
|
cat > "${debian_dir}/prerm" << 'PRERM_EOF'
|
|
#!/bin/sh
|
|
set -e
|
|
|
|
if [ "$1" = "remove" ] || [ "$1" = "deconfigure" ]; then
|
|
# Update ldconfig
|
|
if command -v ldconfig >/dev/null 2>&1; then
|
|
ldconfig
|
|
fi
|
|
fi
|
|
|
|
exit 0
|
|
PRERM_EOF
|
|
|
|
chmod 755 "${debian_dir}/prerm"
|
|
|
|
display_alert "HDMI-TEST" "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 "HDMI-TEST" "Debian package created: ${output_dir}/linux-${pkg_name}-${BOARD}-amlbian_${version}_${architecture}.deb" "success"
|
|
else
|
|
display_alert "HDMI-TEST" "Failed to build Debian package" "err"
|
|
return 1
|
|
fi
|
|
|
|
return 0
|
|
}
|
|
|
|
function amlbian_build_hdmi_test {
|
|
# Check if hdmi-test is enabled in BUILD_UNITS
|
|
if ! is_unit_enabled "hdmi-test"; then
|
|
display_alert "[SKIP] >> hdmi-test disable in BUILD_UNITS" "" "info"
|
|
return
|
|
fi
|
|
|
|
display_alert "AMLOGIC: Building hdmi-test ${HDMI_TEST_VERSION} ${BOARD}" "info"
|
|
|
|
# Define all directory paths (in .tmp directory)
|
|
local build_root="${BUILD_DIR}/.tmp/hdmi-test-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}"
|
|
|
|
# 创建目录
|
|
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"
|
|
|
|
# 准备源代码
|
|
__hdmi_test_prepare_source "${build_dir}"
|
|
|
|
# 构建
|
|
if ! __hdmi_test_build "${build_dir}"; then
|
|
display_alert "AMLOGIC: hdmi-test build failed" "err"
|
|
return 1
|
|
fi
|
|
|
|
# 安装到安装目录
|
|
if ! __hdmi_test_install "${build_dir}" "${install_dir}"; then
|
|
display_alert "AMLOGIC: hdmi-test installation failed" "err"
|
|
return 1
|
|
fi
|
|
|
|
display_alert "AMLOGIC: Creating Debian package..." "info"
|
|
__hdmi_test_create_deb "${build_dir}" "${install_dir}"
|
|
|
|
__unset_hdmi_test_config
|
|
|
|
return 0
|
|
}
|
|
|
|
# ==============================================================================
|
|
# Section 5: Main
|
|
# ==============================================================================
|
|
|
|
display_alert "AMLIbian HDMI Test Build Script" "Version: ${HDMI_TEST_VERSION}, Board: ${BOARD}" "info"
|
|
|
|
amlbian_build_hdmi_test
|
|
|
|
display_alert "AMLOGIC: hdmi-test build completed" "${BUILD_DIR}/output" "info"
|
|
|
|
# ==============================================================================
|
|
# End of build-hdmi-test.sh
|
|
# ============================================================================== |