#
# SPDX-License-Identifier: GPL-2.0
#
# Copyright (c) 2013-2023 Igor Pecovnik, igor@armbian.com
#
# This file is a part of the Armbian Build Framework
# https://github.com/armbian/build/
#
# 'common.conf' is already sourced when this arch is sourced.

declare -g ARCH='arm64'
declare -g ARCHITECTURE='arm64'
declare -g KERNEL_SRC_ARCH='arm64'
declare -g QEMU_BINARY='qemu-aarch64-static'

# Defaults, if not set by board or family.
declare -g KERNEL_IMAGE_TYPE="${KERNEL_IMAGE_TYPE:-"Image"}"
declare -g KERNEL_INSTALL_TYPE="${KERNEL_INSTALL_TYPE:-"install"}"
declare -g NAME_KERNEL="${NAME_KERNEL:-"Image"}"
declare -g NAME_INITRD="${NAME_INITRD:-"uInitrd"}"

[[ -z $KERNEL_COMPILER ]] && KERNEL_COMPILER="aarch64-linux-gnu-"
[[ -z $INITRD_ARCH ]] && INITRD_ARCH=arm64
[[ -z $UBOOT_USE_GCC ]] && UBOOT_USE_GCC='> 8.0'

if [ "$(uname -m)" = "aarch64" ]; then
	[[ $ATF_COMPILE != "no" && -z $ATF_COMPILER ]] && ATF_COMPILER="aarch64-linux-gnu-"
	[[ -z $UBOOT_COMPILER ]] && UBOOT_COMPILER="aarch64-linux-gnu-"
	[[ -z $KERNEL_COMPILER ]] && KERNEL_COMPILER="aarch64-linux-gnu-"
	[[ -z $KERNEL_USE_GCC ]] && KERNEL_USE_GCC='> 8.0'
else
	[[ $ATF_COMPILE != "no" && -z $ATF_COMPILER ]] && ATF_COMPILER="aarch64-none-linux-gnu-"
	[[ -z $UBOOT_COMPILER ]] && UBOOT_COMPILER="aarch64-none-linux-gnu-"
	[[ -z $KERNEL_COMPILER ]] && KERNEL_COMPILER="aarch64-linux-gnu-"
	[[ -z $KERNEL_USE_GCC ]] && KERNEL_USE_GCC='< 9.2'
fi

[[ $ATF_COMPILE != "no" && -z $ATFSOURCE ]] && ATFSOURCE='https://github.com/ARM-software/arm-trusted-firmware'
[[ $ATF_COMPILE != "no" && -z $ATFDIR ]] && ATFDIR='arm-trusted-firmware'
[[ $ATF_COMPILE != "no" && -z $ATFBRANCH ]] && ATFBRANCH='commit:af220ebbe467aa580e6b9ba554676f78ffec930f'
[[ $ATF_COMPILE != "no" && -z $ATF_USE_GCC ]] && ATF_USE_GCC='> 8.0'

# System toolchains don't have the -none- variant, remove it
[[ "${SKIP_EXTERNAL_TOOLCHAINS}" == "yes" ]] && UBOOT_COMPILER="${UBOOT_COMPILER//-none-/-}"
[[ "${SKIP_EXTERNAL_TOOLCHAINS}" == "yes" ]] && ATF_COMPILER="${ATF_COMPILER//-none-/-}"

true # make sure to exit with 0 status; this protects against shortcircuits etc above.
