From 9691b6bfe08f4ba95c68d172c7bea8ad6f06fcba Mon Sep 17 00:00:00 2001 From: Marc Herbert Date: Fri, 9 Aug 2024 23:09:25 +0000 Subject: [PATCH 1/5] set_xtensa_params.sh: silence warnings which are wrong when sourced We can't have a shebang and of course all variables are unused. Signed-off-by: Marc Herbert --- scripts/set_xtensa_params.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scripts/set_xtensa_params.sh b/scripts/set_xtensa_params.sh index 8a0e2aeb808e..47853e9fcd29 100644 --- a/scripts/set_xtensa_params.sh +++ b/scripts/set_xtensa_params.sh @@ -1,6 +1,10 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright(c) 2023 Intel Corporation. All rights reserved. +# Because this is meant to be sourced +# shellcheck disable=SC2148 +# shellcheck disable=SC2034 + ### XTENSA_ toolchain configuration shared across projects ### # These variables are currently used in/by: From b29d34a45936582fc02bc8a05e4207b28133ce4b Mon Sep 17 00:00:00 2001 From: Marc Herbert Date: Fri, 9 Aug 2024 22:29:08 +0000 Subject: [PATCH 2/5] xtensa-build-all.sh: rename local variable COMPILER to build_dir_suffix "COMPILER" is a very common name with a high risk of collision. Don't use it for a minor, local variable. This also reduces confusion. Signed-off-by: Marc Herbert --- scripts/xtensa-build-all.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/xtensa-build-all.sh b/scripts/xtensa-build-all.sh index 952f18184697..ac9591c4c169 100755 --- a/scripts/xtensa-build-all.sh +++ b/scripts/xtensa-build-all.sh @@ -234,15 +234,15 @@ do export XTENSA_SYSTEM=$XTENSA_BUILDS_DIR/$XTENSA_CORE/config printf 'XTENSA_SYSTEM=%s\n' "${XTENSA_SYSTEM}" PATH=$XTENSA_TOOLS_DIR/XtensaTools/bin:$OLDPATH - COMPILER="xcc" + build_dir_suffix='xcc' else TOOLCHAIN=$HOST PATH=$SOF_TOP/../$HOST/bin:$OLDPATH - COMPILER="gcc" + build_dir_suffix='gcc' DEFCONFIG_PATCH="" fi - BUILD_DIR=build_${platform}_${COMPILER} + BUILD_DIR=build_${platform}_${build_dir_suffix} printf "Build in %s\n" "$BUILD_DIR" # only delete binary related to this build From 7826d436a24b978a3d9128b52c160363da44c0e4 Mon Sep 17 00:00:00 2001 From: Marc Herbert Date: Fri, 9 Aug 2024 22:23:37 +0000 Subject: [PATCH 3/5] xtensa-build-all.sh: do not fallback on gcc when xcc dir is wrong If the user requested the Cadence toolchain by defining $XTENSA_TOOLS_ROOT, then do not "correct" the user and fallback on gcc when that variable is wrong. Fail and point at the problem instead. No one ever pays attention to build logs; as shown by new warnings being submitted on a regular basis. This also removes the local variable "XCC", the name of which was collision-prone and confusingly capitalized. Signed-off-by: Marc Herbert --- scripts/xtensa-build-all.sh | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/scripts/xtensa-build-all.sh b/scripts/xtensa-build-all.sh index ac9591c4c169..a17af0db520e 100755 --- a/scripts/xtensa-build-all.sh +++ b/scripts/xtensa-build-all.sh @@ -210,22 +210,17 @@ do XTENSA_TOOLS_DIR="$XTENSA_TOOLS_ROOT/install/tools/$TOOLCHAIN_VER" XTENSA_BUILDS_DIR="$XTENSA_TOOLS_ROOT/install/builds/$TOOLCHAIN_VER" - # make sure the required version of xtensa tools is installed - if [ -d "$XTENSA_TOOLS_DIR" ] - then - XCC="xt-xcc" - else - XCC="none" - >&2 printf 'WARNING: %s -\t is not a directory, reverting to gcc\n' "$XTENSA_TOOLS_DIR" - fi + [ -d "$XTENSA_TOOLS_DIR" ] || { + >&2 printf 'ERROR: %s\t is not a directory\n' "$XTENSA_TOOLS_DIR" + exit 1 + } fi # CMake uses ROOT_DIR for includes and libraries a bit like # --sysroot would. ROOT="$SOF_TOP/../xtensa-root/$HOST" - if [ "$XCC" == "xt-xcc" ] + if [ -n "$XTENSA_TOOLS_ROOT" ] then TOOLCHAIN=xt ROOT="$XTENSA_BUILDS_DIR/$XTENSA_CORE/xtensa-elf" From 7a8c1b716dc0b806da3994f76913dabe385b1216 Mon Sep 17 00:00:00 2001 From: Marc Herbert Date: Fri, 9 Aug 2024 22:42:06 +0000 Subject: [PATCH 4/5] scripts: add new SOF_CC_BASE={xcc,clang,gcc} variable This is required to allow building XTOS with newer, clang-based, Cadence toolchains as just submitted for ACP_7_0 in #9351 Signed-off-by: Marc Herbert --- scripts/cmake/xtensa-toolchain.cmake | 9 ++++++--- scripts/set_xtensa_params.sh | 9 +++++++++ scripts/xtensa-build-all.sh | 3 +++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/scripts/cmake/xtensa-toolchain.cmake b/scripts/cmake/xtensa-toolchain.cmake index 3e070f7f6982..7bc29be3e434 100644 --- a/scripts/cmake/xtensa-toolchain.cmake +++ b/scripts/cmake/xtensa-toolchain.cmake @@ -49,11 +49,14 @@ set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) # xt toolchain only partially follows gcc convention if(TOOLCHAIN STREQUAL "xt") set(XCC 1) - set(CMAKE_C_COMPILER ${CROSS_COMPILE}xcc) -else() - set(CMAKE_C_COMPILER ${CROSS_COMPILE}gcc) endif() +if(NOT DEFINED SOF_CC_BASE) +set(SOF_CC_BASE "gcc") +endif() +# e.g.: "xt-" + "xcc" +set(CMAKE_C_COMPILER ${CROSS_COMPILE}${SOF_CC_BASE}) + find_program(CMAKE_LD NAMES "${CROSS_COMPILE}ld" PATHS ENV PATH NO_DEFAULT_PATH) find_program(CMAKE_AR NAMES "${CROSS_COMPILE}ar" PATHS ENV PATH NO_DEFAULT_PATH) find_program(CMAKE_RANLIB NAMES "${CROSS_COMPILE}ranlib" PATHS ENV PATH NO_DEFAULT_PATH) diff --git a/scripts/set_xtensa_params.sh b/scripts/set_xtensa_params.sh index 47853e9fcd29..fd48edf0bc13 100644 --- a/scripts/set_xtensa_params.sh +++ b/scripts/set_xtensa_params.sh @@ -145,6 +145,15 @@ case "$platform" in ;; esac +# Pre-zephyr "XTOS" build +case "$platform" in + none_yet) + SOF_CC_BASE='clang';; + *) + SOF_CC_BASE='xcc';; +esac + +# For Zephyr unit tests, testbench,... case "$platform" in imx8*|mtl|lnl) ZEPHYR_TOOLCHAIN_VARIANT='xt-clang';; diff --git a/scripts/xtensa-build-all.sh b/scripts/xtensa-build-all.sh index a17af0db520e..84b0526e71d1 100755 --- a/scripts/xtensa-build-all.sh +++ b/scripts/xtensa-build-all.sh @@ -231,6 +231,8 @@ do PATH=$XTENSA_TOOLS_DIR/XtensaTools/bin:$OLDPATH build_dir_suffix='xcc' else + # Override SOF_CC_BASE from set_xtensa_params.sh + SOF_CC_BASE='gcc' TOOLCHAIN=$HOST PATH=$SOF_TOP/../$HOST/bin:$OLDPATH build_dir_suffix='gcc' @@ -248,6 +250,7 @@ do printf 'PATH=%s\n' "$PATH" ( set -x # log the main commands and their parameters cmake -DTOOLCHAIN="$TOOLCHAIN" \ + -DSOF_CC_BASE="$SOF_CC_BASE" \ -DROOT_DIR="$ROOT" \ -DMEU_OPENSSL="${MEU_OPENSSL}" \ "${MEU_PATH_OPTION}" \ From 932ca92d4ec83e742e20702cb89c4b91dea9d421 Mon Sep 17 00:00:00 2001 From: Marc Herbert Date: Fri, 9 Aug 2024 23:11:53 +0000 Subject: [PATCH 5/5] rebuild-testbench.sh: switch to new SOF_CC_BASE variable It was awkward to depend on ZEPHYR_TOOLCHAIN_VARIANT when the testbench has absolutely nothing to do with it. Signed-off-by: Marc Herbert --- scripts/rebuild-testbench.sh | 10 ++-------- scripts/set_xtensa_params.sh | 6 +++--- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/scripts/rebuild-testbench.sh b/scripts/rebuild-testbench.sh index e9c386eb57ce..5204f90031e0 100755 --- a/scripts/rebuild-testbench.sh +++ b/scripts/rebuild-testbench.sh @@ -75,14 +75,8 @@ setup_xtensa_tools_build() test -n "${XTENSA_CORE}" || die "Illegal platform $BUILD_PLATFORM, no XTENSA_CORE found.\n" - # Zephyr is not part of the testbench at all but let's play nice and - # align with that naming convention to keep things simple. - case "${ZEPHYR_TOOLCHAIN_VARIANT}" in - xcc) COMPILER=xt-xcc;; - xt-clang) COMPILER=xt-clang;; - *) die 'Unknown or undefined ZEPHYR_TOOLCHAIN_VARIANT=%s\n' \ - "${ZEPHYR_TOOLCHAIN_VARIANT}";; - esac + # This (local?) variable should probably be inlined + COMPILER=xt-"$SOF_CC_BASE" install_bin=install/tools/$TOOLCHAIN_VER/XtensaTools/bin tools_bin=$XTENSA_TOOLS_ROOT/$install_bin diff --git a/scripts/set_xtensa_params.sh b/scripts/set_xtensa_params.sh index fd48edf0bc13..37c2bdbdf09d 100644 --- a/scripts/set_xtensa_params.sh +++ b/scripts/set_xtensa_params.sh @@ -145,15 +145,15 @@ case "$platform" in ;; esac -# Pre-zephyr "XTOS" build +# Pre-zephyr "XTOS" build, testbench,... case "$platform" in - none_yet) + mtl|lnl) SOF_CC_BASE='clang';; *) SOF_CC_BASE='xcc';; esac -# For Zephyr unit tests, testbench,... +# For Zephyr unit tests case "$platform" in imx8*|mtl|lnl) ZEPHYR_TOOLCHAIN_VARIANT='xt-clang';;