#!/usr/bin/env bash # # SPDX-License-Identifier: GPL-2.0 # # Copyright (c) 2026 AMLOGIC # # Vendor files build script for AMLbian # This script installs vendor configuration files for Amlogic soc_names 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/tvserver AMLBIAN_DIR="$(dirname "${AMLBIAN_DIR}")" # Go up one more level from scripts BUILD_DIR="${AMLBIAN_DIR}/../build" MODULE_BUILD_DIR="${SRC}/output/.tmp" # ============================================================================== # Section 2: Default Configuration # ============================================================================== BOARD="${BOARD:-s6-bq201}" DEB_VERSION="${VENDOR_FILES_VERSION:-1.0.0}" ARCH="${ARCH:-arm64}" # DISTRO_FEATURES from environment DISTRO_FEATURES="${DISTRO_FEATURES:-}" # MACHINE_EXTRA_RRECOMMENDS from environment MACHINE_EXTRA_RRECOMMENDS="${MACHINE_EXTRA_RRECOMMENDS:-}" # ============================================================================== # Section 3: soc_name Mapping Functions # ============================================================================== # Check if DISTRO_FEATURES contains a specific feature function __distro_feature_contains() { local feature="$1" is_feature_contains "${DISTRO_FEATURES}" "${feature}" return $? } # Check if MACHINE_EXTRA_RRECOMMENDS contains a specific item function __machine_extra_rrecommends_contains() { local item="$1" is_feature_contains "${MACHINE_EXTRA_RRECOMMENDS}" "${item}" return $? } # ============================================================================== # Section 4: Vendor Files Build Functions # ============================================================================== function __vendor_files_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 "VENDOR-FILES" "aml-comp not found: ${aml_comp_path}" exit 1 fi local source_dir="${aml_comp_path}/prebuilt/vendor" if [[ ! -d "${source_dir}" ]]; then aml_log error "VENDOR-FILES" "Source directory not found: ${source_dir}" exit 1 fi aml_log info "VENDOR-FILES" "Copying source from ${source_dir} to ${build_dir}" # 清空构建目录 rm -rf "${build_dir}" mkdir -p "${build_dir}" # 复制源代码到构建目录 cp -r "${source_dir}"/* "${build_dir}/" 2>/dev/null || true display_alert "VENDOR-FILES" "Source prepared successfully" "success" } function __vendor_files_install { local build_dir="${1}" local install_dir="${2}" aml_log info "VENDOR-FILES" "Installing vendor configuration files..." # 获取soc_name local soc_name="${CHIPSET_NAME,,}" aml_log info "VENDOR-FILES" "Using soc_name: ${soc_name} for board: ${BOARD}" # 创建基本目录结构 mkdir -p "${install_dir}/vendor/etc" mkdir -p "${install_dir}/vendor/etc/halaudio" mkdir -p "${install_dir}/vendor/etc/tvconfig/pq" mkdir -p "${install_dir}/vendor/firmware" mkdir -p "${install_dir}/vendor/firmware/wireless" mkdir -p "${install_dir}/lib/firmware" local source_tvconfig="${build_dir}/etc/tvconfig" # 检查soc_name目录是否存在 if [[ -d "${source_tvconfig}/${soc_name}" ]]; then # audio_effects.xml if [[ -e "${source_tvconfig}/${soc_name}/audio_effects.xml" ]]; then install -m 0644 -D "${source_tvconfig}/${soc_name}/audio_effects.xml" "${install_dir}/vendor/etc/audio_effects.xml" aml_log debug "VENDOR-FILES" "Installed audio_effects.xml" fi # ms12_tuning.dat if [[ -e "${source_tvconfig}/${soc_name}/ms12_tuning.dat" ]]; then install -m 0644 -D "${source_tvconfig}/${soc_name}/ms12_tuning.dat" "${install_dir}/vendor/etc/ms12_tuning.dat" aml_log debug "VENDOR-FILES" "Installed ms12_tuning.dat" fi # ms12_tuning_v28.dat if [[ -e "${source_tvconfig}/${soc_name}/ms12_tuning_v28.dat" ]]; then install -m 0644 -D "${source_tvconfig}/${soc_name}/ms12_tuning_v28.dat" "${install_dir}/vendor/etc/ms12_tuning_v28.dat" aml_log debug "VENDOR-FILES" "Installed ms12_tuning_v28.dat" fi # aml_audio_config.json if [[ -e "${source_tvconfig}/${soc_name}/aml_audio_config.json" ]]; then if __distro_feature_contains "disable-audio-server"; then if [[ -e "${source_tvconfig}/${soc_name}/aml_audio_config.zapper.json" ]]; then install -m 0644 -D "${source_tvconfig}/${soc_name}/aml_audio_config.zapper.json" "${install_dir}/vendor/etc/halaudio/aml_audio_config.json" aml_log debug "VENDOR-FILES" "Installed aml_audio_config.zapper.json (disable-audio-server)" else install -m 0644 -D "${source_tvconfig}/${soc_name}/aml_audio_config.json" "${install_dir}/vendor/etc/halaudio/aml_audio_config.json" aml_log debug "VENDOR-FILES" "Installed aml_audio_config.json" fi else install -m 0644 -D "${source_tvconfig}/${soc_name}/aml_audio_config.json" "${install_dir}/vendor/etc/halaudio/aml_audio_config.json" aml_log debug "VENDOR-FILES" "Installed aml_audio_config.json" fi else if [[ -e "${source_tvconfig}/default_conf/aml_audio_config.json" ]]; then install -m 0644 -D "${source_tvconfig}/default_conf/aml_audio_config.json" "${install_dir}/vendor/etc/halaudio/aml_audio_config.json" aml_log debug "VENDOR-FILES" "Installed default aml_audio_config.json" fi fi # 低内存配置调整 if __distro_feature_contains "low-memory"; then if [[ -e "${install_dir}/vendor/etc/halaudio/aml_audio_config.json" ]]; then sed -i '/Codec_Support_List/i \\t"Audio_Delay_Max":100,' "${install_dir}/vendor/etc/halaudio/aml_audio_config.json" aml_log debug "VENDOR-FILES" "Applied low-memory configuration to aml_audio_config.json" fi fi # mixer_paths.xml if [[ -e "${source_tvconfig}/${soc_name}/mixer_paths.xml" ]]; then install -m 0644 -D "${source_tvconfig}/${soc_name}/mixer_paths.xml" "${install_dir}/vendor/etc/mixer_paths.xml" aml_log debug "VENDOR-FILES" "Installed mixer_paths.xml" else if [[ -e "${source_tvconfig}/default_conf/mixer_paths.xml" ]]; then install -m 0644 -D "${source_tvconfig}/default_conf/mixer_paths.xml" "${install_dir}/vendor/etc/mixer_paths.xml" aml_log debug "VENDOR-FILES" "Installed default mixer_paths.xml" fi fi # audio_hal_delay_base.json if [[ -e "${source_tvconfig}/${soc_name}/audio_hal_delay_base.json" ]]; then install -m 0644 -D "${source_tvconfig}/${soc_name}/audio_hal_delay_base.json" "${install_dir}/vendor/etc/halaudio/audio_hal_delay_base.json" aml_log debug "VENDOR-FILES" "Installed audio_hal_delay_base.json" else if [[ -e "${source_tvconfig}/default_conf/audio_hal_delay_base.json" ]]; then install -m 0644 -D "${source_tvconfig}/default_conf/audio_hal_delay_base.json" "${install_dir}/vendor/etc/halaudio/audio_hal_delay_base.json" aml_log debug "VENDOR-FILES" "Installed default audio_hal_delay_base.json" fi fi # ms12_audio_profiles.ini if [[ -e "${source_tvconfig}/default_conf/ms12_audio_profiles.ini" ]]; then install -m 0644 -D "${source_tvconfig}/default_conf/ms12_audio_profiles.ini" "${install_dir}/vendor/etc/halaudio/ms12_audio_profiles.ini" aml_log debug "VENDOR-FILES" "Installed ms12_audio_profiles.ini" fi # aml_audio_default_ui.ini if [[ -e "${source_tvconfig}/default_conf/aml_audio_default_ui.ini" ]]; then install -m 0644 -D "${source_tvconfig}/default_conf/aml_audio_default_ui.ini" "${install_dir}/vendor/etc/halaudio/aml_audio_default_ui.ini" aml_log debug "VENDOR-FILES" "Installed aml_audio_default_ui.ini" fi # PQ配置文件 if [[ -e "${source_tvconfig}/${soc_name}/PQ" ]]; then aml_log info "VENDOR-FILES" "Installing PQ configuration files" # pq_default.ini if [[ -e "${source_tvconfig}/${soc_name}/PQ/pq_default.ini" ]]; then install -m 0644 -D "${source_tvconfig}/${soc_name}/PQ/pq_default.ini" "${install_dir}/vendor/etc/tvconfig/pq/pq_default.ini" aml_log debug "VENDOR-FILES" "Installed pq_default.ini" fi # pq.db处理 if [[ -e "${source_tvconfig}/${soc_name}/PQ/pq.db" ]]; then if __distro_feature_contains "pq-compress-db"; then # 压缩pq.db (cd "${source_tvconfig}/${soc_name}/PQ" && \ /usr/bin/zip "${install_dir}/vendor/etc/tvconfig/pq/pq.db.zip" pq.db && \ md5sum pq.db > "${install_dir}/vendor/etc/tvconfig/pq/pq.db.md5") aml_log debug "VENDOR-FILES" "Compressed pq.db to pq.db.zip" # 更新pq_default.ini中的路径 if [[ -e "${install_dir}/vendor/etc/tvconfig/pq/pq_default.ini" ]]; then sed -i '/pq_db_config_path/d' "${install_dir}/vendor/etc/tvconfig/pq/pq_default.ini" sed -i "/^\[PQ\]/a pq_db_config_path = ${PQ_DB_EXTRACT_DEST:-/vendor/etc/tvconfig/pq}" \ "${install_dir}/vendor/etc/tvconfig/pq/pq_default.ini" fi else # 直接复制 install -m 0644 -D "${source_tvconfig}/${soc_name}/PQ/pq.db" "${install_dir}/vendor/etc/tvconfig/pq/pq.db" aml_log debug "VENDOR-FILES" "Installed pq.db" if [[ -e "${source_tvconfig}/${soc_name}/PQ/UI_PQSetting.bin" ]]; then install -m 0644 -D "${source_tvconfig}/${soc_name}/PQ/UI_PQSetting.bin" "${install_dir}/vendor/etc/tvconfig/pq/UI_PQSetting.bin" aml_log debug "VENDOR-FILES" "Installed UI_PQSetting.bin" fi fi fi # overscan.db if [[ -e "${source_tvconfig}/${soc_name}/PQ/overscan.db" ]]; then install -m 0644 -D "${source_tvconfig}/${soc_name}/PQ/overscan.db" "${install_dir}/vendor/etc/tvconfig/pq/overscan.db" aml_log debug "VENDOR-FILES" "Installed overscan.db" fi # 更新vendor分区路径 if ! __distro_feature_contains "vendor-partition"; then if [[ -e "${install_dir}/vendor/etc/tvconfig/pq/pq_default.ini" ]]; then sed -i 's|/vendor/etc/tvconfig/pq|/etc/tvconfig/pq|g' "${install_dir}/vendor/etc/tvconfig/pq/pq_default.ini" aml_log debug "VENDOR-FILES" "Updated vendor partition paths in pq_default.ini" fi fi # 添加用户数据和工厂数据路径 if [[ -e "${install_dir}/vendor/etc/tvconfig/pq/pq_default.ini" ]]; then sed -i '/pq_uiSettingDataFile_path/d; /pq_FactorywhiteBalance_path/d' \ "${install_dir}/vendor/etc/tvconfig/pq/pq_default.ini" sed -i "/^\[PQ\]/a pq_uiSettingDataFile_path = ${PQ_USER_DATA_PATH:-/data/pq_user_data}\npq_FactorywhiteBalance_path = ${PQ_FACTORY_DATA_PATH:-/data/pq_factory_data}" \ "${install_dir}/vendor/etc/tvconfig/pq/pq_default.ini" aml_log debug "VENDOR-FILES" "Added PQ data paths to pq_default.ini" fi fi # tvconfig目录文件 if [[ -e "${source_tvconfig}/${soc_name}/tvconfig" ]]; then aml_log info "VENDOR-FILES" "Installing tvconfig files" cd "${source_tvconfig}/${soc_name}/tvconfig" find . -type f | while read -r file; do install -m 0644 -D "${file}" "${install_dir}/vendor/etc/tvconfig/${file}" done aml_log debug "VENDOR-FILES" "Installed tvconfig files" fi # Soundbar配置 if __distro_feature_contains "soundbar"; then local soundbar_conf="${source_tvconfig}/${soc_name}/soundbar_conf" if [[ -d "${soundbar_conf}" ]]; then aml_log info "VENDOR-FILES" "Installing soundbar configuration" if [[ -e "${soundbar_conf}/audio_effects.xml" ]]; then install -m 0644 -D "${soundbar_conf}/audio_effects.xml" "${install_dir}/vendor/etc/audio_effects.xml" aml_log debug "VENDOR-FILES" "Installed soundbar audio_effects.xml" fi if [[ -e "${soundbar_conf}/mixer_paths.xml" ]]; then install -m 0644 -D "${soundbar_conf}/mixer_paths.xml" "${install_dir}/vendor/etc/mixer_paths.xml" aml_log debug "VENDOR-FILES" "Installed soundbar mixer_paths.xml" fi if [[ -e "${soundbar_conf}/aml_audio_config.json" ]]; then install -m 0644 -D "${soundbar_conf}/aml_audio_config.json" "${install_dir}/vendor/etc/halaudio/aml_audio_config.json" aml_log debug "VENDOR-FILES" "Installed soundbar aml_audio_config.json" fi if [[ -e "${soundbar_conf}/ms12_tuning_2_0.dat" ]]; then install -m 0644 -D "${soundbar_conf}/ms12_tuning_2_0.dat" "${install_dir}/vendor/etc/ms12_tuning.dat" aml_log debug "VENDOR-FILES" "Installed soundbar ms12_tuning_2_0.dat" fi if [[ -e "${soundbar_conf}/ms12_tuning_4_0.dat" ]]; then install -m 0644 -D "${soundbar_conf}/ms12_tuning_4_0.dat" "${install_dir}/vendor/etc/ms12_tuning_4_0.dat" aml_log debug "VENDOR-FILES" "Installed soundbar ms12_tuning_4_0.dat" fi fi fi else # soc_name目录不存在的情况 aml_log warn "VENDOR-FILES" "soc_name directory ${soc_name} not found, creating dummy files" # 创建虚拟文件 install -d "${install_dir}/vendor/etc/tvconfig/" touch "${install_dir}/vendor/etc/tvconfig/dummy" # 检查是否有直接的soc_name目录 if [[ -d "${build_dir}/${soc_name}" ]]; then install -d "${install_dir}/vendor/p1_pxp" cd "${build_dir}/${soc_name}" find . -type f | while read -r file; do install -m 0644 -D "${file}" "${install_dir}/vendor/p1_pxp/${file}" done aml_log debug "VENDOR-FILES" "Installed files to p1_pxp directory" fi fi # 安装蓝牙固件 if __distro_feature_contains "bluetooth"; then if [[ -e "${build_dir}/firmware/remote_ota.bin" ]]; then install -m 0644 "${build_dir}/firmware/remote_ota.bin" "${install_dir}/vendor/firmware/" aml_log debug "VENDOR-FILES" "Installed remote_ota.bin" fi fi # 安装无线固件 if __machine_extra_rrecommends_contains "aml-bt-w2"; then if __distro_feature_contains "amlogic-tv"; then if [[ -d "${build_dir}/wireless" ]]; then # 安装W2蓝牙固件 for fw_file in "${build_dir}/wireless/bt_firmware/w2_bt_"*"usb.bin"; do if [[ -e "${fw_file}" ]]; then install -m 0644 "${fw_file}" "${install_dir}/vendor/firmware/wireless/" aml_log debug "VENDOR-FILES" "Installed W2 BT firmware: $(basename "${fw_file}")" fi done # 安装蓝牙配置文件 if [[ -e "${build_dir}/wireless/aml_bt.conf" ]]; then install -m 0644 "${build_dir}/wireless/aml_bt.conf" "${install_dir}/vendor/firmware/wireless/" aml_log debug "VENDOR-FILES" "Installed aml_bt.conf" fi fi fi fi if __machine_extra_rrecommends_contains "aml-bt-w2l"; then if __distro_feature_contains "amlogic-tv"; then if [[ -d "${build_dir}/wireless" ]]; then # 安装W2L蓝牙固件 for fw_file in "${build_dir}/wireless/bt_firmware/w2l_bt_"*"usb.bin"; do if [[ -e "${fw_file}" ]]; then install -m 0644 "${fw_file}" "${install_dir}/vendor/firmware/wireless/" aml_log debug "VENDOR-FILES" "Installed W2L BT firmware: $(basename "${fw_file}")" fi done # 安装蓝牙配置文件 if [[ -e "${build_dir}/wireless/aml_bt.conf" ]]; then install -m 0644 "${build_dir}/wireless/aml_bt.conf" "${install_dir}/vendor/firmware/wireless/" aml_log debug "VENDOR-FILES" "Installed aml_bt.conf" fi fi fi fi if __distro_feature_contains "audio-sed"; then if [[ -e "${build_dir}/firmware/audio/sed.bin" ]]; then install -m 0644 "${build_dir}/firmware/audio/sed.bin" "${install_dir}/lib/firmware" aml_log debug "VENDOR-FILES" "Applied audio-sed configuration to lib/firmware" fi fi display_alert "VENDOR-FILES" "Installation completed successfully" "success" return 0 } function __vendor_files_create_deb { local build_dir="${1}" local install_dir="${2}" # 设置必要的变量 local pkg_name="vendor-files" local version="${DEB_VERSION}" local architecture="${ARCH}" local maintainer="Armbian Build " local description="Vendor configuration files for Amlogic platforms" local description_long="This package provides vendor configuration files (audio, video, bluetooth, etc.) for Amlogic platforms." aml_log info "VENDOR-FILES" "Creating Debian package for ${pkg_name} ${version}..." # 创建Debian包控制文件 local deb_dir="${build_dir}/deb/${pkg_name}-${version}" local debian_dir="${deb_dir}/DEBIAN" mkdir -p "${debian_dir}" # 将安装目录的内容复制到debian-root if [[ -d "${install_dir}" ]] && [[ "$(ls -A "${install_dir}")" ]]; then cp -r "${install_dir}"/* "${deb_dir}/" 2>/dev/null || true aml_log info "VENDOR-FILES" "Copied installed files to ${deb_dir}" else aml_log warn "VENDOR-FILES" "No installed files found in ${install_dir}" return 0 fi # 创建control文件 cat > "${debian_dir}/control" < "${debian_dir}/postinst" < "${debian_dir}/prerm" <> vendor-files disable in BUILD_UNITS" return fi if ! is_feature_contains "$DISTRO_FEATURES" "vendor-files"; then aml_log info "[SKIP] >> vendor-files disable in DISTRO_FEATURES" return fi aml_log info "AMLOGIC: Building vendor files ${DEB_VERSION} ${BOARD}" # Define all directory paths (in .tmp directory) local build_root="${MODULE_BUILD_DIR}/vendor-files-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}" aml_log info "AMLOGIC: build_dir ${build_dir}" aml_log info "AMLOGIC: install_dir ${install_dir}" aml_log info "AMLOGIC: output_dir ${BUILD_DIR}/output" # 准备源代码 __vendor_files_prepare_source "${build_dir}" # 安装文件 if ! __vendor_files_install "${build_dir}" "${install_dir}"; then aml_log error "AMLOGIC: Vendor files installation failed" return 1 fi aml_log info "AMLOGIC: Creating Debian package..." __vendor_files_create_deb "${build_dir}" "${install_dir}" return 0 } # ============================================================================== # Section 5: Main # ============================================================================== aml_log info "AMLIbian Vendor Files Build Script" "Version: ${DEB_VERSION}, Board: ${BOARD}" amlbian_build_vendor_files aml_log info "AMLOGIC: Vendor files build completed" "${BUILD_DIR}/output" # ============================================================================== # End of build-vendor-files.sh # ==============================================================================