From a605a348575c8a3c7fe177a035c3da0160b41311 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 --- overlay/debian/changelog | 15 ++ overlay/debian/control | 26 +++ overlay/debian/copyright | 24 +++ overlay/debian/postinst | 226 +++++++++++++++++++++++ overlay/debian/postrm | 58 ++++++ overlay/debian/prerm | 97 ++++++++++ overlay/debian/rules | 31 ++++ overlay/debian/video-driver-dkms.install | 10 + overlay/dkms.conf | 21 +++ 9 files changed, 508 insertions(+) create mode 100644 overlay/debian/changelog create mode 100644 overlay/debian/control create mode 100644 overlay/debian/copyright create mode 100755 overlay/debian/postinst create mode 100755 overlay/debian/postrm create mode 100755 overlay/debian/prerm create mode 100755 overlay/debian/rules create mode 100644 overlay/debian/video-driver-dkms.install create mode 100644 overlay/dkms.conf diff --git a/overlay/debian/changelog b/overlay/debian/changelog new file mode 100644 index 00000000..716acaf4 --- /dev/null +++ b/overlay/debian/changelog @@ -0,0 +1,15 @@ +# SPDX-License-Identifier: GPL-2.0-only + +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 overlay directory + * Fixed: Proper handling of multiple compatible strings in device tree + + -- Renjiang Han Tue, 28 Jan 2026 15:10:00 +0800 diff --git a/overlay/debian/control b/overlay/debian/control new file mode 100644 index 00000000..c98fa28d --- /dev/null +++ b/overlay/debian/control @@ -0,0 +1,26 @@ +# SPDX-License-Identifier: GPL-2.0-only + +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/overlay/debian/copyright b/overlay/debian/copyright new file mode 100644 index 00000000..5131d5c8 --- /dev/null +++ b/overlay/debian/copyright @@ -0,0 +1,24 @@ +# SPDX-License-Identifier: GPL-2.0-only + +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 package is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + . + This package 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. + . + You should have received a copy of the GNU General Public License + along with this program. If not, see + . + On Debian systems, the complete text of the GNU General + Public License version 2 can be found in "/usr/share/common-licenses/GPL-2". diff --git a/overlay/debian/postinst b/overlay/debian/postinst new file mode 100755 index 00000000..5baebdc7 --- /dev/null +++ b/overlay/debian/postinst @@ -0,0 +1,226 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0-only +# 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/overlay/debian/postrm b/overlay/debian/postrm new file mode 100755 index 00000000..f6d8f65f --- /dev/null +++ b/overlay/debian/postrm @@ -0,0 +1,58 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0-only +# 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/overlay/debian/prerm b/overlay/debian/prerm new file mode 100755 index 00000000..eb51add7 --- /dev/null +++ b/overlay/debian/prerm @@ -0,0 +1,97 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0-only +# 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/overlay/debian/rules b/overlay/debian/rules new file mode 100755 index 00000000..4d5b7368 --- /dev/null +++ b/overlay/debian/rules @@ -0,0 +1,31 @@ +#!/usr/bin/make -f +# SPDX-License-Identifier: GPL-2.0-only + +%: + 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/overlay/debian/video-driver-dkms.install b/overlay/debian/video-driver-dkms.install new file mode 100644 index 00000000..181f2ad2 --- /dev/null +++ b/overlay/debian/video-driver-dkms.install @@ -0,0 +1,10 @@ +# SPDX-License-Identifier: GPL-2.0-only + +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/overlay/dkms.conf b/overlay/dkms.conf new file mode 100644 index 00000000..3e22bff6 --- /dev/null +++ b/overlay/dkms.conf @@ -0,0 +1,21 @@ +# SPDX-License-Identifier: GPL-2.0-only + +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 2d0d8255880a8c6b623715dfb1378a8f474348a5 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 overlay && ./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 --- overlay/README.md | 618 ++++++++++++++++++++++++++ overlay/build-package.sh | 72 +++ overlay/cleanup.sh | 225 ++++++++++ overlay/scripts/build-wrapper.sh | 84 ++++ overlay/scripts/cross-compile.sh | 174 ++++++++ overlay/scripts/detect-platform.sh | 68 +++ overlay/scripts/dkms-build-wrapper.sh | 45 ++ overlay/scripts/set-build-env.sh | 89 ++++ 8 files changed, 1375 insertions(+) create mode 100644 overlay/README.md create mode 100755 overlay/build-package.sh create mode 100755 overlay/cleanup.sh create mode 100755 overlay/scripts/build-wrapper.sh create mode 100755 overlay/scripts/cross-compile.sh create mode 100755 overlay/scripts/detect-platform.sh create mode 100755 overlay/scripts/dkms-build-wrapper.sh create mode 100755 overlay/scripts/set-build-env.sh diff --git a/overlay/README.md b/overlay/README.md new file mode 100644 index 00000000..53115930 --- /dev/null +++ b/overlay/README.md @@ -0,0 +1,618 @@ +# SPDX-License-Identifier: GPL-2.0-only +# Video Driver DKMS Overlay + +This overlay 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 + +``` +overlay/ +├── debian/ # Debian package configuration files +│ ├── control # Package control file with automatic driver management +│ ├── rules # Build rules +│ ├── changelog # Change log +│ ├── copyright # Copyright information +│ ├── postinst # Post-installation script (automatic driver switching + recovery) +│ ├── prerm # Pre-removal script (intelligent cleanup with overlay detection) +│ ├── postrm # Post-removal script (driver restoration) +│ └── video-driver-dkms.install # Installation file list +├── scripts/ # Build and utility scripts +│ ├── detect-platform.sh # Platform detection script +│ ├── set-build-env.sh # Build environment setup +│ ├── dkms-build-wrapper.sh # DKMS build wrapper (with integrated apport fix) +│ ├── build-wrapper.sh # Build wrapper script +│ └── cross-compile.sh # Cross-compilation development script +├── dkms.conf # DKMS configuration file (with apport fixes) +├── build-package.sh # Debian package build script +├── cleanup.sh # Cleanup and uninstall script +├── build/ # Build output directory +└── 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 qcom-iris if video-driver successfully builds and loads +- **Automatic Rollback**: Restores qcom-iris if video-driver fails at any stage +- **Hardware Conflict Prevention**: Properly unloads conflicting drivers 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 support | +| `qcom,sa8775p-iris` | LEMANS | SA8775P platform support | + +## Usage + +### 1. Build DKMS Debian Package + +```bash +cd overlay +./build-package.sh +``` + +After build completion, package files will be available in `overlay/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 package (video-driver debian package) + +# If dependency issues occur, run: +sudo apt -f install -y +``` + +### 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 +ls -la /var/lib/dkms/video-driver-overlay.flag # Exists if overlay recovery was used +``` + +### 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 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 + - 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 +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 +- 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: + +```bash +# Installation Process: +1. Save qcom_iris state for rollback +2. Build video-driver module (with automatic recovery) +3. Only if build succeeds: + - Unload qcom_iris module + - Add qcom_iris to blacklist + - Load video-driver module + - Verify module is working +4. If any step fails: automatic rollback to qcom_iris + +# Removal Process: +1. Unload video-driver module +2. Detect installation method (DKMS vs overlay) +3. Clean up appropriately: + - DKMS: Use standard DKMS removal + - Overlay: Manual file cleanup + flag removal +4. Remove qcom_iris blacklist +5. Restore qcom_iris module +6. Update initramfs +``` + +### **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 + +## 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: + +```bash +# Auto-detect platform and cross-compile +./scripts/cross-compile.sh + +# Specify platform +./scripts/cross-compile.sh --compatible qcom,sa8775p-iris + +# Full configuration +./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 +./scripts/cross-compile.sh --clean + +# View help +./scripts/cross-compile.sh --help +``` + + +## 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 overlay/build directory + +### DKMS Installation Build Process + +1. DKMS installs source to `/usr/src/video-driver-1.0.0/` +2. Call `scripts/dkms-build-wrapper.sh` +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 with apport error handling +6. **Automatic Recovery**: If DKMS fails, attempt overlay installation +7. **Smart Driver Management**: Only switch drivers if build and load succeed + +## Common Package Management Commands + +### **Installation Commands** +```bash +# Install specific version +sudo dpkg -i package (video-driver debian package) + +# 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 +ls -la /var/lib/dkms/video-driver-overlay.flag # Overlay recovery used if exists + +# Check blacklist status +grep qcom_iris /etc/modprobe.d/blacklist.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 (partial removal) +- `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 +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.19.0-rc5-g6658049e667c-dirty is not supported +``` +**Solution**: The system automatically detects this and performs overlay recovery. + +*Build Dependency Error:* +``` +Error! Build of ./iris_vpu.ko failed for: 6.19.0-rc5-g6658049e667c-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 + +# Check device tree manually +find /proc/device-tree -name "*video*" -o -name "*vidc*" + +# Override platform detection +PLATFORM_OVERRIDE=qcom,sa8775p-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 +``` + +**Binary File Grep Errors (Fixed in Latest Version):** +``` +grep: /etc/modprobe.d/blacklist.conf: binary file matches +``` +**Solution**: This is automatically handled in the latest prerm script with `-a` flag and error suppression. + +## 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 package (video-driver debian package) + +# 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 Features:** +- `NO_WEAK_MODULES="yes"` - Disables apport error reporting for custom kernels +- `REMAKE_INITRD="no"` - Skips initrd regeneration to avoid issues +- `DEST_MODULE_LOCATION[0]="/updates/dkms"` - Unified installation path + +### **Environment Variables (set automatically):** +- `DKMS_DISABLE_APPORT=1` - Disables DKMS error reporting for custom kernels +- `IGNORE_CC_MISMATCH=1` - Ignores compiler version mismatches + +### **Overlay Flag System:** +- **Flag File**: `/var/lib/dkms/video-driver-overlay.flag` +- **Purpose**: Marks installations that used overlay recovery +- **Cleanup**: Automatically removed during uninstall +- **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 +- Blacklist management with initramfs integration +- Overlay installation detection and cleanup + +## Notes + +1. **Non-intrusive**: overlay system will not modify any existing files in video-driver directory +2. **Build isolation**: all build artifacts are in overlay 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 + +## File Permissions + +Ensure scripts have execute permissions: + +```bash +chmod +x overlay/scripts/*.sh +chmod +x overlay/build-package.sh +chmod +x overlay/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 package (video-driver debian package) + +# 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/overlay/build-package.sh b/overlay/build-package.sh new file mode 100755 index 00000000..fdcef47b --- /dev/null +++ b/overlay/build-package.sh @@ -0,0 +1,72 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0-only +set -e + +# Determine script location and project structure +SCRIPT_PATH="$(realpath "$0")" +SCRIPT_DIR="$(dirname "$SCRIPT_PATH")" + +# Check if we're running from overlay directory or video-driver root +if [[ "$SCRIPT_DIR" == */overlay ]]; then + # Running from overlay directory + OVERLAY_DIR="$SCRIPT_DIR" + VIDEO_DRIVER_ROOT="$(dirname "$OVERLAY_DIR")" +else + # Running from video-driver root directory + VIDEO_DRIVER_ROOT="$SCRIPT_DIR" + OVERLAY_DIR="$VIDEO_DRIVER_ROOT/overlay" +fi + +BUILD_OUTPUT="$OVERLAY_DIR/build" + +echo "Building DKMS package for video-driver..." +echo "Script location: $SCRIPT_DIR" +echo "Overlay directory: $OVERLAY_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" != "$OVERLAY_DIR" ]; then + # Temporarily copy overlay files to root directory (cleanup after build) + echo "Copying debian configuration files..." + cp -r "$OVERLAY_DIR/debian" ./ + cp "$OVERLAY_DIR/dkms.conf" ./ + + # Copy scripts directory to root directory + echo "Copying build scripts..." + cp -r "$OVERLAY_DIR/scripts" ./ +else + echo "Already in overlay 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 overlay/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/overlay/cleanup.sh b/overlay/cleanup.sh new file mode 100755 index 00000000..e7c72a3a --- /dev/null +++ b/overlay/cleanup.sh @@ -0,0 +1,225 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0-only + +# 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 (overlay/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 overlay/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/overlay/scripts/build-wrapper.sh b/overlay/scripts/build-wrapper.sh new file mode 100755 index 00000000..cb0cca90 --- /dev/null +++ b/overlay/scripts/build-wrapper.sh @@ -0,0 +1,84 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0-only + +# 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/overlay/scripts/cross-compile.sh b/overlay/scripts/cross-compile.sh new file mode 100755 index 00000000..fed60536 --- /dev/null +++ b/overlay/scripts/cross-compile.sh @@ -0,0 +1,174 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0-only + +# Cross-compilation script for development and testing +# Uses overlay scripts for cross-compilation + +set -e + +SCRIPT_DIR="$(dirname "$0")" +OVERLAY_DIR="$SCRIPT_DIR/overlay" + +# 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 overlay 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 overlay scripts exist +if [ ! -f "$OVERLAY_DIR/scripts/set-build-env.sh" ]; then + echo "Error: Overlay scripts not found. Please ensure overlay 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 overlay script to setup environment +source "$OVERLAY_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/overlay/scripts/detect-platform.sh b/overlay/scripts/detect-platform.sh new file mode 100755 index 00000000..4e2a9e7a --- /dev/null +++ b/overlay/scripts/detect-platform.sh @@ -0,0 +1,68 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0-only + +# 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/overlay/scripts/dkms-build-wrapper.sh b/overlay/scripts/dkms-build-wrapper.sh new file mode 100755 index 00000000..e4ef06ac --- /dev/null +++ b/overlay/scripts/dkms-build-wrapper.sh @@ -0,0 +1,45 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0-only + +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/overlay/scripts/set-build-env.sh b/overlay/scripts/set-build-env.sh new file mode 100755 index 00000000..fc38152a --- /dev/null +++ b/overlay/scripts/set-build-env.sh @@ -0,0 +1,89 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0-only + +# 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 "$@"