407 lines
14 KiB
Bash
407 lines
14 KiB
Bash
#!/usr/bin/env bash
|
|
#
|
|
# SPDX-License-Identifier: GPL-2.0
|
|
#
|
|
# Copyright (c) 2026 AMLOGIC
|
|
#
|
|
# OPTEE video firmware build script for AMLbian
|
|
# This script builds OPTEE video firmware components package
|
|
|
|
set -e
|
|
|
|
# Get script directory
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
AMLBIAN_DIR="$(dirname "${SCRIPT_DIR}")"
|
|
AMLBIAN_DIR="$(dirname "${AMLBIAN_DIR}")" # Go up one more level from multimedia/tee
|
|
AMLBIAN_DIR="$(dirname "${AMLBIAN_DIR}")" # Go up one more level from scripts
|
|
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
|
|
# ==============================================================================
|
|
|
|
PLATFORM_TDK_VERSION="${PLATFORM_TDK_VERSION:-v3.18.0}"
|
|
TDK_VERSION="${TDK_VERSION:-v3.8/dev/S905D5}"
|
|
ARCH="${ARCH:-arm64}"
|
|
BOARD="${BOARD:-s6-bq201}"
|
|
|
|
# ==============================================================================
|
|
# Section 4: OPTEE Video Firmware Build Functions
|
|
# ==============================================================================
|
|
|
|
# Map architecture to ARM_TARGET for OPTEE video firmware
|
|
function __get_optee_video_arm_target() {
|
|
local arch="${1}"
|
|
case "${arch}" in
|
|
"arm"|"armhf")
|
|
echo "arm.aapcs-linux.hard"
|
|
;;
|
|
"arm64"|"aarch64")
|
|
echo "aarch64.lp64."
|
|
;;
|
|
*)
|
|
display_alert "OPTEE-VIDEO-FIRMWARE" "Unsupported architecture: ${arch}" "err"
|
|
exit 1
|
|
;;
|
|
esac
|
|
}
|
|
|
|
# Validate TDK version
|
|
function __validate_tdk_version() {
|
|
local platform_tdk_version="${1}"
|
|
local tdk_version="${2}"
|
|
|
|
case "${platform_tdk_version}" in
|
|
"v2.4.4"|"v3.8.0"|"v3.18.0"|"v4.4.0")
|
|
;;
|
|
*)
|
|
display_alert "OPTEE-VIDEO-FIRMWARE" "Unsupported platform TDK version: ${platform_tdk_version}" "err"
|
|
display_alert "OPTEE-VIDEO-FIRMWARE" "Supported versions: v2.4.4, v3.8.0, v3.18.0, v4.4.0" "info"
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
case "${tdk_version}" in
|
|
"v2.4"|"v3.8"|"v3.8/dev/S905D5"|v3.8/dev/A311Y3)
|
|
;;
|
|
*)
|
|
display_alert "OPTEE-VIDEO-FIRMWARE" "Unsupported TDK version: ${tdk_version}" "err"
|
|
display_alert "OPTEE-VIDEO-FIRMWARE" "Supported versions: v2.4 v3.8 v3.8/dev/S905D5" "info"
|
|
exit 1
|
|
;;
|
|
esac
|
|
}
|
|
|
|
# Get video firmware source path
|
|
function __get_video_firmware_source_path() {
|
|
|
|
# Try to find TDK in aml-comp
|
|
local aml_comp_path="$(amlbian_get_aml_comp_dir)"
|
|
if [[ -z "${aml_comp_path}" ]] || [[ ! -d "${aml_comp_path}" ]]; then
|
|
display_alert "OPTEE-VIDEO-FIRMWARE" "aml-comp not found" "err"
|
|
exit 1
|
|
fi
|
|
|
|
# Based on Yocto recipe: S = "${WORKDIR}/git/secfirmload/secloadbin"
|
|
local firmware_path="${aml_comp_path}/multimedia/secfirmload/secloadbin"
|
|
|
|
# Fallback: check if files are in ca_export directories
|
|
if [[ ! -d "${firmware_path}" ]]; then
|
|
display_alert "OPTEE-VIDEO-FIRMWARE" "Video firmware directory not found: ${firmware_path}" "err"
|
|
exit 1
|
|
fi
|
|
|
|
echo "${firmware_path}"
|
|
}
|
|
|
|
# Helper: Map architecture to ca_export directory name
|
|
function __get_arm_export_target() {
|
|
local arch="${1}"
|
|
case "${arch}" in
|
|
"arm"|"armhf")
|
|
echo "ca_export_arm"
|
|
;;
|
|
"arm64"|"aarch64")
|
|
echo "ca_export_arm64"
|
|
;;
|
|
*)
|
|
echo ""
|
|
;;
|
|
esac
|
|
}
|
|
|
|
# Main Installation Function
|
|
function __optee_video_firmware_install() {
|
|
local install_dir="${1}"
|
|
local platform_tdk_version="${PLATFORM_TDK_VERSION}"
|
|
local tdk_version="${TDK_VERSION}"
|
|
local arch="${ARCH}"
|
|
|
|
#__validate_tdk_version "${platform_tdk_version}" "${tdk_version}"
|
|
|
|
# Determine ARM_TARGET for video firmware
|
|
local arm_target="$(__get_optee_video_arm_target "${arch}")"
|
|
|
|
display_alert "OPTEE-VIDEO-FIRMWARE" "Installing OPTEE video firmware from TDK ${platform_tdk_version} ${tdk_version} (${arm_target})" "info"
|
|
|
|
# Get video firmware source path
|
|
local firmware_source="$(__get_video_firmware_source_path)"
|
|
display_alert "OPTEE-VIDEO-FIRMWARE" "Firmware source: ${firmware_source}" "info"
|
|
|
|
# Create directory structure
|
|
mkdir -p "${install_dir}/usr/bin"
|
|
mkdir -p "${install_dir}/usr/lib"
|
|
mkdir -p "${install_dir}/lib/optee_armtz"
|
|
mkdir -p "${install_dir}/usr/share/optee-video-firmware"
|
|
|
|
# TA target is always "noarch" for video firmware
|
|
local ta_target="noarch"
|
|
|
|
display_alert "OPTEE-VIDEO-FIRMWARE" "Installing TA files..." "info"
|
|
|
|
# Install TA files
|
|
local ta_dir="${firmware_source}/${ta_target}/ta/${tdk_version}"
|
|
if [[ -d "${ta_dir}" ]]; then
|
|
find "${ta_dir}" -name "*.ta" -type f -exec install -m 0644 {} "${install_dir}/lib/optee_armtz/" \;
|
|
local ta_count=$(find "${ta_dir}" -name "*.ta" -type f | wc -l)
|
|
display_alert "OPTEE-VIDEO-FIRMWARE" "Installed ${ta_count} TA files from ${ta_dir}" "debug"
|
|
else
|
|
display_alert "OPTEE-VIDEO-FIRMWARE" "TA directory not found: ${ta_dir}" "warn"
|
|
fi
|
|
|
|
display_alert "OPTEE-VIDEO-FIRMWARE" "Installing library..." "info"
|
|
|
|
# Install library file
|
|
local lib_file="${firmware_source}/${platform_tdk_version}/${arm_target}/libtee_preload_fw.so"
|
|
if [[ -f "${lib_file}" ]]; then
|
|
install -m 0644 "${lib_file}" "${install_dir}/usr/lib/"
|
|
display_alert "OPTEE-VIDEO-FIRMWARE" "Installed libtee_preload_fw.so" "debug"
|
|
else
|
|
display_alert "OPTEE-VIDEO-FIRMWARE" "Library file not found: ${lib_file}" "warn"
|
|
fi
|
|
|
|
display_alert "OPTEE-VIDEO-FIRMWARE" "Installing binary..." "info"
|
|
|
|
# Install binary file
|
|
local bin_file="${firmware_source}/${platform_tdk_version}/${arm_target}/tee_preload_fw"
|
|
if [[ -f "${bin_file}" ]]; then
|
|
install -m 0755 "${bin_file}" "${install_dir}/usr/bin/"
|
|
display_alert "OPTEE-VIDEO-FIRMWARE" "Installed tee_preload_fw" "debug"
|
|
else
|
|
display_alert "OPTEE-VIDEO-FIRMWARE" "Binary file not found: ${bin_file}" "warn"
|
|
fi
|
|
|
|
display_alert "OPTEE-VIDEO-FIRMWARE" "Installing system service files..." "info"
|
|
|
|
# Install systemd service file (if available)
|
|
local service_file="${SCRIPT_DIR}/optee-video-firmware/videoFirmwarePreload.service"
|
|
if [[ -f "${service_file}" ]]; then
|
|
mkdir -p "${install_dir}/usr/lib/systemd/system"
|
|
install -m 0644 "${service_file}" "${install_dir}/usr/lib/systemd/system/"
|
|
display_alert "OPTEE-VIDEO-FIRMWARE" "Installed systemd service file" "debug"
|
|
else
|
|
display_alert "OPTEE-VIDEO-FIRMWARE" "Systemd service file not found, skipping" "info"
|
|
fi
|
|
|
|
# Install init script (if available)
|
|
local init_script="${SCRIPT_DIR}/optee-video-firmware/videoFirmwarePreload.init"
|
|
if [[ -f "${init_script}" ]]; then
|
|
mkdir -p "${install_dir}/etc/init.d"
|
|
install -m 0755 "${init_script}" "${install_dir}/etc/init.d/videoFirmwarePreload"
|
|
display_alert "OPTEE-VIDEO-FIRMWARE" "Installed init script" "debug"
|
|
else
|
|
display_alert "OPTEE-VIDEO-FIRMWARE" "Init script not found, skipping" "info"
|
|
fi
|
|
|
|
display_alert "OPTEE-VIDEO-FIRMWARE" "Installation completed" "success"
|
|
return 0
|
|
}
|
|
|
|
# Debian Package Creation
|
|
function __optee_video_firmware_create_deb() {
|
|
local build_dir="${1}"
|
|
local install_dir="${2}"
|
|
local platform_tdk_version="${PLATFORM_TDK_VERSION}"
|
|
local arch="${ARCH}"
|
|
local pkg_arch="${arch}"
|
|
|
|
# Package details
|
|
local pkg_name="optee-video-firmware"
|
|
local pkg_version="${platform_tdk_version#v}" # Remove 'v' prefix
|
|
local pkg_maintainer="Amlbian Builder <[email protected]>"
|
|
local pkg_description="OPTEE video firmware components (TA files, preload library)"
|
|
local pkg_description_long="This package provides OPTEE (Open Portable Trusted Execution Environment) video firmware components including Trusted Applications (TA), preload library, and system service for video firmware loading."
|
|
|
|
display_alert "OPTEE-VIDEO-FIRMWARE" "Creating Debian package ${pkg_name}_${pkg_version}_${pkg_arch}.deb" "info"
|
|
|
|
# Create package directory structure
|
|
local deb_dir="${build_dir}/deb/${pkg_name}-${pkg_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 "OPTEE-VIDEO-FIRMWARE" "Copied installed files to package directory" "debug"
|
|
else
|
|
display_alert "OPTEE-VIDEO-FIRMWARE" "No installed files found in ${install_dir}" "error"
|
|
return 1
|
|
fi
|
|
|
|
# Create control file with dependency on optee-userspace
|
|
cat > "${debian_dir}/control" <<EOF
|
|
Package: ${pkg_name}
|
|
Version: ${pkg_version}
|
|
Architecture: ${pkg_arch}
|
|
Maintainer: ${pkg_maintainer}
|
|
Depends: optee-userspace, libbz2-1.0
|
|
Description: ${pkg_description}
|
|
${pkg_description_long}
|
|
Section: libs
|
|
Priority: optional
|
|
EOF
|
|
|
|
# Create postinst script for systemd service
|
|
cat > "${debian_dir}/postinst" << 'EOF'
|
|
#!/bin/sh
|
|
set -e
|
|
|
|
case "$1" in
|
|
configure)
|
|
# Update ldconfig cache
|
|
if command -v ldconfig >/dev/null 2>&1; then
|
|
ldconfig
|
|
fi
|
|
|
|
# Enable systemd service if systemd is available
|
|
if command -v systemctl >/dev/null 2>&1 && [ -f /usr/lib/systemd/system/videoFirmwarePreload.service ]; then
|
|
systemctl daemon-reload >/dev/null 2>&1 || true
|
|
systemctl enable videoFirmwarePreload.service >/dev/null 2>&1 || true
|
|
fi
|
|
|
|
# Update init.d scripts if systemd is not used
|
|
if [ ! -x /bin/systemctl ] && [ -f /etc/init.d/videoFirmwarePreload ]; then
|
|
update-rc.d videoFirmwarePreload defaults >/dev/null 2>&1 || true
|
|
fi
|
|
;;
|
|
*)
|
|
;;
|
|
esac
|
|
|
|
exit 0
|
|
EOF
|
|
chmod 755 "${debian_dir}/postinst"
|
|
|
|
# Create prerm script
|
|
cat > "${debian_dir}/prerm" << 'EOF'
|
|
#!/bin/sh
|
|
set -e
|
|
|
|
case "$1" in
|
|
remove|deconfigure)
|
|
# Stop service if running
|
|
if [ -f /etc/init.d/videoFirmwarePreload ]; then
|
|
/etc/init.d/videoFirmwarePreload stop >/dev/null 2>&1 || true
|
|
fi
|
|
|
|
if command -v systemctl >/dev/null 2>&1 && [ -f /usr/lib/systemd/system/videoFirmwarePreload.service ]; then
|
|
systemctl stop videoFirmwarePreload.service >/dev/null 2>&1 || true
|
|
systemctl disable videoFirmwarePreload.service >/dev/null 2>&1 || true
|
|
fi
|
|
;;
|
|
*)
|
|
;;
|
|
esac
|
|
|
|
exit 0
|
|
EOF
|
|
chmod 755 "${debian_dir}/prerm"
|
|
|
|
# Create postrm script
|
|
cat > "${debian_dir}/postrm" << 'EOF'
|
|
#!/bin/sh
|
|
set -e
|
|
|
|
case "$1" in
|
|
purge|remove)
|
|
# Update ldconfig
|
|
if command -v ldconfig >/dev/null 2>&1; then
|
|
ldconfig
|
|
fi
|
|
|
|
# Clean up init.d scripts
|
|
if [ -f /etc/init.d/videoFirmwarePreload ]; then
|
|
update-rc.d -f videoFirmwarePreload remove >/dev/null 2>&1 || true
|
|
rm -f /etc/init.d/videoFirmwarePreload
|
|
fi
|
|
|
|
# Clean up systemd service
|
|
if [ -f /usr/lib/systemd/system/videoFirmwarePreload.service ]; then
|
|
rm -f /usr/lib/systemd/system/videoFirmwarePreload.service
|
|
systemctl daemon-reload >/dev/null 2>&1 || true
|
|
fi
|
|
;;
|
|
*)
|
|
;;
|
|
esac
|
|
|
|
exit 0
|
|
EOF
|
|
chmod 755 "${debian_dir}/postrm"
|
|
|
|
# Build Debian package
|
|
cd "${build_dir}/deb"
|
|
dpkg-deb --build "${pkg_name}-${pkg_version}" >/dev/null 2>&1
|
|
|
|
local deb_file="${pkg_name}-${pkg_version}.deb"
|
|
if [[ -f "${deb_file}" ]]; then
|
|
# Move to output directory
|
|
local output_dir="${BUILD_DIR}/output"
|
|
mkdir -p "${output_dir}"
|
|
mv "${deb_file}" "${output_dir}/linux-${pkg_name}-${BOARD}-amlbian_${pkg_version}_${pkg_arch}.deb"
|
|
display_alert "OPTEE-VIDEO-FIRMWARE" "Package created: ${output_dir}/linux-${pkg_name}-${BOARD}-amlbian_${pkg_version}_${pkg_arch}.deb" "success"
|
|
return 0
|
|
else
|
|
display_alert "OPTEE-VIDEO-FIRMWARE" "Failed to build Debian package" "error"
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
function amlbian_build_optee_video_firmware() {
|
|
# Check if optee-video-firmware is enabled
|
|
if ! is_unit_enabled "optee-video-firmware" && ! is_unit_enabled "optee"; then
|
|
display_alert "[SKIP] >> optee-video-firmware disabled (optee not enabled)" "" "info"
|
|
return
|
|
fi
|
|
|
|
display_alert "AMLOGIC: Building OPTEE video firmware package ${PLATFORM_TDK_VERSION} ${ARCH} ${BOARD}" "info"
|
|
|
|
# Create build directory structure
|
|
local build_root="${BUILD_DIR}/.tmp/optee-video-firmware-build-${ARCH}"
|
|
local build_dir="${build_root}/build"
|
|
local install_dir="${build_root}/install"
|
|
|
|
rm -rf "${build_root}"
|
|
|
|
# Create directories
|
|
mkdir -p "${build_dir}" "${install_dir}"
|
|
|
|
display_alert "AMLOGIC: Build directory: ${build_dir}" "info"
|
|
display_alert "AMLOGIC: Install directory: ${install_dir}" "info"
|
|
display_alert "AMLOGIC: output_dir ${BUILD_DIR}/output" "info"
|
|
|
|
# Install OPTEE video firmware components
|
|
if ! __optee_video_firmware_install "${install_dir}"; then
|
|
display_alert "AMLOGIC: OPTEE video firmware installation failed" "error"
|
|
return 1
|
|
fi
|
|
|
|
# Create Debian package
|
|
if ! __optee_video_firmware_create_deb "${build_dir}" "${install_dir}"; then
|
|
display_alert "AMLOGIC: Package creation failed" "error"
|
|
return 1
|
|
fi
|
|
|
|
display_alert "AMLOGIC: OPTEE video firmware package build completed successfully" "success"
|
|
return 0
|
|
}
|
|
|
|
# ==============================================================================
|
|
# Section 5: Main
|
|
# ==============================================================================
|
|
|
|
display_alert "AMLIbian OPTEE Video Firmware Build Script" "TDK Version: ${PLATFORM_TDK_VERSION}, Arch: ${ARCH}, Board: ${BOARD}" "info"
|
|
|
|
amlbian_build_optee_video_firmware
|
|
|
|
display_alert "AMLOGIC: OPTEE video firmware build completed" "${BUILD_DIR}/output" "info"
|
|
|
|
# ==============================================================================
|
|
# End of build-optee-video-firmware.sh
|
|
# ============================================================================== |