- we've had SKIP_EXTERNAL_TOOLCHAINS=yes for ~5 years now - drop all usages, mostly through `find_toolchains()` - drop all manual PATH env injections (we've centralized if ever needed)
117 lines
4.8 KiB
Bash
117 lines
4.8 KiB
Bash
#!/usr/bin/env bash
|
|
#
|
|
# SPDX-License-Identifier: GPL-2.0
|
|
#
|
|
# Copyright (c) 2013-2026 Igor Pecovnik, igor@armbian.com
|
|
#
|
|
# This file is a part of the Armbian Build Framework
|
|
# https://github.com/armbian/build/
|
|
|
|
compile_atf() {
|
|
if [[ -n "${ATFSOURCE}" && "${ATFSOURCE}" != "none" ]]; then
|
|
display_alert "Downloading sources" "atf" "git"
|
|
fetch_from_repo "$ATFSOURCE" "$ATFDIR" "$ATFBRANCH" "yes"
|
|
fi
|
|
|
|
if [[ $CLEAN_LEVEL == *make-atf* ]]; then
|
|
display_alert "Cleaning ATF tree - CLEAN_LEVEL contains 'make-atf'" "$ATFSOURCEDIR" "info"
|
|
(
|
|
cd "${SRC}/cache/sources/${ATFSOURCEDIR}" || exit_with_error "crazy about ${ATFSOURCEDIR}"
|
|
run_host_command_logged make distclean
|
|
)
|
|
else
|
|
display_alert "Not cleaning ATF tree, use CLEAN_LEVEL=make-atf if needed" "CLEAN_LEVEL=${CLEAN_LEVEL}" "debug"
|
|
fi
|
|
|
|
local atfdir="$SRC/cache/sources/$ATFSOURCEDIR"
|
|
if [[ $USE_OVERLAYFS == yes ]]; then
|
|
atfdir=$(overlayfs_wrapper "wrap" "$SRC/cache/sources/$ATFSOURCEDIR" "atf_${LINUXFAMILY}_${BRANCH}")
|
|
fi
|
|
cd "$atfdir" || exit
|
|
|
|
display_alert "Compiling ATF" "" "info"
|
|
|
|
display_alert "Compiler version" "${ATF_COMPILER}gcc $(eval env "${ATF_COMPILER}gcc" -dumpfullversion -dumpversion)" "info"
|
|
|
|
local target_make target_patchdir target_files
|
|
target_make=$(cut -d';' -f1 <<< "${ATF_TARGET_MAP}")
|
|
target_patchdir=$(cut -d';' -f2 <<< "${ATF_TARGET_MAP}")
|
|
target_files=$(cut -d';' -f3 <<< "${ATF_TARGET_MAP}")
|
|
|
|
advanced_patch "atf" "${ATFPATCHDIR}" "$BOARD" "$target_patchdir" "$BRANCH" "${LINUXFAMILY}-${BOARD}-${BRANCH}"
|
|
|
|
# create patch for manual source changes
|
|
if [[ $CREATE_PATCHES_ATF == yes ]]; then
|
|
userpatch_create "atf"
|
|
return 0
|
|
fi
|
|
|
|
# - "--no-warn-rwx-segment" is *required* for binutils 2.39 - see https://developer.trustedfirmware.org/T996
|
|
# - but *not supported* by 2.38, brilliant...
|
|
# 2026: turns out that *gcc* is the one that takes the flag, and it might or not accept it.
|
|
# distros patch binutils and gcc independently, since it's a security-related flag,
|
|
# might have been backported to one and not the other. what a freaking life.
|
|
# test both -- and only add it if _both_ support it
|
|
function gcc_accepts_flag() {
|
|
{ echo 'int main(){}' | "${ATF_COMPILER}gcc" -Wl,"$1" -x c - -o /dev/null > /dev/null 2>&1; } && return 0
|
|
return 1
|
|
}
|
|
function ld_supports_flag() {
|
|
{ "$("${ATF_COMPILER}gcc" -print-prog-name=ld)" --help 2> /dev/null | grep -q -- "$1"; } && return 0
|
|
return 1
|
|
}
|
|
if gcc_accepts_flag --no-warn-rwx-segment; then
|
|
display_alert "GCC supports '--no-warn-rwx-segment'" "gcc:yes - ld:tba" "debug"
|
|
if ld_supports_flag no-warn-rwx-segment; then
|
|
display_alert "GCC/LD supports '--no-warn-rwx-segment'" "gcc:yes - ld:yes" "debug"
|
|
if [[ "${ATF_SKIP_LDFLAGS:-"no"}" == "yes" ]]; then # IF ATF_SKIP_LDFLAGS==yes, then skip it completely
|
|
display_alert "Skip adding LD flag '--no-warn-rwx-segment' to TF-A build" "ATF_SKIP_LDFLAGS=${ATF_SKIP_LDFLAGS}" "info"
|
|
elif [[ "${ATF_SKIP_LDFLAGS_WL:-"no"}" == "yes" ]]; then # IF ATF_SKIP_LDFLAGS_WL==yes, then don't add the -Wl, prefix
|
|
display_alert "Skip adding '-Wl,' prefix to LD flag '--no-warn-rwx-segment' for TF-A build" "ATF_SKIP_LDFLAGS_WL=${ATF_SKIP_LDFLAGS_WL}" "info"
|
|
binutils_flags_atf="--no-warn-rwx-segment"
|
|
else
|
|
display_alert "Adding full LD flag '-Wl,--no-warn-rwx-segment' to TF-A build" "normal" "info"
|
|
binutils_flags_atf="-Wl,--no-warn-rwx-segment"
|
|
fi
|
|
else
|
|
display_alert "LD does not support '--no-warn-rwx-segment'" "gcc: yes - ld:no" "debug"
|
|
fi
|
|
else
|
|
display_alert "GCC does not support '--no-warn-rwx-segment'" "gcc: no - ld: not tested" "debug"
|
|
fi
|
|
unset -f gcc_accepts_flag ld_supports_flag
|
|
|
|
# - ENABLE_BACKTRACE="0" has been added to workaround a regression in ATF. Check: https://github.com/armbian/build/issues/1157
|
|
|
|
run_host_command_logged "CROSS_COMPILE='ccache ${ATF_COMPILER}'" CCACHE_BASEDIR="$(pwd)" "CC='ccache ${ATF_COMPILER}gcc'" \
|
|
"CFLAGS='-fdiagnostics-color=always -Wno-error=attributes -Wno-error=incompatible-pointer-types'" \
|
|
"TF_LDFLAGS='${binutils_flags_atf}'" \
|
|
make ENABLE_BACKTRACE="0" LOG_LEVEL="40" BUILD_STRING="armbian" $target_make "${CTHREADS}"
|
|
|
|
# @TODO: severely missing logging
|
|
[[ $(type -t atf_custom_postprocess) == function ]] && atf_custom_postprocess 2>&1
|
|
|
|
atftempdir=$(mktemp -d) # subject to TMPDIR/WORKDIR, so is protected by single/common error trapmanager to clean-up.
|
|
chmod 700 ${atftempdir}
|
|
|
|
# copy files to temp directory
|
|
for f in $target_files; do
|
|
local f_src
|
|
f_src=$(cut -d':' -f1 <<< "${f}")
|
|
if [[ $f == *:* ]]; then
|
|
local f_dst
|
|
f_dst=$(cut -d':' -f2 <<< "${f}")
|
|
else
|
|
local f_dst
|
|
f_dst=$(basename "${f_src}")
|
|
fi
|
|
[[ ! -f $f_src ]] && exit_with_error "ATF file not found" "$(basename "${f_src}")"
|
|
cp "${f_src}" "${atftempdir}/${f_dst}"
|
|
done
|
|
|
|
# copy license file to pack it to u-boot package later
|
|
[[ -f license.md ]] && cp license.md "${atftempdir}"/
|
|
|
|
return 0 # avoid error due to short-circuit above
|
|
}
|