From 067d58e84bdbecaa0132806293b5f80cbcc26c0a Mon Sep 17 00:00:00 2001 From: Renjiang Han Date: Wed, 28 Jan 2026 21:02:48 +0530 Subject: [PATCH 1/2] video: driver: add DKMS packaging for MSM VIDC video driver overlay Add Debian packaging files to build the MSM VIDC video driver as a DKMS overlay package. This change introduces: - Initial debian/ packaging (control, rules, changelog, copyright) - DKMS configuration for out-of-tree video kernel module - Install rules to deploy driver sources under /usr/src for DKMS - Support for multiple platforms via device tree compatible detection - Unified build system with DKMS build wrapper - Automatic module build on install using /lib/modules/${kernelver}/build The DKMS package enables on-target kernel module compilation and supports multiple ARM64 platforms with isolated, overlay-based builds. Change-Id: I8ac6a76a63f697984a9c8a7cdd73f7c0c1755b51 Signed-off-by: Renjiang Han --- pkg-video-driver/debian/changelog | 13 + pkg-video-driver/debian/control | 24 ++ pkg-video-driver/debian/copyright | 15 ++ pkg-video-driver/debian/postinst | 228 ++++++++++++++++++ pkg-video-driver/debian/postrm | 60 +++++ pkg-video-driver/debian/prerm | 99 ++++++++ pkg-video-driver/debian/rules | 32 +++ .../debian/video-driver-dkms.install | 8 + pkg-video-driver/dkms.conf | 19 ++ 9 files changed, 498 insertions(+) create mode 100644 pkg-video-driver/debian/changelog create mode 100644 pkg-video-driver/debian/control create mode 100644 pkg-video-driver/debian/copyright create mode 100644 pkg-video-driver/debian/postinst create mode 100644 pkg-video-driver/debian/postrm create mode 100644 pkg-video-driver/debian/prerm create mode 100644 pkg-video-driver/debian/rules create mode 100644 pkg-video-driver/debian/video-driver-dkms.install create mode 100644 pkg-video-driver/dkms.conf diff --git a/pkg-video-driver/debian/changelog b/pkg-video-driver/debian/changelog new file mode 100644 index 00000000..a9ba4c44 --- /dev/null +++ b/pkg-video-driver/debian/changelog @@ -0,0 +1,13 @@ +video-driver (1.0.0-1) unstable; urgency=medium + + * Initial DKMS package for MSM VIDC driver + * Support for multiple platforms via device tree detection + * Automatic platform configuration based on compatible string + * Cross-compilation support for ARM64 platforms + * Platforms supported: hamoa, lemans + * Auto-detection of platform from device tree compatible string + * Unified cross-compilation environment for all platforms + * Complete build isolation in pkg-video-driver directory + * Fixed: Proper handling of multiple compatible strings in device tree + + -- Renjiang Han Tue, 28 Jan 2026 15:10:00 +0800 diff --git a/pkg-video-driver/debian/control b/pkg-video-driver/debian/control new file mode 100644 index 00000000..797e4dca --- /dev/null +++ b/pkg-video-driver/debian/control @@ -0,0 +1,24 @@ +Source: video-driver +Section: kernel +Priority: optional +Maintainer: Renjiang Han +Build-Depends: debhelper-compat (= 13), dkms +Standards-Version: 4.6.2 +Homepage: https://github.com/qualcomm-linux/video-driver + +Package: video-driver-dkms +Architecture: all +Depends: dkms (>= 2.6), kmod, ${misc:Depends} +Conflicts: qcom-iris-dkms +Description: DKMS package for MSM VIDC driver (out-of-tree) + This package installs source for the 'video' kernel module and builds + it via DKMS on the target machine using /lib/modules/${kernelver}/build. + . + DKMS packaging for MSM VIDC driver (out-of-tree). + Build occurs on install via /lib/modules/${kernelver}/build. + . + The driver supports multiple platforms and automatically detects the + platform from device tree compatible string to enable appropriate + configuration macros. + . + Supported platforms: hamoa, lemans. diff --git a/pkg-video-driver/debian/copyright b/pkg-video-driver/debian/copyright new file mode 100644 index 00000000..df2ec246 --- /dev/null +++ b/pkg-video-driver/debian/copyright @@ -0,0 +1,15 @@ +Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Upstream-Name: video-driver +Source: https://github.com/qualcomm-linux/video-driver + +Files: * +Copyright: Qualcomm Technologies, Inc. and/or its subsidiaries. +License: GPL-2.0-only + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License version 2 and + only version 2 as published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. diff --git a/pkg-video-driver/debian/postinst b/pkg-video-driver/debian/postinst new file mode 100644 index 00000000..49de140a --- /dev/null +++ b/pkg-video-driver/debian/postinst @@ -0,0 +1,228 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0-only +# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. + +# postinst script for video-driver-dkms +# This script runs after the package is installed + +set -e + +# Source debconf library +. /usr/share/debconf/confmodule + +case "$1" in + configure) + echo "Configuring video-driver-dkms..." + + # Get kernel version + KERNEL_VERSION=$(uname -r) + MODULE_NAME="video-driver" + DRIVER_VERSION="1.0.0" + BLACKLIST_FILE="/etc/modprobe.d/blacklist.conf" + + # 1. First, let DKMS build the video-driver module + echo "Building video-driver module via DKMS..." + DKMS_BUILD_SUCCESS=true + if ! dkms build -m "$MODULE_NAME" -v "$DRIVER_VERSION" -k "$KERNEL_VERSION"; then + echo "DKMS build failed, attempting automatic recovery..." + DKMS_BUILD_SUCCESS=false + + # Check if module was actually built despite DKMS error + MODULE_PATH="/var/lib/dkms/video-driver/1.0.0/build/video/iris_vpu.ko" + if [ -f "$MODULE_PATH" ]; then + echo "Module file found, proceeding with manual installation..." + + # Step 1: Create target directory (same as DKMS) + TARGET_DIR="/lib/modules/$KERNEL_VERSION/updates/dkms" + TARGET_FILE="$TARGET_DIR/iris_vpu.ko" + echo "Checking module directory..." + if [ ! -d "$TARGET_DIR" ]; then + echo "Creating module directory..." + if mkdir -p "$TARGET_DIR"; then + echo "✓ Module directory created: $TARGET_DIR" + else + echo "✗ Failed to create module directory" + echo "Keeping qcom_iris driver active for system stability" + exit 0 + fi + else + echo "✓ Module directory already exists: $TARGET_DIR" + fi + + # Step 2: Copy module file + echo "Copying module file..." + if cp "$MODULE_PATH" "$TARGET_FILE"; then + echo "✓ Module file copied successfully to: $TARGET_FILE" + else + echo "✗ Failed to copy module file" + echo "Keeping qcom_iris driver active for system stability" + exit 0 + fi + + # Step 3: Update module dependencies + echo "Updating module dependencies..." + if depmod -a; then + echo "✓ Module dependencies updated" + else + echo "✗ Failed to update module dependencies" + echo "Keeping qcom_iris driver active for system stability" + exit 0 + fi + + # Step 4: Test module loading + echo "Testing module loading..." + if modprobe iris_vpu; then + echo "✓ Module loaded successfully via manual recovery" + # Unload it for now, will be loaded properly later + modprobe -r iris_vpu 2>/dev/null || true + DKMS_BUILD_SUCCESS=true + else + echo "✗ Failed to load module even after manual installation" + echo "Keeping qcom_iris driver active for system stability" + exit 0 + fi + + echo "SUCCESS: Manual recovery completed successfully!" + + # Create overlay installation flag + touch "/var/lib/dkms/video-driver-overlay.flag" + echo "✓ Overlay installation flag created" + else + echo "ERROR: Module file not found at $MODULE_PATH" + echo "Build completely failed, keeping qcom_iris driver active" + echo "Please check DKMS build logs: dkms status" + exit 0 + fi + fi + + # 2. Install the DKMS module (skip if manual recovery was used) + DKMS_TARGET_FILE="/lib/modules/$KERNEL_VERSION/updates/dkms/iris_vpu.ko" + if [ "$DKMS_BUILD_SUCCESS" = true ] && [ ! -f "$DKMS_TARGET_FILE" ]; then + echo "Installing video-driver module via DKMS..." + if ! dkms install -m "$MODULE_NAME" -v "$DRIVER_VERSION" -k "$KERNEL_VERSION"; then + echo "ERROR: Failed to install video-driver module" + echo "Keeping qcom_iris driver active for system stability" + echo "Please check DKMS install logs: dkms status" + exit 0 + fi + elif [ -f "$DKMS_TARGET_FILE" ]; then + echo "Module already installed via manual recovery, skipping DKMS install" + fi + + echo "SUCCESS: video-driver module built and installed successfully!" + echo "Now switching from qcom_iris to video-driver..." + + # 3. Save current qcom_iris state for potential rollback + QCOM_IRIS_WAS_LOADED=false + if lsmod | grep -q "qcom_iris"; then + QCOM_IRIS_WAS_LOADED=true + echo "qcom_iris module is currently loaded" + fi + + # 4. Unload qcom_iris module to free hardware resources + if [ "$QCOM_IRIS_WAS_LOADED" = true ]; then + echo "Unloading qcom_iris module to free hardware resources..." + if ! modprobe -r qcom_iris 2>/dev/null; then + echo "Warning: Failed to unload qcom_iris module" + echo "This may cause conflicts with video-driver" + echo "A reboot may be required for proper operation" + fi + fi + + # 5. Add qcom_iris to blacklist to prevent auto-loading + echo "Adding qcom_iris to module blacklist..." + if [ -f "$BLACKLIST_FILE" ]; then + if ! grep -q "blacklist qcom_iris" "$BLACKLIST_FILE"; then + echo "" >> "$BLACKLIST_FILE" + echo "# Added by video-driver-dkms package" >> "$BLACKLIST_FILE" + echo "blacklist qcom_iris" >> "$BLACKLIST_FILE" + echo "install qcom_iris /bin/true" >> "$BLACKLIST_FILE" + fi + else + echo "Creating blacklist file for qcom_iris..." + mkdir -p /etc/modprobe.d + echo "# Blacklist for video-driver-dkms package" > "$BLACKLIST_FILE" + echo "blacklist qcom_iris" >> "$BLACKLIST_FILE" + echo "install qcom_iris /bin/true" >> "$BLACKLIST_FILE" + fi + + # 6. Try to load video-driver module + echo "Loading video-driver module..." + if modprobe iris_vpu 2>/dev/null; then + # 7. Verify the iris_vpu module is actually loaded and working + if lsmod | grep -q "^iris_vpu "; then + echo "SUCCESS: video-driver module loaded and working!" + + # Update initramfs to apply blacklist changes + echo "Updating initramfs to make blacklist permanent..." + update-initramfs -u 2>/dev/null || { + echo "Warning: Failed to update initramfs" + echo "Blacklist may not take effect until manual update" + } + + # Update module dependencies + echo "Updating module dependencies..." + depmod -a 2>/dev/null || true + + echo "video-driver-dkms configuration completed successfully!" + echo "video-driver module is now active, qcom_iris has been disabled." + echo "" + echo "To verify the installation:" + echo " lsmod | grep iris_vpu" + echo " dkms status" + else + echo "ERROR: iris_vpu module loaded but not detected in lsmod" + echo "Rolling back to qcom_iris driver..." + # Rollback procedure + modprobe -r iris_vpu 2>/dev/null || true + # Remove blacklist + if [ -f "$BLACKLIST_FILE" ]; then + grep -v "blacklist qcom_iris" "$BLACKLIST_FILE" | \ + grep -v "install qcom_iris /bin/true" | \ + grep -v "# Added by video-driver-dkms package" > "${BLACKLIST_FILE}.tmp" + mv "${BLACKLIST_FILE}.tmp" "$BLACKLIST_FILE" + fi + # Restore qcom_iris + if [ "$QCOM_IRIS_WAS_LOADED" = true ]; then + modprobe qcom_iris 2>/dev/null || echo "Warning: Failed to restore qcom_iris" + fi + echo "Rollback completed. qcom_iris driver restored." + fi + else + echo "ERROR: Failed to load video-driver module" + echo "Rolling back to qcom_iris driver..." + + # Rollback procedure + echo "Removing qcom_iris from blacklist..." + if [ -f "$BLACKLIST_FILE" ]; then + grep -v "blacklist qcom_iris" "$BLACKLIST_FILE" | \ + grep -v "install qcom_iris /bin/true" | \ + grep -v "# Added by video-driver-dkms package" > "${BLACKLIST_FILE}.tmp" + mv "${BLACKLIST_FILE}.tmp" "$BLACKLIST_FILE" + fi + + # Restore qcom_iris if it was loaded before + if [ "$QCOM_IRIS_WAS_LOADED" = true ]; then + echo "Restoring qcom_iris module..." + if modprobe qcom_iris 2>/dev/null; then + echo "SUCCESS: qcom_iris driver restored" + else + echo "ERROR: Failed to restore qcom_iris driver" + echo "System may need a reboot to restore video functionality" + fi + fi + + echo "Rollback completed. video-driver installation failed but system is stable." + fi + ;; + + abort-upgrade|abort-remove|abort-deconfigure) + ;; + + *) + echo "postinst called with unknown argument \`$1'" >&2 + exit 1 + ;; +esac + +# dh_installdeb will replace this with shell code automatically diff --git a/pkg-video-driver/debian/postrm b/pkg-video-driver/debian/postrm new file mode 100644 index 00000000..20d0248a --- /dev/null +++ b/pkg-video-driver/debian/postrm @@ -0,0 +1,60 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0-only +# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. + +# postrm script for video-driver-dkms +# This script runs after the package is removed + +set -e + +case "$1" in + remove|purge) + echo "Completing video-driver-dkms removal..." + + # 1. Update initramfs to apply blacklist removal + echo "Updating initramfs to remove qcom_iris blacklist..." + update-initramfs -u 2>/dev/null || { + echo "Warning: Failed to update initramfs" + echo "You may need to run 'sudo update-initramfs -u' manually" + } + + # 2. Update module dependencies + echo "Updating module dependencies..." + depmod -a 2>/dev/null || true + + # 3. Try to load qcom_iris module + echo "Attempting to restore qcom_iris module..." + if modprobe qcom_iris 2>/dev/null; then + echo "SUCCESS: qcom_iris module loaded successfully" + echo "Original video driver has been restored" + else + echo "Note: qcom_iris module could not be loaded automatically" + echo "This may be normal if:" + echo " - The module is not available for this kernel" + echo " - Hardware doesn't support it" + echo " - System needs a reboot" + echo "" + echo "To manually load qcom_iris after reboot:" + echo " sudo modprobe qcom_iris" + fi + + # 4. Verify the restoration + if lsmod | grep -q "qcom_iris"; then + echo "Verification: qcom_iris module is now active" + else + echo "Note: qcom_iris module is not currently loaded" + echo "A reboot may be required to fully restore the original driver" + fi + + echo "video-driver-dkms removal completed." + echo "System has been restored to use the original qcom_iris driver." + ;; + + upgrade|failed-upgrade|abort-install|abort-upgrade|disappear) + ;; + + *) + echo "postrm called with unknown argument \`$1'" >&2 + exit 1 + ;; +esac diff --git a/pkg-video-driver/debian/prerm b/pkg-video-driver/debian/prerm new file mode 100644 index 00000000..df78c6e7 --- /dev/null +++ b/pkg-video-driver/debian/prerm @@ -0,0 +1,99 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0-only +# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. + +# prerm script for video-driver-dkms +# This script runs before the package is removed + +# Note: Removed 'set -e' to handle errors gracefully without script termination + +case "$1" in + remove|upgrade|deconfigure) + echo "Preparing to remove video-driver-dkms..." + + # Get kernel version + KERNEL_VERSION=$(uname -r) + MODULE_NAME="video-driver" + DRIVER_VERSION="1.0.0" + + # 1. Unload iris_vpu module if it's loaded + if lsmod | grep -q "^iris_vpu "; then + echo "Unloading iris_vpu module..." + modprobe -r iris_vpu 2>/dev/null || { + echo "Warning: Failed to unload iris_vpu module" + echo "You may need to reboot to complete the removal" + } + fi + + # 2. Remove DKMS module (standard installation) + if dkms status | grep -q "$MODULE_NAME.*$DRIVER_VERSION"; then + echo "Removing video-driver DKMS module..." + dkms remove -m "$MODULE_NAME" -v "$DRIVER_VERSION" --all 2>/dev/null || { + echo "Warning: Failed to remove DKMS module" + } + fi + + # 3. Check for overlay installation and clean up manually installed files + OVERLAY_FLAG="/var/lib/dkms/video-driver-overlay.flag" + if [ -f "$OVERLAY_FLAG" ]; then + echo "Detected overlay installation, cleaning up manually installed files..." + MANUAL_MODULE_FILE="/lib/modules/$KERNEL_VERSION/updates/dkms/iris_vpu.ko" + if [ -f "$MANUAL_MODULE_FILE" ]; then + if rm -f "$MANUAL_MODULE_FILE" 2>/dev/null; then + echo "✓ Manually installed module file removed" + else + echo "Warning: Failed to remove manually installed module file" + fi + fi + + # Remove overlay flag + if rm -f "$OVERLAY_FLAG" 2>/dev/null; then + echo "✓ Overlay installation flag removed" + else + echo "Warning: Failed to remove overlay flag" + fi + + # Clean up empty directories if they exist + DKMS_DIR="/lib/modules/$KERNEL_VERSION/updates/dkms" + if [ -d "$DKMS_DIR" ] && [ -z "$(ls -A "$DKMS_DIR" 2>/dev/null)" ]; then + echo "Removing empty DKMS directory..." + rmdir "$DKMS_DIR" 2>/dev/null || true + fi + else + echo "Standard DKMS installation detected, no manual cleanup needed" + fi + + # 4. Remove qcom_iris from blacklist + BLACKLIST_FILE="/etc/modprobe.d/blacklist.conf" + if [ -f "$BLACKLIST_FILE" ]; then + if grep -a -q "blacklist qcom_iris" "$BLACKLIST_FILE" 2>/dev/null; then + echo "Removing qcom_iris from module blacklist..." + + # Create a temporary file without the qcom_iris blacklist entries + grep -a -v "blacklist qcom_iris" "$BLACKLIST_FILE" 2>/dev/null | \ + grep -a -v "install qcom_iris /bin/true" 2>/dev/null | \ + grep -a -v "# Added by video-driver-dkms package" 2>/dev/null > "${BLACKLIST_FILE}.tmp" || true + + # Replace the original file if temp file was created successfully + if [ -f "${BLACKLIST_FILE}.tmp" ]; then + mv "${BLACKLIST_FILE}.tmp" "$BLACKLIST_FILE" || { + echo "Warning: Failed to update blacklist file" + rm -f "${BLACKLIST_FILE}.tmp" + } + else + echo "Warning: Failed to process blacklist file" + fi + fi + fi + echo "video-driver-dkms pre-removal completed." + ;; + + failed-upgrade) + ;; + *) + echo "prerm called with unknown argument \`$1'" >&2 + exit 1 + ;; +esac + +exit 0 diff --git a/pkg-video-driver/debian/rules b/pkg-video-driver/debian/rules new file mode 100644 index 00000000..bdb63fdf --- /dev/null +++ b/pkg-video-driver/debian/rules @@ -0,0 +1,32 @@ +#!/usr/bin/make -f +# SPDX-License-Identifier: GPL-2.0-only +# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. + +%: + dh $@ --with dkms + +override_dh_auto_clean: + # Skip auto clean for DKMS package + +override_dh_auto_build: + # Skip auto build for DKMS package + +override_dh_auto_test: + # Skip auto test for DKMS package + +override_dh_auto_install: + # Skip auto install for DKMS package + +override_dh_builddeb: + # Ensure maintainer scripts are in place before building package + mkdir -p debian/video-driver-dkms/DEBIAN + if [ -f debian/postinst ]; then \ + install -m 755 debian/postinst debian/video-driver-dkms/DEBIAN/postinst; \ + fi + if [ -f debian/prerm ]; then \ + install -m 755 debian/prerm debian/video-driver-dkms/DEBIAN/prerm; \ + fi + if [ -f debian/postrm ]; then \ + install -m 755 debian/postrm debian/video-driver-dkms/DEBIAN/postrm; \ + fi + dh_builddeb diff --git a/pkg-video-driver/debian/video-driver-dkms.install b/pkg-video-driver/debian/video-driver-dkms.install new file mode 100644 index 00000000..d588718e --- /dev/null +++ b/pkg-video-driver/debian/video-driver-dkms.install @@ -0,0 +1,8 @@ +dkms.conf usr/src/video-driver-1.0.0/ +Makefile usr/src/video-driver-1.0.0/ +Kbuild usr/src/video-driver-1.0.0/ +driver/ usr/src/video-driver-1.0.0/ +video/ usr/src/video-driver-1.0.0/ +include/ usr/src/video-driver-1.0.0/ +config/ usr/src/video-driver-1.0.0/ +scripts/ usr/src/video-driver-1.0.0/ diff --git a/pkg-video-driver/dkms.conf b/pkg-video-driver/dkms.conf new file mode 100644 index 00000000..49cf0894 --- /dev/null +++ b/pkg-video-driver/dkms.conf @@ -0,0 +1,19 @@ +PACKAGE_NAME="video-driver" +PACKAGE_VERSION="1.0.0" + +# Build iris_vpu module only +BUILT_MODULE_NAME[0]="iris_vpu" +BUILT_MODULE_LOCATION[0]="." +DEST_MODULE_LOCATION[0]="/updates/dkms" + +# Use wrapper script +MAKE[0]="scripts/dkms-build-wrapper.sh" +CLEAN="make clean" + +AUTOINSTALL="yes" + +# Configuration for custom kernels - minimal changes to fix apport error +# Disable apport error reporting system for custom kernels +NO_WEAK_MODULES="yes" +# Skip initrd regeneration to avoid issues +REMAKE_INITRD="no" From 2499d1738dae0320347a9a5aad118347d20acaf8 Mon Sep 17 00:00:00 2001 From: Renjiang Han Date: Wed, 28 Jan 2026 21:05:12 +0530 Subject: [PATCH 2/2] video: driver: add script files and docs for DKMS packaging - Add comprehensive DKMS packaging scripts with apport error handling. - Implement automatic recovery system for DKMS failures. - Add smart driver management with rollback capabilities. - Support custom kernels (dirty/rc versions) with compiler mismatch handling. - Add overlay flag system for proper installation cleanup. - Include cross-compilation support and development tools. - Ensure path consistency across all installation methods. Scripts: detect-platform.sh, set-build-env.sh, dkms-build-wrapper.sh, cross-compile.sh, build-package.sh, cleanup.sh. Docs: comprehensive README.md with troubleshooting guide. Usage: ------------- - Build DKMS package. * (cd pkg-video-driver && ./build-package.sh). - Install on target. * sudo dpkg -i package. - Remove old installation. * sudo dkms remove video-driver/1.0.0 --all. * sudo dpkg -r video-driver-dkms. - Develop/test cross-compile. * cross-compile.sh --compatible qcom,sa8775p-iris --arch arm64. Change-Id: Ic2c64652c5ae9353360f24d7ad7406e4a4b3de83 Signed-off-by: Renjiang Han --- pkg-video-driver/README.md | 732 ++++++++++++++++++ pkg-video-driver/build-package.sh | 73 ++ pkg-video-driver/cleanup.sh | 226 ++++++ pkg-video-driver/debian/postinst | 2 +- pkg-video-driver/debian/prerm | 26 +- pkg-video-driver/scripts/build-wrapper.sh | 85 ++ pkg-video-driver/scripts/cross-compile.sh | 175 +++++ pkg-video-driver/scripts/detect-platform.sh | 69 ++ .../scripts/dkms-build-wrapper.sh | 46 ++ pkg-video-driver/scripts/set-build-env.sh | 90 +++ 10 files changed, 1504 insertions(+), 20 deletions(-) create mode 100644 pkg-video-driver/README.md create mode 100755 pkg-video-driver/build-package.sh create mode 100755 pkg-video-driver/cleanup.sh create mode 100755 pkg-video-driver/scripts/build-wrapper.sh create mode 100755 pkg-video-driver/scripts/cross-compile.sh create mode 100755 pkg-video-driver/scripts/detect-platform.sh create mode 100755 pkg-video-driver/scripts/dkms-build-wrapper.sh create mode 100755 pkg-video-driver/scripts/set-build-env.sh diff --git a/pkg-video-driver/README.md b/pkg-video-driver/README.md new file mode 100644 index 00000000..4f0ef1a2 --- /dev/null +++ b/pkg-video-driver/README.md @@ -0,0 +1,732 @@ +# Video Driver pkg-video-driver + +This pkg-video-driver directory contains all scripts and configuration files needed +to create Ubuntu DKMS packages for video-driver with intelligent automatic +driver management and recovery capabilities. + +## Directory Structure + +``` +pkg-video-driver/ +├── debian/ # Debian package configuration files +│ ├── control # Package control file +│ ├── rules # Build rules (debhelper + dkms) +│ ├── changelog # Change log +│ ├── copyright # Copyright information +│ ├── postinst # Post-installation script +│ │ # (DKMS build + recovery + driver switching) +│ ├── prerm # Pre-removal script +│ │ # (intelligent cleanup with overlay detection) +│ ├── postrm # Post-removal script +│ │ # (driver restoration + initramfs update) +│ └── video-driver-dkms.install # Installation file list +├── scripts/ # Build and utility scripts +│ ├── detect-platform.sh # Platform detection from device tree +│ ├── set-build-env.sh # Build environment setup +│ │ # (platform config + cross-compile) +│ ├── dkms-build-wrapper.sh # DKMS build wrapper +│ │ # (called by dkms.conf MAKE directive) +│ ├── build-wrapper.sh # Build wrapper script +│ └── cross-compile.sh # Cross-compilation development/testing script +├── dkms.conf # DKMS configuration file +├── build-package.sh # Debian package build script +├── cleanup.sh # Cleanup and uninstall script +├── build/ # Build output directory (generated) +└── README.md # This file +``` + +## Key Features + +### **🚀 Intelligent Automatic Recovery System** + +- **DKMS Failure Detection**: Automatically detects DKMS apport errors and + build failures +- **Overlay Installation**: When DKMS fails, automatically performs manual + recovery installation +- **Smart Cleanup**: Uses overlay flag system to distinguish between DKMS and + manual installations +- **Zero User Intervention**: Handles common DKMS issues transparently + +### **🛡️ Advanced Driver Management** + +- **Safe Driver Switching**: Only disables the upstream `qcom_iris` module if + video-driver successfully builds and loads +- **Automatic Rollback**: Restores the upstream `qcom_iris` module if + video-driver fails at any stage +- **Hardware Conflict Prevention**: Properly unloads the upstream `qcom_iris` + driver before switching +- **State Preservation**: Remembers original driver state for accurate + restoration + +### **🔧 Custom Kernel Support** + +- **Development Kernel Compatibility**: Handles kernels with "-dirty" and "rc" + versions +- **Apport Error Mitigation**: Built-in fixes for common DKMS apport issues +- **Compiler Mismatch Handling**: Automatically handles compiler version + mismatches + +## Supported Platforms + +Automatically detect and enable corresponding configuration based on device +tree compatible strings (iris format only): + +| Compatible String | Platform | Configuration | +|-----------------------|----------|------------------------| +| `qcom,x1e80100-iris` | HAMOA | X1E80100 platform | +| `qcom,sa8775p-iris` | LEMANS | SA8775P platform | + +## Usage + +### 1. Build DKMS Debian Package + +```bash +cd pkg-video-driver +./build-package.sh +``` + +After build completion, package files will be available in the +`pkg-video-driver/build/` directory. + +### 2. Install DKMS Package + +```bash +# Install dependencies +sudo apt update +sudo apt install -y dkms linux-headers-$(uname -r) + +# Install generated package +sudo dpkg -i build/video-driver-dkms_*.deb + +# If dependency issues occur, run: +sudo apt -f install -y +``` + +> **Note**: This package replaces the upstream `qcom_iris` kernel module +> (in-tree driver). The installation process automatically unloads `qcom_iris` +> and adds it to the module blacklist. Upon package removal, the original +> `qcom_iris` driver is restored automatically. + +### 3. Verify Installation + +```bash +# Check DKMS status +sudo dkms status + +# Check if module is loaded +lsmod | grep iris_vpu + +# View module information +modinfo iris_vpu + +# Check installation method (exists if overlay recovery was used) +ls -la /var/lib/dkms/video-driver-overlay.flag +``` + +### 4. Uninstall and Cleanup + +**Recommended method using cleanup script:** + +```bash +# View current status +./cleanup.sh --status + +# Complete uninstall (recommended) +./cleanup.sh --clean-all + +# Uninstall DKMS package and modules only +./cleanup.sh --uninstall-dkms + +# Clean build artifacts only +./cleanup.sh --clean-build +``` + +**Manual uninstall method:** + +```bash +# Uninstall DKMS package (automatically restores upstream qcom_iris driver) +sudo dpkg -r video-driver-dkms + +# Or complete purge (removes configuration files) +sudo dpkg --purge video-driver-dkms + +# Update module dependencies +sudo depmod -a +``` + +## Automatic Recovery System + +### **How It Works** + +The package includes an intelligent recovery system that handles DKMS failures +automatically: + +1. **Normal DKMS Build**: Attempts standard DKMS build process +2. **Failure Detection**: Detects DKMS apport errors or build failures +3. **Automatic Recovery**: + - Checks if module was actually built despite DKMS error + (at `build/video/iris_vpu.ko`) + - Creates overlay installation flag + (`/var/lib/dkms/video-driver-overlay.flag`) + - Manually installs module to `/lib/modules/$(uname -r)/updates/dkms/` + - Updates module dependencies and tests loading +4. **Smart Cleanup**: During uninstall, detects overlay flag and performs + appropriate cleanup + +### **Recovery Process Details** + +```bash +# When DKMS fails, the system automatically: +# 1. Checks for built module (in video/ subdirectory) +ls -l /var/lib/dkms/video-driver/1.0.0/build/video/iris_vpu.ko + +# 2. Creates target directory (if needed) +mkdir -p /lib/modules/$(uname -r)/updates/dkms + +# 3. Installs module manually +cp /var/lib/dkms/video-driver/1.0.0/build/video/iris_vpu.ko \ + /lib/modules/$(uname -r)/updates/dkms/ + +# 4. Updates dependencies +depmod -a + +# 5. Tests module loading +modprobe iris_vpu + +# 6. Creates overlay flag +touch /var/lib/dkms/video-driver-overlay.flag +``` + +### **Installation Scenarios** + +**Scenario 1: DKMS Success** +- Standard DKMS installation +- Module installed to `/lib/modules/$(uname -r)/updates/dkms/iris_vpu.ko` +- No overlay flag created +- Standard DKMS cleanup during uninstall + +**Scenario 2: DKMS Failure + Successful Recovery** +- DKMS build fails with apport error +- Module actually built successfully (found at `build/video/iris_vpu.ko`) +- Overlay recovery installs module manually +- Overlay flag created: `/var/lib/dkms/video-driver-overlay.flag` +- Smart cleanup during uninstall removes both module and flag + +**Scenario 3: Complete Build Failure** +- DKMS build fails and no module built +- Recovery detects missing module file +- Installation fails gracefully +- `qcom_iris` driver remains active (system stability preserved) + +## Advanced Driver Management + +### **Smart Driver Switching Logic** + +The package implements sophisticated driver management: + +``` +# Installation Process: +1. Build video-driver module via DKMS (with automatic recovery) +2. Only if build succeeds: + - Save qcom_iris state for rollback + - Unload qcom_iris module + - Add qcom_iris to blacklist (/etc/modprobe.d/blacklist-video.conf) + - Load video-driver module (iris_vpu) + - Verify module is working via lsmod + - Update initramfs to make blacklist permanent +3. If any step fails: automatic rollback to qcom_iris + +# Removal Process (prerm + postrm): +1. Unload iris_vpu module +2. Remove DKMS module (standard installation) +3. Detect installation method (DKMS vs overlay flag): + - Overlay: Manual file cleanup + flag removal +4. Remove qcom_iris blacklist file (`/etc/modprobe.d/blacklist-video.conf`) +5. Update initramfs (postrm) +6. Restore qcom_iris module (postrm) +7. Update module dependencies +``` + +### **Safety Features** + +- **No System Breakage**: Always ensures at least one video driver is available +- **Intelligent Fallback**: Automatically handles build failures and hardware + incompatibilities +- **State Preservation**: Remembers original driver state for accurate + restoration +- **Detailed Logging**: Provides clear status messages for troubleshooting +- **Overlay Detection**: Distinguishes between installation methods for proper + cleanup +- **Upstream Driver Replacement**: Safely replaces the upstream `qcom_iris` + module with proper blacklist management and automatic restoration on removal + +## Cross-compilation Support + +System automatically detects if cross-compilation is needed: + +- If host architecture is not aarch64, automatically setup ARM64 + cross-compilation +- Automatically find available cross compilers: + - `aarch64-linux-gnu-` + - `aarch64-none-linux-gnu-` + - `arm64-linux-gnu-` + +### Install Cross Compiler + +```bash +# Ubuntu/Debian +sudo apt install gcc-aarch64-linux-gnu + +# Verify installation +aarch64-linux-gnu-gcc --version +``` + +## Development and Testing + +### Cross-compilation Development Script + +Use the cross-compilation script for development testing. Run from the +**video-driver root directory**: + +```bash +# Auto-detect platform and cross-compile +./pkg-video-driver/scripts/cross-compile.sh + +# Specify platform (use iris-format compatible string) +./pkg-video-driver/scripts/cross-compile.sh --compatible qcom,sa8775p-iris + +# Full configuration +./pkg-video-driver/scripts/cross-compile.sh \ + --compatible qcom,x1e80100-iris \ + --arch arm64 \ + --cross-compile aarch64-linux-gnu- \ + --kernel-src /path/to/kernel \ + --output-dir /path/to/output + +# Clean build artifacts +./pkg-video-driver/scripts/cross-compile.sh --clean + +# View help +./pkg-video-driver/scripts/cross-compile.sh --help +``` + +> **Note**: Only iris-format compatible strings are supported +> (e.g., `qcom,x1e80100-iris`, `qcom,sa8775p-iris`). + +## Build Process + +### DKMS Package Build Process + +1. `build-package.sh` copies configuration files to video-driver root directory +2. `dpkg-buildpackage` builds debian package with maintainer scripts +3. DKMS configuration and scripts are packaged into Debian package file +4. Clean temporary files, keep package in `pkg-video-driver/build/` directory + +### DKMS Installation Build Process + +1. DKMS installs source to `/usr/src/video-driver-1.0.0/` +2. Calls `scripts/dkms-build-wrapper.sh` (as configured in `dkms.conf` + `MAKE` directive) +3. `detect-platform.sh` detects compatible string from device tree +4. `set-build-env.sh` sets environment variables and cross-compilation + based on compatible +5. Execute kernel module build: + `make -C /lib/modules/$(uname -r)/build M=$(pwd) modules` +6. Module is built to `video/iris_vpu.ko` within the build directory +7. **Automatic Recovery**: If DKMS fails, `postinst` attempts overlay + installation +8. **Smart Driver Management**: Only switch drivers if build and load succeed + +### Module File Location + +``` +# After DKMS build, module is located at: +/var/lib/dkms/video-driver/1.0.0/build/video/iris_vpu.ko + +# After installation (both DKMS and overlay), module is installed to: +/lib/modules/$(uname -r)/updates/dkms/iris_vpu.ko +``` + +## Common Package Management Commands + +### **Installation Commands** + +```bash +# Install package +sudo dpkg -i build/video-driver-dkms_*.deb + +# Fix dependency issues after installation +sudo apt -f install -y +``` + +### **Removal Commands** + +```bash +# Remove package (keeps configuration files) +sudo dpkg -r video-driver-dkms + +# Complete purge (removes all files including configuration) +sudo dpkg --purge video-driver-dkms + +# Force removal if package is in broken state +sudo dpkg --force-remove-reinstreq --purge video-driver-dkms +``` + +### **Package Information Commands** + +```bash +# List package files +sudo dpkg -L video-driver-dkms + +# Check package status +dpkg -s video-driver-dkms + +# List all installed packages matching pattern +dpkg -l | grep video-driver +``` + +### **DKMS Management Commands** + +```bash +# Remove DKMS module completely +sudo dkms remove video-driver/1.0.0 --all + +# Check DKMS status +sudo dkms status + +# Build DKMS module manually +sudo dkms build video-driver/1.0.0 + +# Install DKMS module manually +sudo dkms install video-driver/1.0.0 +``` + +## Troubleshooting + +### 1. Check Installation Status + +```bash +# Check package status +dpkg -l | grep video-driver + +# Check module status +lsmod | grep -E "(iris_vpu|qcom_iris)" + +# Check DKMS status +dkms status | grep video-driver + +# Check installation method (overlay recovery used if exists) +ls -la /var/lib/dkms/video-driver-overlay.flag + +# Check blacklist status +grep qcom_iris /etc/modprobe.d/blacklist-video.conf +``` + +### 2. Common Installation Scenarios + +**Package Status Meanings:** +- `ii video-driver-dkms` — Successfully installed and configured +- `pi video-driver-dkms` — Package marked for purge but still installed +- `rc video-driver-dkms` — Package removed but configuration files remain + +**Driver Status Scenarios:** + +*Successful Standard Installation:* + +```bash +lsmod | grep iris_vpu # Should show iris_vpu loaded +lsmod | grep qcom_iris # Should show nothing (unloaded) +ls /var/lib/dkms/video-driver-overlay.flag # Should not exist +``` + +*Successful Overlay Recovery Installation:* + +```bash +lsmod | grep iris_vpu # Should show iris_vpu loaded +lsmod | grep qcom_iris # Should show nothing (unloaded) +ls /var/lib/dkms/video-driver-overlay.flag # Should exist +``` + +*Failed Installation (System Protected):* + +```bash +lsmod | grep iris_vpu # Should show nothing +lsmod | grep qcom_iris # Should show qcom_iris loaded (preserved) +``` + +### 3. Manual Recovery Commands + +If automatic recovery fails, you can perform manual recovery: + +```bash +# Check if module was built (in video/ subdirectory) +ls -la /var/lib/dkms/video-driver/1.0.0/build/video/iris_vpu.ko + +# Manual installation steps +sudo mkdir -p /lib/modules/$(uname -r)/updates/dkms +sudo cp /var/lib/dkms/video-driver/1.0.0/build/video/iris_vpu.ko \ + /lib/modules/$(uname -r)/updates/dkms/ +sudo depmod -a +sudo modprobe iris_vpu + +# Create overlay flag for proper cleanup +sudo touch /var/lib/dkms/video-driver-overlay.flag +``` + +### 4. Custom Kernel Issues + +**Common Errors:** + +*DKMS Apport Error (Automatically Handled):* + +``` +ERROR (dkms apport): kernel package linux-headers-6.x.0-rc5-dirty not supported +``` + +**Solution**: The system automatically detects this and performs overlay +recovery. + +*Build Dependency Error:* + +``` +Error! Build of ./iris_vpu.ko failed for: 6.x.0-rc5-dirty (aarch64) +``` + +**Solution**: Check build logs and ensure kernel headers are available: + +```bash +# Check kernel headers +ls -la /lib/modules/$(uname -r)/build + +# Install if missing +sudo apt install linux-headers-$(uname -r) + +# View build logs +cat /var/lib/dkms/video-driver/1.0.0/build/make.log +``` + +### 5. Platform Detection Issues + +```bash +# Test platform detection +./scripts/detect-platform.sh + +# The script tries the following device tree paths in order: +# /proc/device-tree/soc@0/video-codec@aa00000/compatible +# /proc/device-tree/soc/video-codec@aa00000/compatible +# /proc/device-tree/video-codec@aa00000/compatible +# /proc/device-tree/soc@0/qcom,vidc@aa00000/compatible +# /proc/device-tree/soc/qcom,vidc@aa00000/compatible +# /proc/device-tree/qcom,vidc@aa00000/compatible + +# Check device tree manually +cat /proc/device-tree/soc@0/video-codec@aa00000/compatible 2>/dev/null | strings +cat /proc/device-tree/soc@0/qcom,vidc@aa00000/compatible 2>/dev/null | strings + +# Override platform detection (iris format only) +PLATFORM_OVERRIDE=qcom,sa8775p-iris ./scripts/detect-platform.sh +PLATFORM_OVERRIDE=qcom,x1e80100-iris ./scripts/detect-platform.sh +``` + +### 6. Uninstall Issues + +**Package Stuck in 'pi' State:** + +```bash +# Force complete removal +sudo dpkg --force-remove-reinstreq --purge video-driver-dkms + +# Manual cleanup if needed +sudo rm -f /var/lib/dkms/video-driver-overlay.flag +sudo rm -f /lib/modules/$(uname -r)/updates/dkms/iris_vpu.ko +sudo depmod -a +``` + +**Upstream `qcom_iris` Module Still Loaded After Installation:** + +```bash +# Check if qcom_iris is still loaded +lsmod | grep qcom_iris + +# Manually unload and blacklist if needed +sudo modprobe -r qcom_iris +sudo modprobe iris_vpu + +# Verify blacklist was created +cat /etc/modprobe.d/blacklist-video.conf +``` + +## Testing and Verification + +### Manual Testing Workflow + +```bash +# 1. Check initial system status +lsmod | grep -E "(iris_vpu|qcom_iris)" +dkms status | grep video-driver +dpkg -l | grep video-driver + +# 2. Build and install package +./build-package.sh +sudo dpkg -i build/video-driver-dkms_*.deb + +# 3. Verify installation result +lsmod | grep -E "(iris_vpu|qcom_iris)" +dkms status | grep video-driver +dpkg -l | grep video-driver +ls -la /var/lib/dkms/video-driver-overlay.flag # Check installation method + +# 4. Test removal and restoration +sudo dpkg -r video-driver-dkms + +# 5. Verify qcom_iris restoration +lsmod | grep -E "(iris_vpu|qcom_iris)" +``` + +### Expected Behavior + +**Successful Installation:** +- `iris_vpu` module loaded and working +- `qcom_iris` module unloaded and blacklisted +- Package status: `ii` (installed and configured) +- Overlay flag may or may not exist depending on installation method + +**Failed Installation (build failure):** +- `qcom_iris` module remains active (system stability preserved) +- No blacklist entries for `qcom_iris` +- Package status: `ii` but `iris_vpu` not functional + +**Successful Removal:** +- `iris_vpu` module unloaded and removed +- `qcom_iris` module restored and active +- Blacklist entries removed +- Overlay flag cleaned up (if existed) + +## Technical Details + +### **DKMS Configuration (`dkms.conf`)** + +- `PACKAGE_NAME="video-driver"`, `PACKAGE_VERSION="1.0.0"` +- `BUILT_MODULE_NAME[0]="iris_vpu"` — module name to install +- `BUILT_MODULE_LOCATION[0]="."` — DKMS searches for module in build root +- `MAKE[0]="scripts/dkms-build-wrapper.sh"` — custom build script +- `DEST_MODULE_LOCATION[0]="/updates/dkms"` — installation path under + `/lib/modules/$(uname -r)/` +- `NO_WEAK_MODULES="yes"` — disables apport error reporting for custom kernels +- `REMAKE_INITRD="no"` — skips initrd regeneration to avoid issues +- `AUTOINSTALL="yes"` — automatically rebuild on kernel update + +### **Environment Variables (set automatically)** + +- `DKMS_DISABLE_APPORT=1` — disables DKMS error reporting for custom kernels +- `IGNORE_CC_MISMATCH=1` — ignores compiler version mismatches +- `VIDEO_ROOT` — set to the video-driver source root directory + +### **Overlay Flag System** + +- **Flag File**: `/var/lib/dkms/video-driver-overlay.flag` +- **Purpose**: Marks installations that used overlay recovery +- **Cleanup**: Automatically removed during uninstall (prerm script) +- **Detection**: Used by prerm script to determine cleanup method + +### **Driver Management Features** + +- Intelligent build validation before driver switching +- Automatic rollback on failure +- Hardware resource conflict prevention +- Upstream `qcom_iris` driver replacement: unload, blacklist + (`/etc/modprobe.d/blacklist-video.conf` created on install, + deleted on removal), and restore on removal +- Overlay installation detection and cleanup +- initramfs integration to make blacklist changes persistent across reboots + +## Notes + +1. **Non-intrusive**: pkg-video-driver system will not modify any existing files + in video-driver directory +2. **Build isolation**: all build artifacts are in `pkg-video-driver/build/` + directory +3. **Temporary files**: during build process, `debian/`, `dkms.conf` and + `scripts/` will be temporarily created in root directory, automatically + cleaned after build completion +4. **Platform detection**: must detect compatible string from device tree, + no default values supported (iris format only) +5. **Cross-compilation**: all platforms use unified ARM64 cross-compilation + configuration +6. **Smart driver management**: ensures system stability by maintaining at + least one working video driver +7. **Automatic recovery**: prevents system breakage by handling DKMS failures + transparently +8. **Overlay detection**: distinguishes between installation methods for + proper cleanup +9. **Path consistency**: all module installations use + `/lib/modules/$(uname -r)/updates/dkms/` for consistency +10. **Module subdirectory**: the kernel module is built into + `video/iris_vpu.ko` within the build tree + +## File Permissions + +Ensure scripts have execute permissions: + +```bash +chmod +x pkg-video-driver/scripts/*.sh +chmod +x pkg-video-driver/build-package.sh +chmod +x pkg-video-driver/cleanup.sh +``` + +## Advanced Usage + +### Custom Build Configuration + +```bash +# Build with specific kernel source +export KERNEL_SRC=/path/to/kernel/source +./build-package.sh + +# Build with custom cross-compiler +export CROSS_COMPILE=aarch64-custom-linux-gnu- +./build-package.sh +``` + +### Debug Mode + +```bash +# Enable verbose output during build +export DKMS_DEBUG=1 +sudo dpkg -i build/video-driver-dkms_*.deb + +# Check detailed logs +journalctl -u dkms +cat /var/lib/dkms/video-driver/1.0.0/build/make.log +``` + +### Manual Driver Management + +```bash +# Manually switch to video-driver (if available) +sudo modprobe -r qcom_iris +sudo modprobe iris_vpu + +# Manually switch back to qcom_iris +sudo modprobe -r iris_vpu +sudo modprobe qcom_iris + +# Check current driver status +lsmod | grep -E "(iris_vpu|qcom_iris)" +``` + +### Package Status Management + +```bash +# Check detailed package status +dpkg -s video-driver-dkms + +# List package files +sudo dpkg -L video-driver-dkms + +# Force package reconfiguration +sudo dpkg-reconfigure video-driver-dkms + +# Fix broken package states +sudo dpkg --configure -a +sudo apt --fix-broken install diff --git a/pkg-video-driver/build-package.sh b/pkg-video-driver/build-package.sh new file mode 100755 index 00000000..1b4e4d25 --- /dev/null +++ b/pkg-video-driver/build-package.sh @@ -0,0 +1,73 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0-only +# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. +set -e + +# Determine script location and project structure +SCRIPT_PATH="$(realpath "$0")" +SCRIPT_DIR="$(dirname "$SCRIPT_PATH")" + +# Check if we're running from pkg-video-driver directory or video-driver root +if [[ "$SCRIPT_DIR" == */pkg-video-driver ]]; then + # Running from pkg-video-driver directory + DKMS_DEBIAN_DIR="$SCRIPT_DIR" + VIDEO_DRIVER_ROOT="$(dirname "$DKMS_DEBIAN_DIR")" +else + # Running from video-driver root directory + VIDEO_DRIVER_ROOT="$SCRIPT_DIR" + DKMS_DEBIAN_DIR="$VIDEO_DRIVER_ROOT/pkg-video-driver" +fi + +BUILD_OUTPUT="$DKMS_DEBIAN_DIR/build" + +echo "Building DKMS package for video-driver..." +echo "Script location: $SCRIPT_DIR" +echo "pkg-video-driver directory: $DKMS_DEBIAN_DIR" +echo "Video driver root: $VIDEO_DRIVER_ROOT" + +# Create output directory +mkdir -p "$BUILD_OUTPUT" + +# Execute build in video-driver root directory +cd "$VIDEO_DRIVER_ROOT" + +echo "Preparing build environment..." + +# Clean up any previous build artifacts first +echo "Cleaning up any previous build artifacts..." +rm -rf debian dkms.conf scripts 2>/dev/null || true + +# Check if we need to copy files (avoid copying to same location) +if [ "$PWD" != "$DKMS_DEBIAN_DIR" ]; then + # Temporarily copy pkg-video-driver files to root directory (cleanup after build) + echo "Copying debian configuration files..." + cp -r "$DKMS_DEBIAN_DIR/debian" ./ + cp "$DKMS_DEBIAN_DIR/dkms.conf" ./ + + # Copy scripts directory to root directory + echo "Copying build scripts..." + cp -r "$DKMS_DEBIAN_DIR/scripts" ./ +else + echo "Already in pkg-video-driver directory, skipping file copy..." +fi + +# Set script execution permissions +chmod +x scripts/*.sh +chmod +x debian/rules + +echo "Building debian package..." +# Build debian package +dpkg-buildpackage -us -uc -b + +echo "Moving build artifacts..." +# Move all generated package files and build artifacts to pkg-video-driver/build +mv ../video-driver-dkms_* "$BUILD_OUTPUT/" 2>/dev/null || true + +echo "Cleaning up temporary files..." +# Clean up temporary files +rm -rf debian dkms.conf scripts +rm -f ../video-driver-dkms_* 2>/dev/null || true + +echo "Build completed successfully!" +echo "Package available in: $BUILD_OUTPUT" +ls -la "$BUILD_OUTPUT" diff --git a/pkg-video-driver/cleanup.sh b/pkg-video-driver/cleanup.sh new file mode 100755 index 00000000..5ed20644 --- /dev/null +++ b/pkg-video-driver/cleanup.sh @@ -0,0 +1,226 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0-only +# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. + +# Video Driver DKMS cleanup and uninstall script + +set -e + +SCRIPT_DIR="$(dirname "$0")" +PACKAGE_NAME="video-driver" +PACKAGE_VERSION="1.0.0" + +show_help() { + cat << EOF +Video Driver DKMS Cleanup and Uninstall Tool + +Usage: $0 [OPTIONS] + +OPTIONS: + --clean-build Clean build artifacts (pkg-video-driver/build directory) + --uninstall-dkms Uninstall DKMS package and modules + --clean-all Perform complete cleanup (build artifacts + DKMS uninstall) + --status Show current DKMS status + --help Show this help message + +EXAMPLES: + $0 --clean-build # Clean build artifacts only + $0 --uninstall-dkms # Uninstall DKMS only + $0 --clean-all # Complete cleanup + $0 --status # Show status + +EOF +} + +# Clean build artifacts +clean_build() { + echo "Cleaning build artifacts..." + + # Clean pkg-video-driver/build directory + if [ -d "$SCRIPT_DIR/build" ]; then + echo "Removing $SCRIPT_DIR/build directory..." + rm -rf "$SCRIPT_DIR/build" + echo "Build artifacts cleanup completed" + else + echo "No build artifacts directory found" + fi + + # Clean possible temporary files in root directory + cd "$(dirname "$SCRIPT_DIR")" + echo "Checking root directory temporary files..." + + if [ -d "debian" ]; then + echo "Removing temporary debian/ directory..." + rm -rf debian + fi + + if [ -f "dkms.conf" ]; then + echo "Removing temporary dkms.conf file..." + rm -f dkms.conf + fi + + if [ -d "scripts" ]; then + echo "Removing temporary scripts/ directory..." + rm -rf scripts + fi + + # Clean compilation artifacts + echo "Cleaning compilation artifacts..." + make clean 2>/dev/null || true + find . -name "*.ko" -delete 2>/dev/null || true + find . -name "*.mod" -delete 2>/dev/null || true + find . -name "*.mod.c" -delete 2>/dev/null || true + find . -name "*.mod.o" -delete 2>/dev/null || true + find . -name "*.o" -delete 2>/dev/null || true + find . -name ".*.cmd" -delete 2>/dev/null || true + rm -rf .tmp_versions 2>/dev/null || true + rm -f Module.symvers modules.order 2>/dev/null || true + + echo "Build artifacts cleanup completed" +} + +# Uninstall DKMS package +uninstall_dkms() { + echo "Uninstalling DKMS package and modules..." + + # Check if DKMS package is installed + if dpkg -l | grep -q "video-driver-dkms"; then + echo "Found installed video-driver-dkms package, uninstalling..." + + # Uninstall debian package + sudo dpkg -r video-driver-dkms || true + + echo "Debian package uninstall completed" + else + echo "No installed video-driver-dkms package found" + fi + + # Check DKMS status and cleanup + if command -v dkms >/dev/null 2>&1; then + echo "Checking DKMS status..." + + # Show current status + sudo dkms status | grep "$PACKAGE_NAME" || echo "No DKMS modules found" + + # Try to remove all versions of the module + for version in $(sudo dkms status | grep "$PACKAGE_NAME" | \ + cut -d',' -f2 | cut -d':' -f1 | sort -u); do + echo "Removing DKMS module: $PACKAGE_NAME/$version" + sudo dkms remove "$PACKAGE_NAME/$version" --all || true + done + + # Clean source directory + if [ -d "/usr/src/$PACKAGE_NAME-$PACKAGE_VERSION" ]; then + echo "Removing source directory: /usr/src/$PACKAGE_NAME-$PACKAGE_VERSION" + sudo rm -rf "/usr/src/$PACKAGE_NAME-$PACKAGE_VERSION" + fi + + # Unload module (if loaded) + echo "Checking and unloading loaded modules..." + if lsmod | grep -q "^video "; then + echo "Unloading video module..." + sudo rmmod video || true + fi + + # Update module dependencies + echo "Updating module dependencies..." + sudo depmod -a + + echo "DKMS cleanup completed" + else + echo "DKMS not installed, skipping DKMS cleanup" + fi +} + +# Show status +show_status() { + echo "=== Video Driver DKMS Status ===" + echo + + # Check debian package status + echo "Debian package status:" + if dpkg -l | grep -q "video-driver-dkms"; then + dpkg -l | grep "video-driver-dkms" + else + echo " video-driver-dkms package not installed" + fi + echo + + # Check DKMS status + if command -v dkms >/dev/null 2>&1; then + echo "DKMS status:" + sudo dkms status | grep "$PACKAGE_NAME" || echo " No DKMS modules found" + else + echo "DKMS not installed" + fi + echo + + # Check module load status + echo "Module load status:" + if lsmod | grep -q "^video "; then + lsmod | grep "^video " + else + echo " video module not loaded" + fi + echo + + # Check source directory + echo "Source directory:" + if [ -d "/usr/src/$PACKAGE_NAME-$PACKAGE_VERSION" ]; then + echo " /usr/src/$PACKAGE_NAME-$PACKAGE_VERSION exists" + ls -la "/usr/src/$PACKAGE_NAME-$PACKAGE_VERSION" | head -5 + else + echo " /usr/src/$PACKAGE_NAME-$PACKAGE_VERSION does not exist" + fi + echo + + # Check build artifacts + echo "Build artifacts:" + if [ -d "$SCRIPT_DIR/build" ]; then + echo " $SCRIPT_DIR/build exists" + ls -la "$SCRIPT_DIR/build" + else + echo " $SCRIPT_DIR/build does not exist" + fi +} + +# Complete cleanup +clean_all() { + echo "Performing complete cleanup..." + uninstall_dkms + clean_build + echo "Complete cleanup finished" +} + +# Main function +main() { + if [ $# -eq 0 ]; then + show_help + exit 1 + fi + + case "$1" in + --clean-build) + clean_build + ;; + --uninstall-dkms) + uninstall_dkms + ;; + --clean-all) + clean_all + ;; + --status) + show_status + ;; + --help) + show_help + ;; + *) + echo "Unknown option: $1" + show_help + exit 1 + ;; + esac +} + +main "$@" diff --git a/pkg-video-driver/debian/postinst b/pkg-video-driver/debian/postinst index 49de140a..2a53b2e7 100644 --- a/pkg-video-driver/debian/postinst +++ b/pkg-video-driver/debian/postinst @@ -18,7 +18,7 @@ case "$1" in KERNEL_VERSION=$(uname -r) MODULE_NAME="video-driver" DRIVER_VERSION="1.0.0" - BLACKLIST_FILE="/etc/modprobe.d/blacklist.conf" + BLACKLIST_FILE="/etc/modprobe.d/blacklist-video.conf" # 1. First, let DKMS build the video-driver module echo "Building video-driver module via DKMS..." diff --git a/pkg-video-driver/debian/prerm b/pkg-video-driver/debian/prerm index df78c6e7..6ffa86ff 100644 --- a/pkg-video-driver/debian/prerm +++ b/pkg-video-driver/debian/prerm @@ -63,26 +63,14 @@ case "$1" in echo "Standard DKMS installation detected, no manual cleanup needed" fi - # 4. Remove qcom_iris from blacklist - BLACKLIST_FILE="/etc/modprobe.d/blacklist.conf" + # 4. Remove qcom_iris blacklist file + BLACKLIST_FILE="/etc/modprobe.d/blacklist-video.conf" if [ -f "$BLACKLIST_FILE" ]; then - if grep -a -q "blacklist qcom_iris" "$BLACKLIST_FILE" 2>/dev/null; then - echo "Removing qcom_iris from module blacklist..." - - # Create a temporary file without the qcom_iris blacklist entries - grep -a -v "blacklist qcom_iris" "$BLACKLIST_FILE" 2>/dev/null | \ - grep -a -v "install qcom_iris /bin/true" 2>/dev/null | \ - grep -a -v "# Added by video-driver-dkms package" 2>/dev/null > "${BLACKLIST_FILE}.tmp" || true - - # Replace the original file if temp file was created successfully - if [ -f "${BLACKLIST_FILE}.tmp" ]; then - mv "${BLACKLIST_FILE}.tmp" "$BLACKLIST_FILE" || { - echo "Warning: Failed to update blacklist file" - rm -f "${BLACKLIST_FILE}.tmp" - } - else - echo "Warning: Failed to process blacklist file" - fi + echo "Removing module blacklist file..." + if rm -f "$BLACKLIST_FILE"; then + echo "✓ Blacklist file removed: $BLACKLIST_FILE" + else + echo "Warning: Failed to remove blacklist file: $BLACKLIST_FILE" fi fi echo "video-driver-dkms pre-removal completed." diff --git a/pkg-video-driver/scripts/build-wrapper.sh b/pkg-video-driver/scripts/build-wrapper.sh new file mode 100755 index 00000000..1864abb9 --- /dev/null +++ b/pkg-video-driver/scripts/build-wrapper.sh @@ -0,0 +1,85 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0-only +# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. + +# Universal build wrapper for video driver +# Works in both Ubuntu DKMS and Yocto kernel build environments + +set -e + +echo "Starting video driver build (Universal Mode)..." + +# Get kernel information +KERNEL_VERSION=$(uname -r) +KERNEL_ARCH=$(uname -m) +echo "Target kernel: $KERNEL_VERSION ($KERNEL_ARCH)" + +# Detect build environment +BUILD_ENV="generic" +if [ -n "$YOCTO_VERSION" ] || [ -n "$BB_ENV_EXTRAWHITE" ]; then + BUILD_ENV="yocto" + echo "Build environment: Yocto" +elif [ -d "/var/lib/dkms" ]; then + BUILD_ENV="dkms" + echo "Build environment: DKMS (Ubuntu)" +else + echo "Build environment: Generic" +fi + +# Handle custom/development kernels +if [[ "$KERNEL_VERSION" == *"-dirty" ]] || [[ "$KERNEL_VERSION" == *"rc"* ]]; then + echo "Custom/development kernel detected, enabling compatibility mode..." + export DKMS_DISABLE_APPORT=1 + export IGNORE_CC_MISMATCH=1 +fi + +# Detect platform using unified detection +echo "Detecting platform from device tree..." +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +COMPATIBLE=$("$SCRIPT_DIR/detect-platform.sh") + +if [ -z "$COMPATIBLE" ]; then + echo "Error: Failed to detect platform" >&2 + exit 1 +fi + +echo "Detected compatible: $COMPATIBLE" + +# Setup build environment +echo "Setting up build environment..." +source "$SCRIPT_DIR/set-build-env.sh" "$COMPATIBLE" + +# Set build arguments +MAKE_ARGS="M=$(pwd) VIDEO_ROOT=$(pwd) modules" + +# Handle compiler version mismatch for custom kernels +if [[ "$KERNEL_VERSION" == *"-dirty" ]]; then + MAKE_ARGS="$MAKE_ARGS CONFIG_CC_VERSION_TEXT=\"\"" +fi + +# Determine kernel build directory based on environment +if [ "$BUILD_ENV" = "yocto" ]; then + # In Yocto, use KERNEL_SRC if available, otherwise standard path + KERNEL_BUILD_DIR="${KERNEL_SRC:-/lib/modules/$KERNEL_VERSION/build}" +else + # In Ubuntu/DKMS, use standard path + KERNEL_BUILD_DIR="/lib/modules/$KERNEL_VERSION/build" +fi + +echo "Using kernel build directory: $KERNEL_BUILD_DIR" + +# Build the module +echo "Building kernel module..." +make -C "$KERNEL_BUILD_DIR" $MAKE_ARGS + +echo "Build completed successfully!" + +# Verify module was built +MODULE_FILE="video/iris_vpu.ko" +if [ -f "$MODULE_FILE" ]; then + MODULE_SIZE=$(stat -c%s "$MODULE_FILE") + echo "Module built: $MODULE_FILE ($MODULE_SIZE bytes)" +else + echo "Error: Module file not found: $MODULE_FILE" >&2 + exit 1 +fi diff --git a/pkg-video-driver/scripts/cross-compile.sh b/pkg-video-driver/scripts/cross-compile.sh new file mode 100755 index 00000000..51332297 --- /dev/null +++ b/pkg-video-driver/scripts/cross-compile.sh @@ -0,0 +1,175 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0-only +# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. + +# Cross-compilation script for development and testing +# Uses pkg-video-driver scripts for cross-compilation + +set -e + +SCRIPT_DIR="$(dirname "$0")" +DKMS_DEBIAN_DIR="$SCRIPT_DIR/pkg-video-driver" + +# Default parameters +COMPATIBLE="" +ARCH="" +CROSS_COMPILE="" +KERNEL_SRC="" +OUTPUT_DIR="$SCRIPT_DIR/build-output" +CLEAN_BUILD=false + +# Show help information +show_help() { + cat << EOF +Usage: $0 [OPTIONS] + +Cross-compile video driver using pkg-video-driver scripts. + +OPTIONS: + --compatible COMPAT Specify compatible string (e.g., qcom,hamoa-vidc) + --arch ARCH Target architecture (default: auto-detect) + --cross-compile PREFIX Cross compiler prefix (default: auto-detect) + --kernel-src PATH Kernel source path (default: /lib/modules/\$(uname -r)/build) + --output-dir DIR Output directory (default: ./build-output) + --clean Clean build artifacts before building + --help Show this help message + +EXAMPLES: + # Auto-detect platform and cross-compile + $0 + + # Specify platform + $0 --compatible qcom,pineapple-vidc + + # Full configuration + $0 --compatible qcom,sun-vidc \\ + --arch arm64 \\ + --cross-compile aarch64-linux-gnu- \\ + --kernel-src /path/to/kernel \\ + --output-dir /path/to/output + + # Clean build + $0 --clean + +SUPPORTED PLATFORMS: + hamoa, pineapple, sun, chora, seraph, lemans, nordau, art, canoe, + ravelin, alor, tuna, kera + +EOF +} + +# Parse command line arguments +while [[ $# -gt 0 ]]; do + case $1 in + --compatible) + COMPATIBLE="$2" + shift 2 + ;; + --arch) + ARCH="$2" + shift 2 + ;; + --cross-compile) + CROSS_COMPILE="$2" + shift 2 + ;; + --kernel-src) + KERNEL_SRC="$2" + shift 2 + ;; + --output-dir) + OUTPUT_DIR="$2" + shift 2 + ;; + --clean) + CLEAN_BUILD=true + shift + ;; + --help) + show_help + exit 0 + ;; + *) + echo "Unknown option: $1" + show_help + exit 1 + ;; + esac +done + +# Set default kernel source path +if [ -z "$KERNEL_SRC" ]; then + KERNEL_SRC="/lib/modules/$(uname -r)/build" +fi + +echo "Video Driver Cross-Compilation Script" +echo "=====================================" + +# Clean build artifacts +if [ "$CLEAN_BUILD" = true ]; then + echo "Cleaning build artifacts..." + make clean 2>/dev/null || true + rm -rf "$OUTPUT_DIR" + echo "Clean completed." + exit 0 +fi + +# Check if pkg-video-driver scripts exist +if [ ! -f "$DKMS_DEBIAN_DIR/scripts/set-build-env.sh" ]; then + echo "Error: pkg-video-driver scripts not found. Please ensure pkg-video-driver directory exists." + exit 1 +fi + +# Setup build environment +echo "Setting up build environment..." +if [ -n "$COMPATIBLE" ]; then + echo "Using specified compatible: $COMPATIBLE" + export VIDEO_COMPATIBLE="$COMPATIBLE" +fi + +# Manually set cross-compilation parameters (if specified) +if [ -n "$ARCH" ]; then + export ARCH="$ARCH" +fi +if [ -n "$CROSS_COMPILE" ]; then + export CROSS_COMPILE="$CROSS_COMPILE" +fi + +# Call pkg-video-driver script to setup environment +source "$DKMS_DEBIAN_DIR/scripts/set-build-env.sh" "$COMPATIBLE" + +# Set kernel source path +export KERNEL_SRC="$KERNEL_SRC" + +echo "" +echo "Build Configuration:" +echo " Compatible: ${COMPATIBLE:-auto-detect}" +echo " Architecture: ${ARCH:-native}" +echo " Cross Compiler: ${CROSS_COMPILE:-none}" +echo " Kernel Source: $KERNEL_SRC" +echo " Output Directory: $OUTPUT_DIR" +echo "" + +# Check kernel source path +if [ ! -d "$KERNEL_SRC" ]; then + echo "Error: Kernel source directory not found: $KERNEL_SRC" + echo "Please install kernel headers or specify correct path with --kernel-src" + exit 1 +fi + +# Create output directory +mkdir -p "$OUTPUT_DIR" + +# Execute build +echo "Starting cross-compilation..." +make -C "$KERNEL_SRC" M="$(pwd)" modules + +# Copy build artifacts to output directory +echo "Copying build artifacts to output directory..." +find . -name "*.ko" -exec cp {} "$OUTPUT_DIR/" \; +find . -name "*.mod" -exec cp {} "$OUTPUT_DIR/" \; 2>/dev/null || true + +echo "" +echo "Cross-compilation completed successfully!" +echo "Build artifacts available in: $OUTPUT_DIR" +ls -la "$OUTPUT_DIR" diff --git a/pkg-video-driver/scripts/detect-platform.sh b/pkg-video-driver/scripts/detect-platform.sh new file mode 100755 index 00000000..0dfd0f9c --- /dev/null +++ b/pkg-video-driver/scripts/detect-platform.sh @@ -0,0 +1,69 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0-only +# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. + +# Unified platform detection for all build environments +# Uses device tree compatible string detection for both Ubuntu and Yocto + +# Function to detect platform from device tree +detect_platform_devicetree() { + local compatible="" + + # Try different possible paths for video codec device tree node + local dt_paths=( + "/proc/device-tree/soc@0/video-codec@aa00000/compatible" + "/proc/device-tree/soc/video-codec@aa00000/compatible" + "/proc/device-tree/video-codec@aa00000/compatible" + "/proc/device-tree/soc@0/qcom,vidc@aa00000/compatible" + "/proc/device-tree/soc/qcom,vidc@aa00000/compatible" + "/proc/device-tree/qcom,vidc@aa00000/compatible" + ) + + for path in "${dt_paths[@]}"; do + if [ -f "$path" ]; then + # Use strings to extract null-terminated strings and find first iris compatible + compatible=$(strings "$path" | grep -m1 '\-iris$') + if [ -n "$compatible" ]; then + echo "$compatible" + return 0 + fi + fi + done + + # If no compatible found, return empty + echo "" + return 1 +} + +# Main platform detection function +detect_platform() { + local manual_platform="${PLATFORM_OVERRIDE:-}" + + # Check for manual override first + if [ -n "$manual_platform" ]; then + echo "$manual_platform" + return 0 + fi + + # Always use device tree detection for all environments + detect_platform_devicetree +} + +# Main execution +compatible=$(detect_platform) +if [ -n "$compatible" ]; then + echo "$compatible" + exit 0 +else + echo "Error: Could not detect iris-format compatible from device tree" >&2 + echo "Tried paths:" >&2 + echo " /proc/device-tree/soc@0/video-codec@aa00000/compatible" >&2 + echo " /proc/device-tree/soc/video-codec@aa00000/compatible" >&2 + echo " /proc/device-tree/video-codec@aa00000/compatible" >&2 + echo " /proc/device-tree/soc@0/qcom,vidc@aa00000/compatible" >&2 + echo " /proc/device-tree/soc/qcom,vidc@aa00000/compatible" >&2 + echo " /proc/device-tree/qcom,vidc@aa00000/compatible" >&2 + echo "Note: Only iris-format compatible strings are supported" >&2 + echo "You can override with: PLATFORM_OVERRIDE=qcom,platform-iris $0" >&2 + exit 1 +fi diff --git a/pkg-video-driver/scripts/dkms-build-wrapper.sh b/pkg-video-driver/scripts/dkms-build-wrapper.sh new file mode 100755 index 00000000..d4289dd5 --- /dev/null +++ b/pkg-video-driver/scripts/dkms-build-wrapper.sh @@ -0,0 +1,46 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0-only +# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. + +set -e + +echo "Starting DKMS build for video driver..." + +# Get kernel information +KERNEL_VERSION=$(uname -r) +KERNEL_ARCH=$(uname -m) +echo "Target kernel: $KERNEL_VERSION ($KERNEL_ARCH)" + +# Minimal custom kernel detection for production +if [[ "$KERNEL_VERSION" == *"-dirty" ]] || [[ "$KERNEL_VERSION" == *"rc"* ]]; then + echo "Custom/development kernel detected, enabling basic compatibility..." + export DKMS_DISABLE_APPORT=1 + export IGNORE_CC_MISMATCH=1 +fi + +# Detect platform from device tree +echo "Detecting platform from device tree..." +COMPATIBLE=$($(dirname "$0")/detect-platform.sh) + +if [ -z "$COMPATIBLE" ]; then + echo "Error: Failed to detect platform" >&2 + exit 1 +fi + +echo "Detected compatible: $COMPATIBLE" + +# Setup build environment +echo "Setting up build environment..." +source $(dirname "$0")/set-build-env.sh "$COMPATIBLE" + +# Set build arguments to handle compiler version mismatch +MAKE_ARGS="M=$(pwd) VIDEO_ROOT=$(pwd) modules" +if [[ "$KERNEL_VERSION" == *"-dirty" ]]; then + MAKE_ARGS="$MAKE_ARGS CONFIG_CC_VERSION_TEXT=\"\"" +fi + +# Build the module +echo "Building kernel module..." +make -C /lib/modules/$(uname -r)/build $MAKE_ARGS + +echo "Build completed successfully!" diff --git a/pkg-video-driver/scripts/set-build-env.sh b/pkg-video-driver/scripts/set-build-env.sh new file mode 100755 index 00000000..0aa5429e --- /dev/null +++ b/pkg-video-driver/scripts/set-build-env.sh @@ -0,0 +1,90 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0-only +# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. + +# Setup platform configuration based on compatible string +setup_platform_config() { + local compatible="$1" + + if [ -z "$compatible" ]; then + echo "Error: No compatible string provided" >&2 + exit 1 + fi + + echo "Setting up build environment for: $compatible" + + # Set macros based on compatible string (iris format only) + case "$compatible" in + "qcom,x1e80100-iris") + #export CONFIG_ARCH_X1E80100=y + #export CONFIG_MSM_VIDC_HAMOA=y + #export CONFIG_MSM_VIDC_QLI=y + echo "Platform: HAMOA (X1E80100)" + ;; + "qcom,sa8775p-iris") + #export CONFIG_ARCH_LEMANS=y + #export CONFIG_MSM_VIDC_LEMANS=y + #export CONFIG_QLI_VIDC_SA8775P=y + echo "Platform: LEMANS" + ;; + *) + echo "Error: Unsupported compatible '$compatible'" >&2 + echo "Supported platforms (iris format only):" >&2 + echo " - qcom,x1e80100-iris (HAMOA)" >&2 + echo " - qcom,sa8775p-iris (LEMANS)" >&2 + ;; + esac + + # Setup cross-compilation (unified for all platforms) + setup_cross_compile +} + +# Setup cross-compilation environment +setup_cross_compile() { + local host_arch=$(uname -m) + + echo "Host architecture: $host_arch" + + # Setup cross-compilation if not aarch64 host + if [ "$host_arch" != "aarch64" ]; then + export ARCH=arm64 + + # Find available cross compiler + for cc in aarch64-linux-gnu- aarch64-none-linux-gnu- arm64-linux-gnu-; do + if command -v "${cc}gcc" >/dev/null 2>&1; then + export CROSS_COMPILE="$cc" + echo "Using cross compiler: $cc" + return 0 + fi + done + + echo "Error: No suitable cross compiler found" >&2 + echo "Please install: sudo apt install gcc-aarch64-linux-gnu" >&2 + exit 1 + else + echo "Native aarch64 build" + fi +} + +# Main function +main() { + local compatible="$1" + + # Auto-detect if no compatible provided + if [ -z "$compatible" ]; then + echo "Auto-detecting platform..." + compatible=$($(dirname "$0")/detect-platform.sh) + fi + + setup_platform_config "$compatible" + + echo "Build environment configured successfully" + echo "Compatible: $compatible" + echo "ARCH: ${ARCH:-native}" + echo "CROSS_COMPILE: ${CROSS_COMPILE:-none}" + + # Export environment variables for make + export VIDEO_ROOT=$(pwd) +} + +main "$@"