643 lines
23 KiB
Bash
643 lines
23 KiB
Bash
#!/usr/bin/env bash
|
|
# SPDX-License-Identifier: (GPL-2.0-only OR MIT)
|
|
# Copyright (C) 2026 Amlogic, Inc. All rights reserved
|
|
################################################################################
|
|
# Amlbian Gpu Compilation Module
|
|
#
|
|
# Purpose: Gpu compilation with Hook support and aml-comp integration
|
|
# Provides: Gpu compilation, post-kernel driver preparation
|
|
################################################################################
|
|
|
|
set -e
|
|
|
|
# Get script directory And Set env
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
AMLBIAN_DIR="$(dirname "$(dirname "${SCRIPT_DIR}")")"
|
|
BASE_DIR="$(dirname "$(dirname "${AMLBIAN_DIR}")")"
|
|
GPU_MODE="${GPU_MODE:-vale}"
|
|
GPU_ARCH="${GPU_ARCH:-valhall}"
|
|
|
|
# Source common functions
|
|
if [[ -f "${AMLBIAN_DIR}/lib/function-common.sh" ]]; then
|
|
source "${AMLBIAN_DIR}/lib/function-common.sh"
|
|
fi
|
|
|
|
# ==============================================================================
|
|
# Shared Helper Functions
|
|
# ==============================================================================
|
|
|
|
# ------------------------------------------------------------------------------
|
|
# Step 1: Version and Package Information Definition
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Initialize common package metadata for Mali GPU (libgles)
|
|
function _gpu_libgles_init_package_info() {
|
|
PKG_MAINTAINER="Armbian Build <[email protected]>"
|
|
PKG_DESCRIPTION="OpenGL ES driver for Amlogic GPU with Wayland DRM support"
|
|
PKG_NAME="aml-libgles-eabihf-${GPU_MODE}-wayland-drm"
|
|
PKG_VERSION="1.0-r54p1"
|
|
PKG_ARCH="arm64"
|
|
LIB_DIR="aarch64-linux-gnu"
|
|
MALI_ARCH="arm64"
|
|
FILES_DIR="${SCRIPT_DIR}/files"
|
|
VENDOR_DIR="${BASE_DIR}/aml-comp/vendor/amlogic/meson_mali"
|
|
}
|
|
|
|
# Initialize common package metadata for kernel module
|
|
function _gpu_kernel_init_package_info() {
|
|
PKG_MAINTAINER="Armbian Build <[email protected]>"
|
|
PKG_DESCRIPTION="GPU kernel modules for Amlogic SoCs"
|
|
PKG_NAME="aml-gpu-${GPU_ARCH}-kernel"
|
|
DIR_VERSION="r54p1"
|
|
PKG_VERSION="1.0-r54p1"
|
|
GPU_LOW_MEM="${GPU_LOW_MEM:-0}"
|
|
|
|
PKG_ARCH="arm64"
|
|
LIB_DIR="aarch64-linux-gnu"
|
|
MALI_ARCH="arm64"
|
|
}
|
|
|
|
# ------------------------------------------------------------------------------
|
|
# Step 2: Build Directory Structure Setup
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Create layered build directory structure
|
|
# Parameters:
|
|
# $1 - base name (e.g. "${PKG_NAME}_${PKG_VERSION}_${PKG_ARCH}")
|
|
# Sets: TMP_DIR, BASE_BUILD_DIR, SOURCE_DIR, BUILD_DIR, INSTALL_DIR, PATCH_DIR,
|
|
# DEB_PACKAGE_DIR, DEBIAN_DIR
|
|
function _gpu_create_build_dirs() {
|
|
local base_name="$1"
|
|
|
|
TMP_DIR="${AMLBIAN_DIR}/.tmp"
|
|
mkdir -p "${TMP_DIR}"
|
|
|
|
# 基础构建目录
|
|
BASE_BUILD_DIR="${TMP_DIR}/${base_name}"
|
|
|
|
rm -rf ${BASE_BUILD_DIR}
|
|
# 分层目录
|
|
SOURCE_DIR="${BASE_BUILD_DIR}/source" # 源码目录
|
|
BUILD_DIR="${BASE_BUILD_DIR}/build" # 编译目录
|
|
INSTALL_DIR="${BASE_BUILD_DIR}/install" # 安装目录
|
|
PATCH_DIR="${BASE_BUILD_DIR}/patch" # 补丁目录
|
|
|
|
# 创建所有目录
|
|
mkdir -p "${SOURCE_DIR}"
|
|
mkdir -p "${BUILD_DIR}"
|
|
mkdir -p "${INSTALL_DIR}"
|
|
mkdir -p "${PATCH_DIR}"
|
|
|
|
# 在BUILD_DIR下创建deb/包名目录
|
|
DEB_PACKAGE_DIR="${BUILD_DIR}/deb/${base_name}"
|
|
mkdir -p "${DEB_PACKAGE_DIR}"
|
|
|
|
# 安装目录的子目录
|
|
DEBIAN_DIR="${INSTALL_DIR}/DEBIAN"
|
|
mkdir -p "${DEBIAN_DIR}"
|
|
}
|
|
|
|
# Create standard install subdirectories for Mali GPU libraries
|
|
function _gpu_libgles_create_install_dirs() {
|
|
mkdir -p "${INSTALL_DIR}/usr/include"
|
|
mkdir -p "${INSTALL_DIR}/usr/lib/${LIB_DIR}"
|
|
mkdir -p "${INSTALL_DIR}/usr/lib/pkgconfig"
|
|
mkdir -p "${INSTALL_DIR}/usr/share/vulkan/icd.d"
|
|
mkdir -p "${INSTALL_DIR}/usr/share/vulkan/implicit_layer.d"
|
|
mkdir -p "${INSTALL_DIR}/lib/firmware"
|
|
mkdir -p "${INSTALL_DIR}/etc"
|
|
}
|
|
|
|
# ------------------------------------------------------------------------------
|
|
# Step 3: Debian Packaging Scripts Creation
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Create Debian control file
|
|
# Parameters:
|
|
# $1 - package name
|
|
# $2 - package version
|
|
# $3 - package architecture
|
|
# $4 - maintainer
|
|
# $5 - description
|
|
# $6 - dependencies (optional)
|
|
# $7 - conflicts (optional)
|
|
# $8 - provides (optional)
|
|
# $9 - section (optional, default "libs")
|
|
function _gpu_create_control_file() {
|
|
local pkg_name="$1"
|
|
local pkg_version="$2"
|
|
local pkg_arch="$3"
|
|
local maintainer="$4"
|
|
local description="$5"
|
|
local depends="${6:-}"
|
|
local conflicts="${7:-}"
|
|
local provides="${8:-}"
|
|
local section="${9:-libs}"
|
|
|
|
display_alert "COMPILE-GPU Creating control file DEBIAN/control" "info"
|
|
cat > "${DEBIAN_DIR}/control" <<EOF
|
|
Package: ${pkg_name}
|
|
Version: ${pkg_version}
|
|
Architecture: ${pkg_arch}
|
|
Maintainer: ${maintainer}
|
|
Depends: ${depends}
|
|
Conflicts: ${conflicts}
|
|
Provides: ${provides}
|
|
Section: ${section}
|
|
Priority: optional
|
|
Description: ${description}
|
|
EOF
|
|
}
|
|
|
|
# Create postinst script for Mali GPU libraries
|
|
function _gpu_libgles_create_postinst() {
|
|
display_alert "COMPILE-GPU Creating post-installation script DEBIAN/postinst" "info"
|
|
cat > "${DEBIAN_DIR}/postinst" << EOF
|
|
#!/bin/sh
|
|
set -e
|
|
|
|
if [ "\$1" = "configure" ]; then
|
|
# Update ldconfig cache
|
|
ldconfig
|
|
|
|
# Set up Vulkan ICD
|
|
if [ -d /usr/share/vulkan/icd.d ]; then
|
|
echo "Vulkan ICD files installed"
|
|
fi
|
|
|
|
# Check firmware
|
|
if [ ! -f /lib/firmware/mali_csffw.bin ]; then
|
|
echo "Warning: Mali firmware not found at /lib/firmware/mali_csffw.bin" >&2
|
|
fi
|
|
|
|
if [ -f /usr/lib/${LIB_DIR}/libEGL.so.1.1.0 ]; then
|
|
rm /usr/lib/${LIB_DIR}/libEGL.so.1.1.0
|
|
echo "remove libEGL.so.1.1.0" >&2
|
|
fi
|
|
|
|
# Create symlinks if they don't exist
|
|
if [ -f /usr/lib/${LIB_DIR}/libMali.so ]; then
|
|
cd /usr/lib/${LIB_DIR}
|
|
|
|
# Remove existing symlinks if they're broken
|
|
for lib in libEGL.so libGLESv1_CM.so libGLESv2.so libgbm.so; do
|
|
if [ -L "\${lib}" ] && [ ! -e "\${lib}" ]; then
|
|
rm -f "\${lib}"
|
|
echo "rm lib \${lib}"
|
|
fi
|
|
done
|
|
|
|
# Create symlinks
|
|
ln -sf libMali.so libEGL.so.1.4.0 2>/dev/null || true
|
|
ln -sf libEGL.so.1.4.0 libEGL.so.1 2>/dev/null || true
|
|
ln -sf libEGL.so.1 libEGL.so 2>/dev/null || true
|
|
|
|
ln -sf libMali.so libGLESv1_CM.so.1.1.0 2>/dev/null || true
|
|
ln -sf libGLESv1_CM.so.1.1.0 libGLESv1_CM.so.1 2>/dev/null || true
|
|
ln -sf libGLESv1_CM.so.1 libGLESv1_CM.so 2>/dev/null || true
|
|
|
|
ln -sf libMali.so libGLESv2.so.2.1.0 2>/dev/null || true
|
|
ln -sf libGLESv2.so.2.1.0 libGLESv2.so.2 2>/dev/null || true
|
|
ln -f -s libGLESv2.so.2 libGLESv2.so 2>/dev/null || true
|
|
|
|
ln -sf libMali.so libgbm.so.1.0.0 2>/dev/null || true
|
|
ln -sf libgbm.so.1.0.0 libgbm.so.1 2>/dev/null || true
|
|
ln -sf libgbm.so.1 libgbm.so 2>/dev/null || true
|
|
|
|
# Update ldconfig again
|
|
ldconfig
|
|
|
|
ls libEGL.so* -all
|
|
fi
|
|
fi
|
|
|
|
exit 0
|
|
EOF
|
|
chmod 755 "${DEBIAN_DIR}/postinst"
|
|
}
|
|
|
|
# Create prerm script for Mali GPU libraries
|
|
function _gpu_libgles_create_prerm() {
|
|
display_alert "COMPILE-GPU Creating pre-removal script DEBIAN/prerm" "info"
|
|
cat > "${DEBIAN_DIR}/prerm" << EOF
|
|
#!/bin/sh
|
|
set -e
|
|
|
|
if [ "\$1" = "remove" ] || [ "\$1" = "deconfigure" ]; then
|
|
# Clean up symlinks
|
|
for lib in libEGL.so libGLESv1_CM.so libGLESv2.so libgbm.so; do
|
|
if [ -L /usr/lib/${LIB_DIR}/\${lib} ]; then
|
|
# Only remove if it points to libMali.so
|
|
if [ "$(readlink -f /usr/lib/${LIB_DIR}/\${lib})" = "/usr/lib/${LIB_DIR}/libMali.so" ]; then
|
|
rm -f /usr/lib/${LIB_DIR}/\${lib}
|
|
fi
|
|
fi
|
|
done
|
|
|
|
# Update ldconfig
|
|
ldconfig
|
|
fi
|
|
|
|
exit 0
|
|
EOF
|
|
chmod 755 "${DEBIAN_DIR}/prerm"
|
|
}
|
|
|
|
# Create postinst script for kernel modules
|
|
function _gpu_kernel_create_postinst() {
|
|
local kernel_version="$1"
|
|
display_alert "COMPILE-GPU-DRIVER Creating post-installation script DEBIAN/postinst" "info"
|
|
cat > "${DEBIAN_DIR}/postinst" << EOF
|
|
#!/bin/sh
|
|
set -e
|
|
|
|
if [ "\$1" = "configure" ]; then
|
|
# Update module dependencies
|
|
if [ -d "/lib/modules/${kernel_version}" ]; then
|
|
depmod -a "${kernel_version}"
|
|
else
|
|
echo "Warning: /lib/modules/${kernel_version} not found, skipping depmod"
|
|
fi
|
|
|
|
# Check if module can be loaded
|
|
if modprobe -n mali 2>/dev/null; then
|
|
echo "GPU module can be loaded with 'modprobe mali'"
|
|
fi
|
|
fi
|
|
|
|
exit 0
|
|
EOF
|
|
chmod 755 "${DEBIAN_DIR}/postinst"
|
|
}
|
|
|
|
# Create prerm script for kernel modules
|
|
function _gpu_kernel_create_prerm() {
|
|
display_alert "COMPILE-GPU-DRIVER Creating pre-removal script DEBIAN/prerm" "info"
|
|
cat > "${DEBIAN_DIR}/prerm" << EOF
|
|
#!/bin/sh
|
|
set -e
|
|
|
|
if [ "\$1" = "remove" ] || [ "\$1" = "deconfigure" ]; then
|
|
# Unload module if loaded
|
|
if lsmod | grep -q "mali"; then
|
|
modprobe -r mali 2>/dev/null || true
|
|
fi
|
|
fi
|
|
|
|
exit 0
|
|
EOF
|
|
chmod 755 "${DEBIAN_DIR}/prerm"
|
|
}
|
|
|
|
# ------------------------------------------------------------------------------
|
|
# Step 4: Source/Vendor File Copying
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Copy Mali GPU vendor binaries to install directory
|
|
function _gpu_libgles_copy_vendor_files() {
|
|
display_alert "COMPILE-GPU Copying files from vendor binaries ${VENDOR_DIR}" "info"
|
|
|
|
# Copy headers
|
|
if [[ -d "${VENDOR_DIR}/include" ]]; then
|
|
cp -r "${VENDOR_DIR}/include/"* "${INSTALL_DIR}/usr/include/"
|
|
display_alert "COMPILE-GPU Copied headers EGL, GLES, GLES2, GLES3, KHR" "info"
|
|
else
|
|
display_alert "COMPILE-GPU Headers not found ${VENDOR_DIR}/include" "err"
|
|
fi
|
|
|
|
# Copy library
|
|
if [[ -f "${VENDOR_DIR}/lib/${MALI_ARCH}/${GPU_MODE}/r54p1/wayland/drm/libMali_dmaheap.so" ]]; then
|
|
cp "${VENDOR_DIR}/lib/${MALI_ARCH}/${GPU_MODE}/r54p1/wayland/drm/libMali_dmaheap.so" \
|
|
"${INSTALL_DIR}/usr/lib/${LIB_DIR}/libMali.so"
|
|
display_alert "COMPILE-GPU Copied main library libMali.so" "info"
|
|
else
|
|
# Try alternative path
|
|
if [[ -f "${VENDOR_DIR}/lib/${MALI_ARCH}/${GPU_MODE}/r54p1/wayland/drm/libMali.so" ]]; then
|
|
cp "${VENDOR_DIR}/lib/${MALI_ARCH}/${GPU_MODE}/r54p1/wayland/drm/libMali.so" "${INSTALL_DIR}/usr/lib/${LIB_DIR}/"
|
|
display_alert "COMPILE-GPU Copied main library (alternative path) libMali.so" "info"
|
|
else
|
|
display_alert "COMPILE-GPU Main library not found libMali.so" "err"
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
# Copy pkgconfig files
|
|
if [[ -d "${VENDOR_DIR}/lib/pkgconfig" ]]; then
|
|
cp -r "${VENDOR_DIR}/lib/pkgconfig/"* "${INSTALL_DIR}/usr/lib/pkgconfig/"
|
|
display_alert "COMPILE-GPU Copied pkgconfig files *.pc" "info"
|
|
fi
|
|
|
|
# Copy Vulkan files
|
|
if [[ -d "${VENDOR_DIR}/lib/${MALI_ARCH}/vulkan/r54p1/icd.d" ]]; then
|
|
cp -r "${VENDOR_DIR}/lib/${MALI_ARCH}/vulkan/r54p1/icd.d/"* "${INSTALL_DIR}/usr/share/vulkan/icd.d"
|
|
display_alert "COMPILE-GPU Copied Vulkan files ICD" "info"
|
|
fi
|
|
if [[ -d "${VENDOR_DIR}/lib/${MALI_ARCH}/vulkan/r54p1/implicit_layer.d" ]]; then
|
|
cp -r "${VENDOR_DIR}/lib/${MALI_ARCH}/vulkan/r54p1/implicit_layer.d/"* "${INSTALL_DIR}/usr/share/vulkan/implicit_layer.d"
|
|
display_alert "COMPILE-GPU Copied Vulkan files implicit layers" "info"
|
|
fi
|
|
|
|
# Copy firmware
|
|
if [[ -f "${VENDOR_DIR}/lib/firmware/${GPU_MODE}/r54p1/mali_csffw.bin" ]]; then
|
|
cp "${VENDOR_DIR}/lib/firmware/${GPU_MODE}/r54p1/mali_csffw.bin" "${INSTALL_DIR}/lib/firmware/"
|
|
display_alert "COMPILE-GPU Copied firmware mali_csffw.bin" "info"
|
|
else
|
|
display_alert "COMPILE-GPU Firmware not found mali_csffw.bin" "err"
|
|
fi
|
|
|
|
# Copy configuration file
|
|
if [[ -f "${VENDOR_DIR}/etc/aml_afrc_allowlist.config" ]]; then
|
|
cp "${VENDOR_DIR}/etc/aml_afrc_allowlist.config" "${INSTALL_DIR}/etc/"
|
|
display_alert "COMPILE-GPU Copied configuration file aml_afrc_allowlist.config" "info"
|
|
elif [[ -f "${FILES_DIR}/aml_afrc_allowlist.config" ]]; then
|
|
cp "${FILES_DIR}/aml_afrc_allowlist.config" "${INSTALL_DIR}/etc/"
|
|
display_alert "COMPILE-GPU Copied configuration file from extension aml_afrc_allowlist.config" "info"
|
|
fi
|
|
}
|
|
|
|
# ------------------------------------------------------------------------------
|
|
# Step 5: Symlink Creation (Mali GPU libraries only)
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Create Mali GPU library symlinks in the install directory
|
|
function _gpu_libgles_create_symlinks() {
|
|
display_alert "COMPILE-GPU Creating symlinks in package libMali.so -> libEGL.so, etc." "info"
|
|
cd "${INSTALL_DIR}/usr/lib/${LIB_DIR}"
|
|
ln -sf libMali.so libEGL.so.1.4.0
|
|
ln -sf libEGL.so.1.4.0 libEGL.so.1
|
|
ln -sf libEGL.so.1 libEGL.so
|
|
|
|
ln -sf libMali.so libGLESv1_CM.so.1.1.0
|
|
ln -sf libGLESv1_CM.so.1.1.0 libGLESv1_CM.so.1
|
|
ln -sf libGLESv1_CM.so.1 libGLESv1_CM.so
|
|
|
|
ln -sf libMali.so libGLESv2.so.2.1.0
|
|
ln -sf libGLESv2.so.2.1.0 libGLESv2.so.2
|
|
ln -sf libGLESv2.so.2 libGLESv2.so
|
|
|
|
ln -sf libMali.so libgbm.so.1.0.0
|
|
ln -sf libgbm.so.1.0.0 libgbm.so.1
|
|
ln -sf libgbm.so.1 libgbm.so
|
|
cd - > /dev/null
|
|
}
|
|
|
|
# ------------------------------------------------------------------------------
|
|
# Step 6: Debian Package Building
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Build Debian package from install directory
|
|
# Parameters:
|
|
# $1 - log prefix (e.g. "COMPILE-GPU" or "COMPILE-GPU-DRIVER")
|
|
# $2 - output deb filename (without path)
|
|
# Sets: OUTPUT_DEB
|
|
function _gpu_build_deb_package() {
|
|
local log_prefix="$1"
|
|
local output_deb_name="$2"
|
|
|
|
# 将install目录内容拷贝到deb目录
|
|
display_alert "Copying install directory to deb package directory ${log_prefix}" "info"
|
|
cp -r "${INSTALL_DIR}/"* "${DEB_PACKAGE_DIR}/" 2>&1
|
|
|
|
# 基于deb目录打包
|
|
display_alert "Building Debian package from deb directory ${log_prefix}" "info"
|
|
dpkg-deb --build "${DEB_PACKAGE_DIR}" 2>&1
|
|
|
|
# Move to output directory
|
|
OUTPUT_DEB="${SRC}/output/${output_deb_name}"
|
|
mkdir -p "$(dirname "${OUTPUT_DEB}")"
|
|
mv "${DEB_PACKAGE_DIR}.deb" "${OUTPUT_DEB}"
|
|
|
|
display_alert "${log_prefix} Package built successfully ${output_deb_name}" "info"
|
|
display_alert "${log_prefix} Build directory preserved ${BASE_BUILD_DIR}" "info"
|
|
}
|
|
|
|
# Display build directory info
|
|
# Parameters:
|
|
# $1 - log prefix
|
|
function _gpu_display_build_info() {
|
|
local log_prefix="$1"
|
|
display_alert "${log_prefix} Source dir: ${SOURCE_DIR}" "info"
|
|
display_alert "${log_prefix} Build dir: ${BUILD_DIR}" "info"
|
|
display_alert "${log_prefix} Install dir: ${INSTALL_DIR}" "info"
|
|
display_alert "${log_prefix} Patch dir: ${PATCH_DIR}" "info"
|
|
display_alert "${log_prefix} Deb package dir: ${DEB_PACKAGE_DIR}" "info"
|
|
}
|
|
|
|
# ==============================================================================
|
|
# Main Build Functions (Entry Points - DO NOT RENAME)
|
|
# ==============================================================================
|
|
|
|
# ------------------------------------------------------------------------------
|
|
# Mali GPU Library Build (libgles)
|
|
# Entry point: amlbian_build_libgles
|
|
# ------------------------------------------------------------------------------
|
|
|
|
function amlbian_build_libgles() {
|
|
|
|
# ---- Step 1: Version and Package Information ----
|
|
_gpu_libgles_init_package_info
|
|
|
|
# amlbian_checkout_toolchain
|
|
|
|
# ---- Step 2: Build Directory Setup ----
|
|
_gpu_create_build_dirs "${PKG_NAME}_${PKG_VERSION}_${PKG_ARCH}"
|
|
_gpu_libgles_create_install_dirs
|
|
|
|
# Display info
|
|
display_alert "COMPILE-GPU Building GLES driver package version ${PKG_VERSION} for ${PKG_ARCH}" "info"
|
|
_gpu_display_build_info "COMPILE-GPU"
|
|
|
|
# ---- Step 3: Debian Packaging Scripts ----
|
|
_gpu_create_control_file \
|
|
"${PKG_NAME}" "${PKG_VERSION}" "${PKG_ARCH}" "${PKG_MAINTAINER}" \
|
|
"${PKG_DESCRIPTION}" \
|
|
"libdrm2, libwayland-client0, libwayland-server0, libwayland-egl1" \
|
|
"libmali-valhall-g610-g6p0, libmali-bifrost-g31-g13p0" \
|
|
"libegl1, libgles1, libgles2, libgbm1" \
|
|
"libs"
|
|
|
|
_gpu_libgles_create_postinst
|
|
_gpu_libgles_create_prerm
|
|
|
|
# ---- Step 4: Copy Source/Vendor Files ----
|
|
_gpu_libgles_copy_vendor_files
|
|
|
|
# ---- Step 5: Create Symlinks ----
|
|
_gpu_libgles_create_symlinks
|
|
|
|
# Remove wayland-egl files (as per original recipe)
|
|
display_alert "COMPILE-GPU Removing wayland-egl files as per original recipe" "info"
|
|
rm -f "${INSTALL_DIR}/usr/lib/${LIB_DIR}/libwayland-egl"* 2>/dev/null || true
|
|
find "${INSTALL_DIR}/usr/lib/pkgconfig" -name "wayland-egl.pc" -delete 2>/dev/null || true
|
|
|
|
# ---- Step 6: Build Debian Package ----
|
|
_gpu_build_deb_package "COMPILE-GPU" "${PKG_NAME}_${PKG_VERSION}_${PKG_ARCH}.deb"
|
|
|
|
return 0
|
|
}
|
|
|
|
# ------------------------------------------------------------------------------
|
|
# GPU Kernel Module Build
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# ------------------------------------------------------------------------------
|
|
# Shared helper: Build kernel modules in a temp directory
|
|
# Parameters:
|
|
# $1 - kernel build directory
|
|
# $2 - driver source path
|
|
# $3 - include path
|
|
# $4 - build output directory
|
|
# $5 - extra cflags
|
|
# Outputs: sets MALI_KO_SRC, PMA_KO_SRC
|
|
# ------------------------------------------------------------------------------
|
|
function _gpu_build_kernel_modules() {
|
|
local kernel_build_dir="$1"
|
|
local drv_src="$2"
|
|
local inc_dir="$3"
|
|
local build_out_dir="$4"
|
|
local extra_cflags="$5"
|
|
|
|
local module_build_dir="${build_out_dir}/module_build"
|
|
mkdir -p "${module_build_dir}"
|
|
|
|
display_alert "COMPILE-GPU-DRIVER Copying source files to build directory to avoid pollution" "info"
|
|
cp -r "${drv_src}" "${module_build_dir}/"
|
|
cp -r "${inc_dir}" "${module_build_dir}/"
|
|
|
|
local build_drv_src="${module_build_dir}/drivers"
|
|
local build_inc_dir="${module_build_dir}/include"
|
|
|
|
display_alert "COMPILE-GPU-DRIVER Building GPU kernel modules in build directory kernel_build_dir ${kernel_build_dir} build_drv_src ${build_drv_src} extra_cflags ${extra_cflags} build_inc_dir ${build_inc_dir}" "info"
|
|
make -C "${kernel_build_dir}" M="${build_drv_src}" \
|
|
EXTRA_CFLAGS="${extra_cflags} -I${build_inc_dir}" \
|
|
CONFIG_MALI_MIDGARD=m \
|
|
CONFIG_MALI_DEVFREQ=y \
|
|
ARCH=arm64 \
|
|
CROSS_COMPILE=${CROSS_COMPILE:-aarch64-linux-gnu-} \
|
|
CONFIG_MALI_GATOR_SUPPORT=y \
|
|
CONFIG_MALI_REAL_HW=y \
|
|
CONFIG_MALI_CSF_SUPPORT=y \
|
|
CONFIG_MALI_PROTECTED_MEMORY_ALLOCATOR=y \
|
|
CONFIG_MALI_PLATFORM_NAME="devicetree" \
|
|
modules
|
|
|
|
MALI_KO_SRC="${build_drv_src}/gpu/arm/midgard/mali_kbase.ko"
|
|
PMA_KO_SRC="${build_drv_src}/base/arm/protected_memory_allocator/protected_memory_allocator.ko"
|
|
|
|
if [[ ! -f "${MALI_KO_SRC}" || ! -f "${PMA_KO_SRC}" ]]; then
|
|
display_alert "COMPILE-GPU-DRIVER Module build failed. Missing .ko files" "error"
|
|
exit 1
|
|
fi
|
|
|
|
display_alert "COMPILE-GPU-DRIVER" "Modules build successfully" "info"
|
|
|
|
# Return the module build dir for cleanup
|
|
echo "${module_build_dir}"
|
|
}
|
|
|
|
# ------------------------------------------------------------------------------
|
|
# Shared helper: Install kernel modules to install directory
|
|
# Parameters:
|
|
# $1 - module directory under INSTALL_DIR
|
|
# $2 - mali.ko source path
|
|
# $3 - protected_memory_allocator.ko source path
|
|
# ------------------------------------------------------------------------------
|
|
function _gpu_install_kernel_modules() {
|
|
local module_dir="$1"
|
|
local mali_ko_src="$2"
|
|
local pma_ko_src="$3"
|
|
|
|
display_alert "COMPILE-GPU-DRIVER Installing modules to ${module_dir}" "info"
|
|
install -m 0644 "${mali_ko_src}" "${module_dir}/mali.ko"
|
|
install -m 0644 "${pma_ko_src}" "${module_dir}/protected_memory_allocator.ko"
|
|
}
|
|
|
|
# ------------------------------------------------------------------------------
|
|
# GPU Kernel Module Build
|
|
# Entry point: amlbian_build_gpu_driver
|
|
# ------------------------------------------------------------------------------
|
|
|
|
function amlbian_build_gpu_driver() {
|
|
set -e
|
|
|
|
# ---- Step 1: Version and Package Information ----
|
|
_gpu_kernel_init_package_info
|
|
# amlbian_checkout_toolchain
|
|
|
|
# Source directories
|
|
local gpu_src_dir="${BASE_DIR}/aml-comp/hardware/arm/gpu/${GPU_ARCH}/${DIR_VERSION}/kernel"
|
|
local gpu_drv_src="${gpu_src_dir}/drivers"
|
|
local gpu_inc_dir="${gpu_src_dir}/include"
|
|
|
|
if [[ ! -d "${gpu_drv_src}" || ! -d "${gpu_inc_dir}" ]]; then
|
|
display_alert "COMPILE-GPU-DRIVER GPU source code not found. Expected at: ${gpu_src_dir}" "error"
|
|
exit 1
|
|
fi
|
|
|
|
local kernel_version
|
|
kernel_version=$(make -s -C "${BASE_DIR}/aml-comp/kernel/aml-6.12/build" kernelrelease 2>/dev/null || true)
|
|
kernel_version="${kernel_version:-unknown-$(date +%Y%m%d)}"
|
|
|
|
display_alert "COMPILE-GPU-DRIVER Building GPU kernel modules version ${PKG_VERSION} for ${PKG_ARCH}" "info"
|
|
display_alert "COMPILE-GPU-DRIVER Building for kernel version ${kernel_version}" "info"
|
|
|
|
# ---- Step 2: Build Directory Setup ----
|
|
_gpu_create_build_dirs "${PKG_NAME}_${PKG_VERSION}_${PKG_ARCH}"
|
|
local module_dir="${INSTALL_DIR}/lib/modules/${kernel_version}/kernel/drivers/arm/gpu"
|
|
mkdir -p "${module_dir}"
|
|
_gpu_display_build_info "COMPILE-GPU-DRIVER"
|
|
|
|
# Copy source to source directory
|
|
display_alert "COMPILE-GPU-DRIVER Copying source files to source directory" "info"
|
|
cp -r "${gpu_drv_src}" "${SOURCE_DIR}/drivers"
|
|
cp -r "${gpu_inc_dir}" "${SOURCE_DIR}/include"
|
|
|
|
local kernel_build_dir="${BASE_DIR}/aml-comp/kernel/aml-6.12/build"
|
|
display_alert "COMPILE-GPU-DRIVER kernel_build_dir ${kernel_build_dir}" "info"
|
|
|
|
# ---- Step 3: Debian Packaging Scripts ----
|
|
_gpu_create_control_file \
|
|
"${PKG_NAME}" "${PKG_VERSION}" "${PKG_ARCH}" "${PKG_MAINTAINER}" \
|
|
"${PKG_DESCRIPTION}" "" "" "" "kernel"
|
|
|
|
_gpu_kernel_create_postinst "${kernel_version}"
|
|
_gpu_kernel_create_prerm
|
|
|
|
# ---- Step 4: Build Kernel Modules ----
|
|
local extra_cflags="-DCONFIG_MALI_DEVFREQ -DCONFIG_MALI_GATOR_SUPPORT -DCONFIG_MALI_CSF_SUPPORT -DCONFIG_MALI_REAL_HW"
|
|
extra_cflags="${extra_cflags} -I${gpu_inc_dir} -DCONFIG_MALI_LOW_MEM=${GPU_LOW_MEM}"
|
|
|
|
local module_build_dir
|
|
module_build_dir=$(_gpu_build_kernel_modules \
|
|
"${kernel_build_dir}" "${gpu_drv_src}" "${gpu_inc_dir}" \
|
|
"${BUILD_DIR}" "${extra_cflags}")
|
|
|
|
MALI_KO_SRC="${BUILD_DIR}/module_build/drivers/gpu/arm/midgard/mali_kbase.ko"
|
|
PMA_KO_SRC="${BUILD_DIR}/module_build/drivers/base/arm/protected_memory_allocator/protected_memory_allocator.ko"
|
|
|
|
display_alert "COMPILE-GPU-DRIVER MALI_KO_SRC ${MALI_KO_SRC} PMA_KO_SRC ${PMA_KO_SRC}" "info"
|
|
_gpu_install_kernel_modules "${module_dir}" "${MALI_KO_SRC}" "${PMA_KO_SRC}"
|
|
|
|
# Clean up temporary build directory
|
|
rm -rf "${BUILD_DIR}/module_build"
|
|
|
|
# ---- Step 5: Build Debian Package ----
|
|
_gpu_build_deb_package "COMPILE-GPU-DRIVER" "${PKG_NAME}_${PKG_VERSION}_${kernel_version}_${PKG_ARCH}.deb"
|
|
|
|
display_alert "COMPILE-GPU-DRIVER GPU modules build completed. Successfully built for ${PKG_ARCH} with kernel ${kernel_version}" "info"
|
|
return 0
|
|
}
|
|
|
|
function amlbian_build_gpu() {
|
|
if ! is_unit_enabled "gpu"; then
|
|
echo "[SKIP] >> Gpu disable in BUILD_UNITS"
|
|
return
|
|
fi
|
|
amlbian_build_libgles
|
|
amlbian_build_gpu_driver
|
|
}
|
|
|
|
display_alert "AMLbian gpu Build Script" "Version: ${KERNEL_VERSION} GPU_MODE : ${GPU_MODE}, GPU_ARCH: ${GPU_ARCH}, Board: ${BOARD}" "info"
|
|
amlbian_build_gpu
|
|
display_alert "AMLOGIC: gpu build completed" "${OUTPUT_DIR}" "info"
|