From cdb9166b810cb7b663a52b13b6b866b4edca04c6 Mon Sep 17 00:00:00 2001 From: Daniel Leung Date: Tue, 8 Oct 2024 11:41:29 -0700 Subject: [PATCH] cmake: toolchain/xcc,xt-clang: env vars for multiple cores To use Xtensa toolchain, various environment variables must be set so the executables can find necessary files and what core to compile for. This becomes an annoyance when you have to test multiple boards with different cores. You have to use one set of environment variables per core. Twister cannot test them all in one setting, and it is especially annoying doing west builds. So enhance the environment variables handling so that TOOLCHAIN_VER and XTENSA_CORE can be replaced by TOOLCHAIN_VAR_ and XTENSA_CORE_ where is the normalized board target (think .yaml). CMake will then figure out the core ID for the toolchain to use. Signed-off-by: Daniel Leung --- arch/xtensa/core/CMakeLists.txt | 2 +- cmake/compiler/xcc/generic.cmake | 4 +-- cmake/toolchain/xcc/common.cmake | 24 ++++++++++++- doc/develop/toolchains/cadence_xcc.rst | 47 ++++++++++++++++++++------ 4 files changed, 62 insertions(+), 15 deletions(-) diff --git a/arch/xtensa/core/CMakeLists.txt b/arch/xtensa/core/CMakeLists.txt index d03e3641b42..7d7e260ca0b 100644 --- a/arch/xtensa/core/CMakeLists.txt +++ b/arch/xtensa/core/CMakeLists.txt @@ -53,7 +53,7 @@ set(CORE_ISA_DM ${CMAKE_BINARY_DIR}/zephyr/include/generated/zephyr/core-isa-dM. set(CORE_ISA_IN ${CMAKE_BINARY_DIR}/zephyr/include/generated/core-isa-dM.c) file(WRITE ${CORE_ISA_IN} "#include \n") add_custom_command(OUTPUT ${CORE_ISA_DM} - COMMAND ${CMAKE_C_COMPILER} -E -dM -U__XCC__ + COMMAND ${CMAKE_C_COMPILER} -E -dM -U__XCC__ ${XTENSA_CORE_LOCAL_C_FLAG} -I${ZEPHYR_XTENSA_MODULE_DIR}/zephyr/soc/${CONFIG_SOC} -I${SOC_FULL_DIR} ${CORE_ISA_IN} -o ${CORE_ISA_DM}) diff --git a/cmake/compiler/xcc/generic.cmake b/cmake/compiler/xcc/generic.cmake index b6be58ceb9f..d9020bf59bf 100644 --- a/cmake/compiler/xcc/generic.cmake +++ b/cmake/compiler/xcc/generic.cmake @@ -17,13 +17,13 @@ TOOLCHAIN_VER: ${TOOLCHAIN_VER} endif() execute_process( - COMMAND ${CMAKE_C_COMPILER} --version + COMMAND ${CMAKE_C_COMPILER} --version ${XTENSA_CORE_LOCAL_C_FLAG} RESULT_VARIABLE ret OUTPUT_VARIABLE stdoutput ) if(ret) message(FATAL_ERROR "Executing the below command failed. Are permissions set correctly? - ${CMAKE_C_COMPILER} --version + ${CMAKE_C_COMPILER} --version ${XTENSA_CORE_LOCAL_C_FLAG} ${stdoutput} " ) diff --git a/cmake/toolchain/xcc/common.cmake b/cmake/toolchain/xcc/common.cmake index 7bca32f4e45..06127567a30 100644 --- a/cmake/toolchain/xcc/common.cmake +++ b/cmake/toolchain/xcc/common.cmake @@ -7,7 +7,29 @@ if(NOT EXISTS ${XTENSA_TOOLCHAIN_PATH}) message(FATAL_ERROR "Nothing found at XTENSA_TOOLCHAIN_PATH: '${XTENSA_TOOLCHAIN_PATH}'") endif() -set(TOOLCHAIN_HOME ${XTENSA_TOOLCHAIN_PATH}/$ENV{TOOLCHAIN_VER}/XtensaTools) +zephyr_get(TOOLCHAIN_VER) +if(DEFINED TOOLCHAIN_VER) + set(XTENSA_TOOLCHAIN_VER ${TOOLCHAIN_VER}) +else() + zephyr_get(TOOLCHAIN_VER_${NORMALIZED_BOARD_TARGET}) + if(DEFINED TOOLCHAIN_VER_${NORMALIZED_BOARD_TARGET}) + set(XTENSA_TOOLCHAIN_VER ${TOOLCHAIN_VER_${NORMALIZED_BOARD_TARGET}}) + else() + message(FATAL "Environment variable TOOLCHAIN_VER must be set or given as -DTOOLCHAIN_VER=") + endif() +endif() + +zephyr_get(XTENSA_CORE_${NORMALIZED_BOARD_TARGET}) +if(DEFINED XTENSA_CORE_${NORMALIZED_BOARD_TARGET}) + set(XTENSA_CORE_LOCAL_C_FLAG "--xtensa-core=${XTENSA_CORE_${NORMALIZED_BOARD_TARGET}}") + list(APPEND TOOLCHAIN_C_FLAGS "--xtensa-core=${XTENSA_CORE_${NORMALIZED_BOARD_TARGET}}") +else() + # Not having XTENSA_CORE is not necessarily fatal as + # the toolchain can have a default core configuration to use. + set(XTENSA_CORE_LOCAL_C_FLAG) +endif() + +set(TOOLCHAIN_HOME ${XTENSA_TOOLCHAIN_PATH}/${XTENSA_TOOLCHAIN_VER}/XtensaTools) set(LINKER ld) set(BINTOOLS gnu) diff --git a/doc/develop/toolchains/cadence_xcc.rst b/doc/develop/toolchains/cadence_xcc.rst index f1de7ed1e53..5826985f56d 100644 --- a/doc/develop/toolchains/cadence_xcc.rst +++ b/doc/develop/toolchains/cadence_xcc.rst @@ -31,21 +31,46 @@ Cadence Tensilica Xtensa C/C++ Compiler (XCC) * Set :envvar:`ZEPHYR_TOOLCHAIN_VARIANT` to ``xcc`` or ``xt-clang``. * Set :envvar:`XTENSA_TOOLCHAIN_PATH` to the toolchain installation directory. - * Set :envvar:`XTENSA_CORE` to the SoC ID where application is being - targeting. - * Set :envvar:`TOOLCHAIN_VER` to the Xtensa SDK version. + + * There are two ways to specify the SoC ID and the SDK version to use. + They are mutually exclusive, and cannot be used together. + + #. When building for a single SoC: + + * Set :envvar:`XTENSA_CORE` to the SoC ID where application is being + targeted. + * Set :envvar:`TOOLCHAIN_VER` to the Xtensa SDK version. + + #. When building for multiple SoCs, for each SoC and board combination: + + * Set :envvar:`XTENSA_CORE_{normalized_board_target}` + to the SoC ID where application is being targeted. + * Set :envvar:`TOOLCHAIN_VAR_{normalized_board_target}` + to the Xtensa SDK version. #. For example, assuming the SDK is installed in ``/opt/xtensa``, and - using the SDK for application development on ``intel_adsp_cavs15``, - setup the environment using: + using the SDK for application development on ``intel_adsp/ace15_mtpm``, + setup the environment using the two above mentioned ways: - .. code-block:: console + #. Single SoC: - # Linux - export ZEPHYR_TOOLCHAIN_VARIANT=xcc - export XTENSA_TOOLCHAIN_PATH=/opt/xtensa/XtDevTools/install/tools/ - export XTENSA_CORE=X6H3SUE_RI_2018_0 - export TOOLCHAIN_VER=RI-2018.0-linux + .. code-block:: console + + # Linux + export ZEPHYR_TOOLCHAIN_VARIANT=xt-clang + export XTENSA_TOOLCHAIN_PATH=/opt/xtensa/XtDevTools/install/tools/ + export XTENSA_CORE=ace10_LX7HiFi4_2022_10 + export TOOLCHAIN_VER=RI-2022.10-linux + + #. Muiltiple SoCs: + + .. code-block:: console + + # Linux + export ZEPHYR_TOOLCHAIN_VARIANT=xt-clang + export XTENSA_TOOLCHAIN_PATH=/opt/xtensa/XtDevTools/install/tools/ + export TOOLCHAIN_VER_intel_adsp_ace15_mtpm=RI-2022.10-linux + export XTENSA_CORE_intel_adsp_ace15_mtpm=ace10_LX7HiFi4_2022_10 #. To use Clang-based compiler: