308 lines
11 KiB
Bash
308 lines
11 KiB
Bash
#!/usr/bin/env bash
|
|
# SPDX-License-Identifier: (GPL-2.0-only OR MIT)
|
|
# Copyright (C) 2026 Amlogic, Inc. All rights reserved
|
|
################################################################################
|
|
# Amlbian Modules Load Compilation Module
|
|
#
|
|
# Purpose: Compile and package modules load scripts for kernel modules
|
|
# Provides: modules-load.sh and aml_wifi_load.sh installation
|
|
################################################################################
|
|
|
|
set -e
|
|
|
|
# Get script directory
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
AMLBIAN_DIR="$(dirname "$(dirname "${SCRIPT_DIR}")")"
|
|
BASE_DIR="$(dirname "$(dirname "${AMLBIAN_DIR}")")"
|
|
|
|
# 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: Package Information Definition
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Initialize package metadata for Modules Load scripts
|
|
function _modules_load_init_package_info() {
|
|
PKG_MAINTAINER="Armbian Build <[email protected]>"
|
|
PKG_DESCRIPTION="Modules load scripts for Amlogic kernel modules"
|
|
PKG_NAME="aml-modules-load"
|
|
PKG_VERSION="1.0"
|
|
PKG_ARCH="all"
|
|
COMPONENT="MODULES-LOAD"
|
|
|
|
# Source directory for modules load scripts
|
|
MODULES_SRC_DIR="${SCRIPT_DIR}/files"
|
|
}
|
|
|
|
# ------------------------------------------------------------------------------
|
|
# 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 _modules_load_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}"
|
|
mkdir -p "${INSTALL_DIR}/etc"
|
|
mkdir -p "${INSTALL_DIR}/usr/bin"
|
|
}
|
|
|
|
# Display build directory info
|
|
# Parameters:
|
|
# $1 - log prefix
|
|
function _modules_load_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"
|
|
display_alert "${log_prefix} Modules source dir: ${MODULES_SRC_DIR}" "info"
|
|
}
|
|
|
|
# ------------------------------------------------------------------------------
|
|
# Step 3: Source File Validation and Copying
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Validate and copy modules-load.sh
|
|
function _modules_load_copy_modules_load_sh() {
|
|
display_alert "COMPILE-${COMPONENT} Copying modules-load.sh from ${MODULES_SRC_DIR}" "info"
|
|
|
|
if [[ -f "${MODULES_SRC_DIR}/modules-load.sh" ]]; then
|
|
cp "${MODULES_SRC_DIR}/modules-load.sh" "${INSTALL_DIR}/etc/"
|
|
chmod 0755 "${INSTALL_DIR}/etc/modules-load.sh"
|
|
display_alert "COMPILE-${COMPONENT} Copied modules-load.sh" "info"
|
|
else
|
|
display_alert "COMPILE-${COMPONENT} modules-load.sh not found at ${MODULES_SRC_DIR}/modules-load.sh" "error"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
# Validate and copy aml_wifi_load.sh
|
|
function _modules_load_copy_aml_wifi_load_sh() {
|
|
display_alert "COMPILE-${COMPONENT} Copying aml_wifi_load.sh from ${MODULES_SRC_DIR}" "info"
|
|
|
|
if [[ -f "${MODULES_SRC_DIR}/aml_wifi_load.sh" ]]; then
|
|
cp "${MODULES_SRC_DIR}/aml_wifi_load.sh" "${INSTALL_DIR}/usr/bin/"
|
|
chmod 0755 "${INSTALL_DIR}/usr/bin/aml_wifi_load.sh"
|
|
display_alert "COMPILE-${COMPONENT} Copied aml_wifi_load.sh" "info"
|
|
else
|
|
display_alert "COMPILE-${COMPONENT} aml_wifi_load.sh not found at ${MODULES_SRC_DIR}/aml_wifi_load.sh" "error"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
# Validate and copy set-usb-serial.sh
|
|
function _modules_load_copy_aml_usb_serial_load_sh() {
|
|
display_alert "COMPILE-${COMPONENT} Copying set-usb-serial.sh from ${MODULES_SRC_DIR}" "info"
|
|
|
|
if [[ -f "${MODULES_SRC_DIR}/set-usb-serial.sh" ]]; then
|
|
cp "${MODULES_SRC_DIR}/set-usb-serial.sh" "${INSTALL_DIR}/usr/bin/"
|
|
chmod 0755 "${INSTALL_DIR}/usr/bin/set-usb-serial.sh"
|
|
display_alert "COMPILE-${COMPONENT} Copied set-usb-serial.sh" "info"
|
|
else
|
|
display_alert "COMPILE-${COMPONENT} set-usb-serial.sh not found at ${MODULES_SRC_DIR}/set-usb-serial.sh" "error"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
# ------------------------------------------------------------------------------
|
|
# Step 4: Debian Packaging Scripts Creation
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Create Debian control file
|
|
function _modules_load_create_control_file() {
|
|
display_alert "COMPILE-${COMPONENT} Creating control file DEBIAN/control" "info"
|
|
cat > "${DEBIAN_DIR}/control" <<EOF
|
|
Package: ${PKG_NAME}
|
|
Version: ${PKG_VERSION}
|
|
Architecture: ${PKG_ARCH}
|
|
Maintainer: ${PKG_MAINTAINER}
|
|
Depends:
|
|
Section: admin
|
|
Priority: optional
|
|
Description: ${PKG_DESCRIPTION}
|
|
This package provides scripts for loading kernel modules on Amlogic SoCs.
|
|
The package includes:
|
|
* /etc/modules-load.sh - Main script for loading various kernel modules
|
|
* /usr/bin/aml_wifi_load.sh - Script for loading WiFi drivers
|
|
These scripts are executed during system boot to ensure required kernel
|
|
modules are properly loaded for hardware functionality.
|
|
EOF
|
|
}
|
|
|
|
# Create post-installation script
|
|
function _modules_load_create_postinst() {
|
|
display_alert "COMPILE-${COMPONENT} Creating post-installation script DEBIAN/postinst" "info"
|
|
cat > "${DEBIAN_DIR}/postinst" << EOF
|
|
#!/bin/sh
|
|
set -e
|
|
|
|
if [ "\$1" = "configure" ]; then
|
|
# Ensure scripts are executable
|
|
chmod 0755 /etc/modules-load.sh 2>/dev/null || true
|
|
chmod 0755 /usr/bin/aml_wifi_load.sh 2>/dev/null || true
|
|
|
|
# Create symlink for backward compatibility if needed
|
|
if [ ! -e /usr/sbin/aml_wifi_load.sh ] && [ -e /usr/bin/aml_wifi_load.sh ]; then
|
|
ln -sf /usr/bin/aml_wifi_load.sh /usr/sbin/aml_wifi_load.sh 2>/dev/null || true
|
|
fi
|
|
|
|
echo "Modules load scripts installed successfully"
|
|
echo "Main script: /etc/modules-load.sh"
|
|
echo "WiFi loader: /usr/bin/aml_wifi_load.sh"
|
|
fi
|
|
|
|
exit 0
|
|
EOF
|
|
chmod 755 "${DEBIAN_DIR}/postinst"
|
|
}
|
|
|
|
# Create pre-removal script
|
|
function _modules_load_create_prerm() {
|
|
display_alert "COMPILE-${COMPONENT} Creating pre-removal script DEBIAN/prerm" "info"
|
|
cat > "${DEBIAN_DIR}/prerm" << EOF
|
|
#!/bin/sh
|
|
set -e
|
|
|
|
if [ "\$1" = "remove" ] || [ "\$1" = "deconfigure" ]; then
|
|
# Remove symlink if it exists
|
|
if [ -L /usr/sbin/aml_wifi_load.sh ]; then
|
|
rm -f /usr/sbin/aml_wifi_load.sh
|
|
fi
|
|
|
|
echo "Modules load scripts package being removed"
|
|
fi
|
|
|
|
exit 0
|
|
EOF
|
|
chmod 755 "${DEBIAN_DIR}/prerm"
|
|
}
|
|
|
|
# ------------------------------------------------------------------------------
|
|
# Step 5: Debian Package Building
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Build Debian package from install directory
|
|
# Parameters:
|
|
# $1 - log prefix (e.g. "COMPILE-MODULES-LOAD")
|
|
# $2 - output deb filename (without path)
|
|
# Sets: OUTPUT_DEB
|
|
function _modules_load_build_deb_package() {
|
|
local log_prefix="$1"
|
|
local output_deb_name="$2"
|
|
|
|
# 将install目录内容拷贝到deb目录
|
|
display_alert "${log_prefix} Copying install directory to deb package directory" "info"
|
|
cp -r "${INSTALL_DIR}/"* "${DEB_PACKAGE_DIR}/"
|
|
|
|
# 基于deb目录打包
|
|
display_alert "${log_prefix} Building Debian package from deb directory" "info"
|
|
dpkg-deb --build "${DEB_PACKAGE_DIR}"
|
|
|
|
# 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"
|
|
}
|
|
|
|
# ------------------------------------------------------------------------------
|
|
# Step 6: Display Installation Information
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Display installation information
|
|
function _modules_load_display_install_info() {
|
|
display_alert "COMPILE-${COMPONENT} Modules load scripts will be installed to:" "info"
|
|
display_alert "COMPILE-${COMPONENT} - /etc/modules-load.sh" "info"
|
|
display_alert "COMPILE-${COMPONENT} - /usr/bin/aml_wifi_load.sh" "info"
|
|
}
|
|
|
|
# ==============================================================================
|
|
# Main Build Function (Entry Point)
|
|
# ==============================================================================
|
|
|
|
# Main Modules Load scripts package build function
|
|
function amlbian_build_modules_load() {
|
|
set -e
|
|
|
|
if ! is_unit_enabled "modules-load"; then
|
|
echo "[SKIP] >> modules-load disable in BUILD_UNITS"
|
|
return
|
|
fi
|
|
# ---- Step 1: Package Information ----
|
|
_modules_load_init_package_info
|
|
|
|
display_alert "COMPILE-${COMPONENT} Building modules load scripts package version ${PKG_VERSION}" "info"
|
|
|
|
# ---- Step 2: Build Directory Setup ----
|
|
_modules_load_create_build_dirs "${PKG_NAME}_${PKG_VERSION}_${PKG_ARCH}"
|
|
_modules_load_display_build_info "COMPILE-${COMPONENT}"
|
|
|
|
# ---- Step 3: Source File Validation and Copying ----
|
|
_modules_load_copy_modules_load_sh
|
|
_modules_load_copy_aml_wifi_load_sh
|
|
_modules_load_copy_aml_usb_serial_load_sh
|
|
|
|
# ---- Step 4: Debian Packaging Scripts ----
|
|
_modules_load_create_control_file
|
|
_modules_load_create_postinst
|
|
_modules_load_create_prerm
|
|
|
|
# ---- Step 5: Build Debian Package ----
|
|
_modules_load_build_deb_package "COMPILE-${COMPONENT}" "${PKG_NAME}_${PKG_VERSION}_${PKG_ARCH}.deb"
|
|
|
|
# ---- Step 6: Display Installation Information ----
|
|
_modules_load_display_install_info
|
|
|
|
display_alert "COMPILE-${COMPONENT} Modules load scripts package build completed" "success"
|
|
return 0
|
|
}
|
|
|
|
# ==============================================================================
|
|
# Main Execution
|
|
# ==============================================================================
|
|
|
|
display_alert "AMLbian Modules Load Build Script" "Starting modules load scripts build" "info"
|
|
amlbian_build_modules_load
|
|
display_alert "AMLOGIC: Modules load scripts build completed" "Check output directory for packages" "info"
|