183 lines
5.4 KiB
Bash
183 lines
5.4 KiB
Bash
#!/bin/bash
|
|||
|
|
#
|
||
|
|
# SPDX-License-Identifier: GPL-2.0
|
||
|
|
#
|
||
|
|
# Copyright (c) 2026 AMLOGIC
|
||
|
|
#
|
||
|
|
# Environment configuration functions for AMLbian
|
||
|
|
#
|
||
|
|
# host_env_check.sh
|
||
|
|
#
|
||
|
|
# Check whether the current host environment is ready for building.
|
||
|
|
#
|
||
|
|
|
||
|
|
set -u
|
||
|
|
|
||
|
|
ERRORS=0
|
||
|
|
|
||
|
|
error() {
|
||
|
|
echo "[ERROR] $1" >&2
|
||
|
|
ERRORS=$((ERRORS + 1))
|
||
|
|
}
|
||
|
|
|
||
|
|
warn() {
|
||
|
|
echo "[WARN] $1" >&2
|
||
|
|
}
|
||
|
|
|
||
|
|
info() {
|
||
|
|
echo "[INFO] $1"
|
||
|
|
}
|
||
|
|
|
||
|
|
check_toolchain_dir() {
|
||
|
|
local dir="$1"
|
||
|
|
local name="$2"
|
||
|
|
|
||
|
|
if [[ -d "$dir" ]]; then
|
||
|
|
info "Toolchain '$name' found at $dir"
|
||
|
|
else
|
||
|
|
error "Required toolchain '$name' is missing: $dir"
|
||
|
|
warn "Please install '$name' toolchain before starting the build."
|
||
|
|
fi
|
||
|
|
}
|
||
|
|
|
||
|
|
check_arm_gnu_linux_toolchain() {
|
||
|
|
local exact_dir="/opt/arm-gnu-toolchain-11.3.rel1-x86_64-aarch64-none-linux-gnu"
|
||
|
|
local min_version="11.3.rel1"
|
||
|
|
local pattern="/opt/arm-gnu-toolchain-*-x86_64-aarch64-none-linux-gnu"
|
||
|
|
|
||
|
|
if [[ -d "$exact_dir" ]]; then
|
||
|
|
info "Toolchain 'arm-gnu-toolchain-11.3.rel1 aarch64-none-linux-gnu' found at $exact_dir"
|
||
|
|
return
|
||
|
|
fi
|
||
|
|
|
||
|
|
local found=0
|
||
|
|
local found_dir=""
|
||
|
|
local found_version=""
|
||
|
|
|
||
|
|
for dir in $pattern; do
|
||
|
|
# If no matches, the literal pattern is returned; skip it.
|
||
|
|
[[ -d "$dir" ]] || continue
|
||
|
|
|
||
|
|
local version
|
||
|
|
version=$(echo "$dir" | sed -E 's|.*/arm-gnu-toolchain-([^/-]+)-x86_64-aarch64-none-linux-gnu|\1|')
|
||
|
|
|
||
|
|
if version_ge "$version" "$min_version"; then
|
||
|
|
found=1
|
||
|
|
found_dir="$dir"
|
||
|
|
found_version="$version"
|
||
|
|
break
|
||
|
|
fi
|
||
|
|
done
|
||
|
|
|
||
|
|
if [[ "$found" -eq 1 ]]; then
|
||
|
|
info "Compatible aarch64-none-linux-gnu toolchain found at $found_dir (version $found_version, >= $min_version)"
|
||
|
|
warn "Please confirm this toolchain version is suitable before starting the build."
|
||
|
|
else
|
||
|
|
error "Required toolchain 'arm-gnu-toolchain-11.3.rel1 aarch64-none-linux-gnu' is missing"
|
||
|
|
warn "Please install 'arm-gnu-toolchain-11.3.rel1-x86_64-aarch64-none-linux-gnu' or a newer compatible version."
|
||
|
|
fi
|
||
|
|
}
|
||
|
|
|
||
|
|
check_arch_test_arm64() {
|
||
|
|
if ! command -v arch-test >/dev/null 2>&1; then
|
||
|
|
error "arch-test is not installed or not in PATH"
|
||
|
|
warn "Please install arch-test and ensure arm64 support is available."
|
||
|
|
return
|
||
|
|
fi
|
||
|
|
|
||
|
|
if arch-test arm64 >/dev/null 2>&1; then
|
||
|
|
info "arch-test reports arm64 support is available"
|
||
|
|
else
|
||
|
|
error "arch-test does NOT report arm64 support"
|
||
|
|
warn "Please prepare arm64 execution support (e.g. binfmt/qemu-user) before starting the build."
|
||
|
|
fi
|
||
|
|
}
|
||
|
|
|
||
|
|
# Compare two dotted version strings.
|
||
|
|
# Returns 0 if $1 >= $2, 1 otherwise.
|
||
|
|
version_ge() {
|
||
|
|
local v1="$1"
|
||
|
|
local v2="$2"
|
||
|
|
|
||
|
|
# Normalize to three numeric fields, discarding any trailing non-numeric suffix.
|
||
|
|
local a1 a2 a3
|
||
|
|
local b1 b2 b3
|
||
|
|
|
||
|
|
a1=$(echo "$v1" | sed -n -E 's/^([0-9]+).*/\1/p')
|
||
|
|
a2=$(echo "$v1" | sed -n -E 's/^[0-9]+\.([0-9]+).*/\1/p')
|
||
|
|
a3=$(echo "$v1" | sed -n -E 's/^[0-9]+\.[0-9]+\.([0-9]+).*/\1/p')
|
||
|
|
|
||
|
|
b1=$(echo "$v2" | sed -n -E 's/^([0-9]+).*/\1/p')
|
||
|
|
b2=$(echo "$v2" | sed -n -E 's/^[0-9]+\.([0-9]+).*/\1/p')
|
||
|
|
b3=$(echo "$v2" | sed -n -E 's/^[0-9]+\.[0-9]+\.([0-9]+).*/\1/p')
|
||
|
|
|
||
|
|
# Treat missing fields as 0.
|
||
|
|
a1=${a1:-0}; a2=${a2:-0}; a3=${a3:-0}
|
||
|
|
b1=${b1:-0}; b2=${b2:-0}; b3=${b3:-0}
|
||
|
|
|
||
|
|
if [[ "$a1" -gt "$b1" ]]; then return 0; fi
|
||
|
|
if [[ "$a1" -lt "$b1" ]]; then return 1; fi
|
||
|
|
if [[ "$a2" -gt "$b2" ]]; then return 0; fi
|
||
|
|
if [[ "$a2" -lt "$b2" ]]; then return 1; fi
|
||
|
|
if [[ "$a3" -ge "$b3" ]]; then return 0; fi
|
||
|
|
return 1
|
||
|
|
}
|
||
|
|
|
||
|
|
check_qemu_aarch64() {
|
||
|
|
local cmd="qemu-aarch64-static"
|
||
|
|
local min_version="6.2.0"
|
||
|
|
|
||
|
|
if ! command -v "$cmd" >/dev/null 2>&1; then
|
||
|
|
error "$cmd is not installed or not in PATH"
|
||
|
|
warn "Please install QEMU user-mode static for aarch64 (>= $min_version) before starting the build."
|
||
|
|
return
|
||
|
|
fi
|
||
|
|
|
||
|
|
local version_line
|
||
|
|
version_line=$($cmd --version 2>&1 | head -n1)
|
||
|
|
|
||
|
|
local version
|
||
|
|
version=$(echo "$version_line" | sed -E 's/.*version[[:space:]]+([0-9]+(\.[0-9]+)*).*/\1/')
|
||
|
|
|
||
|
|
if [[ -z "$version" ]]; then
|
||
|
|
error "Could not determine $cmd version from: $version_line"
|
||
|
|
warn "Please ensure $cmd is working and >= $min_version."
|
||
|
|
return
|
||
|
|
fi
|
||
|
|
|
||
|
|
if version_ge "$version" "$min_version"; then
|
||
|
|
info "$cmd version $version is OK (>= $min_version)"
|
||
|
|
else
|
||
|
|
error "$cmd version $version is too old (minimum required: $min_version)"
|
||
|
|
warn "Please upgrade $cmd to >= $min_version before starting the build."
|
||
|
|
fi
|
||
|
|
}
|
||
|
|
|
||
|
|
main() {
|
||
|
|
echo "========================================"
|
||
|
|
echo "Host environment check"
|
||
|
|
echo "========================================"
|
||
|
|
|
||
|
|
check_toolchain_dir "/opt/gcc-linaro-7.3.1-2018.05-i686_aarch64-elf" "gcc-linaro-7.3.1 aarch64-elf"
|
||
|
|
check_toolchain_dir "/opt/riscv-none-gcc" "riscv-none-gcc"
|
||
|
|
check_toolchain_dir "/opt/arm-gnu-toolchain-13.2.Rel1-x86_64-aarch64-none-elf" "arm-gnu-toolchain-13.2.Rel1 aarch64-none-elf"
|
||
|
|
|
||
|
|
check_arm_gnu_linux_toolchain
|
||
|
|
|
||
|
|
check_arch_test_arm64
|
||
|
|
|
||
|
|
check_qemu_aarch64
|
||
|
|
|
||
|
|
echo "========================================"
|
||
|
|
if [[ "$ERRORS" -eq 0 ]]; then
|
||
|
|
echo "Result: PASS - Host environment looks ready."
|
||
|
|
return 0
|
||
|
|
else
|
||
|
|
echo "Result: FAIL - $ERRORS issue(s) found. Please fix them before starting the build."
|
||
|
|
warn "Please read the Release Notes carefully or contact FAE for technical support."
|
||
|
|
return 1
|
||
|
|
fi
|
||
|
|
}
|
||
|
|
|
||
|
|
main "$@"
|